6
0
Fork 0
jiqu-library-server/app/Console/Commands/OrderCompleteCommand.php

53 lines
1.1 KiB
PHP

<?php
namespace App\Console\Commands;
use App\Models\Order;
use App\Services\OrderService;
use Illuminate\Console\Command;
class OrderCompleteCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'order:complete';
/**
* The console command description.
*
* @var string
*/
protected $description = '将可自动完成的订单标记为已完成';
/**
* Execute the console command.
*
* @return int
*/
public function handle(OrderService $orderService)
{
while (true) {
$page = 0;
Order::with('packages')->completable()->chunkById(200, function ($orders) use ($orderService, &$page) {
foreach ($orders as $order) {
$orderService->confirm($order);
}
$page++;
});
if ($page === 0) {
sleep(60);
} elseif ($page === 1) {
sleep(30);
} else {
sleep(15);
}
}
}
}