fix:logo历史列表调整

This commit is contained in:
momo 2023-09-07 16:54:49 +08:00
parent b48417eee0
commit 818eee78be
5 changed files with 52 additions and 26 deletions

View File

@ -15,7 +15,7 @@ type RelaFsUserMaterial struct {
FsUserMaterial
// 关联字段填充
ResourceInfo *RelaFsResource `json:"resource_info" gorm:"foreignkey:resource_id;references:resource_id"`
MetaDataMap map[string]interface{} `json:"meta_data_map" gorm:"-"`
MetaDataMap map[string]interface{} `json:"metadata_map" gorm:"-"`
}
func (p *FsUserMaterialModel) CreateOrUpdate(ctx context.Context, req *FsUserMaterial) (resp *FsUserMaterial, err error) {

View File

@ -95,16 +95,19 @@ func (l *UserInfoSetLogic) UserInfoSet(req *types.UserInfoSetReq, userinfo *auth
var nowTime = time.Now().UTC()
if userInfo.Id != 0 {
var reqMetadata map[string]int64
var reqMetadata map[string]interface{}
json.Unmarshal([]byte(req.Metadata), &reqMetadata)
var metadataMapOld map[string]interface{}
json.Unmarshal(*userInfo.Metadata, &metadataMapOld)
var metadataMap map[string]interface{}
json.Unmarshal(*userInfo.Metadata, &metadataMap)
logoSelectedId, isEx := metadataMap["logo_selected_id"]
if isEx {
var materialId int64 = int64(logoSelectedId.(float64))
err = l.svcCtx.MysqlConn.WithContext(l.ctx).Transaction(func(tx *gorm.DB) error {
// 更新merchant_category
if req.Module == "merchant_category" {
err = l.svcCtx.MysqlConn.WithContext(l.ctx).Transaction(func(tx *gorm.DB) error {
logoSelectedId, isEx := metadataMapOld["logo_selected_id"]
if isEx {
var materialId int64 = int64(logoSelectedId.(float64))
var userMaterialInfo gmodel.FsUserMaterial
userMaterialGorm := tx.Where("id = ?", materialId)
resUserMaterialInfo := userMaterialGorm.First(&userMaterialInfo)
@ -113,7 +116,6 @@ func (l *UserInfoSetLogic) UserInfoSet(req *types.UserInfoSetReq, userinfo *auth
logc.Errorf(l.ctx, "FsUserMaterial First err%+v", err)
return err
}
var metadataMap map[string]interface{}
var metadataMapOld map[string]interface{}
if userMaterialInfo.Id > 0 {
err = json.Unmarshal(*userMaterialInfo.Metadata, &metadataMapOld)
@ -143,15 +145,39 @@ func (l *UserInfoSetLogic) UserInfoSet(req *types.UserInfoSetReq, userinfo *auth
return err
}
}
return nil
})
}
} else {
var metadataChild = make(map[string]interface{}, 1)
metadataChild["logo_selected_id"] = reqMetadata["logo_selected_id"]
metadataMap, err = metadata.SetMetadata(metadataChild, metadataMapOld)
if err != nil {
logx.Error(err)
return resp.SetStatus(basic.CodeDbSqlErr, "service fail")
logc.Errorf(l.ctx, "metadata SetMetadata err%+v", err)
return err
}
metadataB, err := json.Marshal(metadataMap)
if err != nil {
logc.Errorf(l.ctx, "metadata marshal err%+v", err)
return err
}
userInfo.Metadata = &metadataB
userInfo.Utime = &nowTime
resUpdates := tx.Model(&userInfo).Select("metadata").Where("id = ?", userInfo.Id).Updates(&userInfo)
err = resUpdates.Error
if err != nil {
if err != gorm.ErrRecordNotFound {
logc.Errorf(l.ctx, "FsUserInfo Updates err%+v", err)
return err
}
}
}
return nil
})
if err != nil {
logx.Error(err)
return resp.SetStatus(basic.CodeDbSqlErr, "service fail")
}
return resp.SetStatus(basic.CodeOK)
} else {
userInfo.GuestId = &guestId

View File

@ -84,7 +84,7 @@ func (l *UserLogoListLogic) UserLogoList(req *types.UserLogoListReq, userinfo *a
merchantCategoryId := int64(merchantCategory.(float64))
merchantCategoryIds = append(merchantCategoryIds, merchantCategoryId)
}
metadataMap["merchant_category_info"] = nil
v.MetaDataMap = metadataMap
}

View File

@ -6,8 +6,8 @@ import (
)
type UserInfoSetReq struct {
Module string `form:"module,options=[merchant_category,logo_merchant_category]"` // json格式字符串
Metadata string `form:"metadata"` // json格式字符串
Module string `form:"module,options=[merchant_category,logo_merchant_category,profile]"` // json格式字符串
Metadata string `form:"metadata"` // json格式字符串
}
type UserAgainOrderReq struct {

View File

@ -71,8 +71,8 @@ service home-user-auth {
type (
UserInfoSetReq {
Module string `form:"module,options=[merchant_category,logo_merchant_category]"` // json格式字符串
Metadata string `form:"metadata"` // json格式字符串
Module string `form:"module,options=[merchant_category,logo_merchant_category,profile]"` // json格式字符串
Metadata string `form:"metadata"` // json格式字符串
}
)