46 行
1.5 KiB
PHP
46 行
1.5 KiB
PHP
<?php
|
|
|
|
namespace addons\shopro\job;
|
|
|
|
use app\common\library\PrinterService;
|
|
use think\Db;
|
|
use think\queue\Job;
|
|
|
|
class OrderPrintStatus extends BaseJob
|
|
{
|
|
public function handle(Job $job, $data)
|
|
{
|
|
$taskId = isset($data['task_id']) ? (int)$data['task_id'] : 0;
|
|
$task = $taskId ? Db::name('shopro_order_print_task')->where('id', $taskId)->find() : null;
|
|
if (!$task || (int)$task['status'] !== 3 || empty($task['cloud_order_id'])) {
|
|
$job->delete();
|
|
return;
|
|
}
|
|
|
|
$result = (new PrinterService())->queryOrderState($task['cloud_order_id']);
|
|
$attempts = (int)$task['verify_attempts'] + 1;
|
|
$update = [
|
|
'verify_attempts' => $attempts,
|
|
'updated_at' => time(),
|
|
'printer_response' => $result['response'],
|
|
'last_error' => !empty($result['accepted']) ? '' : $result['error'],
|
|
];
|
|
|
|
if (!empty($result['printed'])) {
|
|
$update['status'] = 1;
|
|
$update['printed_at'] = time();
|
|
Db::name('shopro_order_print_task')->where('id', $taskId)->update($update);
|
|
$job->delete();
|
|
return;
|
|
}
|
|
|
|
Db::name('shopro_order_print_task')->where('id', $taskId)->update($update);
|
|
if ($attempts < 30) {
|
|
\think\Queue::later(60, '\\addons\\shopro\\job\\OrderPrintStatus@handle', ['task_id' => $taskId], 'shopro-high');
|
|
} else {
|
|
\think\Log::warning('订单小票云端状态未确认,任务ID ' . $taskId);
|
|
}
|
|
$job->delete();
|
|
}
|
|
}
|