From 12c9732fa82caf4aa375a5db47e3f59824fda752 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 25 Oct 2023 12:30:37 +0800 Subject: [PATCH] fix --- model/gmodel/fs_user_info_logic.go | 31 ++++++++++++++++++- .../internal/logic/getproductdetaillogic.go | 17 ++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/model/gmodel/fs_user_info_logic.go b/model/gmodel/fs_user_info_logic.go index ce76d7cb..31101b78 100644 --- a/model/gmodel/fs_user_info_logic.go +++ b/model/gmodel/fs_user_info_logic.go @@ -62,7 +62,7 @@ func (m *FsUserInfoModel) GetProfile(ctx context.Context, pkey string, userId in } rawsql := fmt.Sprintf("select JSON_EXTRACT(metadata,'$%s') as query from %s where user_id = ? and module = 'profile' order by ctime DESC limit 1", pkey, tname) - err := m.db.Raw(rawsql, userId).Take(&baseinfo).Error + err := m.db.WithContext(ctx).Raw(rawsql, userId).Take(&baseinfo).Error if err != nil { return nil, err } @@ -87,3 +87,32 @@ func (m *FsUserInfoModel) FindOneByUser(ctx context.Context, userId, guestId int } return resp, err } +func (m *FsUserInfoModel) GetProfileByUserIdGuestId(ctx context.Context, pkey string, userId, guestId int64) (map[string]any, error) { + + var baseinfo map[string]any + tname := fssql.GetGormTableName(m.db, FsUserInfo{}) + + if pkey == "." { + pkey = "" + } else { + pkey = "." + pkey + } + + rawsql := fmt.Sprintf("select JSON_EXTRACT(metadata,'$%s') as query from %s where user_id = ? and guest_id = ? and module = 'profile' order by ctime DESC limit 1", pkey, tname) + err := m.db.WithContext(ctx).Raw(rawsql, userId, guestId).Take(&baseinfo).Error + if err != nil { + return nil, err + } + + v, ok := baseinfo["query"].(string) + if !ok { + return nil, nil + } + + var info map[string]any + err = json.Unmarshal([]byte(v), &info) + if err != nil { + return nil, err + } + return info, nil +} diff --git a/server/product/internal/logic/getproductdetaillogic.go b/server/product/internal/logic/getproductdetaillogic.go index 79262e10..1b9f8ee9 100644 --- a/server/product/internal/logic/getproductdetaillogic.go +++ b/server/product/internal/logic/getproductdetaillogic.go @@ -12,6 +12,7 @@ import ( "fusenapi/utils/s3url_to_s3id" "fusenapi/utils/template_switch_info" "gorm.io/gorm" + "reflect" "strings" "context" @@ -343,6 +344,22 @@ func (l *GetProductDetailLogic) GetTemplateTagColor(req *types.GetProductDetailR if req.SelectedColorIndex < 0 { return types.TemplateTagColorInfo{}, errors.New("param selected_color_index is invalid") } + if req.Logo == "" { + //颜色选择置0 + req.SelectedColorIndex = 0 + //获取默认profile从中获取logo + profile, err := l.svcCtx.AllModels.FsUserInfo.GetProfileByUserIdGuestId(l.ctx, "logo_selected.logo_url", 0, 0) + if err != nil { + if errors.Is(err, gorm.ErrRecordNotFound) { + return types.TemplateTagColorInfo{}, errors.New("the default profile info is not exists") + } + logx.Error(err) + return types.TemplateTagColorInfo{}, errors.New("failed to get default profile info for without logo") + } + if profile["logo_url"] != nil && reflect.TypeOf(profile["logo_url"]).String() == "string" { + req.Logo = profile["logo_url"].(string) + } + } //根据logo查询素材资源 resourceId := s3url_to_s3id.GetS3ResourceIdFormUrl(req.Logo) if resourceId == "" {