This commit is contained in:
laodaming
2023-09-20 12:13:27 +08:00
parent 8768588a8f
commit 039137ce23
5 changed files with 41 additions and 22 deletions

View File

@@ -0,0 +1,21 @@
package shopping_cart
import (
"fusenapi/utils/step_price"
"math"
)
// 计算价格
func CaculateCartPrice(purchaseQuantity int64, stepPrice, stepNum []int, fittingPrice, eachBoxNum int64) (ItemPrice, totalPrice int64) {
//请求的数量
reqPurchaseQuantity := purchaseQuantity
//购买箱数
boxQuantity := int(math.Ceil(float64(reqPurchaseQuantity) / float64(eachBoxNum)))
//根据数量获取阶梯价格中对应的价格
itemPrice := step_price.GetCentStepPrice(boxQuantity, stepNum, stepPrice)
//如果有配件,单价也要加入配件价格
itemPrice += fittingPrice
//单个购物车总价
totalPrice = itemPrice * reqPurchaseQuantity
return itemPrice, totalPrice
}