6
0
Fork 0

更新关闭过期的订单任务

release
李静 2022-01-20 16:52:01 +08:00
parent b10dd4e092
commit 738ff1b6f1
1 changed files with 18 additions and 6 deletions

View File

@ -28,12 +28,24 @@ class OrderCloseExpiredCommand extends Command
*/ */
public function handle() public function handle()
{ {
Order::select('id')->expired()->chunkById(1000, function ($orders) { while (true) {
Order::whereIn('id', $orders->pluck('id')->all())->where('status', Order::STATUS_PENDING)->update([ $page = 0;
'status' => Order::STATUS_CANCELLED,
]);
});
return 0; Order::select('id')->expired()->chunkById(1000, function ($orders, &$page) {
Order::whereIn('id', $orders->pluck('id')->all())->where('status', Order::STATUS_PENDING)->update([
'status' => Order::STATUS_CANCELLED,
]);
$page++;
});
if ($page === 0) {
sleep(60);
} elseif ($page === 1) {
sleep(30);
} else {
sleep(60);
}
}
} }
} }