fix: 优化官方产品统计数据处理逻辑

This commit is contained in:
renzhiyuan 2026-01-21 15:10:24 +08:00
parent 5c2d7176c7
commit c478e9f43d
2 changed files with 15 additions and 7 deletions

View File

@ -428,7 +428,7 @@ func (b *BbxtTools) GetStatisOfficialProductSum(now time.Time, productName []str
if err != nil {
return
}
var total = make([][]string, len(ids))
var total = make([][]string, 0)
for _, v := range data.OfficialProductSum {
var (
yeterDatyDiff string
@ -444,16 +444,16 @@ func (b *BbxtTools) GetStatisOfficialProductSum(now time.Time, productName []str
} else {
lastWeekDiff = fmt.Sprintf("%s↓%d", GreenStyle, v.HistoryTwoDiff)
}
total[productMap[v.OfficialProductName]] = []string{
total = append(total, []string{
fmt.Sprintf("%s", v.OfficialProductName),
fmt.Sprintf("%d", v.CurrentNum),
fmt.Sprintf("%d", v.HistoryOneNum),
yeterDatyDiff,
fmt.Sprintf("%d", v.HistoryTwoNum),
lastWeekDiff,
}
})
}
timeCh := now.Format("1月2日15点")
title := "截至" + timeCh + "销售同比分析"
//总量生成excel

View File

@ -79,14 +79,22 @@ func Test_GetStatisOfficialProductSumDecline(t *testing.T) {
}
func Test_GetStatisOfficialProductSum(t *testing.T) {
run()
configs := configConfig
o, err := NewBbxtTools(nil, lsxd.NewLogin(configs, utils.NewRdb(configConfig)))
if err != nil {
panic(err)
}
s := "官方--美团外卖红包5元,官方--美团外卖红包10元,官方--饿了么超级会员月卡,官方--网易云黑胶vip月卡,官方--喜马拉雅巅峰会员月卡,官方--芒果-PC季卡,官方--芒果-PC月卡,官方--芒果-PC周卡,官方--腾讯-周卡,官方--优酷周卡,官方--QQ音乐-绿钻月卡,官方--爱奇艺-周卡,官方--腾讯-月卡,官方--腾讯-季卡,官方--腾讯-年卡,官方--优酷月卡,官方--优酷季卡,官方--优酷年卡,官方--爱奇艺-月卡,官方--爱奇艺-季卡,官方--爱奇艺-年卡"
report, err := o.GetStatisOfficialProductSum(time.Now(), strings.Split(s, ","))
s := "官方--腾讯-周卡,官方--腾讯-月卡,官方--腾讯-季卡,官方--腾讯-年卡,官方--优酷周卡,官方--优酷月卡,官方--优酷季卡,官方--优酷年卡,官方--爱奇艺-周卡,官方--爱奇艺-月卡,官方--爱奇艺-季卡,官方--爱奇艺-年卡,官方--芒果-PC周卡,官方--芒果-PC月卡,官方--芒果-PC季卡,官方--美团外卖红包5元,官方--美团外卖红包10元,官方--QQ音乐-绿钻月卡,官方--饿了么超级会员月卡,官方--网易云黑胶vip月卡,官方--喜马拉雅巅峰会员月卡"
now := time.Now()
noon := time.Date(
now.Year(),
now.Month(),
now.Day(),
12, 0, 0, 0,
now.Location(),
)
report, err := o.GetStatisOfficialProductSum(noon, strings.Split(s, ","))
t.Log(report, err)