From ef946ed0e88f5fc156508b32381e01927d6d42cc Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Tue, 12 Sep 2023 17:26:44 +0800 Subject: [PATCH] 11 --- model/gmodel/fs_product_model3d_logic.go | 8 +++++-- model/gmodel/fs_product_size_logic.go | 8 +++++-- model/gmodel/fs_product_template_v2_logic.go | 15 ++++++++----- .../internal/logic/getsizebypidlogic.go | 21 ++++++++++++++++++- .../internal/logic/ws_render_image.go | 2 +- 5 files changed, 43 insertions(+), 11 deletions(-) diff --git a/model/gmodel/fs_product_model3d_logic.go b/model/gmodel/fs_product_model3d_logic.go index 741fdac2..5ff31216 100755 --- a/model/gmodel/fs_product_model3d_logic.go +++ b/model/gmodel/fs_product_model3d_logic.go @@ -4,8 +4,12 @@ import ( "context" ) -func (d *FsProductModel3dModel) FindOne(ctx context.Context, id int64) (resp *FsProductModel3d, err error) { - err = d.db.WithContext(ctx).Model(&FsProductModel3d{}).Where("`id` = ? ", id).First(&resp).Error +func (d *FsProductModel3dModel) FindOne(ctx context.Context, id int64, fields ...string) (resp *FsProductModel3d, err error) { + db := d.db.WithContext(ctx).Model(&FsProductModel3d{}).Where("`id` = ? ", id) + if len(fields) > 0 { + db = db.Select(fields[0]) + } + err = db.Take(&resp).Error return resp, err } func (d *FsProductModel3dModel) GetAllByIds(ctx context.Context, ids []int64, orderBy string, fields ...string) (resp []FsProductModel3d, err error) { diff --git a/model/gmodel/fs_product_size_logic.go b/model/gmodel/fs_product_size_logic.go index e5d67b46..d7009dfc 100755 --- a/model/gmodel/fs_product_size_logic.go +++ b/model/gmodel/fs_product_size_logic.go @@ -4,8 +4,12 @@ import ( "context" ) -func (s *FsProductSizeModel) FindOne(ctx context.Context, id int64) (resp *FsProductSize, err error) { - err = s.db.WithContext(ctx).Model(&FsProductSize{}).Where("`id` = ? ", id).Take(&resp).Error +func (s *FsProductSizeModel) FindOne(ctx context.Context, id int64, fields ...string) (resp *FsProductSize, err error) { + db := s.db.WithContext(ctx).Model(&FsProductSize{}).Where("`id` = ? ", id) + if len(fields) > 0 { + db = db.Select(fields[0]) + } + err = db.Take(&resp).Error return resp, err } func (s *FsProductSizeModel) GetAllByIds(ctx context.Context, ids []int64, sort string) (resp []FsProductSize, err error) { diff --git a/model/gmodel/fs_product_template_v2_logic.go b/model/gmodel/fs_product_template_v2_logic.go index d141ef47..1462d7b9 100755 --- a/model/gmodel/fs_product_template_v2_logic.go +++ b/model/gmodel/fs_product_template_v2_logic.go @@ -124,12 +124,17 @@ func (t *FsProductTemplateV2Model) FindOneCloudRenderByProductIdModelIdTemplateT } // 获取开启云渲染模板2 -func (t *FsProductTemplateV2Model) FindOneCloudRenderByProductIdTemplateTag(ctx context.Context, productId int64, templateTag string) (resp *FsProductTemplateV2, err error) { - err = t.db.WithContext(ctx).Model(&FsProductTemplateV2{}). +func (t *FsProductTemplateV2Model) FindOneCloudRenderByProductIdTemplateTag(ctx context.Context, productId int64, templateTag string, sort string, fields ...string) (resp *FsProductTemplateV2, err error) { + db := t.db.WithContext(ctx).Model(&FsProductTemplateV2{}). Where("product_id = ? and template_tag = ? and element_model_id > ? ", productId, templateTag, 0). - Where("status = ? and is_del = ?", 1, 0). - Order("sort ASC"). - Take(&resp).Error + Where("status = ? and is_del = ?", 1, 0) + if sort != "" { + db = db.Order(sort) + } + if len(fields) > 0 { + db = db.Select(fields[0]) + } + err = db.Take(&resp).Error return resp, err } func (t *FsProductTemplateV2Model) FindAllByModelIdsTemplateTag(ctx context.Context, modelIds []int64, templateTag string, orderBy string, fields ...string) (resp []FsProductTemplateV2, err error) { diff --git a/server/product/internal/logic/getsizebypidlogic.go b/server/product/internal/logic/getsizebypidlogic.go index 573b9eb9..3ab04044 100644 --- a/server/product/internal/logic/getsizebypidlogic.go +++ b/server/product/internal/logic/getsizebypidlogic.go @@ -50,6 +50,21 @@ func (l *GetSizeByPidLogic) GetSizeByPid(req *types.GetSizeByPidReq, userinfo *a logx.Error(err) return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product info") } + //获取跟列表页云渲染一样的默认渲染尺寸(模板->尺寸) + defaultSizeId := int64(0) + defaultTemplate, err := l.svcCtx.AllModels.FsProductTemplateV2.FindOneCloudRenderByProductIdTemplateTag(l.ctx, productInfo.Id, req.TemplateTag, "sort ASC", "model_id") + if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get default template ") + } else { + //根据模板找到模型sizeId + defaultModel3d, err := l.svcCtx.AllModels.FsProductModel3d.FindOne(l.ctx, *defaultTemplate.ModelId, "size_id") + if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get default model ") + } + defaultSizeId = *defaultModel3d.SizeId + } //获取产品尺寸列表(需要正序排序) sizeList, err := l.svcCtx.AllModels.FsProductSize.GetAllByProductIds(l.ctx, []int64{productInfo.Id}, "is_hot DESC,sort ASC") if err != nil { @@ -58,9 +73,13 @@ func (l *GetSizeByPidLogic) GetSizeByPid(req *types.GetSizeByPidReq, userinfo *a } sizeIds := make([]int64, 0, len(sizeList)) productIds := make([]int64, 0, len(sizeList)) - for _, v := range sizeList { + for k, v := range sizeList { sizeIds = append(sizeIds, v.Id) productIds = append(productIds, *v.ProductId) + //把默认的排第一 + if v.Id == defaultSizeId { + sizeList[0], sizeList[k] = sizeList[k], sizeList[0] + } } //获取产品价格列表 productPriceList, err := l.svcCtx.AllModels.FsProductPrice.GetSimplePriceListByProductIds(l.ctx, productIds) diff --git a/server/websocket/internal/logic/ws_render_image.go b/server/websocket/internal/logic/ws_render_image.go index be229a59..1afe255d 100644 --- a/server/websocket/internal/logic/ws_render_image.go +++ b/server/websocket/internal/logic/ws_render_image.go @@ -303,7 +303,7 @@ func (w *wsConnectItem) getProductRelateionInfoWithSizeId(renderImageData *webso func (w *wsConnectItem) getProductRelateionInfoWithNoSizeId(renderImageData *websocket_data.RenderImageReqMsg) (productSize *gmodel.FsProductSize, productTemplate *gmodel.FsProductTemplateV2, model3d *gmodel.FsProductModel3d, err error) { //指定尺寸(尺寸 -> 模型 ->模板) //获取模板 - productTemplate, err = w.logic.svcCtx.AllModels.FsProductTemplateV2.FindOneCloudRenderByProductIdTemplateTag(w.logic.ctx, renderImageData.RenderData.ProductId, renderImageData.RenderData.TemplateTag) + productTemplate, err = w.logic.svcCtx.AllModels.FsProductTemplateV2.FindOneCloudRenderByProductIdTemplateTag(w.logic.ctx, renderImageData.RenderData.ProductId, renderImageData.RenderData.TemplateTag, "sort ASC") if err != nil { if errors.Is(err, gorm.ErrRecordNotFound) { w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "找不到对应开启云渲染模板", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0)