6
0
Fork 0

关闭已过期的订单

release
李静 2021-12-16 19:02:29 +08:00
parent 21dc7f18c2
commit a02fce3f3a
2 changed files with 47 additions and 0 deletions

View File

@ -0,0 +1,39 @@
<?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;
}
}

View File

@ -71,6 +71,14 @@ class Order extends Model
self::PAY_WAY_BALANCE => '余额',
];
/**
* 仅查询支付过期的订单
*/
public function scopeExpired()
{
return $this->where('status', static::STATUS_PENDING)->where('created_at', '<=', now()->subSeconds(1800));
}
/**
* 属于此订单的商品
*/