diff --git a/internal/tools/bbxt/bbxt.go b/internal/tools/bbxt/bbxt.go index 3281325..7a03cce 100644 --- a/internal/tools/bbxt/bbxt.go +++ b/internal/tools/bbxt/bbxt.go @@ -403,10 +403,6 @@ func (b *BbxtTools) GetProfitRankingSum(now time.Time) (report *ReportRes, err e // GetStatisOfficialProductSum 销量同比分析 func (b *BbxtTools) GetStatisOfficialProductSum(now time.Time, productName []string) (report *ReportRes, err error) { - var productMap = make(map[string]int) - for k, v := range productName { - productMap[v] = k - } ct := []string{ time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location()).Format("2006-01-02 15:04:05"), adjustedTime(now), @@ -428,7 +424,11 @@ func (b *BbxtTools) GetStatisOfficialProductSum(now time.Time, productName []str if err != nil { return } - var total = make([][]string, 0) + + // 创建临时map存储产品数据 + productDataMap := make(map[string][]string) + var productNamesInResult []string + for _, v := range data.OfficialProductSum { var ( yeterDatyDiff string @@ -444,14 +444,28 @@ func (b *BbxtTools) GetStatisOfficialProductSum(now time.Time, productName []str } else { lastWeekDiff = fmt.Sprintf("%s↓%d", GreenStyle, v.HistoryTwoDiff) } - total = append(total, []string{ + + rowData := []string{ fmt.Sprintf("%s", v.OfficialProductName), fmt.Sprintf("%d", v.CurrentNum), fmt.Sprintf("%d", v.HistoryOneNum), yeterDatyDiff, fmt.Sprintf("%d", v.HistoryTwoNum), lastWeekDiff, - }) + } + + // 存储到map中,key为产品名 + productDataMap[v.OfficialProductName] = rowData + productNamesInResult = append(productNamesInResult, v.OfficialProductName) + } + + // 按照productName的顺序构建total + var total [][]string + + for _, name := range productName { + if rowData, exists := productDataMap[name]; exists { + total = append(total, rowData) + } } timeCh := now.Format("1月2日15点")