关闭已过期的订单
parent
21dc7f18c2
commit
a02fce3f3a
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -71,6 +71,14 @@ class Order extends Model
|
||||||
self::PAY_WAY_BALANCE => '余额',
|
self::PAY_WAY_BALANCE => '余额',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 仅查询支付过期的订单
|
||||||
|
*/
|
||||||
|
public function scopeExpired()
|
||||||
|
{
|
||||||
|
return $this->where('status', static::STATUS_PENDING)->where('created_at', '<=', now()->subSeconds(1800));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 属于此订单的商品
|
* 属于此订单的商品
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue