From 738ff1b6f197afc2b289685775f72db94064dc2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=9D=99?= Date: Thu, 20 Jan 2022 16:52:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=85=B3=E9=97=AD=E8=BF=87?= =?UTF-8?q?=E6=9C=9F=E7=9A=84=E8=AE=A2=E5=8D=95=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Commands/OrderCloseExpiredCommand.php | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/app/Console/Commands/OrderCloseExpiredCommand.php b/app/Console/Commands/OrderCloseExpiredCommand.php index 5a0f66a5..b3c240b5 100644 --- a/app/Console/Commands/OrderCloseExpiredCommand.php +++ b/app/Console/Commands/OrderCloseExpiredCommand.php @@ -28,12 +28,24 @@ class OrderCloseExpiredCommand extends Command */ public function handle() { - Order::select('id')->expired()->chunkById(1000, function ($orders) { - Order::whereIn('id', $orders->pluck('id')->all())->where('status', Order::STATUS_PENDING)->update([ - 'status' => Order::STATUS_CANCELLED, - ]); - }); + while (true) { + $page = 0; - 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); + } + } } }