fix
This commit is contained in:
@@ -1,20 +1,9 @@
|
||||
package step_price
|
||||
|
||||
// 返回美元
|
||||
func GetStepPrice(minBuyNum int, stepNum []int, stepPrice []int) float64 {
|
||||
if minBuyNum > stepNum[len(stepNum)-1] {
|
||||
return float64(stepPrice[len(stepPrice)-1]) / float64(1000)
|
||||
}
|
||||
for k, v := range stepNum {
|
||||
if minBuyNum <= v {
|
||||
if k <= (len(stepPrice) - 1) {
|
||||
return float64(stepPrice[k]) / float64(1000)
|
||||
}
|
||||
return float64(stepPrice[len(stepPrice)-1]) / float64(1000)
|
||||
}
|
||||
}
|
||||
return float64(stepPrice[len(stepPrice)-1]) / float64(1000)
|
||||
}
|
||||
import (
|
||||
"errors"
|
||||
"fusenapi/model/gmodel"
|
||||
)
|
||||
|
||||
// 返回厘
|
||||
func GetCentStepPrice(minBuyNum int, stepNum []int, stepPrice []int) int64 {
|
||||
@@ -31,3 +20,47 @@ func GetCentStepPrice(minBuyNum int, stepNum []int, stepPrice []int) int64 {
|
||||
}
|
||||
return int64(stepPrice[len(stepPrice)-1])
|
||||
}
|
||||
|
||||
// 新的阶梯价格(返回美元)
|
||||
func GetNewStepPrice(purchaseQuantity int64, stepPrice gmodel.StepPriceJsonStruct, fittingPrice int64) (price float64, err error) {
|
||||
l := len(stepPrice.PriceRange)
|
||||
if l == 0 {
|
||||
return 0, errors.New("price range is not set")
|
||||
}
|
||||
//遍历查询合适的价格
|
||||
for k, v := range stepPrice.PriceRange {
|
||||
//购买数量>起点
|
||||
if purchaseQuantity > v.StartQuantity {
|
||||
//最后一个 || 小于等于终点
|
||||
if k == l-1 || purchaseQuantity <= v.EndQuantity {
|
||||
return float64(v.Price+fittingPrice) / 1000, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
//遍历里面没有则返回第一个
|
||||
return float64(stepPrice.PriceRange[0].Price+fittingPrice) / 1000, nil
|
||||
}
|
||||
|
||||
// 新的阶梯价格(返回厘)
|
||||
func GetNewCentStepPrice(purchaseQuantity int64, stepPrice gmodel.StepPriceJsonStruct, fittingPrice int64) (price int64, err error) {
|
||||
l := len(stepPrice.PriceRange)
|
||||
if l == 0 {
|
||||
return 0, errors.New("price range is not set")
|
||||
}
|
||||
//遍历查询合适的价格
|
||||
for k, v := range stepPrice.PriceRange {
|
||||
//购买数量>起点
|
||||
if purchaseQuantity > v.StartQuantity {
|
||||
//最后一个
|
||||
if k == l-1 {
|
||||
return v.Price + fittingPrice, nil
|
||||
}
|
||||
//小于等于终点
|
||||
if purchaseQuantity <= v.EndQuantity {
|
||||
return v.Price + fittingPrice, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
//遍历里面没有则返回第一个
|
||||
return stepPrice.PriceRange[0].Price + fittingPrice, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user