文件
xiaozhongchuf/backups/receipt-fix-20260727-1728/candidate/application/admin/command/ShoproPrintRetry.php
2026-09-23 17:04:10 +08:00

50 行
1.6 KiB
PHP

<?php
namespace app\admin\command;
use think\Db;
use think\console\Command;
use think\console\Input;
use think\console\input\Option;
use think\console\Output;
class ShoproPrintRetry extends Command
{
protected function configure()
{
$this->setName('shopro:print-retry')
->addOption('order-id', null, Option::VALUE_REQUIRED, 'failed print task order id')
->addOption('all', null, Option::VALUE_NONE, 'retry all failed print tasks')
->setDescription('Requeue failed Shopro receipt print tasks');
}
protected function execute(Input $input, Output $output)
{
$orderId = (int)$input->getOption('order-id');
$all = (bool)$input->getOption('all');
if (!$orderId && !$all) {
$output->error('Use --order-id=<id> or --all.');
return 1;
}
$staleBefore = time() - 300;
$query = Db::name('shopro_order_print_task')
->whereRaw('(status = -1 OR (status = 2 AND updated_at < ' . $staleBefore . '))');
if ($orderId) {
$query->where('order_id', $orderId);
}
$tasks = $query->select();
foreach ($tasks as $task) {
Db::name('shopro_order_print_task')->where('id', $task['id'])->update([
'status' => 0,
'updated_at' => time(),
'last_error' => '',
]);
\think\Queue::push('\\addons\\shopro\\job\\OrderPrint@handle', ['order_id' => $task['order_id']], 'shopro-high');
}
$output->info('Requeued ' . count($tasks) . ' receipt print task(s).');
return 0;
}
}