feat(shopro_huifu): 添加分账配置提交功能和接收方绑定机制 - 实现 shouldDeferWalletUntilGatewaySplitResolves 方法,确保分销/区域结算事件早于 split_timing 时等待分账结束再入钱包 - 新增 SyncSplitReceivers 命令用于提交商户分账配置并绑定已审核通过的汇付号为分账接收方 - 扩展 HuifuClient 添加 submitMerchantSplitConfig 接口实现 v2/merchant/split/config 调用 - 创建 HuifuMerchantSplitService 处理主商户分账配置提交和进件子户绑定为分账接收方逻辑 - 在进件成功后自动调用 split/config 接口绑定分账接收方 - 添加数据库表结构升级脚本,增加分账绑定状态相关字段 - 注册新的命令行工具到应用配置中 ```
85 行
3.4 KiB
PHP
85 行
3.4 KiB
PHP
<?php
|
||
|
||
namespace addons\shopro_huifu\command;
|
||
|
||
use addons\shopro_huifu\library\Bridge;
|
||
use addons\shopro_huifu\library\HuifuClient;
|
||
use addons\shopro_huifu\library\split\HuifuMerchantSplitService;
|
||
use think\console\Command;
|
||
use think\console\Input;
|
||
use think\console\input\Option;
|
||
use think\console\Output;
|
||
|
||
class SyncSplitReceivers extends Command
|
||
{
|
||
protected function configure()
|
||
{
|
||
$this->setName('shopro_huifu:sync-split-receivers')
|
||
->addOption('dry-run', null, Option::VALUE_NONE, '仅预览将提交的接收方与参数,不调汇付')
|
||
->addOption('init-only', null, Option::VALUE_NONE, '仅提交主商户分账开关(rule_origin=01),不带接收方列表')
|
||
->addOption('huifu-id', null, Option::VALUE_OPTIONAL, '主商户汇付号,默认 platform_huifu_id 或插件 huifu_id')
|
||
->setDescription('Submit v2/merchant/split/config and bind approved onboard huifu_ids as split receivers');
|
||
}
|
||
|
||
protected function execute(Input $input, Output $output)
|
||
{
|
||
if (!Bridge::isEnabled()) {
|
||
$output->writeln('[FAIL] 汇付插件未启用');
|
||
return 1;
|
||
}
|
||
|
||
$service = new HuifuMerchantSplitService();
|
||
$main = trim((string) $input->getOption('huifu-id'));
|
||
if ($main === '') {
|
||
$main = $service->resolveMainHuifuId();
|
||
}
|
||
$output->writeln('主商户 huifu_id: ' . $main);
|
||
$output->writeln('apply_ratio(最大分账比例%): ' . $service->resolveApplyRatio());
|
||
|
||
$dryRun = (bool) $input->getOption('dry-run');
|
||
$initOnly = (bool) $input->getOption('init-only');
|
||
$options = [
|
||
'dry_run' => $dryRun,
|
||
'main_huifu_id' => $main,
|
||
];
|
||
|
||
if ($initOnly) {
|
||
$output->writeln('模式: init-only(不带 acct_split_bunch_list)');
|
||
$result = $service->submitSplitConfig([], $options);
|
||
} else {
|
||
$output->writeln('模式: 全量(远端已绑 + 本地已进件 approved)');
|
||
$result = $service->syncAllApprovedReceivers($options);
|
||
}
|
||
|
||
if (!empty($result['dry_run'])) {
|
||
$output->writeln('[DRY-RUN] 将提交接收方 ' . count($result['receivers'] ?? []) . ' 个');
|
||
$output->writeln(json_encode($result['data'] ?? [], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
|
||
return 0;
|
||
}
|
||
|
||
$output->writeln('resp: ' . ($result['message'] ?? ''));
|
||
if (isset($result['resp_code'])) {
|
||
$output->writeln('resp_code: ' . $result['resp_code']);
|
||
}
|
||
if (isset($result['submitted'])) {
|
||
$output->writeln('提交接收方数量: ' . $result['submitted']
|
||
. '(远端已有 ' . ($result['remote'] ?? 0) . ',本地进件 ' . ($result['local'] ?? 0) . ')');
|
||
}
|
||
if (!empty($result['receivers'])) {
|
||
foreach ($result['receivers'] as $hid) {
|
||
$output->writeln(' - ' . $hid);
|
||
}
|
||
}
|
||
|
||
if (empty($result['ok'])) {
|
||
$output->writeln('[FAIL] 提交未成功,请查看日志 [shopro_huifu] split/config');
|
||
return 1;
|
||
}
|
||
|
||
$output->writeln('');
|
||
$output->writeln('下一步: php think shopro_huifu:query-split-config --huifu-id=' . $main);
|
||
$output->writeln('(配置若走异步审核,需等待生效后再测 delaytrans/confirm)');
|
||
return 0;
|
||
}
|
||
}
|