fix: 补齐渠道全量合计筛选导出及有效端目标遗漏
This commit is contained in:
@@ -30,6 +30,7 @@ type AnalyticsFilter struct {
|
||||
Sources, GameNames []string
|
||||
PromoteName string
|
||||
PromoteType *int
|
||||
HasRegister, HasPay *bool
|
||||
StartDate, EndDate *time.Time
|
||||
Begin, End, SortField string
|
||||
Ascending bool
|
||||
@@ -113,6 +114,12 @@ func analyticsValues(row *AnalyticsRow) error {
|
||||
return nil
|
||||
}
|
||||
func (uc *AnalyticsUsecase) List(ctx context.Context, kind AnalyticsKind, filter AnalyticsFilter, page, size int) (*AnalyticsPage, error) {
|
||||
return uc.list(ctx, kind, filter, page, size, false)
|
||||
}
|
||||
func (uc *AnalyticsUsecase) ListAll(ctx context.Context, kind AnalyticsKind, filter AnalyticsFilter) (*AnalyticsPage, error) {
|
||||
return uc.list(ctx, kind, filter, 1, 0, true)
|
||||
}
|
||||
func (uc *AnalyticsUsecase) list(ctx context.Context, kind AnalyticsKind, filter AnalyticsFilter, page, size int, all bool) (*AnalyticsPage, error) {
|
||||
actor, account, err := uc.accounts.actor(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -130,16 +137,23 @@ func (uc *AnalyticsUsecase) List(ctx context.Context, kind AnalyticsKind, filter
|
||||
filter.PromoteName = ""
|
||||
filter.PromoteType = nil
|
||||
}
|
||||
if filter.StartDate == nil || filter.EndDate == nil {
|
||||
if filter.EndDate == nil || kind == GameAnalytics && filter.StartDate == nil {
|
||||
now := uc.now().In(portraitLocation)
|
||||
day := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, portraitLocation)
|
||||
filter.StartDate = &day
|
||||
filter.EndDate = &day
|
||||
if kind == GameAnalytics && filter.StartDate == nil {
|
||||
filter.StartDate = &day
|
||||
}
|
||||
if filter.EndDate == nil {
|
||||
filter.EndDate = &day
|
||||
}
|
||||
}
|
||||
if filter.EndDate.Before(*filter.StartDate) {
|
||||
if filter.StartDate != nil && filter.EndDate.Before(*filter.StartDate) {
|
||||
return nil, ErrAnalyticsDateOrder
|
||||
}
|
||||
filter.Begin = filter.StartDate.Format("2006-01-02")
|
||||
filter.Begin = ""
|
||||
if filter.StartDate != nil {
|
||||
filter.Begin = filter.StartDate.Format("2006-01-02")
|
||||
}
|
||||
filter.End = filter.EndDate.Format("2006-01-02")
|
||||
out := &AnalyticsPage{Rows: []*AnalyticsRow{}, Begin: filter.Begin, End: filter.End, Available: true}
|
||||
scope := AnalyticsScope{Viewer: viewer, IncludeSub: pref.IncludeSubPromote, IDCardDedup: pref.IDCardDedup}
|
||||
@@ -221,6 +235,18 @@ func (uc *AnalyticsUsecase) List(ctx context.Context, kind AnalyticsKind, filter
|
||||
return nil, err
|
||||
}
|
||||
out.Total = int64(len(data.Rows))
|
||||
if all {
|
||||
if out.Total > 10000 {
|
||||
return nil, ErrLedgerExportLimit
|
||||
}
|
||||
out.Rows = data.Rows
|
||||
if !namesBeforeSort {
|
||||
if err := fillNames(out.Rows); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
if page < 1 {
|
||||
page = 1
|
||||
}
|
||||
@@ -243,7 +269,7 @@ func (uc *AnalyticsUsecase) List(ctx context.Context, kind AnalyticsKind, filter
|
||||
return out, nil
|
||||
}
|
||||
func sortAnalytics(rows []*AnalyticsRow, kind AnalyticsKind, field string, ascending bool) error {
|
||||
if kind == GameAnalytics && field == "" {
|
||||
if field == "" {
|
||||
sort.SliceStable(rows, func(i, j int) bool {
|
||||
if rows[i].SourceDB != rows[j].SourceDB {
|
||||
return rows[i].SourceDB < rows[j].SourceDB
|
||||
|
||||
@@ -81,6 +81,30 @@ func TestChannelAnalyticsSummaryDependsOnViewer(t *testing.T) {
|
||||
t.Fatal("超管应使用筛选范围内全局去重汇总")
|
||||
}
|
||||
}
|
||||
|
||||
func TestChannelAnalyticsAllPagesSummaryAndOpenDateRange(t *testing.T) {
|
||||
uc, repo := analyticsFixture()
|
||||
repo.data.EffectiveCount = 3
|
||||
for _, pageNum := range []int{1, 2, 8} {
|
||||
page, err := uc.List(accountContext(7, 901), ChannelAnalytics, AnalyticsFilter{}, pageNum, 1)
|
||||
if err != nil || page.Total != 2 || page.Summary.Counts.Register != 5 || page.Summary.Counts.Active != 10 || page.Summary.Counts.Pay != 3 || page.Summary.Counts.NewPay != 2 || page.Summary.Pay != "50.00" || page.Summary.PayRate != "30.00" || page.EffectiveCount != 3 {
|
||||
t.Fatalf("翻页不能改变完整合计: page=%d %+v %v", pageNum, page, err)
|
||||
}
|
||||
if page.Begin != "" || page.End != "2026-11-04" || repo.filter.StartDate != nil {
|
||||
t.Fatalf("渠道统计缺省应从最早数据统计至今天: %+v", repo.filter)
|
||||
}
|
||||
}
|
||||
for _, sample := range []struct {
|
||||
field string
|
||||
asc bool
|
||||
source string
|
||||
}{{"totalPay", true, "lx"}, {"totalPay", false, "hw"}, {"", false, "hw"}} {
|
||||
page, err := uc.List(accountContext(7, 901), ChannelAnalytics, AnalyticsFilter{SortField: sample.field, Ascending: sample.asc}, 1, 1)
|
||||
if err != nil || page.Rows[0].SourceDB != sample.source {
|
||||
t.Fatalf("取消排序应恢复稳定原始顺序: %+v %v", page, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
func TestAnalyticsSortAndMissingData(t *testing.T) {
|
||||
uc, r := analyticsFixture()
|
||||
r.data.Rows[0].Pay = "9007199254740993.00"
|
||||
|
||||
@@ -34,6 +34,8 @@ type ChannelKey struct {
|
||||
type Channel struct {
|
||||
ChannelKey
|
||||
Account, Nickname, ParentName, RealName string
|
||||
Phone string
|
||||
SettlementDays *int
|
||||
Level, RegisterType, Status, LockStatus *int
|
||||
ParentID, TopPromoteID, BusierID uint64
|
||||
BusierUserID *uint
|
||||
@@ -75,12 +77,21 @@ type ChannelFilter struct {
|
||||
Sources []string
|
||||
BusierUserID *uint
|
||||
BusierAccount, Keyword string
|
||||
Phone, SortField string
|
||||
SettlementDays *int
|
||||
CreatedBegin, CreatedEnd *time.Time
|
||||
LoginBegin, LoginEnd *time.Time
|
||||
Ascending bool
|
||||
Level, RegisterType, Status, LockStatus *int
|
||||
}
|
||||
type ChannelStatusCounts struct {
|
||||
Normal, Locked, Terminated int64
|
||||
}
|
||||
type ChannelPage struct {
|
||||
Rows []*Channel
|
||||
Total int64
|
||||
Available bool
|
||||
Rows []*Channel
|
||||
Total int64
|
||||
Available bool
|
||||
StatusCounts *ChannelStatusCounts
|
||||
}
|
||||
type ChannelPlayer struct {
|
||||
ChannelKey
|
||||
|
||||
Reference in New Issue
Block a user