From 86c39263be8a27e638b8e5e22b6dcf184eb75086 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 20 Sep 2023 10:31:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=B4=AD=E7=89=A9=E8=BD=A6?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=81=AF=E5=85=89=E4=BF=A1=E6=81=AF=E4=BF=9D?= =?UTF-8?q?=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gmodel/fs_product_model3d_light_logic.go | 4 ++++ model/gmodel/fs_shopping_cart_gen.go | 2 ++ .../internal/logic/addtocartlogic.go | 22 +++++++++++++++++++ utils/shopping_cart/shopping_cart_snapshot.go | 5 +++++ 4 files changed, 33 insertions(+) diff --git a/model/gmodel/fs_product_model3d_light_logic.go b/model/gmodel/fs_product_model3d_light_logic.go index 445c26c0..76fb12b3 100755 --- a/model/gmodel/fs_product_model3d_light_logic.go +++ b/model/gmodel/fs_product_model3d_light_logic.go @@ -2,6 +2,10 @@ package gmodel import "context" +func (l *FsProductModel3dLightModel) FindOne(ctx context.Context, id int64) (resp *FsProductModel3dLight, err error) { + err = l.db.WithContext(ctx).Model(&FsProductModel3dLight{}).Where("`id` = ? and `status` = ?", id, 1).Take(&resp).Error + return resp, err +} func (l *FsProductModel3dLightModel) GetAllByIds(ctx context.Context, ids []int64) (resp []FsProductModel3dLight, err error) { if len(ids) == 0 { return diff --git a/model/gmodel/fs_shopping_cart_gen.go b/model/gmodel/fs_shopping_cart_gen.go index 04996ad2..88ecb052 100644 --- a/model/gmodel/fs_shopping_cart_gen.go +++ b/model/gmodel/fs_shopping_cart_gen.go @@ -13,9 +13,11 @@ type FsShoppingCart struct { TemplateId *int64 `gorm:"default:0;" json:"template_id"` // 模板id ModelId *int64 `gorm:"default:0;" json:"model_id"` // 模型id SizeId *int64 `gorm:"default:0;" json:"size_id"` // 尺寸id + LightId *int64 `gorm:"default:0;" json:"light_id"` // 灯光id FittingId *int64 `gorm:"default:0;" json:"fitting_id"` // 配件id PurchaseQuantity *int64 `gorm:"default:0;" json:"purchase_quantity"` // 购买数量 Snapshot *string `gorm:"default:'';" json:"snapshot"` // + IsSelected *int64 `gorm:"default:0;" json:"is_selected"` // 是否被选中 0非 1是 IsHighlyCustomized *int64 `gorm:"default:0;" json:"is_highly_customized"` // 是否高度定制 0非 1是(针对客人高度定制只能后台增加如购物车) Ctime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"ctime"` // Utime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"utime"` // diff --git a/server/shopping-cart/internal/logic/addtocartlogic.go b/server/shopping-cart/internal/logic/addtocartlogic.go index e792eefe..43021ab3 100644 --- a/server/shopping-cart/internal/logic/addtocartlogic.go +++ b/server/shopping-cart/internal/logic/addtocartlogic.go @@ -66,6 +66,8 @@ func (l *AddToCartLogic) AddToCart(req *types.AddToCartReq, userinfo *auth.UserI templateTag string //模板表的模板标签 fittingJson string //配件的json设计信息 fittingName string //配件名 + lightJson string //灯光设计数据 + lightName string //灯光名字 ) //有模板 if req.TemplateId > 0 { @@ -140,6 +142,21 @@ func (l *AddToCartLogic) AddToCart(req *types.AddToCartReq, userinfo *auth.UserI if modelInfo.ModelInfo == nil || *modelInfo.ModelInfo == "" { return resp.SetStatusWithMessage(basic.CodeServiceErr, "the model`s design info is empty") } + //获取灯光信息 + if *modelInfo.Light > 0 { + lightInfo, err := l.svcCtx.AllModels.FsProductModel3dLight.FindOne(l.ctx, *modelInfo.Light) + if err != nil { + if errors.Is(err, gorm.ErrRecordNotFound) { + return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "the model`s light info is not exists") + } + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get light info") + } + lightName = *lightInfo.Name + if lightInfo.Info != nil && *lightInfo.Info != "" { + lightJson = *lightInfo.Info + } + } var sizeKeyInfo shopping_cart.SizeInfo if err = json.Unmarshal([]byte(*sizeInfo.Title), &sizeKeyInfo); err != nil { logx.Error(err) @@ -174,6 +191,10 @@ func (l *AddToCartLogic) AddToCart(req *types.AddToCartReq, userinfo *auth.UserI Qrcode: req.DiyInfo.Qrcode, Slogan: req.DiyInfo.Slogan, }, + LightInfo: shopping_cart.LightInfo{ + LightJson: lightJson, + LightName: lightName, + }, } snapshotJsonBytes, _ := json.Marshal(snapshot) snapshotJsonStr := string(snapshotJsonBytes) @@ -183,6 +204,7 @@ func (l *AddToCartLogic) AddToCart(req *types.AddToCartReq, userinfo *auth.UserI ProductId: &req.ProductId, TemplateId: &req.TemplateId, ModelId: &modelInfo.Id, + LightId: modelInfo.Light, SizeId: &req.SizeId, FittingId: &req.FittingId, PurchaseQuantity: &req.PurchaseQuantity, diff --git a/utils/shopping_cart/shopping_cart_snapshot.go b/utils/shopping_cart/shopping_cart_snapshot.go index 07df7c9c..45539065 100644 --- a/utils/shopping_cart/shopping_cart_snapshot.go +++ b/utils/shopping_cart/shopping_cart_snapshot.go @@ -11,6 +11,7 @@ type CartSnapshot struct { SizeInfo SizeInfo `json:"size_info"` //尺寸基本信息 ProductInfo ProductInfo `json:"product_info"` //产品基本信息(只记录不要使用) UserDiyInformation UserDiyInformation `json:"user_diy_information"` //用户diy数据 + LightInfo LightInfo `json:"light_info"` //灯光数据 } type ProductInfo struct { ProductName string `json:"product_name"` @@ -39,3 +40,7 @@ type UserDiyInformation struct { Qrcode string `json:"qrcode"` //二维码 Slogan string `json:"slogan"` //slogan } +type LightInfo struct { + LightJson string `json:"light_json"` //灯光设计json数据 + LightName string `json:"light_name"` //名称 +}