新功能: withdrawal_log 接口加 summary 字段 + admin 禁直接扣减 commission

接口侧:
- /v1/public/user/withdrawal_log 响应新增 summary 字段, 包含:
  - commission_balance (当前余额)
  - locked_by_pending (待审批占用)
  - available_to_withdraw (可提现)
  - total_historical_amount (已通过提现总额)
  - total_refunded_amount (退款回扣总额)
  - total_income_amount (收入总额)
- 前端可据此自洽展示账目对账, 用户能在一个接口里看清整笔账

代码守护:
- updateUserBasicInfoLogic 拒绝任何 change<0 的 commission 修改
- 扣减必须走 approveWithdrawal 写 type=334 日志
- 防止未来 admin 误操作再次造成 user.commission 与 system_logs 失衡

时间戳修复:
- queryWithdrawalLogLogic 和 queryCommissionReturnLogLogic 的时间戳
  从 UnixMilli 改回 Unix (秒级), 符合项目"后端统一秒级"约定

测试:
- 补 buildSummary 的 4 个 mock 查询期望
- 加 summary 字段值正确性断言
This commit is contained in:
2026-06-12 19:49:03 -07:00
parent 077dba3d98
commit be09a115ec
6 changed files with 123 additions and 12 deletions
@@ -110,6 +110,16 @@ func (l *UpdateUserBasicInfoLogic) UpdateUserBasicInfo(req *types.UpdateUserBasi
return errors.Wrapf(xerr.NewErrCode(xerr.InvalidAccess), "commission overwrite is blocked in withdrawal scene")
}
change := *req.Commission - userInfo.Commission
if change < 0 {
// 禁止直接扣减佣金:扣减必须走 approveWithdrawal 写 type=334 日志,
// 否则 user.commission 和 system_logs 会再次失衡,破坏账目闭环。
l.Logger.Errorw("blocked direct commission deduction via admin update",
logger.Field("user_id", userInfo.Id),
logger.Field("change", change),
)
return errors.Wrapf(xerr.NewErrCode(xerr.InvalidAccess),
"commission deduction must go through withdrawal approval, not direct edit")
}
if err = l.svcCtx.UserModel.UpdateCommission(l.ctx, userInfo.Id, change, tx); err != nil {
return err
}