From b7882ef06f450f2431215b03b512e58aa9a98936 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Fri, 8 Sep 2023 14:25:47 +0800 Subject: [PATCH] fix --- model/gmodel/fs_product_logic.go | 8 ++++++-- server/websocket/internal/logic/ws_render_image.go | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/model/gmodel/fs_product_logic.go b/model/gmodel/fs_product_logic.go index 95c301ce..8e7cca3c 100755 --- a/model/gmodel/fs_product_logic.go +++ b/model/gmodel/fs_product_logic.go @@ -2,8 +2,12 @@ package gmodel import "context" -func (p *FsProductModel) FindOne(ctx context.Context, id int64) (resp *FsProduct, err error) { - err = p.db.WithContext(ctx).Model(&FsProduct{}).Where("`id` = ? ", id).First(&resp).Error +func (p *FsProductModel) FindOne(ctx context.Context, id int64, fields ...string) (resp *FsProduct, err error) { + db := p.db.WithContext(ctx).Model(&FsProduct{}).Where("`id` = ? ", id) + if len(fields) != 0 { + db = db.Select(fields[0]) + } + err = db.Take(&resp).Error return resp, err } func (p *FsProductModel) FindOneBySn(ctx context.Context, sn string, fields ...string) (resp *FsProduct, err error) { diff --git a/server/websocket/internal/logic/ws_render_image.go b/server/websocket/internal/logic/ws_render_image.go index 167d3831..84f858df 100644 --- a/server/websocket/internal/logic/ws_render_image.go +++ b/server/websocket/internal/logic/ws_render_image.go @@ -94,8 +94,8 @@ func (w *wsConnectItem) renderImage(data []byte) { logx.Error("invalid format of websocket render image message", err) return } - //获取产品信息 - productInfo, err := w.logic.svcCtx.AllModels.FsProduct.FindOne(w.logic.ctx, renderImageData.RenderData.ProductId) + //获取产品信息(部分字段) + productInfo, err := w.logic.svcCtx.AllModels.FsProduct.FindOne(w.logic.ctx, renderImageData.RenderData.ProductId, "id,is_customization") 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)