53 lines
1.4 KiB
PHP
53 lines
1.4 KiB
PHP
<?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分钟执行一次):
|
|
* 0,10,20,30,40,50 * * * * cd /path/to/server && php think express:auto-update >> /dev/null 2>&1
|
|
*/
|
|
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(50);
|
|
|
|
$duration = round(microtime(true) - $startTime, 2);
|
|
|
|
$output->writeln("更新完成!");
|
|
$output->writeln("总数: {$result['total']}");
|
|
$output->writeln("成功: {$result['success']}");
|
|
$output->writeln("失败: {$result['failed']}");
|
|
$output->writeln("耗时: {$duration}秒");
|
|
|
|
return 0;
|
|
} catch (\Throwable $e) {
|
|
$output->error("更新失败: " . $e->getMessage());
|
|
return 1;
|
|
}
|
|
}
|
|
}
|