This commit is contained in:
laodaming 2023-09-20 17:11:48 +08:00
parent 29f1122120
commit 18aaef0e31
4 changed files with 28 additions and 8 deletions

View File

@ -43,8 +43,8 @@ func (pt *FsProductTemplateTagsModel) GetListByTagNames(ctx context.Context, tag
err = db.Limit(limit).Find(&resp).Error
return resp, err
}
func (pt *FsProductTemplateTagsModel) FindOneByTagName(ctx context.Context, tagName string, fields ...string) (resp *FsProductTemplateTags, err error) {
db := pt.db.WithContext(ctx).Model(&FsProductTemplateTags{}).Where("`template_tag` = ? and `status` = ?", tagName, 1)
func (pt *FsProductTemplateTagsModel) FindOneByTagName(ctx context.Context, templateTagName string, fields ...string) (resp *FsProductTemplateTags, err error) {
db := pt.db.WithContext(ctx).Model(&FsProductTemplateTags{}).Where("`template_tag` = ? and `status` = ?", templateTagName, 1)
if len(fields) != 0 {
db = db.Select(fields[0])
}

View File

@ -46,9 +46,19 @@ func (l *GetTemplateTagColorLogic) GetTemplateTagColor(req *types.GetTemplateTag
}
resourceId := s[len(s)-1]
var (
userMaterial *gmodel.FsUserMaterial
err error
userMaterial *gmodel.FsUserMaterial
templateTagInfo *gmodel.FsProductTemplateTags
err error
)
//获取模板标签信息
templateTagInfo, err = l.svcCtx.AllModels.FsProductTemplateTags.FindOneByTagName(l.ctx, req.TemplateTag)
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "the template tag is not exists")
}
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get template tag info")
}
//游客或者用户
if userinfo.IsUser() || userinfo.IsGuest() {
userMaterial, err = l.svcCtx.AllModels.FsUserMaterial.FindOneByUserAndLogoUrl(l.ctx, userinfo.UserId, userinfo.GuestId, resourceId)
@ -85,9 +95,17 @@ func (l *GetTemplateTagColorLogic) GetTemplateTagColor(req *types.GetTemplateTag
if req.SelectedColorIndex >= len(colors) {
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "select color index is out of range !!")
}
var templateTagGroups interface{}
if templateTagInfo.Groups != nil && *templateTagInfo.Groups != "" {
if err = json.Unmarshal([]byte(*templateTagInfo.Groups), &templateTagGroups); err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse template tag`s groups info")
}
}
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetTemplateTagColorRsp{
Colors: colors,
SelectedColorIndex: req.SelectedColorIndex,
TemplateTagGroups: templateTagGroups,
})
}

View File

@ -27,8 +27,9 @@ type GetTemplateTagColorReq struct {
}
type GetTemplateTagColorRsp struct {
Colors [][]string `json:"colors"`
SelectedColorIndex int `json:"selected_color_index"`
Colors [][]string `json:"colors"`
SelectedColorIndex int `json:"selected_color_index"`
TemplateTagGroups interface{} `json:"template_tag_groups"`
}
type Request struct {

View File

@ -39,6 +39,7 @@ type GetTemplateTagColorReq {
SelectedColorIndex int `form:"selected_color_index"`
}
type GetTemplateTagColorRsp {
Colors [][]string `json:"colors"`
SelectedColorIndex int `json:"selected_color_index"`
Colors [][]string `json:"colors"`
SelectedColorIndex int `json:"selected_color_index"`
TemplateTagGroups interface{} `json:"template_tag_groups"`
}