fix: 按订单数汇总顺运宝颜色来源 (#293)

This commit is contained in:
chengma
2026-08-24 00:17:02 +08:00
parent a0f4e3c593
commit 8b761d7d05
+8 -5
View File
@@ -155,11 +155,14 @@ func collectProductColors(q repository.Execer, goodsID string) ([]ProductColorSo
formalCount, sybCount int formalCount, sybCount int
} }
byKey := map[string]*accumulator{} byKey := map[string]*accumulator{}
add := func(raw string, formal bool) { add := func(raw string, formal bool, count int) {
key := NormalizeProductColorKey(raw) key := NormalizeProductColorKey(raw)
if key == "" { if key == "" {
return return
} }
if count < 1 {
count = 1
}
item := byKey[key] item := byKey[key]
if item == nil { if item == nil {
item = &accumulator{raw: strings.TrimSpace(raw)} item = &accumulator{raw: strings.TrimSpace(raw)}
@@ -168,9 +171,9 @@ func collectProductColors(q repository.Execer, goodsID string) ([]ProductColorSo
item.raw = candidate item.raw = candidate
} }
if formal { if formal {
item.formalCount++ item.formalCount += count
} else { } else {
item.sybCount++ item.sybCount += count
} }
} }
skus, err := repository.ListShopeeSKUsByGoodsID(q, goodsID) skus, err := repository.ListShopeeSKUsByGoodsID(q, goodsID)
@@ -178,7 +181,7 @@ func collectProductColors(q repository.Execer, goodsID string) ([]ProductColorSo
return nil, err return nil, err
} }
for _, sku := range skus { for _, sku := range skus {
add(sku.Color, true) add(sku.Color, true, 1)
} }
observations, err := repository.ListSybSpecObservations(q, goodsID) observations, err := repository.ListSybSpecObservations(q, goodsID)
if err != nil { if err != nil {
@@ -186,7 +189,7 @@ func collectProductColors(q repository.Execer, goodsID string) ([]ProductColorSo
} }
for _, observation := range observations { for _, observation := range observations {
if parsed, ok := spec.ParseShopeeSpec(observation.SpecRaw); ok { if parsed, ok := spec.ParseShopeeSpec(observation.SpecRaw); ok {
add(parsed.Color, false) add(parsed.Color, false, observation.OrderCount)
} }
} }
result := make([]ProductColorSource, 0, len(byKey)) result := make([]ProductColorSource, 0, len(byKey))