| 1234567891011121314151617181920212223242526272829303132 |
- <?php
- namespace App\Console\Commands;
- use App\Models\PaymentOrder;
- use App\Services\AdminRealtime\AdminRealtime;
- use App\Services\PaymentOrderService;
- use Illuminate\Console\Command;
- class PaymentPayTimeout extends Command
- {
- protected $signature = 'payment:pay-timeout';
- protected $description = '在线充值订单处理中超过30分钟未支付的标记为超时(迟到的支付回调仍可入账)';
- public function handle()
- {
- $timeoutAt = date('Y-m-d H:i:s', strtotime('-' . PaymentOrderService::PAY_TIMEOUT_MINUTES . ' minutes'));
- do {
- $ids = PaymentOrder::where('type', PaymentOrderService::TYPE_PAY)
- ->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);
- return 0;
- }
- }
|