11
This commit is contained in:
@@ -6,15 +6,13 @@ import (
|
||||
"fmt"
|
||||
"fusenapi/constants"
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/server/shopping-cart/internal/svc"
|
||||
"fusenapi/server/shopping-cart/internal/types"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
"fusenapi/utils/format"
|
||||
"fusenapi/utils/shopping_cart"
|
||||
"gorm.io/gorm"
|
||||
"strings"
|
||||
|
||||
"fusenapi/server/shopping-cart/internal/svc"
|
||||
"fusenapi/server/shopping-cart/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
@@ -109,23 +107,6 @@ func (l *CalculateCartPriceLogic) CalculateCartPrice(req *types.CalculateCartPri
|
||||
if !ok {
|
||||
return errors.New(fmt.Sprintf("there carts contain some one which have no price info:%d_%d", *cart.ProductId, *cart.SizeId))
|
||||
}
|
||||
//阶梯数量切片
|
||||
stepNum, err := format.StrSlicToIntSlice(strings.Split(*sizePrice.StepNum, ","))
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return errors.New(fmt.Sprintf("failed to parse step number:%d_%d", *cart.ProductId, *cart.SizeId))
|
||||
}
|
||||
lenStepNum := len(stepNum)
|
||||
//阶梯价格切片
|
||||
stepPrice, err := format.StrSlicToIntSlice(strings.Split(*sizePrice.StepPrice, ","))
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return errors.New(fmt.Sprintf("failed to parse step price:%d_%d", *cart.ProductId, *cart.SizeId))
|
||||
}
|
||||
lenStepPrice := len(stepPrice)
|
||||
if lenStepPrice == 0 || lenStepNum == 0 {
|
||||
return errors.New(fmt.Sprintf("step price or step number is not set:%d_%d", *cart.ProductId, *cart.SizeId))
|
||||
}
|
||||
//请求的数量
|
||||
reqPurchaseQuantity := mapCalculateQuantity[cart.Id].PurchaseQuantity
|
||||
isSelected := int64(0)
|
||||
@@ -142,7 +123,11 @@ func (l *CalculateCartPriceLogic) CalculateCartPrice(req *types.CalculateCartPri
|
||||
}
|
||||
}
|
||||
//计算价格
|
||||
itemPrice, totalPrice := shopping_cart.CaculateCartPrice(reqPurchaseQuantity, stepPrice, stepNum, fittingPrice, *sizePrice.EachBoxNum)
|
||||
itemPrice, totalPrice, _, _, err := shopping_cart.CaculateCartPrice(reqPurchaseQuantity, &sizePrice, fittingPrice)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return err
|
||||
}
|
||||
calculateResultList = append(calculateResultList, types.CalculateResultItem{
|
||||
CartId: cart.Id,
|
||||
ItemPrice: fmt.Sprintf("%.3f", format.CentitoDollar(itemPrice)),
|
||||
|
||||
@@ -7,16 +7,14 @@ import (
|
||||
"fmt"
|
||||
"fusenapi/constants"
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/server/shopping-cart/internal/svc"
|
||||
"fusenapi/server/shopping-cart/internal/types"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
"fusenapi/utils/format"
|
||||
"fusenapi/utils/s3url_to_s3id"
|
||||
"fusenapi/utils/shopping_cart"
|
||||
"math"
|
||||
"strings"
|
||||
|
||||
"fusenapi/server/shopping-cart/internal/svc"
|
||||
"fusenapi/server/shopping-cart/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
@@ -115,23 +113,6 @@ func (l *GetCartsLogic) GetCarts(req *types.GetCartsReq, userinfo *auth.UserInfo
|
||||
if !ok {
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, fmt.Sprintf("the size`s price info is not exists:%d_%d", *cart.ProductId, *cart.SizeId))
|
||||
}
|
||||
//阶梯数量切片
|
||||
stepNum, err := format.StrSlicToIntSlice(strings.Split(*sizePrice.StepNum, ","))
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, fmt.Sprintf("failed to parse step number:%d_%d", *cart.ProductId, *cart.SizeId))
|
||||
}
|
||||
lenStepNum := len(stepNum)
|
||||
//阶梯价格切片
|
||||
stepPrice, err := format.StrSlicToIntSlice(strings.Split(*sizePrice.StepPrice, ","))
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, fmt.Sprintf("failed to parse step price:%d_%d", *cart.ProductId, *cart.SizeId))
|
||||
}
|
||||
lenStepPrice := len(stepPrice)
|
||||
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))
|
||||
}
|
||||
//如果有配件,单价也要加入配件价格
|
||||
fittingPrice := int64(0)
|
||||
if *cart.FittingId > 0 {
|
||||
@@ -142,11 +123,15 @@ func (l *GetCartsLogic) GetCarts(req *types.GetCartsReq, userinfo *auth.UserInfo
|
||||
}
|
||||
}
|
||||
//计算价格
|
||||
itemPrice, totalPrice := shopping_cart.CaculateCartPrice(*cart.PurchaseQuantity, stepPrice, stepNum, fittingPrice, *sizePrice.EachBoxNum)
|
||||
itemPrice, totalPrice, stepNum, _, err := shopping_cart.CaculateCartPrice(*cart.PurchaseQuantity, &sizePrice, fittingPrice)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, err.Error())
|
||||
}
|
||||
//获取阶梯数量
|
||||
stepQuantityList := make([]int64, 0, 20)
|
||||
tmpMinBuyNum := *sizePrice.MinBuyNum
|
||||
for tmpMinBuyNum < (int64(stepNum[lenStepNum-1]) + 5) {
|
||||
for tmpMinBuyNum < (int64(stepNum[len(stepNum)-1]) + 5) {
|
||||
//阶梯数
|
||||
tmpQuantity := tmpMinBuyNum * (*sizePrice.EachBoxNum)
|
||||
stepQuantityList = append(stepQuantityList, tmpQuantity)
|
||||
|
||||
Reference in New Issue
Block a user