fix:购物车下单

This commit is contained in:
momo 2023-09-20 16:21:06 +08:00
parent 591abd34e0
commit f67f8be823

View File

@ -4,15 +4,10 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"errors" "errors"
"fmt"
"fusenapi/constants" "fusenapi/constants"
"fusenapi/model/gmodel" "fusenapi/model/gmodel"
"fusenapi/utils/basic" "fusenapi/utils/basic"
"fusenapi/utils/format"
"fusenapi/utils/order" "fusenapi/utils/order"
"fusenapi/utils/step_price"
"math"
"strings"
"time" "time"
"github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/aws/session"
@ -209,43 +204,12 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe
} }
/* 计算价格 */ /* 计算价格 */
productPrice, productTotalPrice, stepNum, stepPrice, err := NewShoppingCart(tx, nil, nil).CaculateCartPrice(*shoppingCart.PurchaseQuantity, shoppingCartProductPrice, *shoppingCart.ShoppingCartProductModel3dFitting.Price)
//阶梯数量切片
stepNum, err := format.StrSlicToIntSlice(strings.Split(*shoppingCartProductPrice.StepNum, ","))
if err != nil { if err != nil {
errorCode = *basic.CodeErrOrderCreatProductPriceAbsent errorCode = *basic.CodeErrOrderCreatProductPriceAbsent
errorCode.Message = fmt.Sprintf("failed to parse step number:%d_%d", *shoppingCart.ProductId, *shoppingCart.SizeId) errorCode.Message = "create order failed, step price of product '" + shoppingCartSnapshot.ProductInfo.ProductName + "'is failed"
return errors.New(errorCode.Message) 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
/* 计算价格 */ /* 计算价格 */
// 订单商品总价(厘) // 订单商品总价(厘)