feat: 展示顺运宝观测规格 (#140)
This commit is contained in:
@@ -5,10 +5,12 @@ package service
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"cmautobuy/admin/model"
|
||||
"cmautobuy/admin/repository"
|
||||
"cmautobuy/admin/spec"
|
||||
)
|
||||
|
||||
// ShopeeProductView 是列表页一行要显示的全部内容,全部已经是字符串,
|
||||
@@ -215,8 +217,16 @@ type ShopeeProductDetail struct {
|
||||
CollectMsg string
|
||||
CanCollect bool
|
||||
|
||||
SKUs []ShopeeSpecView
|
||||
PendingCount int
|
||||
SKUs []ShopeeSpecView
|
||||
PendingCount int
|
||||
SybObservations []SybObservationView
|
||||
}
|
||||
|
||||
// SybObservationView 是详情页只读的顺运宝历史观测,不是正式 SKU。
|
||||
type SybObservationView struct {
|
||||
SpecRaw, PriceText, ImageURL, LastObservedAt string
|
||||
OrderCount, TotalQuantity int
|
||||
MatchedSKUID, Color, Size, MatchText string
|
||||
}
|
||||
|
||||
// GetShopeeProductDetail 读一个蝦皮商品的详情(商品信息 + 完整规格表)。
|
||||
@@ -287,5 +297,27 @@ func GetShopeeProductDetail(db *sql.DB, goodsID string) (*ShopeeProductDetail, e
|
||||
}
|
||||
d.SKUs = append(d.SKUs, row)
|
||||
}
|
||||
observations, err := repository.ListSybSpecObservations(db, goodsID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
formalByKey := map[string][]model.ShopeeSKU{}
|
||||
for _, sk := range skus {
|
||||
if key, keyErr := spec.SpecKey(sk.SpecRaw); keyErr == nil {
|
||||
formalByKey[key] = append(formalByKey[key], sk)
|
||||
}
|
||||
}
|
||||
for _, observation := range observations {
|
||||
view := SybObservationView{SpecRaw: observation.SpecRaw, PriceText: fmt.Sprintf("NT$%.2f", float64(observation.LatestPriceCent)/100), ImageURL: observation.LatestImageURL, OrderCount: observation.OrderCount, TotalQuantity: observation.TotalQuantity, LastObservedAt: formatLocalTime(observation.LastObservedAt), MatchText: "待目录补全"}
|
||||
if matches := formalByKey[observation.SpecKey]; len(matches) == 1 {
|
||||
view.MatchedSKUID = matches[0].SKUID
|
||||
view.Color = matches[0].Color
|
||||
view.Size = matches[0].Size
|
||||
view.MatchText = "唯一匹配"
|
||||
} else if len(matches) > 1 {
|
||||
view.MatchText = "多条匹配,待人工确认"
|
||||
}
|
||||
d.SybObservations = append(d.SybObservations, view)
|
||||
}
|
||||
return d, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user