From 8a317876e070dbdf86291b8ae62687629c0f7a0d Mon Sep 17 00:00:00 2001 From: Jing Li Date: Mon, 20 May 2024 10:13:19 +0800 Subject: [PATCH] Update --- app/Console/Commands/TaskLedgerGenerateCommand.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/Console/Commands/TaskLedgerGenerateCommand.php b/app/Console/Commands/TaskLedgerGenerateCommand.php index 84edba3..7c82a6d 100644 --- a/app/Console/Commands/TaskLedgerGenerateCommand.php +++ b/app/Console/Commands/TaskLedgerGenerateCommand.php @@ -42,8 +42,14 @@ class TaskLedgerGenerateCommand extends Command protected function generateTasks(Carbon $datetime): void { + $stores = Store::with(['master'])->get(); + + if ($stores->isEmpty()) { + return; + } + /** @var \App\Models\PlanLedger */ - $planable = DB::transaction(function () use ($datetime) { + $planable = DB::transaction(function () use ($datetime, $stores) { /** @var \App\Models\PlanLedger */ $planable = PlanLedger::firstOrNew([ 'date' => $datetime->format('Y-m-d'), @@ -63,8 +69,6 @@ class TaskLedgerGenerateCommand extends Command return $planable->setRelation('plan', $plan); }); - $stores = Store::with(['master'])->get(); - /** @var \App\Models\Store */ foreach ($stores as $store) { DB::transaction(function () use ($store, $planable) {