diff --git a/admin/service/color_mapping.go b/admin/service/color_mapping.go index c1a9096..cf6b700 100644 --- a/admin/service/color_mapping.go +++ b/admin/service/color_mapping.go @@ -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))