6
0
Fork 0
jiqu-library-server/app/Console/Commands/OrderCloseExpiredCommand.php

52 lines
1.1 KiB
PHP

<?php
namespace App\Console\Commands;
use App\Models\Order;
use Illuminate\Console\Command;
class OrderCloseExpiredCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'order:close-expired';
/**
* The console command description.
*
* @var string
*/
protected $description = '关闭过期的订单';
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
while (true) {
$page = 0;
Order::select('id')->expired()->chunkById(1000, function ($orders) use (&$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(15);
}
}
}
}