22 lines
693 B
Go
22 lines
693 B
Go
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
|
|
}
|