diff --git a/app/Console/Commands/Dealer/OrderAutoAllocate.php b/app/Console/Commands/Dealer/OrderAutoAllocate.php index 50f9d11a..6b7ba32e 100644 --- a/app/Console/Commands/Dealer/OrderAutoAllocate.php +++ b/app/Console/Commands/Dealer/OrderAutoAllocate.php @@ -32,25 +32,37 @@ class OrderAutoAllocate extends Command */ public function handle() { - DealerOrder::where('status', DealerOrderStatus::Pending) - ->where('consignor_id', '>', 1)//到1用户或者公司的订单不需要再分配 - ->where('allocated_at', '<', now()->subMinutes(app_settings('dealer.order_auto_allocate_times'))) - ->chunkById(200, function ($orders) { - $orders->load([ - 'consignor', - ]); - $orderService = new OrderService(); - foreach ($orders as $order) { - try { - DB::beginTransaction(); - $orderService->updateOrderConsignor($order); - DB::commit(); - } catch (Throwable $th) { - DB::rollBack(); - report($th); - } + do { + $page = 0; + + DealerOrder::where('status', DealerOrderStatus::Pending) + ->where('consignor_id', '>', 1) // 到1用户或者公司的订单不需要再分配 + ->where('allocated_at', '<', now()->subMinutes(app_settings('dealer.order_auto_allocate_times'))) + ->chunkById(200, function ($orders) use (&$page) { + $orders->load([ + 'consignor', + ]); + $orderService = new OrderService(); + foreach ($orders as $order) { + try { + DB::beginTransaction(); + $orderService->updateOrderConsignor($order); + DB::commit(); + } catch (Throwable $th) { + DB::rollBack(); + report($th); + } + } + + $page++; + }); + + if ($page > 1) { + sleep(15); + } else { + sleep(60); } - }); + } while (true); return 0; }