feat: 初始化雄戈商城服务端代码与Webhook自动部署配置

这个提交包含在:
wikiboss
2026-09-12 16:40:24 +08:00
当前提交 e90ec58e61
共有 6438 个文件被更改,包括 1136083 次插入 和 0 次删除

查看文件

@@ -0,0 +1,26 @@
<?php
namespace addons\shopro_wechat_trade\command;
use addons\shopro_wechat_trade\library\WxShippingService;
use think\console\Command;
use think\console\Input;
use think\console\input\Option;
use think\console\Output;
class BackfillShipping extends Command
{
protected function configure()
{
$this->setName('shopro_wechat_trade:backfill')
->addOption('limit', null, Option::VALUE_OPTIONAL, 'Max orders', 50)
->setDescription('Backfill WeChat shipping info for shipped orders');
}
protected function execute(Input $input, Output $output)
{
$limit = intval($input->getOption('limit') ?: 50);
$count = (new WxShippingService())->backfillShippedOrders($limit);
$output->writeln('Backfill attempted for ' . $count . ' order(s).');
}
}

查看文件

@@ -0,0 +1,34 @@
<?php
namespace addons\shopro_wechat_trade\command;
use addons\shopro_wechat_trade\library\WxOrderPathService;
use think\console\Command;
use think\console\Input;
use think\console\Output;
class InitOrderPath extends Command
{
protected function configure()
{
$this->setName('shopro_wechat_trade:init-path')
->setDescription('Configure WeChat mini program order detail path');
}
protected function execute(Input $input, Output $output)
{
try {
$result = (new WxOrderPathService())->updatePath();
$output->writeln('Order detail path configured. errcode=0');
if (!empty($result['path'])) {
$output->writeln('path=' . $result['path']);
}
} catch (\Exception $e) {
$output->writeln('Failed: ' . $e->getMessage());
$output->writeln('');
$output->writeln('若 errcode=10060035:请先发布含 pages/order/detail 的小程序到微信线上/提审版,再重试。');
$output->writeln('发货同步(upload_shipping_info)不依赖本接口,可先配置发货管理并测试发货。');
$output->writeln('诊断: php think shopro_wechat_trade:probe-path');
}
}
}

查看文件

@@ -0,0 +1,23 @@
<?php
namespace addons\shopro_wechat_trade\command;
use addons\shopro_wechat_trade\library\Installer;
use think\console\Command;
use think\console\Input;
use think\console\Output;
class InstallFull extends Command
{
protected function configure()
{
$this->setName('shopro_wechat_trade:install')
->setDescription('Install/repair shopro_wechat_trade plugin');
}
protected function execute(Input $input, Output $output)
{
Installer::run($output);
$output->writeln('Run: php think shopro_wechat_trade:verify');
}
}

查看文件

@@ -0,0 +1,66 @@
<?php
namespace addons\shopro_wechat_trade\command;
use addons\shopro_wechat_trade\library\WxOrderPathService;
use addons\shopro_wechat_trade\library\WxTradeConfig;
use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\Db;
class ProbeOrderPath extends Command
{
protected function configure()
{
$this->setName('shopro_wechat_trade:probe-path')
->setDescription('Diagnose WeChat order detail path (10060035)');
}
protected function execute(Input $input, Output $output)
{
$output->writeln('=== 微信订单详情 path 诊断 ===');
$mini = Db::name('shopro_config')->where('name', 'wxMiniProgram')->value('value');
$mini = json_decode($mini, true);
$appId = $mini['app_id'] ?? '';
$output->writeln('小程序 AppID(商城配置): ' . ($appId ?: '(未配置)'));
$config = WxTradeConfig::getInstance();
$path = WxOrderPathService::normalizePath($config->getOrderDetailPath());
$output->writeln('待配置 path: ' . $path);
$pathService = new WxOrderPathService();
try {
$current = $pathService->getPath();
$output->writeln('当前已配置 path: ' . ($current['path'] ?? '(空)'));
} catch (\Exception $e) {
$output->writeln('查询当前 path 失败: ' . $e->getMessage());
}
try {
$managed = $pathService->isTradeManaged();
$output->writeln('is_trade_managed: ' . json_encode($managed, JSON_UNESCAPED_UNICODE));
} catch (\Exception $e) {
$output->writeln('is_trade_managed 失败: ' . $e->getMessage());
}
$output->writeln('');
$output->writeln('尝试 update_order_detail_path ...');
try {
$result = $pathService->updatePath($path);
$output->writeln('[OK] 配置成功: ' . json_encode($result, JSON_UNESCAPED_UNICODE));
} catch (\Exception $e) {
$output->writeln('[FAIL] ' . $e->getMessage());
$output->writeln('');
$output->writeln('10060035 常见原因(按概率):');
$output->writeln(' 1. 小程序「线上版」或「审核中版本」里没有 pages/order/detail —— 须先上传并提审/发布');
$output->writeln(' 2. 商城配置的 AppID 与当前要开通能力的小程序不一致');
$output->writeln(' 3. 可在微信后台手动填 path,不必强依赖 API');
$output->writeln('');
$output->writeln('说明:upload_shipping_info 发货同步不依赖本 path;path 仅用于「购物订单」跳转详情');
$output->writeln('建议 path: pages/order/detail?id=${商品订单号}');
}
}
}

查看文件

@@ -0,0 +1,26 @@
<?php
namespace addons\shopro_wechat_trade\command;
use addons\shopro_wechat_trade\library\WxShippingService;
use think\console\Command;
use think\console\Input;
use think\console\input\Option;
use think\console\Output;
class RetryFailed extends Command
{
protected function configure()
{
$this->setName('shopro_wechat_trade:retry-failed')
->addOption('limit', null, Option::VALUE_OPTIONAL, 'Max rows', 50)
->setDescription('Retry failed WeChat trade sync records');
}
protected function execute(Input $input, Output $output)
{
$limit = intval($input->getOption('limit') ?: 50);
$count = (new WxShippingService())->retryFailed($limit);
$output->writeln('Retried ' . $count . ' sync record(s).');
}
}

查看文件

@@ -0,0 +1,42 @@
<?php
namespace addons\shopro_wechat_trade\command;
use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\Db;
class VerifyInstall extends Command
{
protected function configure()
{
$this->setName('shopro_wechat_trade:verify')
->setDescription('Verify shopro_wechat_trade plugin installation');
}
protected function execute(Input $input, Output $output)
{
$checks = [
'addon_dir' => is_dir(ADDON_PATH . 'shopro_wechat_trade'),
'hooks' => is_file(ADDON_PATH . 'shopro_wechat_trade/hooks.php'),
'config_tbl' => $this->tableExists('shopro_wechat_trade_config'),
'sync_tbl' => $this->tableExists('shopro_wechat_trade_sync'),
'enabled' => intval(get_addon_info('shopro_wechat_trade')['state'] ?? 0) === 1,
];
foreach ($checks as $name => $ok) {
$output->writeln(sprintf('[%s] %s', $ok ? 'OK' : 'FAIL', $name));
}
}
protected function tableExists($name)
{
try {
Db::name($name)->limit(1)->select();
return true;
} catch (\Exception $e) {
return false;
}
}
}