- 修复CaculateSkuPrice四舍五入的bug
This commit is contained in:
@@ -211,16 +211,16 @@ func CaculateSkuPrice(unitPrice int, specQuality float32, specUnit string, skuNa
|
||||
return unitPrice
|
||||
}
|
||||
specQuality2 := RegularizeSkuQuality(specQuality, specUnit)
|
||||
price := int(math.Round(float64(unitPrice * specQuality2 / model.SpecialSpecQuality)))
|
||||
floatPrice := float64(unitPrice) * float64(specQuality2) / float64(model.SpecialSpecQuality)
|
||||
// if specQuality2 < 250 {
|
||||
// price = price * 110 / 100
|
||||
// floatPrice = floatPrice * 110 / 100
|
||||
// } else if specQuality2 < 500 {
|
||||
// price = price * 105 / 100
|
||||
// floatPrice = floatPrice * 105 / 100
|
||||
// }
|
||||
if price <= 0 {
|
||||
price = 1
|
||||
if floatPrice <= 1 {
|
||||
floatPrice = 1
|
||||
}
|
||||
return price
|
||||
return int(math.Round(floatPrice))
|
||||
}
|
||||
|
||||
// 计算SKU标准价格,CaculateSkuPrice的逆过程
|
||||
@@ -268,7 +268,7 @@ func CaculateSkuPriceFromVendor(vendorPrice, percentage, catPercentage int) int
|
||||
catPercentage = 100
|
||||
}
|
||||
percentage = percentage * catPercentage / 100
|
||||
price := int(math.Round(float64(vendorPrice * 100 / percentage)))
|
||||
price := int(math.Round(float64(vendorPrice) * 100 / float64(percentage)))
|
||||
if price < 0 {
|
||||
price = 0
|
||||
}
|
||||
|
||||
@@ -126,3 +126,41 @@ func TestCalcPolygonAreaAutonavi(t *testing.T) {
|
||||
}
|
||||
t.Log(strBuilder.String())
|
||||
}
|
||||
|
||||
func TestCaculateSkuPrice(t *testing.T) {
|
||||
type tTestInfo struct {
|
||||
DesiredPrice int
|
||||
UnitPrice int
|
||||
SpecQuality float32
|
||||
SpecUnit string
|
||||
Unit string
|
||||
}
|
||||
for _, v := range []*tTestInfo{
|
||||
&tTestInfo{
|
||||
DesiredPrice: 458,
|
||||
UnitPrice: 915,
|
||||
SpecQuality: 250,
|
||||
SpecUnit: "g",
|
||||
Unit: "份",
|
||||
},
|
||||
&tTestInfo{
|
||||
DesiredPrice: 123,
|
||||
UnitPrice: 123,
|
||||
SpecQuality: 888,
|
||||
SpecUnit: "g",
|
||||
Unit: "个",
|
||||
},
|
||||
&tTestInfo{
|
||||
DesiredPrice: 1,
|
||||
UnitPrice: 5,
|
||||
SpecQuality: 1,
|
||||
SpecUnit: "g",
|
||||
Unit: "份",
|
||||
},
|
||||
} {
|
||||
price := CaculateSkuPrice(v.UnitPrice, v.SpecQuality, v.SpecUnit, v.Unit)
|
||||
if price != v.DesiredPrice {
|
||||
t.Errorf("price:%d,desiredPrice:%d", price, v.DesiredPrice)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user