fix:购物车下单

This commit is contained in:
momo 2023-09-20 11:55:51 +08:00
parent ca12242768
commit c004b927ad

View File

@ -4,13 +4,16 @@ import (
"context"
"encoding/json"
"errors"
"fmt"
"fusenapi/constants"
"fusenapi/model/gmodel"
"fusenapi/utils/basic"
"fusenapi/utils/format"
"fusenapi/utils/order"
"fusenapi/utils/shopping_cart"
"fusenapi/utils/step_price"
"math"
"strings"
"time"
"github.com/aws/aws-sdk-go/aws/session"
@ -186,9 +189,6 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe
shoppingCart.ShoppingCartProductModel3dList = []*gmodel.FsProductModel3d{shoppingCartProductModel3d}
}
var purchaseQuantity float64 = float64(*shoppingCart.PurchaseQuantity)
var eachBoxNum float64 = float64(*shoppingCartProductPrice.EachBoxNum)
var boxNum float64 = math.Ceil(purchaseQuantity / eachBoxNum)
var stepNum []int
var stepPrice []int
if *shoppingCartProductPrice.StepNum == "" {
@ -205,11 +205,42 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe
} else {
json.Unmarshal([]byte(*shoppingCartProductPrice.StepPrice), &stepPrice)
}
// 商品单价(厘)
productPrice := step_price.GetCentStepPrice(int(boxNum), stepNum, stepPrice)
// 商品总价(厘)
productTotalPrice := productPrice * *shoppingCart.PurchaseQuantity
//阶梯数量切片
stepNum, err := format.StrSlicToIntSlice(strings.Split(*shoppingCartProductPrice.StepNum, ","))
if err != nil {
errorCode = *basic.CodeErrOrderCreatProductPriceAbsent
errorCode.Message = fmt.Sprintf("failed to parse step number:%d_%d", *shoppingCart.ProductId, *shoppingCart.SizeId)
return errors.New(errorCode.Message)
}
lenStepNum := len(stepNum)
//阶梯价格切片
stepPrice, err = format.StrSlicToIntSlice(strings.Split(*shoppingCartProductPrice.StepPrice, ","))
if err != nil {
errorCode = *basic.CodeErrOrderCreatProductPriceAbsent
errorCode.Message = fmt.Sprintf("failed to parse step price:%d_%d", *shoppingCart.ProductId, *shoppingCart.SizeId)
return errors.New(errorCode.Message)
}
lenStepPrice := len(stepPrice)
if lenStepPrice == 0 || lenStepNum == 0 {
errorCode = *basic.CodeErrOrderCreatProductPriceAbsent
errorCode.Message = fmt.Sprintf("step price or step number is not set:%d_%d", *shoppingCart.ProductId, *shoppingCart.SizeId)
return errors.New(errorCode.Message)
}
// 购买数量
reqPurchaseQuantity := *shoppingCart.PurchaseQuantity
// 购买箱数
boxQuantity := int(math.Ceil(float64(reqPurchaseQuantity) / float64(*shoppingCartProductPrice.EachBoxNum)))
// 根据数量获取阶梯价格中对应的价格
productPrice := step_price.GetCentStepPrice(boxQuantity, stepNum, stepPrice)
// 如果有配件,单价也要加入配件价格
if *shoppingCart.FittingId > 0 {
if shoppingCart.ShoppingCartProductModel3dFitting != nil {
productPrice = productPrice + *shoppingCart.ShoppingCartProductModel3dFitting.Price
}
}
// 单个购物车总价(厘)
productTotalPrice := productPrice * reqPurchaseQuantity
// 订单商品总价(厘)
orderProductTotal = orderProductTotal + productTotalPrice