11
This commit is contained in:
21
utils/shopping_cart/caculate_cart_price.go
Normal file
21
utils/shopping_cart/caculate_cart_price.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user