Browse Source

超时订单定时任务增加已付定金状态

develop
李可松 4 years ago
parent
commit
10ecbe33e9
  1. 13
      app/Console/Commands/OrderTimeout.php

13
app/Console/Commands/OrderTimeout.php

@ -41,14 +41,16 @@ class OrderTimeout extends Command
*/ */
public function handle() public function handle()
{ {
//需要处理的订单状态
$status_arr = [OrderStatus::UNPAID, OrderStatus::PAY_EARNEST];
//记录最小ID,下次查询时按ID正序查询,只处理大于该ID的订单,避免重复扫描数据库 //记录最小ID,下次查询时按ID正序查询,只处理大于该ID的订单,避免重复扫描数据库
$min_id = Order::query()->where('status', OrderStatus::UNPAID)->min('id');
$min_id = Order::query()->whereIn('status', $status_arr)->min('id');
while (true) { while (true) {
Order::query() Order::query()
->where([
['status', '=', OrderStatus::UNPAID],
['id', '>=', $min_id],
])
->where('id', '>=', $min_id)
->whereIn('status', $status_arr)
->whereNotNull('timeout') ->whereNotNull('timeout')
->orderBy('id') ->orderBy('id')
->chunk(100, function ($order) use (&$min_id) { ->chunk(100, function ($order) use (&$min_id) {
@ -66,6 +68,7 @@ class OrderTimeout extends Command
DB::commit(); DB::commit();
} catch (\Exception $exception) { } catch (\Exception $exception) {
DB::rollBack(); DB::rollBack();
$this->line("订单ID {$v->id} 错误:" . $exception->getMessage());
} }
} }
$min_id = $v->id; $min_id = $v->id;

Loading…
Cancel
Save