where('status', PaymentOrderService::STATUS_PROCESS) ->where('created_at', '<', $timeoutAt) ->limit(500)->pluck('id')->all(); if (!$ids) break; // 带状态条件更新,避免覆盖同一时刻回调已改成成功/失败的订单 PaymentOrder::whereIn('id', $ids)->where('status', PaymentOrderService::STATUS_PROCESS) ->update(['status' => PaymentOrderService::STATUS_TIMEOUT]); AdminRealtime::record('payment_orders', $ids); } while (count($ids) === 500); // 代理在线充值同样处理(不推送后台实时消息);迁移未执行前跳过。 if (!\Illuminate\Support\Facades\DB::getSchemaBuilder()->hasTable('agent_payment_orders')) return 0; AgentPaymentOrder::query()->where('type', PaymentOrderService::TYPE_PAY) ->where('status', PaymentOrderService::STATUS_PROCESS)->where('created_at', '<', $timeoutAt) ->update(['status' => PaymentOrderService::STATUS_TIMEOUT, 'updated_at' => now()]); return 0; } }