v2board/app/Console/Commands/CheckOrder.php

65 lines
1.3 KiB
PHP
Raw Normal View History

2019-10-29 15:33:36 +08:00
<?php
namespace App\Console\Commands;
2020-03-17 20:00:46 +08:00
use App\Services\OrderService;
2019-10-29 15:33:36 +08:00
use Illuminate\Console\Command;
use App\Models\Order;
use App\Models\User;
use App\Models\Plan;
2020-04-09 13:35:27 +08:00
use Illuminate\Support\Facades\DB;
2019-10-29 15:33:36 +08:00
class CheckOrder extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'check:order';
/**
* The console command description.
*
* @var string
*/
protected $description = '订单检查任务';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
ini_set('memory_limit', -1);
2021-05-24 20:10:54 +08:00
$orders = Order::whereIn('status', [0, 1])
->get();
2020-03-17 20:00:46 +08:00
foreach ($orders as $item) {
2020-10-04 14:21:09 +08:00
$orderService = new OrderService($item);
2019-10-29 15:33:36 +08:00
switch ($item->status) {
2019-11-25 00:27:36 +08:00
// cancel
2019-10-29 15:33:36 +08:00
case 0:
2021-08-02 02:00:01 +08:00
if ($item->created_at <= (time() - 1800)) {
2020-03-17 20:00:46 +08:00
$orderService->cancel();
2019-10-29 15:33:36 +08:00
}
break;
case 1:
2020-10-04 14:21:09 +08:00
$orderService->open();
2019-10-29 15:33:36 +08:00
break;
}
2020-01-11 13:36:52 +08:00
2019-10-29 15:33:36 +08:00
}
}
}