CheckOrder.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Services\OrderService;
  4. use Illuminate\Console\Command;
  5. use App\Models\Order;
  6. use App\Models\User;
  7. use App\Models\Plan;
  8. use Illuminate\Support\Facades\DB;
  9. class CheckOrder extends Command
  10. {
  11. /**
  12. * The name and signature of the console command.
  13. *
  14. * @var string
  15. */
  16. protected $signature = 'check:order';
  17. /**
  18. * The console command description.
  19. *
  20. * @var string
  21. */
  22. protected $description = '订单检查任务';
  23. /**
  24. * Create a new command instance.
  25. *
  26. * @return void
  27. */
  28. public function __construct()
  29. {
  30. parent::__construct();
  31. }
  32. /**
  33. * Execute the console command.
  34. *
  35. * @return mixed
  36. */
  37. public function handle()
  38. {
  39. ini_set('memory_limit', -1);
  40. $orders = Order::whereIn('status', [0, 1])
  41. ->get();
  42. foreach ($orders as $item) {
  43. $orderService = new OrderService($item);
  44. switch ($item->status) {
  45. // cancel
  46. case 0:
  47. if (strtotime($item->created_at) <= (time() - 1800)) {
  48. $orderService->cancel();
  49. }
  50. break;
  51. case 1:
  52. $orderService->open();
  53. break;
  54. }
  55. }
  56. }
  57. }