52 lines
1.4 KiB
PHP
52 lines
1.4 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('id','4126')
|
|
->field('id, create_time, dispatch_time')
|
|
->select();
|
|
|
|
foreach ($orders as $order) {
|
|
$createTime = strtotime($order['create_time']);
|
|
$dispatchTime = $order['dispatch_time'] ? strtotime($order['dispatch_time']) : $now;
|
|
|
|
$diffMinutes = ($dispatchTime - $createTime) / 60;
|
|
|
|
if ($diffMinutes > 20) {
|
|
Db::name('order')
|
|
->where('id', $order['id'])
|
|
->update(['is_overtime' => 1]);
|
|
$count++;
|
|
}else{
|
|
Db::name('order')
|
|
->where('id', $order['id'])
|
|
->update(['is_overtime' => 0]);
|
|
}
|
|
echo 'deal' . $count . PHP_EOL;
|
|
}
|
|
|
|
$output->writeln("已更新超时订单数量: $count");
|
|
$output->info('OVER');
|
|
}
|
|
}
|