69 lines
2.6 KiB
PHP
Executable File
69 lines
2.6 KiB
PHP
Executable File
<?php
|
||
|
||
declare(strict_types=1);
|
||
|
||
namespace app\command;
|
||
|
||
use app\common\service\ExpressTrackingService;
|
||
use think\console\Command;
|
||
use think\console\Input;
|
||
use think\console\Output;
|
||
|
||
/**
|
||
* 物流自动更新定时任务
|
||
*
|
||
* 使用方法:
|
||
* php think express:auto-update
|
||
*
|
||
* 配置 crontab(每 10 分钟):拉快递 100 + 按履约「已发货」核对释放诊单医助(跳过已完成/已签收业务单,与是否甘草单无关)
|
||
* 0,10,20,30,40,50 * * * * cd /path/to/server && php think express:auto-update >> /dev/null 2>&1
|
||
*
|
||
* 已对「业务订单创建人非二中心」(或创建人为开方医生时按待释放身份判定)执行发货/签收自动释放的诊单会写入 tcm_diagnosis.shipped_non_er_assistant_cleared_at,
|
||
* 后续履约核对不再重复扫描(需先执行 sql/1.9.20260507/add_diagnosis_shipped_non_er_assistant_cleared_at.sql)。
|
||
*/
|
||
class ExpressAutoUpdate extends Command
|
||
{
|
||
protected function configure()
|
||
{
|
||
$this->setName('express:auto-update')
|
||
->setDescription('自动更新物流追踪信息');
|
||
}
|
||
|
||
protected function execute(Input $input, Output $output)
|
||
{
|
||
$output->writeln('开始自动更新物流信息...');
|
||
|
||
$startTime = microtime(true);
|
||
|
||
try {
|
||
$result = ExpressTrackingService::autoUpdateBatch(1000);
|
||
$recon = ExpressTrackingService::reconcileAssistantReleaseForShippedPrescriptionOrders(1000);
|
||
|
||
|
||
$duration = round(microtime(true) - $startTime, 2);
|
||
|
||
$output->writeln("更新完成!");
|
||
$output->writeln("总数: {$result['total']}");
|
||
$output->writeln("成功: {$result['success']}");
|
||
$output->writeln("失败: {$result['failed']}");
|
||
$output->writeln("医助已移除(物流任务+指派日志): " . (int) ($result['assistant_cleared'] ?? 0));
|
||
$output->writeln("医助已移除(履约已发货核对): " . (int) ($recon['cleared'] ?? 0) . " (扫描 " . (int) ($recon['scanned'] ?? 0) . " 单)");
|
||
$lines = array_merge($result['assistant_lines'] ?? [], $recon['lines'] ?? []);
|
||
if ($lines === []) {
|
||
$output->writeln('医助明细: (无)');
|
||
} else {
|
||
$output->writeln('医助明细:');
|
||
foreach ($lines as $line) {
|
||
$output->writeln(' ' . $line);
|
||
}
|
||
}
|
||
$output->writeln("耗时: {$duration}秒");
|
||
|
||
return 0;
|
||
} catch (\Throwable $e) {
|
||
$output->error("更新失败: " . $e->getMessage());
|
||
return 1;
|
||
}
|
||
}
|
||
}
|