CheckOrder.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. $orders = Order::get();
  40. foreach ($orders as $item) {
  41. $orderService = new OrderService($item);
  42. switch ($item->status) {
  43. // cancel
  44. case 0:
  45. if (strtotime($item->created_at) <= (time() - 1800)) {
  46. $orderService->cancel();
  47. }
  48. break;
  49. case 1:
  50. $orderService->open();
  51. break;
  52. }
  53. }
  54. }
  55. }