f ‘部分退款’
This commit is contained in:
@@ -58,8 +58,15 @@ func (l *GetAgentCommissionLogic) GetAgentCommission(req *types.GetCommissionReq
|
||||
if copyErr != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "获取代理佣金列表, %v", err)
|
||||
}
|
||||
// 显式设置 status 字段
|
||||
// 显式设置 status 字段和已退款金额
|
||||
commission.Status = agentCommissionModel.Status
|
||||
commission.RefundedAmount = agentCommissionModel.RefundedAmount
|
||||
// 计算净佣金金额(防御性处理,避免出现负数)
|
||||
netAmount := agentCommissionModel.Amount - agentCommissionModel.RefundedAmount
|
||||
if netAmount < 0 {
|
||||
netAmount = 0
|
||||
}
|
||||
commission.NetAmount = netAmount
|
||||
product, findProductErr := l.svcCtx.ProductModel.FindOne(l.ctx, agentCommissionModel.ProductId)
|
||||
if findProductErr != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "获取代理佣金列表, %v", err)
|
||||
|
||||
@@ -126,30 +126,36 @@ func calculateDirectPushReport(commissions []*model.AgentCommission, loc *time.L
|
||||
// 转换时区
|
||||
createTime := c.CreateTime
|
||||
|
||||
// 只统计非退款的佣金(status != 2)
|
||||
// 只统计未被全部退款的佣金
|
||||
if c.Status == 2 {
|
||||
continue
|
||||
}
|
||||
|
||||
// 统计净佣金:原始金额减去已退款金额
|
||||
netAmount := c.Amount - c.RefundedAmount
|
||||
if netAmount <= 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
// 统计总量
|
||||
report.TotalCommission += c.Amount
|
||||
report.TotalCommission += netAmount
|
||||
report.TotalReport++
|
||||
|
||||
// 近24小时(滚动周期)
|
||||
if createTime.After(todayStart) {
|
||||
report.Today.Commission += c.Amount
|
||||
report.Today.Commission += netAmount
|
||||
report.Today.Report++
|
||||
}
|
||||
|
||||
// 近7天(滚动周期)
|
||||
if createTime.After(last7dStart) {
|
||||
report.Last7D.Commission += c.Amount
|
||||
report.Last7D.Commission += netAmount
|
||||
report.Last7D.Report++
|
||||
}
|
||||
|
||||
// 近30天(滚动周期)
|
||||
if createTime.After(last30dStart) {
|
||||
report.Last30D.Commission += c.Amount
|
||||
report.Last30D.Commission += netAmount
|
||||
report.Last30D.Report++
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user