From 818eee78be6cd910a61dfaca4560877bbea32f53 Mon Sep 17 00:00:00 2001 From: momo <1012651275@qq.com> Date: Thu, 7 Sep 2023 16:54:49 +0800 Subject: [PATCH] =?UTF-8?q?fix:logo=E5=8E=86=E5=8F=B2=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- model/gmodel/fs_user_material_logic.go | 2 +- .../internal/logic/userinfosetlogic.go | 50 ++++++++++++++----- .../internal/logic/userlogolistlogic.go | 2 +- server/home-user-auth/internal/types/types.go | 4 +- server_api/home-user-auth.api | 20 ++++---- 5 files changed, 52 insertions(+), 26 deletions(-) diff --git a/model/gmodel/fs_user_material_logic.go b/model/gmodel/fs_user_material_logic.go index c1d34cb3..c353b9ad 100644 --- a/model/gmodel/fs_user_material_logic.go +++ b/model/gmodel/fs_user_material_logic.go @@ -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) { diff --git a/server/home-user-auth/internal/logic/userinfosetlogic.go b/server/home-user-auth/internal/logic/userinfosetlogic.go index c8357233..777e50b3 100644 --- a/server/home-user-auth/internal/logic/userinfosetlogic.go +++ b/server/home-user-auth/internal/logic/userinfosetlogic.go @@ -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 diff --git a/server/home-user-auth/internal/logic/userlogolistlogic.go b/server/home-user-auth/internal/logic/userlogolistlogic.go index 2188282a..033fd0ed 100644 --- a/server/home-user-auth/internal/logic/userlogolistlogic.go +++ b/server/home-user-auth/internal/logic/userlogolistlogic.go @@ -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 } diff --git a/server/home-user-auth/internal/types/types.go b/server/home-user-auth/internal/types/types.go index 2ee68e06..0d1c0fc6 100644 --- a/server/home-user-auth/internal/types/types.go +++ b/server/home-user-auth/internal/types/types.go @@ -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 { diff --git a/server_api/home-user-auth.api b/server_api/home-user-auth.api index 9a512adb..d97db2ca 100644 --- a/server_api/home-user-auth.api +++ b/server_api/home-user-auth.api @@ -10,7 +10,7 @@ info ( import "basic.api" service home-user-auth { - + // @handler UserRegisterHandler // post /api/user/register(RequestUserRegister) returns (response); //用户字体 @@ -37,33 +37,33 @@ service home-user-auth { //联系服务 @handler UserContactServiceHandler post /api/user/contact-service (RequestContactService) returns (response); - + // @handler UserOderListHandler // get /api/user/order-list(RequestOrderId) returns (response); //删除订单 @handler UserOderDeleteHandler post /api/user/order-delete(RequestOrderId) returns (response); - + //订单列表 @handler UserOrderListHandler get /api/user/order-list (UserOrderListReq) returns (response); - + //删除订单 @handler UserOrderDeleteHandler get /api/user/order-delete (UserOrderDeleteReq) returns (response); - + //取消订单 @handler UserOrderCancelHandler get /api/user/order-cancel (UserOrderCancelReq) returns (response); - + // 用户logo列表 @handler UserLogoListHandler get /api/user/logo-list (UserLogoListReq) returns (response); - + // 再来一单 @handler UserAgainOrderHandler get /api/user/one-more-order (UserAgainOrderReq) returns (response); - + // 保存商户信息 @handler UserInfoSetHandler post /api/user/set_user_info (UserInfoSetReq) returns (response); @@ -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格式字符串 } )