fix
This commit is contained in:
@@ -109,8 +109,7 @@ func (l *GetTeamListLogic) GetTeamList(req *types.GetTeamListReq) (resp *types.G
|
||||
|
||||
// 7. 查询所有下级代理信息(不进行手机号过滤,因为需要模糊搜索)
|
||||
builder := l.svcCtx.AgentModel.SelectBuilder().
|
||||
Where(squirrel.Eq{"id": subordinateIds}).
|
||||
Where("del_state = ?", globalkey.DelStateNo)
|
||||
Where(squirrel.Eq{"id": subordinateIds})
|
||||
|
||||
allTeamMembers, err := l.svcCtx.AgentModel.FindAll(l.ctx, builder, "")
|
||||
if err != nil {
|
||||
@@ -207,10 +206,10 @@ func (l *GetTeamListLogic) calculateTeamStatistics(agentId string, subordinateId
|
||||
stats.TodayNewMembers = todayNewCount
|
||||
stats.MonthNewMembers = monthNewCount
|
||||
|
||||
// 统计团队总查询量(仅统计有返佣给当前用户的订单,通过agent_rebate表去重统计order_id)
|
||||
// 统计团队总查询量(仅统计有返佣给当前用户的订单,通过agent_rebate表去重统计order_id,排除已取消的记录 status=3)
|
||||
if len(subordinateIds) > 0 {
|
||||
rebateBuilder := l.svcCtx.AgentRebateModel.SelectBuilder().
|
||||
Where("agent_id = ? AND del_state = ?", agentId, globalkey.DelStateNo).
|
||||
Where("agent_id = ? AND del_state = ? AND status != ?", agentId, globalkey.DelStateNo, 3).
|
||||
Where("source_agent_id != ?", agentId). // 明确排除自己
|
||||
Where(squirrel.Eq{"source_agent_id": subordinateIds})
|
||||
|
||||
@@ -229,14 +228,15 @@ func (l *GetTeamListLogic) calculateTeamStatistics(agentId string, subordinateId
|
||||
stats.MonthPromotions = monthPromotions
|
||||
}
|
||||
|
||||
// 统计收益:只统计从下级获得的返佣(依靠团队得到的收益)
|
||||
// 统计收益:只统计从下级获得的返佣(依靠团队得到的收益,排除已取消的记录 status=3)
|
||||
// 返佣:从agent_rebate表统计(从下级获得的返佣)
|
||||
// agent_id = 当前代理ID(获得返佣的代理)
|
||||
// source_agent_id IN 下级ID列表(来源代理,即产生订单的下级代理)
|
||||
// 明确排除自己:source_agent_id != agentId(确保不统计自己的数据)
|
||||
// 排除已取消:status != 3(确保不统计已撤销的返佣)
|
||||
if len(subordinateIds) > 0 {
|
||||
rebateBuilder := l.svcCtx.AgentRebateModel.SelectBuilder().
|
||||
Where("agent_id = ? AND del_state = ?", agentId, globalkey.DelStateNo).
|
||||
Where("agent_id = ? AND del_state = ? AND status != ?", agentId, globalkey.DelStateNo, 3).
|
||||
Where("source_agent_id != ?", agentId). // 明确排除自己
|
||||
Where(squirrel.Eq{"source_agent_id": subordinateIds})
|
||||
totalRebate, _ := l.svcCtx.AgentRebateModel.FindSum(l.ctx, rebateBuilder, "rebate_amount")
|
||||
@@ -304,16 +304,16 @@ func (l *GetTeamListLogic) buildTeamMemberItem(agentId string, member *model.Age
|
||||
}
|
||||
}
|
||||
|
||||
// 统计查询量(仅统计有返佣给当前用户的订单,通过agent_rebate表去重统计order_id)
|
||||
// 统计查询量(仅统计有返佣给当前用户的订单,通过agent_rebate表去重统计order_id,排除已取消的记录 status=3)
|
||||
rebateBuilder := l.svcCtx.AgentRebateModel.SelectBuilder().
|
||||
Where("agent_id = ? AND source_agent_id = ? AND del_state = ?", agentId, member.Id, globalkey.DelStateNo)
|
||||
Where("agent_id = ? AND source_agent_id = ? AND del_state = ? AND status != ?", agentId, member.Id, globalkey.DelStateNo, 3)
|
||||
totalQueries := l.countDistinctOrdersForMember(l.ctx, rebateBuilder)
|
||||
todayRebateBuilder := rebateBuilder.Where("create_time >= ?", todayStart)
|
||||
todayQueries := l.countDistinctOrdersForMember(l.ctx, todayRebateBuilder)
|
||||
monthRebateBuilder := rebateBuilder.Where("create_time >= ?", monthStart)
|
||||
monthQueries := l.countDistinctOrdersForMember(l.ctx, monthRebateBuilder)
|
||||
|
||||
// 统计返佣给我的金额(从agent_rebate表,source_agent_id = member.Id, agent_id = agentId)
|
||||
// 统计返佣给我的金额(从agent_rebate表,source_agent_id = member.Id, agent_id = agentId,排除已取消的记录 status=3)
|
||||
totalRebateAmount, _ := l.svcCtx.AgentRebateModel.FindSum(l.ctx, rebateBuilder, "rebate_amount")
|
||||
todayRebateAmount, _ := l.svcCtx.AgentRebateModel.FindSum(l.ctx, rebateBuilder.Where("create_time >= ?", todayStart), "rebate_amount")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user