文件
xionggeshop/addons/shopro_huifu/library/onboard/HuifuOnboardReceiverSync.php
可乐加冰 e946a357c1 ```
feat(shopro_huifu): 添加分账配置提交功能和接收方绑定机制

- 实现 shouldDeferWalletUntilGatewaySplitResolves 方法,确保分销/区域结算事件早于
  split_timing 时等待分账结束再入钱包
- 新增 SyncSplitReceivers 命令用于提交商户分账配置并绑定已审核通过的汇付号为分账接收方
- 扩展 HuifuClient 添加 submitMerchantSplitConfig 接口实现 v2/merchant/split/config 调用
- 创建 HuifuMerchantSplitService 处理主商户分账配置提交和进件子户绑定为分账接收方逻辑
- 在进件成功后自动调用 split/config 接口绑定分账接收方
- 添加数据库表结构升级脚本,增加分账绑定状态相关字段
- 注册新的命令行工具到应用配置中
```
2026-10-13 10:04:10 +08:00

92 行
3.0 KiB
PHP

<?php
namespace addons\shopro_huifu\library\onboard;
use addons\shopro\model\split\Receiver;
use addons\shopro_huifu\model\Onboard;
use think\Db;
class HuifuOnboardReceiverSync
{
public static function sync(Onboard $row)
{
if ($row['onboard_status'] !== Onboard::STATUS_APPROVED || empty($row['huifu_id'])) {
return false;
}
$roleId = $row['user_id'];
if ($row['role_type'] === 'regional_agent') {
$roleId = $row['user_id'];
}
$payload = json_decode($row['payload'] ?? '', true);
$name = '用户' . $roleId;
if (is_array($payload)) {
if (($payload['account_type'] ?? 'indv') === 'ent' && !empty($payload['reg_name'])) {
$name = $payload['reg_name'];
} elseif (!empty($payload['name'])) {
$name = $payload['name'];
}
}
$existing = Receiver::where('role_type', $row['role_type'])
->where('role_id', $roleId)
->where('channel', 'huifu')
->find();
$now = time();
if ($existing) {
$existing->receiver_type = 'HUIFU_ID';
$existing->receiver_account = $row['huifu_id'];
$existing->receiver_name = $name;
$existing->status = 'normal';
$existing->updatetime = $now;
$existing->save();
self::bindHuifuSplitReceiver($row);
return $existing;
}
$created = Receiver::create([
'role_type' => $row['role_type'],
'role_id' => $roleId,
'channel' => 'huifu',
'receiver_type' => 'HUIFU_ID',
'receiver_account' => $row['huifu_id'],
'receiver_name' => $name,
'relation_type' => 'USER',
'wx_status' => 0,
'status' => 'normal',
'createtime' => $now,
'updatetime' => $now,
]);
self::bindHuifuSplitReceiver($row);
return $created;
}
/**
* 进件通过后向汇付主商户提交 split/config,绑定子户为分账接收方
*/
protected static function bindHuifuSplitReceiver(Onboard $row)
{
if (!class_exists('\\addons\\shopro_huifu\\library\\split\\HuifuMerchantSplitService')) {
return;
}
try {
(new \addons\shopro_huifu\library\split\HuifuMerchantSplitService())->bindOnboardReceiver($row);
} catch (\Throwable $e) {
\think\Log::error('[shopro_huifu] onboard split bind: ' . $e->getMessage());
}
}
public static function bindOnboardId($roleType, $roleRefId, $onboardId)
{
if ($roleType === 'promoter') {
Db::name('shopro_commission_agent')->where('user_id', $roleRefId)->update(['huifu_onboard_id' => $onboardId]);
return;
}
if ($roleType === 'regional_agent') {
Db::name('shopro_regional_agent')->where('id', $roleRefId)->update(['huifu_onboard_id' => $onboardId]);
}
}
}