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; } }