From 9e6f919fa8bb70656d5b7c82e3354f80d897517b Mon Sep 17 00:00:00 2001 From: momo <1012651275@qq.com> Date: Tue, 26 Sep 2023 16:53:34 +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_shopping_cart_logic.go | 6 ++--- service/repositories/order.go | 31 +++----------------------- 2 files changed, 6 insertions(+), 31 deletions(-) diff --git a/model/gmodel/fs_shopping_cart_logic.go b/model/gmodel/fs_shopping_cart_logic.go index 9df6ccf0..21f020a8 100644 --- a/model/gmodel/fs_shopping_cart_logic.go +++ b/model/gmodel/fs_shopping_cart_logic.go @@ -12,9 +12,9 @@ func (m *FsShoppingCartModel) TableName() string { // 关联查询 type RelaFsShoppingCart struct { FsShoppingCart - ShoppingCartProduct *RelaFsProduct `json:"shopping_cart_product" gorm:"foreignkey:product_id;references: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"` + ShoppingCartProduct *RelaFsProduct `json:"shopping_cart_product" gorm:"foreignkey:product_id;references:id"` + ShoppingCartProductModel3d *FsProductModel3d `json:"shopping_cart_product_model3d_list" gorm:"foreignkey:model_id;references:id"` + ShoppingCartProductModel3dFitting *FsProductModel3d `json:"shopping_cart_product_model3d_list_fitting" gorm:"foreignkey:fitting_id;references:id"` } type FsShoppingCartData struct { Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // id diff --git a/service/repositories/order.go b/service/repositories/order.go index cfcfe27b..e3d1e4c7 100644 --- a/service/repositories/order.go +++ b/service/repositories/order.go @@ -746,7 +746,7 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe Preload("ShoppingCartProduct", func(dbPreload *gorm.DB) *gorm.DB { return dbPreload.Table(gmodel.NewFsProductModel(tx).TableName()).Preload("CoverResource") }). - Preload("ShoppingCartProductModel3dList"). + Preload("ShoppingCartProductModel3d"). Preload("ShoppingCartProductModel3dFitting"). Where("id IN ?", in.CartIds). Where("user_id = ?", in.UserId). @@ -807,9 +807,6 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe for _, shoppingCart := range shoppingCartList { // 购物车快照 var shoppingCartSnapshot gmodel.CartSnapshot - - // 购物车商品模型 - var shoppingCartProductModel3d *gmodel.FsProductModel3d if shoppingCart.Snapshot != nil { json.Unmarshal([]byte(*shoppingCart.Snapshot), &shoppingCartSnapshot) } @@ -820,31 +817,9 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe return errors.New(errorCode.Message) } - // 商品模型异常 - if len(shoppingCart.ShoppingCartProductModel3dList) == 0 { - errorCode = *basic.CodeErrOrderCreatProductAccessoryAbsent - errorCode.Message = "create order failed, accessoryof product '" + shoppingCartSnapshot.ProductInfo.ProductName + "'is absent" - return errors.New(errorCode.Message) - } else { - var isProductModel bool - for _, shoppingCartProductModel3dInfo := range shoppingCart.ShoppingCartProductModel3dList { - if *shoppingCart.SizeId == *shoppingCartProductModel3dInfo.SizeId { - shoppingCartProductModel3d = shoppingCartProductModel3dInfo - isProductModel = true - break - } - } - if !isProductModel { - errorCode = *basic.CodeErrOrderCreatProductAccessoryAbsent - errorCode.Message = "create order failed, accessory of product '" + shoppingCartSnapshot.ProductInfo.ProductName + "'is absent" - return errors.New(errorCode.Message) - } - shoppingCart.ShoppingCartProductModel3dList = []*gmodel.FsProductModel3d{shoppingCartProductModel3d} - } - var stepPriceJson gmodel.StepPriceJsonStruct - if shoppingCartProductModel3d.StepPrice != nil && len(*shoppingCartProductModel3d.StepPrice) != 0 { - err = json.Unmarshal(*shoppingCartProductModel3d.StepPrice, &shoppingCartProductModel3d.StepPrice) + if shoppingCart.ShoppingCartProductModel3d.StepPrice != nil { + err = json.Unmarshal(*shoppingCart.ShoppingCartProductModel3d.StepPrice, &stepPriceJson) if err != nil { return err }