diff --git a/app/Console/Commands/TaskLedgerGenerateCommand.php b/app/Console/Commands/TaskLedgerGenerateCommand.php index aa01cbb..f6229c0 100644 --- a/app/Console/Commands/TaskLedgerGenerateCommand.php +++ b/app/Console/Commands/TaskLedgerGenerateCommand.php @@ -63,7 +63,7 @@ class TaskLedgerGenerateCommand extends Command return $planable->setRelation('plan', $plan); }); - $stores = Store::all(); + $stores = Store::with(['master'])->all(); /** @var \App\Models\Store */ foreach ($stores as $store) { @@ -71,6 +71,8 @@ class TaskLedgerGenerateCommand extends Command $taskable = TaskLedger::firstOrNew([ 'store_id' => $store->id, 'date' => $planable->date, + ], [ + 'store_master_id' => $store->master?->id, ]); if ($taskable->exists) { diff --git a/app/Models/TaskLedger.php b/app/Models/TaskLedger.php index 3bed357..00a525a 100644 --- a/app/Models/TaskLedger.php +++ b/app/Models/TaskLedger.php @@ -13,8 +13,9 @@ class TaskLedger extends Model use HasFactory, HasDateTimeFormatter; protected $fillable = [ - 'store_id', 'date', + 'store_id', + 'store_master_id', ]; public function task(): MorphOne diff --git a/database/migrations/2024_04_15_081617_create_task_ledgers_table.php b/database/migrations/2024_04_15_081617_create_task_ledgers_table.php index 07b128e..3d9baa5 100644 --- a/database/migrations/2024_04_15_081617_create_task_ledgers_table.php +++ b/database/migrations/2024_04_15_081617_create_task_ledgers_table.php @@ -13,8 +13,9 @@ return new class extends Migration { Schema::create('task_ledgers', function (Blueprint $table) { $table->id(); - $table->foreignId('store_id')->comment('门店ID'); $table->date('date')->comment('日期'); + $table->foreignId('store_id')->comment('门店ID'); + $table->foreignId('store_master_id')->comment('店长'); $table->timestamps(); }); }