fix:优化
This commit is contained in:
parent
8806dbb034
commit
e9f862e144
|
@ -44,46 +44,23 @@ func (l *UserLogoTemplateTagSetLogic) UserLogoTemplateTagSet(req *types.UserLogo
|
||||||
// 如果是,返回未授权的错误码
|
// 如果是,返回未授权的错误码
|
||||||
return resp.SetStatus(basic.CodeUnAuth)
|
return resp.SetStatus(basic.CodeUnAuth)
|
||||||
}
|
}
|
||||||
if req.LogoSelectedId == 0 {
|
|
||||||
return resp.SetStatus(basic.CodeApiErr, "logo logo_selected_id not null")
|
|
||||||
}
|
|
||||||
if req.TemplateTag == "" {
|
if req.TemplateTag == "" {
|
||||||
return resp.SetStatus(basic.CodeApiErr, "logo template tag not null")
|
return resp.SetStatus(basic.CodeApiErr, "logo template tag not null")
|
||||||
}
|
}
|
||||||
var userId int64
|
var userId int64
|
||||||
var guestId int64
|
var guestId int64
|
||||||
NewFsUserMaterialModel := gmodel.NewFsUserMaterialModel(l.svcCtx.MysqlConn)
|
|
||||||
NewFsUserMaterialModelRow := NewFsUserMaterialModel.RowSelectBuilder(nil).Where("id = ?", req.LogoSelectedId)
|
|
||||||
|
|
||||||
if userinfo.IsGuest() {
|
if userinfo.IsGuest() {
|
||||||
// 如果是,使用游客ID和游客键名格式
|
// 如果是,使用游客ID和游客键名格式
|
||||||
guestId = userinfo.GuestId
|
guestId = userinfo.GuestId
|
||||||
NewFsUserMaterialModelRow.Where("guest_id = ?", guestId)
|
|
||||||
} else {
|
} else {
|
||||||
// 否则,使用用户ID和用户键名格式
|
// 否则,使用用户ID和用户键名格式
|
||||||
userId = userinfo.UserId
|
userId = userinfo.UserId
|
||||||
NewFsUserMaterialModelRow.Where("user_id = ?", userId)
|
|
||||||
}
|
|
||||||
|
|
||||||
userMaterialInfo, err := NewFsUserMaterialModel.FindOne(l.ctx, NewFsUserMaterialModelRow.Model(&gmodel.FsUserMaterial{}))
|
|
||||||
if err != nil {
|
|
||||||
logc.Errorf(l.ctx, "FsUserMaterial FindOne err:%+v", err)
|
|
||||||
return resp.SetStatus(basic.CodeLogoSetCategory, "logo not find")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var nowTime = time.Now().UTC()
|
var nowTime = time.Now().UTC()
|
||||||
err = l.svcCtx.MysqlConn.WithContext(l.ctx).Transaction(func(tx *gorm.DB) error {
|
err := l.svcCtx.MysqlConn.WithContext(l.ctx).Transaction(func(tx *gorm.DB) error {
|
||||||
var metadataMapOldUserMaterial map[string]interface{}
|
|
||||||
if userMaterialInfo.Metadata != nil {
|
|
||||||
err = json.Unmarshal(*userMaterialInfo.Metadata, &metadataMapOldUserMaterial)
|
|
||||||
if err != nil {
|
|
||||||
logc.Errorf(l.ctx, "userMaterialInfo Metadata Unmarshal err:%+v", err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var module = "profile"
|
var module = "profile"
|
||||||
|
|
||||||
var userInfo = &gmodel.FsUserInfo{}
|
var userInfo = &gmodel.FsUserInfo{}
|
||||||
BuilderDB := tx.Model(&gmodel.FsUserInfo{}).Where("module = ?", module)
|
BuilderDB := tx.Model(&gmodel.FsUserInfo{}).Where("module = ?", module)
|
||||||
if userId > 0 {
|
if userId > 0 {
|
||||||
|
@ -92,7 +69,7 @@ func (l *UserLogoTemplateTagSetLogic) UserLogoTemplateTagSet(req *types.UserLogo
|
||||||
BuilderDB.Where("guest_id=?", guestId)
|
BuilderDB.Where("guest_id=?", guestId)
|
||||||
}
|
}
|
||||||
userInfoFirstRes := BuilderDB.First(userInfo)
|
userInfoFirstRes := BuilderDB.First(userInfo)
|
||||||
err = userInfoFirstRes.Error
|
err := userInfoFirstRes.Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !errors.Is(err, gorm.ErrRecordNotFound) {
|
if !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
logc.Errorf(l.ctx, "userInfo First err:%+v", err)
|
logc.Errorf(l.ctx, "userInfo First err:%+v", err)
|
||||||
|
@ -110,8 +87,25 @@ func (l *UserLogoTemplateTagSetLogic) UserLogoTemplateTagSet(req *types.UserLogo
|
||||||
|
|
||||||
var metadataChildUserInfo = make(map[string]interface{}, 1)
|
var metadataChildUserInfo = make(map[string]interface{}, 1)
|
||||||
|
|
||||||
_, userInfoLogoSelectedEx := metadataMapOldUserInfo["logo_selected"]
|
userInfoLogoSelectedData, userInfoLogoSelectedEx := metadataMapOldUserInfo["logo_selected"]
|
||||||
if userInfoLogoSelectedEx {
|
if userInfoLogoSelectedEx {
|
||||||
|
logoSelectedId := int64(userInfoLogoSelectedData.(map[string]interface{})["logo_selected_id"].(float64))
|
||||||
|
NewFsUserMaterialModel := gmodel.NewFsUserMaterialModel(l.svcCtx.MysqlConn)
|
||||||
|
NewFsUserMaterialModelRow := NewFsUserMaterialModel.RowSelectBuilder(nil).Where("id = ?", logoSelectedId)
|
||||||
|
userMaterialInfo, err := NewFsUserMaterialModel.FindOne(l.ctx, NewFsUserMaterialModelRow.Model(&gmodel.FsUserMaterial{}))
|
||||||
|
if err != nil {
|
||||||
|
logc.Errorf(l.ctx, "FsUserMaterial FindOne err:%+v", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
var metadataMapOldUserMaterial map[string]interface{}
|
||||||
|
if userMaterialInfo.Metadata != nil {
|
||||||
|
err = json.Unmarshal(*userMaterialInfo.Metadata, &metadataMapOldUserMaterial)
|
||||||
|
if err != nil {
|
||||||
|
logc.Errorf(l.ctx, "userMaterialInfo Metadata Unmarshal err:%+v", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
userMaterialTemplateTagData, userMaterialTemplateTagEx := metadataMapOldUserMaterial["template_tag"]
|
userMaterialTemplateTagData, userMaterialTemplateTagEx := metadataMapOldUserMaterial["template_tag"]
|
||||||
if !userMaterialTemplateTagEx {
|
if !userMaterialTemplateTagEx {
|
||||||
logc.Errorf(l.ctx, "userMaterialInfo Metadata template_tag err:%+v", err)
|
logc.Errorf(l.ctx, "userMaterialInfo Metadata template_tag err:%+v", err)
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type UserLogoTemplateTagSetReq struct {
|
type UserLogoTemplateTagSetReq struct {
|
||||||
LogoSelectedId int64 `form:"logo_selected_id"`
|
|
||||||
TemplateTag string `form:"template_tag"`
|
TemplateTag string `form:"template_tag"`
|
||||||
TemplateTagColorIndex int64 `form:"template_tag_color_index"`
|
TemplateTagColorIndex int64 `form:"template_tag_color_index"`
|
||||||
}
|
}
|
||||||
|
@ -230,10 +229,10 @@ type File struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Meta struct {
|
type Meta struct {
|
||||||
TotalCount int64 `json:"totalCount"`
|
TotalCount int64 `json:"total_count"`
|
||||||
PageCount int64 `json:"pageCount"`
|
PageCount int64 `json:"page_count"`
|
||||||
CurrentPage int `json:"currentPage"`
|
CurrentPage int `json:"current_page"`
|
||||||
PerPage int `json:"perPage"`
|
PerPage int `json:"per_page"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set 设置Response的Code和Message值
|
// Set 设置Response的Code和Message值
|
||||||
|
|
|
@ -79,7 +79,6 @@ service home-user-auth {
|
||||||
|
|
||||||
type (
|
type (
|
||||||
UserLogoTemplateTagSetReq {
|
UserLogoTemplateTagSetReq {
|
||||||
LogoSelectedId int64 `form:"logo_selected_id"`
|
|
||||||
TemplateTag string `form:"template_tag"`
|
TemplateTag string `form:"template_tag"`
|
||||||
TemplateTagColorIndex int64 `form:"template_tag_color_index"`
|
TemplateTagColorIndex int64 `form:"template_tag_color_index"`
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user