11
This commit is contained in:
parent
8768588a8f
commit
039137ce23
|
@ -9,9 +9,8 @@ import (
|
|||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
"fusenapi/utils/format"
|
||||
"fusenapi/utils/step_price"
|
||||
"fusenapi/utils/shopping_cart"
|
||||
"gorm.io/gorm"
|
||||
"math"
|
||||
"strings"
|
||||
|
||||
"fusenapi/server/shopping-cart/internal/svc"
|
||||
|
@ -133,20 +132,17 @@ func (l *CalculateCartPriceLogic) CalculateCartPrice(req *types.CalculateCartPri
|
|||
if mapCalculateQuantity[cart.Id].IsSelected {
|
||||
isSelected = 1
|
||||
}
|
||||
//购买箱数
|
||||
boxQuantity := int(math.Ceil(float64(reqPurchaseQuantity) / float64(*sizePrice.EachBoxNum)))
|
||||
//根据数量获取阶梯价格中对应的价格
|
||||
itemPrice := step_price.GetCentStepPrice(boxQuantity, stepNum, stepPrice)
|
||||
//如果有配件,单价也要加入配件价格
|
||||
fittingPrice := int64(0)
|
||||
if *cart.FittingId > 0 {
|
||||
if fittingPrice, ok := mapFitting[*cart.FittingId]; ok {
|
||||
itemPrice += fittingPrice
|
||||
if fPrice, ok := mapFitting[*cart.FittingId]; ok {
|
||||
fittingPrice = fPrice
|
||||
} else {
|
||||
return errors.New(fmt.Sprintf("cart contain some one witch lose fitting:%d", *cart.FittingId))
|
||||
}
|
||||
}
|
||||
//单个购物车总价
|
||||
totalPrice := itemPrice * reqPurchaseQuantity
|
||||
//计算价格
|
||||
itemPrice, totalPrice := shopping_cart.CaculateCartPrice(reqPurchaseQuantity, stepPrice, stepNum, fittingPrice, *sizePrice.EachBoxNum)
|
||||
calculateResultList = append(calculateResultList, types.CalculateResultItem{
|
||||
CartId: cart.Id,
|
||||
ItemPrice: fmt.Sprintf("%.3f", format.CentitoDollar(itemPrice)),
|
||||
|
|
|
@ -12,7 +12,6 @@ import (
|
|||
"fusenapi/utils/format"
|
||||
"fusenapi/utils/s3url_to_s3id"
|
||||
"fusenapi/utils/shopping_cart"
|
||||
"fusenapi/utils/step_price"
|
||||
"math"
|
||||
"strings"
|
||||
|
||||
|
@ -133,8 +132,17 @@ func (l *GetCartsLogic) GetCarts(req *types.GetCartsReq, userinfo *auth.UserInfo
|
|||
if lenStepPrice == 0 || lenStepNum == 0 {
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, fmt.Sprintf("step price or step number is not set:%d_%d ", *cart.ProductId, *cart.SizeId))
|
||||
}
|
||||
//购买箱数
|
||||
boxQuantity := int(math.Ceil(float64(*cart.PurchaseQuantity) / float64(*sizePrice.EachBoxNum)))
|
||||
//如果有配件,单价也要加入配件价格
|
||||
fittingPrice := int64(0)
|
||||
if *cart.FittingId > 0 {
|
||||
if curFittingInfo, ok := mapModel[*cart.FittingId]; ok {
|
||||
fittingPrice = *curFittingInfo.Price
|
||||
} else {
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, fmt.Sprintf("cart contain some one witch lose fitting:%d", *cart.FittingId))
|
||||
}
|
||||
}
|
||||
//计算价格
|
||||
itemPrice, totalPrice := shopping_cart.CaculateCartPrice(*cart.PurchaseQuantity, stepPrice, stepNum, fittingPrice, *sizePrice.EachBoxNum)
|
||||
//获取阶梯数量
|
||||
stepQuantityList := make([]int64, 0, 20)
|
||||
tmpMinBuyNum := *sizePrice.MinBuyNum
|
||||
|
@ -148,19 +156,10 @@ func (l *GetCartsLogic) GetCarts(req *types.GetCartsReq, userinfo *auth.UserInfo
|
|||
if sizeInfo, ok := mapSize[*cart.SizeId]; ok {
|
||||
sizeCapacity = *sizeInfo.Capacity
|
||||
}
|
||||
//根据数量获取阶梯价格中对应的价格
|
||||
itemPrice := step_price.GetCentStepPrice(boxQuantity, stepNum, stepPrice)
|
||||
//如果有配件,单价也要加入配件价格
|
||||
if *cart.FittingId > 0 {
|
||||
if curFittingInfo, ok := mapModel[*cart.FittingId]; ok {
|
||||
itemPrice += *curFittingInfo.Price
|
||||
}
|
||||
}
|
||||
fittingName := snapShot.FittingInfo.FittingName
|
||||
if fittingInfo, ok := mapModel[*cart.FittingId]; ok {
|
||||
fittingName = *fittingInfo.Name
|
||||
}
|
||||
totalPrice := itemPrice * (*cart.PurchaseQuantity)
|
||||
productCover := "" //产品封面图
|
||||
productName := snapShot.ProductInfo.ProductName
|
||||
productSn := snapShot.ProductInfo.ProductSn
|
||||
|
@ -174,6 +173,7 @@ func (l *GetCartsLogic) GetCarts(req *types.GetCartsReq, userinfo *auth.UserInfo
|
|||
}
|
||||
}
|
||||
item := types.CartItem{
|
||||
CartId: cart.Id,
|
||||
ProductInfo: types.ProductInfo{
|
||||
ProductId: *cart.ProductId,
|
||||
ProductName: productName,
|
||||
|
|
|
@ -39,6 +39,7 @@ type GetCartsRsp struct {
|
|||
}
|
||||
|
||||
type CartItem struct {
|
||||
CartId int64 `json:"cart_id"`
|
||||
ProductInfo ProductInfo `json:"product_info"` //产品信息
|
||||
SizeInfo SizeInfo `json:"size_info"` //尺寸信息
|
||||
FittingInfo FittingInfo `json:"fitting_info"` //配件信息
|
||||
|
|
|
@ -56,6 +56,7 @@ type GetCartsRsp {
|
|||
CartList []CartItem `json:"cart_list"`
|
||||
}
|
||||
type CartItem {
|
||||
CartId int64 `json:"cart_id"`
|
||||
ProductInfo ProductInfo `json:"product_info"` //产品信息
|
||||
SizeInfo SizeInfo `json:"size_info"` //尺寸信息
|
||||
FittingInfo FittingInfo `json:"fitting_info"` //配件信息
|
||||
|
|
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
|
||||
}
|
Loading…
Reference in New Issue
Block a user