Commit 07e7e857 by 杨树贤

支持浮点数

parent a68834bb
Showing with 8 additions and 7 deletions
...@@ -154,7 +154,7 @@ type SpuExtra struct { ...@@ -154,7 +154,7 @@ 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"`
} }
......
...@@ -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,12 +654,14 @@ func ConvertToGrams(input string) (int, error) { ...@@ -654,12 +654,14 @@ 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)
} }
} }
\ No newline at end of file
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