v1.1
This commit is contained in:
@@ -59,7 +59,7 @@ func (l *GetConversionRateLogic) GetConversionRate() (resp *types.ConversionRate
|
||||
}
|
||||
|
||||
// calculateSubordinateConversionRate 计算下级转化率(考虑历史关系)
|
||||
func (l *GetConversionRateLogic) calculateSubordinateConversionRate(parentAgentId int64) types.ConversionRateData {
|
||||
func (l *GetConversionRateLogic) calculateSubordinateConversionRate(parentAgentId string) types.ConversionRateData {
|
||||
// 使用Asia/Shanghai时区,与数据库保持一致
|
||||
loc, _ := time.LoadLocation("Asia/Shanghai")
|
||||
now := time.Now().In(loc)
|
||||
@@ -120,7 +120,7 @@ func (l *GetConversionRateLogic) calculateSubordinateConversionRate(parentAgentI
|
||||
|
||||
// calculateConversionRate 计算转化率
|
||||
// agentId > 0 时统计该代理的转化率,否则统计 subordinateIds 列表的转化率
|
||||
func (l *GetConversionRateLogic) calculateConversionRate(agentId int64, subordinateIds []int64) types.ConversionRateData {
|
||||
func (l *GetConversionRateLogic) calculateConversionRate(agentId string, subordinateIds []string) types.ConversionRateData {
|
||||
// 使用Asia/Shanghai时区,与数据库保持一致
|
||||
loc, _ := time.LoadLocation("Asia/Shanghai")
|
||||
now := time.Now().In(loc)
|
||||
@@ -182,13 +182,13 @@ func (l *GetConversionRateLogic) calculateConversionRate(agentId int64, subordin
|
||||
}
|
||||
|
||||
// calculatePeriodConversion 计算指定时间段的转化率数据
|
||||
func (l *GetConversionRateLogic) calculatePeriodConversion(agentId int64, subordinateIds []int64, periodLabel string, startTime, endTime time.Time) types.PeriodConversionData {
|
||||
func (l *GetConversionRateLogic) calculatePeriodConversion(agentId string, subordinateIds []string, periodLabel string, startTime, endTime time.Time) types.PeriodConversionData {
|
||||
// 构建 agent_order 查询条件
|
||||
agentOrderBuilder := l.svcCtx.AgentOrderModel.SelectBuilder().
|
||||
Where("del_state = ?", globalkey.DelStateNo).
|
||||
Where("create_time >= ? AND create_time < ?", startTime, endTime)
|
||||
|
||||
if agentId > 0 {
|
||||
if agentId != "" {
|
||||
// 统计我的转化率
|
||||
agentOrderBuilder = agentOrderBuilder.Where("agent_id = ?", agentId)
|
||||
} else if len(subordinateIds) > 0 {
|
||||
@@ -208,7 +208,7 @@ func (l *GetConversionRateLogic) calculatePeriodConversion(agentId int64, subord
|
||||
}
|
||||
|
||||
// 添加调试日志
|
||||
if agentId == 0 && len(subordinateIds) > 0 {
|
||||
if agentId == "" && len(subordinateIds) > 0 {
|
||||
l.Infof("calculatePeriodConversion: 统计下级转化率,periodLabel=%s, startTime=%v, endTime=%v, subordinateIds数量=%d",
|
||||
periodLabel, startTime, endTime, len(subordinateIds))
|
||||
}
|
||||
@@ -228,7 +228,7 @@ func (l *GetConversionRateLogic) calculatePeriodConversion(agentId int64, subord
|
||||
}
|
||||
|
||||
if len(agentOrders) == 0 {
|
||||
if agentId == 0 && len(subordinateIds) > 0 {
|
||||
if agentId == "" && len(subordinateIds) > 0 {
|
||||
l.Infof("calculatePeriodConversion: 未找到代理订单,periodLabel=%s, startTime=%v, endTime=%v",
|
||||
periodLabel, startTime, endTime)
|
||||
}
|
||||
@@ -245,7 +245,7 @@ func (l *GetConversionRateLogic) calculatePeriodConversion(agentId int64, subord
|
||||
l.Infof("calculatePeriodConversion: 找到代理订单数量=%d, periodLabel=%s", len(agentOrders), periodLabel)
|
||||
|
||||
// 收集订单ID
|
||||
orderIds := make([]int64, 0, len(agentOrders))
|
||||
orderIds := make([]string, 0, len(agentOrders))
|
||||
for _, ao := range agentOrders {
|
||||
orderIds = append(orderIds, ao.OrderId)
|
||||
}
|
||||
@@ -271,8 +271,8 @@ func (l *GetConversionRateLogic) calculatePeriodConversion(agentId int64, subord
|
||||
// 统计查询订单数、付费订单数、用户数和总金额
|
||||
var totalAmount float64
|
||||
paidOrderCount := 0
|
||||
queryUserSet := make(map[int64]bool)
|
||||
paidUserSet := make(map[int64]bool)
|
||||
queryUserSet := make(map[string]bool)
|
||||
paidUserSet := make(map[string]bool)
|
||||
|
||||
for _, order := range orders {
|
||||
// 查询用户数(所有订单的用户,去重)
|
||||
@@ -303,7 +303,7 @@ func (l *GetConversionRateLogic) calculatePeriodConversion(agentId int64, subord
|
||||
// 结合使用agent_rebate表和agent_order表:
|
||||
// 1. 查询量:通过agent_order表统计所有查询(包括未付费的)
|
||||
// 2. 付费量和金额:通过agent_rebate表统计(只有付费的订单才会产生返佣)
|
||||
func (l *GetConversionRateLogic) calculateSubordinatePeriodConversion(parentAgentId int64, periodLabel string, startTime, endTime time.Time) types.PeriodConversionData {
|
||||
func (l *GetConversionRateLogic) calculateSubordinatePeriodConversion(parentAgentId string, periodLabel string, startTime, endTime time.Time) types.PeriodConversionData {
|
||||
// 1. 查询agent_rebate表:获取所有曾经给当前用户产生返佣的source_agent_id(这些代理在某个时间点是下级)
|
||||
// 不限制时间,获取所有历史返佣记录,用于确定哪些代理曾经是下级
|
||||
rebateBuilder := l.svcCtx.AgentRebateModel.SelectBuilder().
|
||||
@@ -324,9 +324,9 @@ func (l *GetConversionRateLogic) calculateSubordinatePeriodConversion(parentAgen
|
||||
}
|
||||
|
||||
// 收集所有曾经产生返佣的source_agent_id(这些代理在某个时间点是下级)
|
||||
sourceAgentIdSet := make(map[int64]bool)
|
||||
paidOrderIdSet := make(map[int64]bool) // 已付费的订单ID(有返佣的订单)
|
||||
paidOrderIdToAmount := make(map[int64]float64) // 已付费订单的金额
|
||||
sourceAgentIdSet := make(map[string]bool)
|
||||
paidOrderIdSet := make(map[string]bool) // 已付费的订单ID(有返佣的订单)
|
||||
paidOrderIdToAmount := make(map[string]float64) // 已付费订单的金额
|
||||
|
||||
for _, rebate := range allRebates {
|
||||
sourceAgentIdSet[rebate.SourceAgentId] = true
|
||||
@@ -351,7 +351,7 @@ func (l *GetConversionRateLogic) calculateSubordinatePeriodConversion(parentAgen
|
||||
}
|
||||
}
|
||||
|
||||
sourceAgentIds := make([]int64, 0, len(sourceAgentIdSet))
|
||||
sourceAgentIds := make([]string, 0, len(sourceAgentIdSet))
|
||||
for agentId := range sourceAgentIdSet {
|
||||
sourceAgentIds = append(sourceAgentIds, agentId)
|
||||
}
|
||||
@@ -391,8 +391,8 @@ func (l *GetConversionRateLogic) calculateSubordinatePeriodConversion(parentAgen
|
||||
}
|
||||
|
||||
// 3. 通过order_id去重,获取所有订单ID(用于查询订单详情)
|
||||
orderIdSet := make(map[int64]bool)
|
||||
orderIdToAgentOrder := make(map[int64]*model.AgentOrder)
|
||||
orderIdSet := make(map[string]bool)
|
||||
orderIdToAgentOrder := make(map[string]*model.AgentOrder)
|
||||
|
||||
for _, ao := range agentOrders {
|
||||
orderIdSet[ao.OrderId] = true
|
||||
@@ -406,7 +406,7 @@ func (l *GetConversionRateLogic) calculateSubordinatePeriodConversion(parentAgen
|
||||
}
|
||||
}
|
||||
|
||||
orderIds := make([]int64, 0, len(orderIdSet))
|
||||
orderIds := make([]string, 0, len(orderIdSet))
|
||||
for orderId := range orderIdSet {
|
||||
orderIds = append(orderIds, orderId)
|
||||
}
|
||||
@@ -459,8 +459,8 @@ func (l *GetConversionRateLogic) calculateSubordinatePeriodConversion(parentAgen
|
||||
// 6. 统计查询订单数、付费订单数、用户数和总金额
|
||||
var totalAmount float64
|
||||
paidOrderCount := 0
|
||||
queryUserSet := make(map[int64]bool)
|
||||
paidUserSet := make(map[int64]bool)
|
||||
queryUserSet := make(map[string]bool)
|
||||
paidUserSet := make(map[string]bool)
|
||||
|
||||
for _, order := range orders {
|
||||
// 查询用户数(所有订单的用户,去重)
|
||||
|
||||
Reference in New Issue
Block a user