feat(shopro_wechat_trade): 添加重新同步物流信息命令 新增 ResyncShipping 命令,支持强制重新上传微信物流信息, 不依赖 sync 表的 failed/pending 状态,适用于修改自提配置后 需要重传的场景。 同时修改 RetryFailed 命令,在没有待重试记录时提供操作提示, 并扩展 WxShippingService 的 retryFailed 方法支持处理 failed 状态的记录。 ```
66 行
2.2 KiB
PHP
66 行
2.2 KiB
PHP
<?php
|
||
|
||
namespace addons\shopro_wechat_trade\command;
|
||
|
||
use addons\shopro_wechat_trade\library\Bridge;
|
||
use addons\shopro_wechat_trade\library\WxShippingService;
|
||
use think\console\Command;
|
||
use think\console\Input;
|
||
use think\console\input\Option;
|
||
use think\console\Output;
|
||
|
||
/**
|
||
* 强制再次 upload_shipping_info(不依赖 sync 表 failed/pending)
|
||
*/
|
||
class ResyncShipping extends Command
|
||
{
|
||
protected function configure()
|
||
{
|
||
$this->setName('shopro_wechat_trade:resync-shipping')
|
||
->addOption('sn', null, Option::VALUE_REQUIRED, '订单号,多个英文逗号分隔')
|
||
->addOption('id', null, Option::VALUE_REQUIRED, '订单 id,多个英文逗号分隔')
|
||
->setDescription('Force re-upload WeChat shipping (e.g. after force self-pickup config)');
|
||
}
|
||
|
||
protected function execute(Input $input, Output $output)
|
||
{
|
||
if (!Bridge::isEnabled()) {
|
||
$output->writeln('[FAIL] shopro_wechat_trade 未启用');
|
||
return 1;
|
||
}
|
||
|
||
$sns = [];
|
||
$snOpt = trim((string) $input->getOption('sn'));
|
||
if ($snOpt !== '') {
|
||
foreach (preg_split('/[\s,,]+/', $snOpt) as $sn) {
|
||
$sn = trim($sn);
|
||
if ($sn !== '') {
|
||
$sns[] = $sn;
|
||
}
|
||
}
|
||
}
|
||
$idOpt = trim((string) $input->getOption('id'));
|
||
if ($idOpt !== '') {
|
||
foreach (preg_split('/[\s,,]+/', $idOpt) as $id) {
|
||
$id = intval($id);
|
||
if ($id > 0) {
|
||
$row = \think\Db::name('shopro_order')->where('id', $id)->value('order_sn');
|
||
if ($row) {
|
||
$sns[] = $row;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
if (!$sns) {
|
||
$output->writeln('请指定 --sn=订单号 或 --id=订单id');
|
||
return 1;
|
||
}
|
||
|
||
$service = new WxShippingService();
|
||
$result = $service->resyncShippingByOrderSns(array_unique($sns));
|
||
$output->writeln('Resync shipping: ok=' . $result['ok'] . ', fail=' . $result['fail']);
|
||
$output->writeln('说明:retry-failed 只处理 sync 表 pending/failed;已成功的老单请用本命令重传。');
|
||
return $result['fail'] > 0 ? 1 : 0;
|
||
}
|
||
}
|