From f67f8be8231bc6b2cd5e488b11055954e8f6ac90 Mon Sep 17 00:00:00 2001 From: momo <1012651275@qq.com> Date: Wed, 20 Sep 2023 16:21:06 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E8=B4=AD=E7=89=A9=E8=BD=A6=E4=B8=8B?= =?UTF-8?q?=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- service/repositories/order.go | 42 +++-------------------------------- 1 file changed, 3 insertions(+), 39 deletions(-) diff --git a/service/repositories/order.go b/service/repositories/order.go index 987cff47..1a45e42f 100644 --- a/service/repositories/order.go +++ b/service/repositories/order.go @@ -4,15 +4,10 @@ import ( "context" "encoding/json" "errors" - "fmt" "fusenapi/constants" "fusenapi/model/gmodel" "fusenapi/utils/basic" - "fusenapi/utils/format" "fusenapi/utils/order" - "fusenapi/utils/step_price" - "math" - "strings" "time" "github.com/aws/aws-sdk-go/aws/session" @@ -209,43 +204,12 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe } /* 计算价格 */ - - //阶梯数量切片 - stepNum, err := format.StrSlicToIntSlice(strings.Split(*shoppingCartProductPrice.StepNum, ",")) + productPrice, productTotalPrice, stepNum, stepPrice, err := NewShoppingCart(tx, nil, nil).CaculateCartPrice(*shoppingCart.PurchaseQuantity, shoppingCartProductPrice, *shoppingCart.ShoppingCartProductModel3dFitting.Price) 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) + errorCode.Message = "create order failed, step price of product '" + shoppingCartSnapshot.ProductInfo.ProductName + "'is failed" + return err } - 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 - /* 计算价格 */ // 订单商品总价(厘)