PaymentPayTimeout.php 1.2 KB

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Models\PaymentOrder;
  4. use App\Services\AdminRealtime\AdminRealtime;
  5. use App\Services\PaymentOrderService;
  6. use Illuminate\Console\Command;
  7. class PaymentPayTimeout extends Command
  8. {
  9. protected $signature = 'payment:pay-timeout';
  10. protected $description = '在线充值订单处理中超过30分钟未支付的标记为超时(迟到的支付回调仍可入账)';
  11. public function handle()
  12. {
  13. $timeoutAt = date('Y-m-d H:i:s', strtotime('-' . PaymentOrderService::PAY_TIMEOUT_MINUTES . ' minutes'));
  14. do {
  15. $ids = PaymentOrder::where('type', PaymentOrderService::TYPE_PAY)
  16. ->where('status', PaymentOrderService::STATUS_PROCESS)
  17. ->where('created_at', '<', $timeoutAt)
  18. ->limit(500)->pluck('id')->all();
  19. if (!$ids) break;
  20. // 带状态条件更新,避免覆盖同一时刻回调已改成成功/失败的订单
  21. PaymentOrder::whereIn('id', $ids)->where('status', PaymentOrderService::STATUS_PROCESS)
  22. ->update(['status' => PaymentOrderService::STATUS_TIMEOUT]);
  23. AdminRealtime::record('payment_orders', $ids);
  24. } while (count($ids) === 500);
  25. return 0;
  26. }
  27. }