From c65385a21cfc6d626f950791e051c654ee6180d0 Mon Sep 17 00:00:00 2001 From: panliang <1163816051@qq.com> Date: Mon, 23 May 2022 11:27:38 +0800 Subject: [PATCH] console --- app/Console/Commands/OrderDistribute.php | 38 +++++++++++++----------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/app/Console/Commands/OrderDistribute.php b/app/Console/Commands/OrderDistribute.php index 7d5aeeed..fd23abcf 100644 --- a/app/Console/Commands/OrderDistribute.php +++ b/app/Console/Commands/OrderDistribute.php @@ -41,25 +41,27 @@ class OrderDistribute extends Command public function handle() { $service = new \App\Services\DistributeService(); - try { - DB::beginTransaction(); - $query = Order::completable(); - if ($id = $this->argument('order')) { - $query->whereIn('id', explode(',', $id)); + while (true) { + try { + DB::beginTransaction(); + $query = Order::completable(); + if ($id = $this->argument('order')) { + $query->whereIn('id', explode(',', $id)); + } + $orders = $query->get(); + $this->line('总数: ' . $orders->count()); + $count = 0; + foreach($orders as $order) { + $profit = $service->storeByOrder($order); + $count++; + } + $this->info('符合要求: ' . $count); + DB::commit(); + } catch (Throwable $th) { + DB::rollBack(); + $this->line($th); } - $orders = $query->get(); - $this->line('总数: ' . $orders->count()); - $count = 0; - foreach($orders as $order) { - $profit = $service->storeByOrder($order); - $count++; - } - $this->info('符合要求: ' . $count); - DB::commit(); - } catch (Throwable $th) { - DB::rollBack(); - $this->line($th); + sleep(60); } - return 0; } }