```
feat(shopro): 完善汇付分账功能的错误处理和调试信息 - 添加主商户号验证逻辑,当platform_huifu_id为空时使用插件主商户 - 改进分账剩余金额显示逻辑,区分主商户留存和平台分账情况 - 更新错误提示信息,明确2200002错误的处理方式 - 新增acct_infos预览功能,便于调试分账配置 - 优化分账服务中的商户号处理,避免主商户重复分账 fix(shopro_huifu): 修复汇付分账配置错误提示和分账逻辑 - 更新22000002错误排查说明,简化表述并突出关键点 - 修复分账服务中构建分账信息的逻辑,确保不包含收款主商户 - 添加日志记录,当跳过分账方为自己时进行警告 - 优化剩余金额处理,当日志平台即收款主商户时剩余款项保留在主商户 - 增强分账验证,当无有效分账接收方时抛出异常 ```
这个提交包含在:
@@ -158,6 +158,13 @@ class HuifuSplitService
|
||||
|
||||
protected function buildAcctInfos(array $items, $payFee)
|
||||
{
|
||||
$payFee = number_format((float) $payFee, 2, '.', '');
|
||||
$paymentHuifuId = trim((string) $this->config->get('huifu_id'));
|
||||
$platformHuifuId = trim((string) ((new SplitConfig())->all()['platform_huifu_id'] ?? $paymentHuifuId));
|
||||
if ($platformHuifuId === '') {
|
||||
$platformHuifuId = $paymentHuifuId;
|
||||
}
|
||||
|
||||
$infos = [];
|
||||
$allocated = '0.00';
|
||||
foreach ($items as $item) {
|
||||
@@ -165,28 +172,45 @@ class HuifuSplitService
|
||||
if (bccomp($amt, '0.00', 2) <= 0) {
|
||||
continue;
|
||||
}
|
||||
$receiverHuifuId = trim((string) ($item['receiver_account'] ?? ''));
|
||||
if ($receiverHuifuId === '') {
|
||||
continue;
|
||||
}
|
||||
// 汇付要求:分账方勿与收款主商户相同(剩余款留在主商户,勿写入 acct_infos)
|
||||
if ($paymentHuifuId !== '' && $receiverHuifuId === $paymentHuifuId) {
|
||||
\think\Log::warning('[shopro_huifu] split skip self receiver in acct_infos huifu_id=' . $receiverHuifuId);
|
||||
continue;
|
||||
}
|
||||
$infos[] = [
|
||||
'huifu_id' => $item['receiver_account'],
|
||||
'huifu_id' => $receiverHuifuId,
|
||||
'div_amt' => $amt,
|
||||
];
|
||||
$allocated = bcadd($allocated, $amt, 2);
|
||||
}
|
||||
|
||||
$platformHuifuId = (new SplitConfig())->all()['platform_huifu_id'] ?? $this->config->get('huifu_id');
|
||||
$remain = bcsub($payFee, $allocated, 2);
|
||||
if (bccomp($remain, '0.00', 2) > 0) {
|
||||
$infos[] = [
|
||||
'huifu_id' => $platformHuifuId,
|
||||
'div_amt' => $remain,
|
||||
];
|
||||
$platformIsCollector = ($platformHuifuId === $paymentHuifuId);
|
||||
if (!$platformIsCollector) {
|
||||
$infos[] = [
|
||||
'huifu_id' => $platformHuifuId,
|
||||
'div_amt' => $remain,
|
||||
];
|
||||
} else {
|
||||
\think\Log::info('[shopro_huifu] split platform remainder stays on collector: remain=' . $remain
|
||||
. ' huifu_id=' . $paymentHuifuId);
|
||||
}
|
||||
}
|
||||
|
||||
$sum = '0.00';
|
||||
foreach ($infos as $info) {
|
||||
$sum = bcadd($sum, $info['div_amt'], 2);
|
||||
}
|
||||
if (bccomp($sum, $payFee, 2) !== 0) {
|
||||
throw new \RuntimeException('分账金额之和必须等于订单实付');
|
||||
if (empty($infos)) {
|
||||
throw new \RuntimeException('分账明细为空:无有效分账接收方(勿将主商户号作为分账方)');
|
||||
}
|
||||
if (bccomp($sum, $payFee, 2) > 0) {
|
||||
throw new \RuntimeException('分账金额之和不能超过待确认金额');
|
||||
}
|
||||
return $infos;
|
||||
}
|
||||
|
||||
在新工单中引用
屏蔽一个用户