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
}
byKey := map[string]*accumulator{}
add := func(raw string, formal bool) {
add := func(raw string, formal bool, count int) {
key := NormalizeProductColorKey(raw)
if key == "" {
return
}
if count < 1 {
count = 1
}
item := byKey[key]
if item == nil {
item = &accumulator{raw: strings.TrimSpace(raw)}
@@ -168,9 +171,9 @@ func collectProductColors(q repository.Execer, goodsID string) ([]ProductColorSo
item.raw = candidate
}
if formal {
item.formalCount++
item.formalCount += count
} else {
item.sybCount++
item.sybCount += count
}
}
skus, err := repository.ListShopeeSKUsByGoodsID(q, goodsID)
@@ -178,7 +181,7 @@ func collectProductColors(q repository.Execer, goodsID string) ([]ProductColorSo
return nil, err
}
for _, sku := range skus {
add(sku.Color, true)
add(sku.Color, true, 1)
}
observations, err := repository.ListSybSpecObservations(q, goodsID)
if err != nil {
@@ -186,7 +189,7 @@ func collectProductColors(q repository.Execer, goodsID string) ([]ProductColorSo
}
for _, observation := range observations {
if parsed, ok := spec.ParseShopeeSpec(observation.SpecRaw); ok {
add(parsed.Color, false)
add(parsed.Color, false, observation.OrderCount)
}
}
result := make([]ProductColorSource, 0, len(byKey))