Commit 2a5fcbf0 by 杨树贤

Merge branch 'ysx-tme重量需求-20250228' into dev

# Conflicts:
#	model/ly_sku.go
parents eacff7c5 1fc9cbab
Showing with 7 additions and 6 deletions
...@@ -154,10 +154,9 @@ type SpuExtra struct { ...@@ -154,10 +154,9 @@ type SpuExtra struct {
SpuId string `bson:"spu_id" json:"spu_id"` SpuId string `bson:"spu_id" json:"spu_id"`
Height string `json:"height" bson:"height"` Height string `json:"height" bson:"height"`
Weight string `json:"-" bson:"weight"` Weight string `json:"-" bson:"weight"`
TransformedWeight int `json:"weight"` TransformedWeight float64 `json:"weight"`
Width string `json:"width" bson:"width"` Width string `json:"width" bson:"width"`
Length string `json:"length" bson:"length"` Length string `json:"length" bson:"length"`
EnPdfUrl string `bson:"en_pdf_url" json:"en_pdf_url"`
} }
// 为什么不直接映射到结构,而要用gjson,因为redis存的数据结构不一定正常,可能类型不一致 // 为什么不直接映射到结构,而要用gjson,因为redis存的数据结构不一定正常,可能类型不一致
......
...@@ -627,7 +627,7 @@ func DivFloat(first float64, second float64) float64 { ...@@ -627,7 +627,7 @@ func DivFloat(first float64, second float64) float64 {
} }
// 将重量单位统一转换为克,同时清洗数据 // 将重量单位统一转换为克,同时清洗数据
func ConvertToGrams(input string) (int, error) { func ConvertToGrams(input string) (float64, error) {
// 清洗数据:去除左右空格,去除中间空格 // 清洗数据:去除左右空格,去除中间空格
input = strings.ReplaceAll(strings.TrimSpace(input), " ", "") input = strings.ReplaceAll(strings.TrimSpace(input), " ", "")
...@@ -654,11 +654,13 @@ func ConvertToGrams(input string) (int, error) { ...@@ -654,11 +654,13 @@ func ConvertToGrams(input string) (int, error) {
// 根据单位返回对应的克数 // 根据单位返回对应的克数
switch unit { switch unit {
case "kg", "千克": case "kg", "千克":
return int(num * 1000), nil return float64(num * 1000), nil
case "g", "克": case "g", "克":
return int(num), nil return float64(num), nil
case "t", "吨": case "t", "吨":
return int(num * 1000000), nil return float64(num * 1000000), nil
case "mg", "毫克":
return float64(num / 1000), nil
default: default:
return 0, fmt.Errorf("未知的重量单位: %s", unit) return 0, fmt.Errorf("未知的重量单位: %s", unit)
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment