From 751e0e6e6bd4b5399620bef6c0e3dde1d134cc6e Mon Sep 17 00:00:00 2001 From: momo <1012651275@qq.com> Date: Thu, 7 Sep 2023 16:25:29 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:logo=E5=8E=86=E5=8F=B2=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- model/gmodel/fs_resource_logic.go | 4 + model/gmodel/fs_user_material_logic.go | 32 +++++++ server/home-user-auth/etc/home-user-auth.yaml | 12 +++ .../home-user-auth/internal/config/config.go | 15 ++++ .../internal/logic/userinfosetlogic.go | 86 +++++++++++++++++-- .../internal/logic/userlogolistlogic.go | 65 +++++++++++++- .../internal/svc/servicecontext.go | 17 +++- .../internal/logic/resourceinfologic.go | 4 +- service/repositories/image_handle.go | 76 +++++++++++++--- 9 files changed, 284 insertions(+), 27 deletions(-) diff --git a/model/gmodel/fs_resource_logic.go b/model/gmodel/fs_resource_logic.go index 5b4736b6..69a43361 100644 --- a/model/gmodel/fs_resource_logic.go +++ b/model/gmodel/fs_resource_logic.go @@ -8,6 +8,10 @@ import ( ) // TODO: 使用model的属性做你想做的 +type RelaFsResource struct { + FsResource + MetaDataMap map[string]interface{} `json:"meta_data_map" gorm:"-"` +} func (p *FsResourceModel) FindOneById(ctx context.Context, resourceId string) (resp *FsResource, err error) { err = p.db.Table(p.name).WithContext(ctx).Where("resource_id =?", resourceId).Take(&resp).Error diff --git a/model/gmodel/fs_user_material_logic.go b/model/gmodel/fs_user_material_logic.go index 4128ddef..c1d34cb3 100644 --- a/model/gmodel/fs_user_material_logic.go +++ b/model/gmodel/fs_user_material_logic.go @@ -11,6 +11,13 @@ import ( // TODO: 使用model的属性做你想做的 +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:"-"` +} + func (p *FsUserMaterialModel) CreateOrUpdate(ctx context.Context, req *FsUserMaterial) (resp *FsUserMaterial, err error) { rowBuilder := p.db.Table(p.name).WithContext(ctx) if req.Id > 0 { @@ -46,6 +53,31 @@ func (m *FsUserMaterialModel) FindAll(ctx context.Context, rowBuilder *gorm.DB, } } +func (m *FsUserMaterialModel) FindList(ctx context.Context, rowBuilder *gorm.DB, filterMap map[string]string, orderBy string) ([]*RelaFsUserMaterial, error) { + var resp []*RelaFsUserMaterial + // 过滤 + if filterMap != nil { + rowBuilder = rowBuilder.Scopes(handlers.FilterData(filterMap)) + } + + // 排序 + if orderBy != "" { + var fieldsMap = make(map[string]struct{}) + s := reflect.TypeOf(&FsUserMaterial{}).Elem() //通过反射获取type定义 + for i := 0; i < s.NumField(); i++ { + fieldsMap[s.Field(i).Tag.Get("json")] = struct{}{} + } + rowBuilder = rowBuilder.Scopes(handlers.OrderCheck(orderBy, fieldsMap)) + } + + result := rowBuilder.WithContext(ctx).Find(&resp) + if result.Error != nil { + return nil, result.Error + } else { + return resp, nil + } +} + func (m *FsUserMaterialModel) RowSelectBuilder(selectData []string) *gorm.DB { var rowBuilder = m.db.Table(m.name) diff --git a/server/home-user-auth/etc/home-user-auth.yaml b/server/home-user-auth/etc/home-user-auth.yaml index dea74873..d94b4406 100644 --- a/server/home-user-auth/etc/home-user-auth.yaml +++ b/server/home-user-auth/etc/home-user-auth.yaml @@ -22,3 +22,15 @@ PayConfig: EndpointSecret: "whsec_f5f9a121d43af3789db7459352f08cf523eb9e0fbf3381f91ba6c97c324c174d" SuccessURL: "http://www.baidu.com" CancelURL: "http://www.baidu.com" +AWS: + S3: + Credentials: + AccessKeyID: AKIAZB2JKUXDPNRP4YT2 + Secret: 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 + Token: +BLMService: + Url: "http://18.119.109.254:8999" + # Url: "http://192.168.1.9:8999" + LogoCombine: + #Url: "http://192.168.1.7:8999/LogoCombine" + Url: "http://18.119.109.254:8999/LogoCombine" \ No newline at end of file diff --git a/server/home-user-auth/internal/config/config.go b/server/home-user-auth/internal/config/config.go index 87384558..be3d3142 100644 --- a/server/home-user-auth/internal/config/config.go +++ b/server/home-user-auth/internal/config/config.go @@ -26,4 +26,19 @@ type Config struct { SuccessURL string } } + AWS struct { + S3 struct { + Credentials struct { + AccessKeyID string + Secret string + Token string + } + } + } + BLMService struct { + Url string + LogoCombine struct { + Url string + } + } } diff --git a/server/home-user-auth/internal/logic/userinfosetlogic.go b/server/home-user-auth/internal/logic/userinfosetlogic.go index 47c692b0..c8357233 100644 --- a/server/home-user-auth/internal/logic/userinfosetlogic.go +++ b/server/home-user-auth/internal/logic/userinfosetlogic.go @@ -1,9 +1,12 @@ package logic import ( + "encoding/json" + "errors" "fusenapi/model/gmodel" "fusenapi/utils/auth" "fusenapi/utils/basic" + "fusenapi/utils/metadata" "fusenapi/utils/validate" "time" @@ -12,7 +15,9 @@ import ( "fusenapi/server/home-user-auth/internal/svc" "fusenapi/server/home-user-auth/internal/types" + "github.com/zeromicro/go-zero/core/logc" "github.com/zeromicro/go-zero/core/logx" + "gorm.io/gorm" ) type UserInfoSetLogic struct { @@ -68,17 +73,86 @@ func (l *UserInfoSetLogic) UserInfoSet(req *types.UserInfoSetReq, userinfo *auth var userInfo = &gmodel.FsUserInfo{} fsUserInfoModel := gmodel.NewFsUserInfoModel(l.svcCtx.MysqlConn) BuilderDB := fsUserInfoModel.BuilderDB(l.ctx, nil).Model(&gmodel.FsUserInfo{}) - BuilderDB1 := BuilderDB.Where("module = ?", req.Module).Where("user_id=?", userId).Where("guest_id=?", guestId) + BuilderDB1 := fsUserInfoModel.BuilderDB(l.ctx, nil).Model(&gmodel.FsUserInfo{}) + if req.Module == "merchant_category" { + BuilderDB1.Where("module = ?", "profile") + } else { + BuilderDB1.Where("module = ?", req.Module) + } + //.Where("user_id=?", userId).Where("guest_id=?", guestId) + if userId > 0 { + BuilderDB1.Where("user_id=?", userId) + } else { + BuilderDB1.Where("guest_id=?", guestId) + } userInfo, err = fsUserInfoModel.FindOne(BuilderDB1, nil) if err != nil { - logx.Error(err) - return resp.SetStatus(basic.CodeDbSqlErr, "UserInfoSet error system failed") + if errors.Is(err, gorm.ErrRecordNotFound) { + logx.Error(err) + return resp.SetStatus(basic.CodeDbSqlErr, "UserInfoSet error system failed") + } } + var nowTime = time.Now().UTC() if userInfo.Id != 0 { - v := []byte(req.Metadata) - userInfo.Metadata = &v - userInfo.Utime = &nowTime + var reqMetadata map[string]int64 + json.Unmarshal([]byte(req.Metadata), &reqMetadata) + var metadataMap map[string]interface{} + json.Unmarshal(*userInfo.Metadata, &metadataMap) + logoSelectedId, isEx := metadataMap["logo_selected_id"] + if isEx { + var materialId int64 = int64(logoSelectedId.(float64)) + // 更新merchant_category + if req.Module == "merchant_category" { + err = l.svcCtx.MysqlConn.WithContext(l.ctx).Transaction(func(tx *gorm.DB) error { + var userMaterialInfo gmodel.FsUserMaterial + userMaterialGorm := tx.Where("id = ?", materialId) + resUserMaterialInfo := userMaterialGorm.First(&userMaterialInfo) + err = resUserMaterialInfo.Error + if err != nil { + 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) + if err != nil { + logc.Errorf(l.ctx, "userMaterialInfo Metadata Unmarshal err:%+v", err) + return err + } + } + var metadataChild = make(map[string]interface{}, 1) + metadataChild["merchant_category"] = reqMetadata["category_id"] + metadataMap, err = metadata.SetMetadata(metadataChild, metadataMapOld) + if err != nil { + 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 + } + userMaterialInfo.Metadata = &metadataB + resUpdates := tx.Select("metadata").Where("id = ?", materialId).Updates(&userMaterialInfo) + err = resUpdates.Error + if err != nil { + if err != gorm.ErrRecordNotFound { + logc.Errorf(l.ctx, "userMaterialInfo 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 userInfo.UserId = &userId diff --git a/server/home-user-auth/internal/logic/userlogolistlogic.go b/server/home-user-auth/internal/logic/userlogolistlogic.go index 14bc97d4..2188282a 100644 --- a/server/home-user-auth/internal/logic/userlogolistlogic.go +++ b/server/home-user-auth/internal/logic/userlogolistlogic.go @@ -1,6 +1,7 @@ package logic import ( + "encoding/json" "errors" "fusenapi/model/gmodel" "fusenapi/utils/auth" @@ -55,9 +56,15 @@ func (l *UserLogoListLogic) UserLogoList(req *types.UserLogoListReq, userinfo *a } userMaterialModel := gmodel.NewFsUserMaterialModel(l.svcCtx.MysqlConn) - userMaterialRSB := userMaterialModel.RowSelectBuilder(nil). - Where("module = ?", "logo").Where("user_id = ?", userId).Where("guest_id = ?", guestId).Order("id desc") - list, err := userMaterialModel.FindAll(l.ctx, userMaterialRSB, nil, "") + userMaterialRSB := userMaterialModel.RowSelectBuilder(nil).Preload("ResourceInfo", func(dbPreload *gorm.DB) *gorm.DB { + return dbPreload.Table(gmodel.NewFsResourceModel(l.svcCtx.MysqlConn).TableName()) + }).Where("module = ?", "logo").Order("id desc").Limit(10) + if userId != 0 { + userMaterialRSB.Where("user_id = ?", userId) + } else { + userMaterialRSB.Where("guest_id = ?", guestId) + } + list, err := userMaterialModel.FindList(l.ctx, userMaterialRSB, nil, "") if err != nil { if errors.Is(err, gorm.ErrRecordNotFound) { return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "data not found") @@ -65,6 +72,58 @@ func (l *UserLogoListLogic) UserLogoList(req *types.UserLogoListReq, userinfo *a logx.Error(err) return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get data list") } + if len(list) > 0 { + var merchantCategoryIds []int64 + for _, v := range list { + var metadataMap map[string]interface{} + if v.Metadata != nil { + json.Unmarshal(*v.Metadata, &metadataMap) + + merchantCategory, merchantCategoryEix := metadataMap["merchant_category"] + if merchantCategoryEix { + merchantCategoryId := int64(merchantCategory.(float64)) + merchantCategoryIds = append(merchantCategoryIds, merchantCategoryId) + } + + v.MetaDataMap = metadataMap + } + + if v.ResourceInfo != nil { + if v.ResourceInfo.Metadata != nil { + var resourceMetadata map[string]interface{} + json.Unmarshal([]byte(*v.ResourceInfo.Metadata), &resourceMetadata) + v.ResourceInfo.MetaDataMap = resourceMetadata + } + } + } + if len(merchantCategoryIds) > 0 { + newFsMerchantCategoryModel := gmodel.NewFsMerchantCategoryModel(l.svcCtx.MysqlConn) + fsMerchantCategoryDb := newFsMerchantCategoryModel.BuilderDB(l.ctx, nil).Model(&gmodel.FsMerchantCategory{}).Where("id in ?", merchantCategoryIds) + resfsMerchantCategoryDb, err := newFsMerchantCategoryModel.FindAll(fsMerchantCategoryDb, nil, "") + if err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "newFsMerchantCategoryModel FindAll db") + } + merchantCategoryDataLen := len(resfsMerchantCategoryDb) + var merchantCategoryData = make(map[int64]*gmodel.FsMerchantCategory, merchantCategoryDataLen) + if merchantCategoryDataLen > 0 { + for _, v := range resfsMerchantCategoryDb { + merchantCategoryData[v.Id] = v + } + } + for _, v := range list { + if v.MetaDataMap != nil { + merchantCategory1, merchantCategoryEix1 := v.MetaDataMap["merchant_category"] + if merchantCategoryEix1 { + merchantCategoryId1 := int64(merchantCategory1.(float64)) + v.MetaDataMap["merchant_category_info"] = merchantCategoryData[merchantCategoryId1] + } else { + v.MetaDataMap["merchant_category_info"] = nil + } + } + } + } + } return resp.SetStatus(basic.CodeOK, map[string]interface{}{ "list": list, }) diff --git a/server/home-user-auth/internal/svc/servicecontext.go b/server/home-user-auth/internal/svc/servicecontext.go index ac309bbc..492fcdba 100644 --- a/server/home-user-auth/internal/svc/servicecontext.go +++ b/server/home-user-auth/internal/svc/servicecontext.go @@ -5,6 +5,9 @@ import ( "fusenapi/model/gmodel" "fusenapi/shared" + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/aws/credentials" + "github.com/aws/aws-sdk-go/aws/session" "github.com/golang-jwt/jwt" "gorm.io/gorm" @@ -18,19 +21,27 @@ type ServiceContext struct { Config config.Config SharedState *shared.SharedState - MysqlConn *gorm.DB - AllModels *gmodel.AllModelsGen + MysqlConn *gorm.DB + AllModels *gmodel.AllModelsGen + Repositories *initalize.Repositories } func NewServiceContext(c config.Config) *ServiceContext { conn := initalize.InitMysql(c.SourceMysql) // StateServer := shared.StartNode(c.ReplicaId, autoconfig.AutoGetAllServerConfig(), conn) - + config := aws.Config{ + Credentials: credentials.NewStaticCredentials(c.AWS.S3.Credentials.AccessKeyID, c.AWS.S3.Credentials.Secret, c.AWS.S3.Credentials.Token), + } return &ServiceContext{ Config: c, MysqlConn: conn, SharedState: nil, AllModels: gmodel.NewAllModels(initalize.InitMysql(c.SourceMysql)), + Repositories: initalize.NewAllRepositories(&initalize.NewAllRepositorieData{ + GormDB: initalize.InitMysql(c.SourceMysql), + BLMServiceUrl: &c.BLMService.Url, + AwsSession: session.Must(session.NewSession(&config)), + }), } } diff --git a/server/resource/internal/logic/resourceinfologic.go b/server/resource/internal/logic/resourceinfologic.go index 395bce18..24f247d4 100644 --- a/server/resource/internal/logic/resourceinfologic.go +++ b/server/resource/internal/logic/resourceinfologic.go @@ -55,7 +55,9 @@ func (l *ResourceInfoLogic) ResourceInfo(req *types.ResourceInfoReq, userinfo *a if err == nil && resourceInfo.ResourceId != "" { resourceId = resourceInfo.ResourceId resourceUrl = *resourceInfo.ResourceUrl - json.Unmarshal([]byte(*resourceInfo.Metadata), &resourceMetadata) + if resourceInfo.Metadata != nil { + json.Unmarshal([]byte(*resourceInfo.Metadata), &resourceMetadata) + } } return resp.SetStatus(basic.CodeOK, map[string]interface{}{ "resource_id": resourceId, diff --git a/service/repositories/image_handle.go b/service/repositories/image_handle.go index 903ca4a7..b05e1360 100644 --- a/service/repositories/image_handle.go +++ b/service/repositories/image_handle.go @@ -63,23 +63,71 @@ func (l *defaultImageHandle) LogoInfo(ctx context.Context, in *LogoInfoReq) (*Lo var metadata *string var logoUrl *string - userMaterialModel := gmodel.NewFsUserMaterialModel(l.MysqlConn) - userMaterialInfo, err := userMaterialModel.FindLatestOne(ctx, in.UserId, in.GuestId) - + // 更新用户信息 + var module = "profile" + userInfoGorm := l.MysqlConn.Where("module = ?", module) + userInfo := gmodel.FsUserInfo{} + if in.UserId > 0 { + userInfoGorm.Where("user_id = ?", in.UserId) + userInfo.UserId = &in.UserId + } else { + userInfoGorm.Where("guest_id = ?", in.GuestId) + userInfo.GuestId = &in.GuestId + } + resFirst := userInfoGorm.First(&userInfo) + err := resFirst.Error if err != nil { - if errors.Is(err, gorm.ErrRecordNotFound) { - userMaterialInfoDefault, err := userMaterialModel.FindOneById(ctx, 0) - if err != nil { - logx.Error(err) - return nil, err - } - metadataB := string(*userMaterialInfoDefault.Metadata) - metadata = &metadataB - logoUrl = userMaterialInfoDefault.ResourceUrl - } else { - logx.Error(err) + if err != gorm.ErrRecordNotFound { + logc.Errorf(ctx, "FsUserInfo First err:%+v", err) return nil, err } + } + var userMaterialInfo gmodel.FsUserMaterial + userMaterialModel := gmodel.NewFsUserMaterialModel(l.MysqlConn) + + if userInfo.Id == 0 { + userMaterialInfo, err = userMaterialModel.FindLatestOne(ctx, in.UserId, in.GuestId) + if err != gorm.ErrRecordNotFound { + logc.Errorf(ctx, "FsUserMaterial FindLatestOne err:%+v", err) + return nil, err + } + } else { + if userInfo.Metadata != nil { + var metadata map[string]interface{} + err = json.Unmarshal([]byte(*userInfo.Metadata), &metadata) + if err != nil { + logc.Errorf(ctx, "userInfo.Metadata Unmarshal err:%+v", err) + return nil, err + } + logoSelectedId, isEx := metadata["logo_selected_id"] + if isEx { + var materialId int64 = int64(logoSelectedId.(float64)) + userMaterialInfos, err := userMaterialModel.FindOneById(ctx, materialId) + if err != nil { + if err != gorm.ErrRecordNotFound { + logc.Errorf(ctx, "FsUserInfo First err:%+v", err) + return nil, err + } + } + if userMaterialInfos.Id != 0 { + userMaterialInfo = *userMaterialInfos + } + } + } + } + + if userMaterialInfo.Id == 0 { + userMaterialInfoDefault, err := userMaterialModel.FindOneById(ctx, 0) + if err != nil { + if err != gorm.ErrRecordNotFound { + logc.Errorf(ctx, "userMaterialModel FindOneById defaul err:%+v", err) + return nil, err + } + } + metadataB := string(*userMaterialInfoDefault.Metadata) + metadata = &metadataB + logoUrl = userMaterialInfoDefault.ResourceUrl + } else { metadataB := string(*userMaterialInfo.Metadata) metadata = &metadataB 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 2/2] =?UTF-8?q?fix:logo=E5=8E=86=E5=8F=B2=E5=88=97?= =?UTF-8?q?=E8=A1=A8=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格式字符串 } )