allocatr/application/common/command/FixOrderOvertime.php
2025-07-02 16:28:41 +08:00

48 lines
1.2 KiB
PHP

<?php
namespace app\common\command;
use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\Db;
class FixOrderOvertime extends Command
{
protected function configure()
{
$this->setName('fix:order_overtime')
->setDescription('修复订单超时派单标记');
}
protected function execute(Input $input, Output $output)
{
$now = time();
$count = 0;
// 取出可能未超时标记的订单
$orders = Db::name('order')
->where('is_overtime', 0)
->field('id, create_time, dispatch_time')
->select();
foreach ($orders as $order) {
$createTime = (int)$order['create_time'];
$dispatchTime = $order['dispatch_time'] ? strtotime($order['dispatch_time']) : strtotime($now);
$diffMinutes = ($dispatchTime - $createTime) / 60;
if ($diffMinutes > 20) {
Db::name('order')
->where('id', $order['id'])
->update(['is_overtime' => 1]);
$count++;
}
echo 'deal' . $count . PHP_EOL;
}
$output->writeln("已更新超时订单数量: $count");
$output->info('OVER');
}
}