OrderExpired.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Models\OrderModel;
  4. use Illuminate\Console\Command;
  5. class OrderStatusExpired extends Command
  6. {
  7. /**
  8. * The name and signature of the console command.
  9. *
  10. * @var string
  11. */
  12. protected $signature = 'order:status-expired';
  13. /**
  14. * The console command description.
  15. *
  16. * @var string
  17. */
  18. protected $description = '支付订单过期处理';
  19. /**
  20. * Create a new command instance.
  21. *
  22. * @return void
  23. */
  24. public function __construct()
  25. {
  26. parent::__construct();
  27. }
  28. /**
  29. * Execute the console command.
  30. *
  31. * @return mixed
  32. */
  33. public function handle()
  34. {
  35. $this->comment("开始处理过期订单");
  36. $expiredTime = date('Y-m-d H:i:s', time() - 400);
  37. $orderData = OrderModel::query()->where('created_at', '<', $expiredTime)->where('status', 1)->get(['id']);
  38. if ($orderData->isNotEmpty()) {
  39. foreach ($orderData as $var) {
  40. OrderModel::query()->where('id', $var->id)->update(['status' => 3]);
  41. }
  42. }
  43. $this->comment("过期订单处理完成");
  44. }
  45. }