fix:合并

This commit is contained in:
momo
2023-09-15 18:30:45 +08:00
parent 86450d3c9d
commit 95b826d8a6
2 changed files with 38 additions and 22 deletions

View File

@@ -7,6 +7,7 @@ import (
"fusenapi/model/gmodel"
"fusenapi/utils/basic"
"fusenapi/utils/shopping_cart"
"fusenapi/utils/step_price"
"math"
"github.com/aws/aws-sdk-go/aws/session"
@@ -85,13 +86,13 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe
// 商品异常
if shoppingCart.ShoppingCartProduct == nil || (shoppingCart.ShoppingCartProduct != nil && *shoppingCart.ShoppingCartProduct.IsShelf == 0) {
errorCode = *basic.CodeErrOrderCreatProductAbsent
errorCode.Message = "create order failed, product '" + shoppingCartSnapshot.ProductInfo.ProductName + "'is absent"
errorCode.Message = "create order failed, product '" + shoppingCartSnapshot.ProductInfo.ProductName + "'is absent"
return errors.New(errorCode.Message)
}
// 商品价格异常
if len(shoppingCart.ShoppingCartProductPriceList) == 0 {
errorCode = *basic.CodeErrOrderCreatProductPriceAbsent
errorCode.Message = "create order failed, price of product '" + shoppingCartSnapshot.ProductInfo.ProductName + "'is absent"
errorCode.Message = "create order failed, price of product '" + shoppingCartSnapshot.ProductInfo.ProductName + "'is absent"
return errors.New(errorCode.Message)
} else {
var isProductPrice bool
@@ -104,7 +105,7 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe
}
if !isProductPrice {
errorCode = *basic.CodeErrOrderCreatProductPriceAbsent
errorCode.Message = "create order failed, price of product '" + shoppingCartSnapshot.ProductInfo.ProductName + "'is absent"
errorCode.Message = "create order failed, price of product '" + shoppingCartSnapshot.ProductInfo.ProductName + "'is absent"
return errors.New(errorCode.Message)
}
shoppingCart.ShoppingCartProductPriceList = []*gmodel.FsProductPrice{shoppingCartProductPrice}
@@ -113,7 +114,7 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe
// 商品模型异常
if len(shoppingCart.ShoppingCartProductModel3dList) == 0 {
errorCode = *basic.CodeErrOrderCreatProductAccessoryAbsent
errorCode.Message = "create order failed, accessoryof product '" + shoppingCartSnapshot.ProductInfo.ProductName + "'is absent"
errorCode.Message = "create order failed, accessoryof product '" + shoppingCartSnapshot.ProductInfo.ProductName + "'is absent"
return errors.New(errorCode.Message)
} else {
var isProductModel bool
@@ -126,7 +127,7 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe
}
if !isProductModel {
errorCode = *basic.CodeErrOrderCreatProductAccessoryAbsent
errorCode.Message = "create order failed, accessoryof product '" + shoppingCartSnapshot.ProductInfo.ProductName + "'is absent"
errorCode.Message = "create order failed, accessory of product '" + shoppingCartSnapshot.ProductInfo.ProductName + "'is absent"
return errors.New(errorCode.Message)
}
shoppingCart.ShoppingCartProductModel3dList = []*gmodel.FsProductModel3d{shoppingCartProductModel3d}
@@ -134,7 +135,28 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe
var purchaseQuantity float64 = float64(*shoppingCart.PurchaseQuantity)
var eachBoxNum float64 = float64(*shoppingCartProductPrice.EachBoxNum)
var boxNum int64 = math.Ceil(purchaseQuantity / eachBoxNum)
var boxNum float64 = math.Ceil(purchaseQuantity / eachBoxNum)
var stepNum []int
var stepPrice []int
if *shoppingCartProductPrice.StepNum == "" {
errorCode = *basic.CodeErrOrderCreatProductPriceAbsent
errorCode.Message = "create order failed, step num of product '" + shoppingCartSnapshot.ProductInfo.ProductName + "'is failed"
return errors.New(errorCode.Message)
} else {
json.Unmarshal([]byte(*shoppingCartProductPrice.StepNum), &stepNum)
}
if *shoppingCartProductPrice.StepPrice == "" {
errorCode = *basic.CodeErrOrderCreatProductPriceAbsent
errorCode.Message = "create order failed, step price of product '" + shoppingCartSnapshot.ProductInfo.ProductName + "'is failed"
return errors.New(errorCode.Message)
} else {
json.Unmarshal([]byte(*shoppingCartProductPrice.StepPrice), &stepPrice)
}
// 商品单价
productPrice := step_price.GetCentStepPrice(int(boxNum), stepNum, stepPrice)
// 商品总价
productTotalPrice := productPrice * *shoppingCart.PurchaseQuantity
// 存储订单商品
orderProductList = append(orderProductList, &gmodel.OrderProduct{})