|
|
|
|
@@ -745,7 +745,7 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe
|
|
|
|
|
resShoppingCartFind := tx.Table(gmodel.NewFsShoppingCartModel(tx).TableName()).
|
|
|
|
|
Preload("ShoppingCartProduct", func(dbPreload *gorm.DB) *gorm.DB {
|
|
|
|
|
return dbPreload.Table(gmodel.NewFsProductModel(tx).TableName()).Preload("CoverResource")
|
|
|
|
|
}).Preload("ShoppingCartProductPriceList").
|
|
|
|
|
}).
|
|
|
|
|
Preload("ShoppingCartProductModel3dList").
|
|
|
|
|
Preload("ShoppingCartProductModel3dFitting").
|
|
|
|
|
Where("id IN ?", in.CartIds).
|
|
|
|
|
@@ -807,8 +807,7 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe
|
|
|
|
|
for _, shoppingCart := range shoppingCartList {
|
|
|
|
|
// 购物车快照
|
|
|
|
|
var shoppingCartSnapshot gmodel.CartSnapshot
|
|
|
|
|
// 购物车商品价格
|
|
|
|
|
var shoppingCartProductPrice *gmodel.FsProductPrice
|
|
|
|
|
|
|
|
|
|
// 购物车商品模型
|
|
|
|
|
var shoppingCartProductModel3d *gmodel.FsProductModel3d
|
|
|
|
|
if shoppingCart.Snapshot != nil {
|
|
|
|
|
@@ -820,27 +819,6 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe
|
|
|
|
|
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"
|
|
|
|
|
return errors.New(errorCode.Message)
|
|
|
|
|
} else {
|
|
|
|
|
var isProductPrice bool
|
|
|
|
|
for _, shoppingCartProductPriceInfo := range shoppingCart.ShoppingCartProductPriceList {
|
|
|
|
|
if *shoppingCart.SizeId == *shoppingCartProductPriceInfo.SizeId {
|
|
|
|
|
shoppingCartProductPrice = shoppingCartProductPriceInfo
|
|
|
|
|
isProductPrice = true
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if !isProductPrice {
|
|
|
|
|
errorCode = *basic.CodeErrOrderCreatProductPriceAbsent
|
|
|
|
|
errorCode.Message = "create order failed, price of product '" + shoppingCartSnapshot.ProductInfo.ProductName + "'is absent"
|
|
|
|
|
return errors.New(errorCode.Message)
|
|
|
|
|
}
|
|
|
|
|
shoppingCart.ShoppingCartProductPriceList = []*gmodel.FsProductPrice{shoppingCartProductPrice}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 商品模型异常
|
|
|
|
|
if len(shoppingCart.ShoppingCartProductModel3dList) == 0 {
|
|
|
|
|
@@ -864,25 +842,17 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe
|
|
|
|
|
shoppingCart.ShoppingCartProductModel3dList = []*gmodel.FsProductModel3d{shoppingCartProductModel3d}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
var stepPriceJson gmodel.StepPriceJsonStruct
|
|
|
|
|
if shoppingCartProductModel3d.StepPrice != nil {
|
|
|
|
|
json.Unmarshal(*shoppingCartProductModel3d.StepPrice, &shoppingCartProductModel3d.StepPrice)
|
|
|
|
|
} 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)
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 计算价格 */
|
|
|
|
|
productPrice, productTotalPrice, stepNum, stepPrice, err := NewShoppingCart(tx, nil, nil).CaculateCartPrice(*shoppingCart.PurchaseQuantity, shoppingCartProductPrice, *shoppingCart.ShoppingCartProductModel3dFitting.Price)
|
|
|
|
|
productPrice, productTotalPrice, err := NewShoppingCart(tx, nil, nil).CaculateStepPrice(*shoppingCart.PurchaseQuantity, stepPriceJson, *shoppingCart.ShoppingCartProductModel3dFitting.Price)
|
|
|
|
|
if err != nil {
|
|
|
|
|
errorCode = *basic.CodeErrOrderCreatProductPriceAbsent
|
|
|
|
|
errorCode.Message = "create order failed, step price of product '" + shoppingCartSnapshot.ProductInfo.ProductName + "'is failed"
|
|
|
|
|
@@ -960,7 +930,6 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe
|
|
|
|
|
Cm: shoppingCartSnapshot.SizeInfo.Cm,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
StepNum: stepNum,
|
|
|
|
|
IsHighlyCustomized: *shoppingCart.IsHighlyCustomized,
|
|
|
|
|
}
|
|
|
|
|
orderProductList = append(orderProductList, productInter)
|
|
|
|
|
|