This commit is contained in:
laodaming
2023-09-26 11:40:27 +08:00
parent 47a1ecfc79
commit 01cc115a60
8 changed files with 143 additions and 82 deletions

View File

@@ -5,7 +5,7 @@ import (
"fusenapi/model/gmodel"
)
// 返回厘
// 旧的返回厘(即将废弃)
func GetCentStepPrice(minBuyNum int, stepNum []int, stepPrice []int) int64 {
if minBuyNum > stepNum[len(stepNum)-1] {
return int64(stepPrice[len(stepPrice)-1])
@@ -22,10 +22,10 @@ func GetCentStepPrice(minBuyNum int, stepNum []int, stepPrice []int) int64 {
}
// 新的阶梯价格(返回美元)
func GetNewStepPrice(purchaseQuantity int64, stepPrice gmodel.StepPriceJsonStruct, fittingPrice int64) (price float64, err error) {
func GetNewStepPrice(purchaseQuantity int64, stepPrice gmodel.StepPriceJsonStruct, fittingPrice int64) (totalPrice, itemPrice float64, err error) {
l := len(stepPrice.PriceRange)
if l == 0 {
return 0, errors.New("price range is not set")
return 0, 0, errors.New("price range is not set")
}
//遍历查询合适的价格
for k, v := range stepPrice.PriceRange {
@@ -33,34 +33,34 @@ func GetNewStepPrice(purchaseQuantity int64, stepPrice gmodel.StepPriceJsonStruc
if purchaseQuantity > v.StartQuantity {
//最后一个 || 小于等于终点
if k == l-1 || purchaseQuantity <= v.EndQuantity {
return float64(v.Price+fittingPrice) / 1000, nil
itemPrice = float64(v.Price+fittingPrice) / 1000
return itemPrice * float64(purchaseQuantity), itemPrice / 1000, nil
}
}
}
//遍历里面没有则返回第一个
return float64(stepPrice.PriceRange[0].Price+fittingPrice) / 1000, nil
itemPrice = float64(stepPrice.PriceRange[0].Price+fittingPrice) / 1000
return itemPrice * float64(purchaseQuantity), itemPrice, nil
}
// 新的阶梯价格(返回厘)
func GetNewCentStepPrice(purchaseQuantity int64, stepPrice gmodel.StepPriceJsonStruct, fittingPrice int64) (price int64, err error) {
func GetNewCentStepPrice(purchaseQuantity int64, stepPrice gmodel.StepPriceJsonStruct, fittingPrice int64) (totalPrice, itemPrice int64, err error) {
l := len(stepPrice.PriceRange)
if l == 0 {
return 0, errors.New("price range is not set")
return 0, 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
//最后一个 || 小于等于终点
if k == l-1 || purchaseQuantity <= v.EndQuantity {
itemPrice = v.Price + fittingPrice
return itemPrice * purchaseQuantity, itemPrice, nil
}
}
}
//遍历里面没有则返回第一个
return stepPrice.PriceRange[0].Price + fittingPrice, nil
itemPrice = stepPrice.PriceRange[0].Price + fittingPrice
return itemPrice * purchaseQuantity, itemPrice, nil
}