40 lines
831 B
PHP
40 lines
831 B
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Models\Order;
|
|
use Illuminate\Console\Command;
|
|
|
|
class OrderCloseExpired 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()
|
|
{
|
|
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,
|
|
]);
|
|
});
|
|
|
|
return 0;
|
|
}
|
|
}
|