From f20b4fad3e4bd7f5215b3e6b89baa96e65e73bf1 Mon Sep 17 00:00:00 2001 From: momo <1012651275@qq.com> Date: Tue, 26 Sep 2023 16:16:58 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E6=94=AF=E4=BB=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- model/gmodel/fs_order_logic.go | 1 - model/gmodel/fs_shopping_cart_logic.go | 1 - model/gmodel/fs_user_gen.go | 2 +- service/repositories/order.go | 45 ++++---------------------- 4 files changed, 8 insertions(+), 41 deletions(-) diff --git a/model/gmodel/fs_order_logic.go b/model/gmodel/fs_order_logic.go index fcd0aee1..b068a734 100644 --- a/model/gmodel/fs_order_logic.go +++ b/model/gmodel/fs_order_logic.go @@ -109,7 +109,6 @@ type OrderProduct struct { DiyInformation *UserDiyInformation `json:"diy_information"` SizeInfo *OrderProductSizeInfo `json:"size_info"` FittingInfo *OrderProductFittingInfo `json:"fitting_info"` - StepNum []int `json:"step_num"` // 阶梯数量 IsHighlyCustomized int64 `json:"is_highly_customized"` } type PurchaseQuantity struct { diff --git a/model/gmodel/fs_shopping_cart_logic.go b/model/gmodel/fs_shopping_cart_logic.go index 782bab82..9df6ccf0 100644 --- a/model/gmodel/fs_shopping_cart_logic.go +++ b/model/gmodel/fs_shopping_cart_logic.go @@ -13,7 +13,6 @@ func (m *FsShoppingCartModel) TableName() string { type RelaFsShoppingCart struct { FsShoppingCart ShoppingCartProduct *RelaFsProduct `json:"shopping_cart_product" gorm:"foreignkey:product_id;references:id"` - ShoppingCartProductPriceList []*FsProductPrice `json:"shopping_cart_product_price_list" gorm:"foreignkey:product_id;references:product_id"` ShoppingCartProductModel3dList []*FsProductModel3d `json:"shopping_cart_product_model3d_list" gorm:"foreignkey:product_id;references:product_id"` ShoppingCartProductModel3dFitting *FsProductModel3d `json:"shopping_cart_product_model3d_list_fitting" gorm:"foreignkey:fitting_id;references:id"` } diff --git a/model/gmodel/fs_user_gen.go b/model/gmodel/fs_user_gen.go index 75f1e5a1..b3166fb2 100644 --- a/model/gmodel/fs_user_gen.go +++ b/model/gmodel/fs_user_gen.go @@ -14,7 +14,7 @@ type FsUser struct { LastName *string `gorm:"default:'';" json:"last_name"` // LastName Username *string `gorm:"index;default:'';" json:"username"` // Company *string `gorm:"default:'';" json:"company"` // 公司名称 - Mobile *string `gorm:"default:'';" json:"mobile"` // 手机号码 + Mobile *string `gorm:"default:'';" json:"mobile"` // PasswordHash *string `gorm:"default:'';" json:"password_hash"` // VerificationToken *string `gorm:"default:'';" json:"verification_token"` // PasswordResetToken *string `gorm:"default:'';" json:"password_reset_token"` // diff --git a/service/repositories/order.go b/service/repositories/order.go index 8d2cabda..7bdf1d4d 100644 --- a/service/repositories/order.go +++ b/service/repositories/order.go @@ -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)