From 4ca6e78619b30bc50f15ffd2a1639e8ee6bdd74c Mon Sep 17 00:00:00 2001 From: Jing Li Date: Wed, 17 Apr 2024 10:27:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E6=8A=A5=E6=95=B0=E6=8D=AE=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E5=A2=9E=E5=8A=A0=E5=BA=97=E9=95=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Console/Commands/TaskLedgerGenerateCommand.php | 4 +++- app/Models/TaskLedger.php | 3 ++- .../2024_04_15_081617_create_task_ledgers_table.php | 3 ++- 3 files changed, 7 insertions(+), 3 deletions(-) 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(); }); }