feat: 迁移渠道画像累计指标和玩家付费分层

This commit is contained in:
Yvan
2026-11-03 23:50:05 +08:00
parent 0de822f121
commit f5b7ce21b9
38 changed files with 1424 additions and 37 deletions
+25 -12
View File
@@ -97,6 +97,9 @@ func (r *businessPortraitRepo) PlatformBusiness(ctx context.Context, key busines
}
func portraitPromoteScope(db *gorm.DB, scope business.PortraitReportScope, sourceColumn, promoteColumn string) *gorm.DB {
if scope.Root != nil {
return channelGameTree(db, business.ChannelGameScope{Root: scope.Root, IncludeSub: scope.IncludeSub}).Select("1").Where("p.source_db = " + sourceColumn + " AND p.id = " + promoteColumn)
}
q := db.Table("tab_promote scope_promote").Select("1").Where("scope_promote.source_db = " + sourceColumn + " AND scope_promote.id = " + promoteColumn)
if len(scope.Pairs) == 0 {
return q.Where("1=0")
@@ -148,7 +151,7 @@ func toPortraitCounts(rows []portraitCountPO) business.PortraitCounts {
func (r *businessPortraitRepo) Statistics(ctx context.Context, scope business.PortraitReportScope) (*business.PortraitStatistics, error) {
result := &business.PortraitStatistics{CurrentPay: "0", PreviousPay: "0", RegisterSeries: map[string]string{}, PaySeries: map[string]string{}, RegisterRanks: []*business.PortraitStatRank{}, PayRanks: []*business.PortraitStatRank{}, Available: true}
if len(scope.Pairs) == 0 {
if len(scope.Pairs) == 0 && scope.Root == nil {
return result, nil
}
db := r.data.DB().WithContext(ctx)
@@ -172,11 +175,19 @@ func (r *businessPortraitRepo) Statistics(ctx context.Context, scope business.Po
}
begin, end := scope.Range.Begin.Format("2006-01-02"), scope.Range.End.Format("2006-01-02")
previousBegin, previousEnd := scope.Range.PreviousBegin.Format("2006-01-02"), scope.Range.PreviousEnd.Format("2006-01-02")
for _, period := range []struct {
periods := []struct {
begin, end string
counts *business.PortraitCounts
pay *string
}{{begin, end, &result.Current, &result.CurrentPay}, {previousBegin, previousEnd, &result.Previous, &result.PreviousPay}} {
}{{begin, end, &result.Current, &result.CurrentPay}}
if !scope.NoCompare {
periods = append(periods, struct {
begin, end string
counts *business.PortraitCounts
pay *string
}{previousBegin, previousEnd, &result.Previous, &result.PreviousPay})
}
for _, period := range periods {
var rows []portraitCountPO
q := portraitReportQuery(db, scope, "tab_sw_report_day_key", period.begin, period.end, mode)
if err := q.Select("r.metric,COUNT(DISTINCT " + portraitIdentity(db, scope.IDCardDedup) + ") AS count").Group("r.metric").Scan(&rows).Error; err != nil {
@@ -196,16 +207,18 @@ func (r *businessPortraitRepo) Statistics(ctx context.Context, scope business.Po
return nil, err
}
}
register, err := portraitRankQuery(db, scope, mode, begin, end, false)
if err != nil {
return nil, err
if scope.RankLimit > 0 {
register, err := portraitRankQuery(db, scope, mode, begin, end, false)
if err != nil {
return nil, err
}
result.RegisterRanks = register
pay, err := portraitRankQuery(db, scope, 0, begin, end, true)
if err != nil {
return nil, err
}
result.PayRanks = pay
}
result.RegisterRanks = register
pay, err := portraitRankQuery(db, scope, 0, begin, end, true)
if err != nil {
return nil, err
}
result.PayRanks = pay
return result, nil
}
func portraitDaily(db *gorm.DB, scope business.PortraitReportScope, mode int, begin, end string, result *business.PortraitStatistics) error {