fix: limit channel report rows to the selected period

This commit is contained in:
Yvan
2026-11-05 14:45:58 +08:00
parent 22ba319f7f
commit dd02620b5e
2 changed files with 47 additions and 31 deletions
+2 -17
View File
@@ -216,23 +216,8 @@ func (r *analyticsRepo) Aggregate(ctx context.Context, kind business.AnalyticsKi
putAnalyticsCount(&rowFor(po).Counts, po.Metric, po.Count)
}
}
// Keep visible channels with no events in the selected period so that
// "no registration / no recharge" can find genuinely inactive channels.
if kind == business.ChannelAnalytics && len(f.GameNames) == 0 {
root := "p.id"
if scope.IncludeSub {
root = "CASE WHEN p.promote_level=1 THEN p.id WHEN p.top_promote_id>0 THEN p.top_promote_id ELSE p.id END"
}
var channels []analyticsAggPO
if err := analyticsPromotes(db, scope, f, "p").Select("DISTINCT p.source_db," + root + " AS entity_id").Scan(&channels).Error; err != nil {
return nil, business.ErrStorage
}
for _, po := range channels {
if po.ID != nil {
rowFor(po)
}
}
}
// Report rows come from facts in the selected period. Registration/payment
// filters narrow that same set; they must not add the entire channel catalog.
if kind == business.ChannelAnalytics && !scope.Viewer.All {
if err := filterAnalyticsRows(db, scope, f, rowMap); err != nil {
return nil, err