CheckOrder.php 1.3 KB

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