feat(split): 添加分账模式scene参数支持及扩展信息配置 - 在SyncSplitReceivers命令中新增--scene选项,用于指定分账模式 - 支持通过插件配置split_config_scene设置默认分账场景 - 实现buildSplitExtInfoJson方法,根据分账比例和场景自动生成扩展信息 - 当分账比例超过30%或场景为'00'时自动添加业务说明信息 - 在数据库升级脚本中新增分账场景相关配置项 - 完善分账配置的参数验证和错误处理机制 ```
90 行
3.7 KiB
PHP
90 行
3.7 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')
|
||
->addOption('scene', null, Option::VALUE_OPTIONAL, '分账模式 scene,默认插件 split_config_scene(A5)')
|
||
->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());
|
||
$sceneOpt = trim((string) $input->getOption('scene'));
|
||
$scene = $sceneOpt !== '' ? $sceneOpt : $service->resolveSplitConfigScene();
|
||
$output->writeln('scene(分账模式): ' . $scene);
|
||
|
||
$dryRun = (bool) $input->getOption('dry-run');
|
||
$initOnly = (bool) $input->getOption('init-only');
|
||
$options = [
|
||
'dry_run' => $dryRun,
|
||
'main_huifu_id' => $main,
|
||
'scene' => $scene,
|
||
];
|
||
|
||
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;
|
||
}
|
||
}
|