修复 UrsCheckWebhook 手续费计算问题,应该使用 URS 推广模块的手续费计算服务,而不是自己计算。
2025-06-22 19:18:45 - 2025-06-22 19:18:45
UrsCheckWebhook 在计算提现手续费时,使用了 TransferThirdPartyService::calculateWithdrawFee() 方法,但该方法没有传递用户上下文信息,导致 URS 推广模块的手续费监听器无法获取用户信息来计算正确的手续费率。
calculateWithdrawFee 方法没有传递用户ID等上下文信息UrsTransferFeeListener 需要用户ID来根据房屋等级和达人等级计算手续费率在 app/Module/Transfer/Services/TransferThirdPartyService.php 中:
calculateWithdrawFee 方法(向后兼容)calculateWithdrawFeeWithContext 方法,支持传递上下文信息原方法内部调用新方法,传递空数组作为上下文
/**
* 计算提现手续费(带上下文信息)
*
* @param int $thirdPartyAppId 三方应用ID
* @param string $amount 提现金额
* @param array $context 上下文信息(包含用户ID等,用于URS推广模块计算手续费率)
* @return TransferFeeDto
*/
public static function calculateWithdrawFeeWithContext(int $thirdPartyAppId, string $amount, array $context = []): TransferFeeDto
在 ThirdParty/Urs/Webhook/UrsCheckWebhook.php 中:
calculateWithdrawFee 调用改为 calculateWithdrawFeeWithContext传递农场用户ID作为上下文信息,让URS推广模块能够计算正确的手续费率
// 修改前
$feeDto = \App\Module\Transfer\Services\TransferThirdPartyService::calculateWithdrawFee(
$thirdPartyAppId,
$amount
);
// 修改后
$feeDto = \App\Module\Transfer\Services\TransferThirdPartyService::calculateWithdrawFeeWithContext(
$thirdPartyAppId,
$amount,
['user_id' => $farmUserId] // 传递农场用户ID
);
通过编写测试脚本验证修改效果:
不带用户上下文的手续费计算:
带用户上下文的手续费计算:
直接调用URS推广模块服务:
UrsCheckWebhook 调用 calculateWithdrawFeeWithContext 并传递用户IDTransferThirdPartyService 调用 TransferApp::calculateOutFee 并传递上下文TransferApp::calculateOutFee 调用 FeeService::calculateOutFeeFeeService 触发 FeeCalculatingEvent 事件UrsTransferFeeListener 监听到事件,获取用户IDcalculateWithdrawFee 的代码不受影响修复UrsCheckWebhook手续费计算问题
- 修改UrsCheckWebhook使用URS推广模块的手续费计算服务
- 在TransferThirdPartyService中添加calculateWithdrawFeeWithContext方法
- 传递用户ID上下文信息,让URS推广模块能够根据房屋等级和达人等级计算正确的手续费率
- 测试验证:不带上下文使用默认费率1%,带上下文使用URS推广模块费率4%