From 6cc35e6198ac540afa84be88735ace9add845bee Mon Sep 17 00:00:00 2001 From: momo <1012651275@qq.com> Date: Thu, 7 Sep 2023 18:52:01 +0800 Subject: [PATCH 01/14] =?UTF-8?q?feat:=E7=94=A8=E6=88=B7=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?logo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../home-user-auth/internal/handler/routes.go | 5 + .../internal/handler/userlogosethandler.go | 35 ++++ .../internal/logic/userlogosetlogic.go | 166 ++++++++++++++++++ server/home-user-auth/internal/types/types.go | 5 + .../internal/logic/uploadfilesbackendlogic.go | 1 + .../upload/internal/logic/uploadlogologic.go | 88 ++-------- server_api/home-user-auth.api | 11 ++ 7 files changed, 234 insertions(+), 77 deletions(-) create mode 100644 server/home-user-auth/internal/handler/userlogosethandler.go create mode 100644 server/home-user-auth/internal/logic/userlogosetlogic.go diff --git a/server/home-user-auth/internal/handler/routes.go b/server/home-user-auth/internal/handler/routes.go index 9fbecfd9..60b66955 100644 --- a/server/home-user-auth/internal/handler/routes.go +++ b/server/home-user-auth/internal/handler/routes.go @@ -87,6 +87,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { Path: "/api/user/set_user_info", Handler: UserInfoSetHandler(serverCtx), }, + { + Method: http.MethodGet, + Path: "/api/user/logo-set", + Handler: UserLogoSetHandler(serverCtx), + }, }, ) } diff --git a/server/home-user-auth/internal/handler/userlogosethandler.go b/server/home-user-auth/internal/handler/userlogosethandler.go new file mode 100644 index 00000000..26f953c8 --- /dev/null +++ b/server/home-user-auth/internal/handler/userlogosethandler.go @@ -0,0 +1,35 @@ +package handler + +import ( + "net/http" + "reflect" + + "fusenapi/utils/basic" + + "fusenapi/server/home-user-auth/internal/logic" + "fusenapi/server/home-user-auth/internal/svc" + "fusenapi/server/home-user-auth/internal/types" +) + +func UserLogoSetHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + + var req types.UserLogoSetReq + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } + + // 创建一个业务逻辑层实例 + l := logic.NewUserLogoSetLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + + resp := l.UserLogoSet(&req, userinfo) + + if !basic.AfterLogic(w, r, rl, resp) { + basic.NormalAfterLogic(w, r, resp) + } + } +} diff --git a/server/home-user-auth/internal/logic/userlogosetlogic.go b/server/home-user-auth/internal/logic/userlogosetlogic.go new file mode 100644 index 00000000..91b93fb0 --- /dev/null +++ b/server/home-user-auth/internal/logic/userlogosetlogic.go @@ -0,0 +1,166 @@ +package logic + +import ( + "encoding/json" + "errors" + "fusenapi/model/gmodel" + "fusenapi/utils/auth" + "fusenapi/utils/basic" + "fusenapi/utils/metadata" + "time" + + "context" + + "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 UserLogoSetLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewUserLogoSetLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserLogoSetLogic { + return &UserLogoSetLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +// 处理进入前逻辑w,r +// func (l *UserLogoSetLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) { +// } + +func (l *UserLogoSetLogic) UserLogoSet(req *types.UserLogoSetReq, userinfo *auth.UserInfo) (resp *basic.Response) { + // 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data) + // userinfo 传入值时, 一定不为null + // 更新用户信息 + if userinfo.IsOnlooker() { + // 如果是,返回未授权的错误码 + return resp.SetStatus(basic.CodeUnAuth) + } + + var userId int64 + var guestId int64 + + // 检查用户是否是游客 + if userinfo.IsGuest() { + // 如果是,使用游客ID和游客键名格式 + guestId = userinfo.GuestId + } else { + // 否则,使用用户ID和用户键名格式 + userId = userinfo.UserId + } + + var userInfo = &gmodel.FsUserInfo{} + fsUserInfoModel := gmodel.NewFsUserInfoModel(l.svcCtx.MysqlConn) + BuilderDB := fsUserInfoModel.BuilderDB(l.ctx, nil).Model(&gmodel.FsUserInfo{}).Where("module = ?", "profile") + if userId > 0 { + BuilderDB.Where("user_id=?", userId) + } else { + BuilderDB.Where("guest_id=?", guestId) + } + userInfo, err := fsUserInfoModel.FindOne(BuilderDB, nil) + if err != nil { + if errors.Is(err, gorm.ErrRecordNotFound) { + logx.Error(err) + return resp.SetStatus(basic.CodeDbSqlErr, "UserInfoSet error system failed") + } + } + + var nowTime = time.Now().UTC() + + var metadataMap map[string]interface{} + err = l.svcCtx.MysqlConn.WithContext(l.ctx).Transaction(func(tx *gorm.DB) error { + if userInfo.Id != 0 { + var metadataMapOld map[string]interface{} + json.Unmarshal(*userInfo.Metadata, &metadataMapOld) + } + // 更新merchant_category + if req.Module == "merchant_category" { + 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) + err = resUserMaterialInfo.Error + if err != nil { + logc.Errorf(l.ctx, "FsUserMaterial First err:%+v", err) + return err + } + 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 + } + } + } + } 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 { + 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) +} + +// 处理逻辑后 w,r 如:重定向, resp 必须重新处理 +// func (l *UserLogoSetLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) { +// // httpx.OkJsonCtx(r.Context(), w, resp) +// } diff --git a/server/home-user-auth/internal/types/types.go b/server/home-user-auth/internal/types/types.go index 0d1c0fc6..763ebe23 100644 --- a/server/home-user-auth/internal/types/types.go +++ b/server/home-user-auth/internal/types/types.go @@ -5,6 +5,11 @@ import ( "fusenapi/utils/basic" ) +type UserLogoSetReq struct { + LogoSelectedId int64 `form:"logo_selected_id"` + CategoryId int64 `form:"category_id,optional"` +} + type UserInfoSetReq struct { Module string `form:"module,options=[merchant_category,logo_merchant_category,profile]"` // json格式字符串 Metadata string `form:"metadata"` // json格式字符串 diff --git a/server/upload/internal/logic/uploadfilesbackendlogic.go b/server/upload/internal/logic/uploadfilesbackendlogic.go index cedbb8de..7552f894 100644 --- a/server/upload/internal/logic/uploadfilesbackendlogic.go +++ b/server/upload/internal/logic/uploadfilesbackendlogic.go @@ -207,6 +207,7 @@ type UploadData struct { } type UploadUrl struct { + LogoId int64 `json:"logo_id"` Key string `json:"key"` Status int64 `json:"status"` ApiType int64 `json:"api_type"` diff --git a/server/upload/internal/logic/uploadlogologic.go b/server/upload/internal/logic/uploadlogologic.go index 658077cb..7db0fed9 100644 --- a/server/upload/internal/logic/uploadlogologic.go +++ b/server/upload/internal/logic/uploadlogologic.go @@ -1,7 +1,6 @@ package logic import ( - "encoding/json" "fmt" "fusenapi/model/gmodel" "fusenapi/service/repositories" @@ -9,7 +8,6 @@ import ( "fusenapi/utils/basic" "fusenapi/utils/file" "fusenapi/utils/hash" - "fusenapi/utils/metadata" "io" "net/http" "time" @@ -190,88 +188,23 @@ func (l *UploadLogoLogic) UploadLogo(req *types.UploadLogoReq, userinfo *auth.Us var module = "logo" var nowTime = time.Now().UTC() + // 新增素材记录 + materialInfo := gmodel.FsUserMaterial{ + Module: &module, + UserId: &userId, + GuestId: &guestId, + ResourceId: &uploadRes.ResourceId, + ResourceUrl: &uploadRes.ResourceUrl, + Metadata: &resultStrB, + Ctime: &nowTime, + } err = l.svcCtx.MysqlConn.WithContext(l.ctx).Transaction(func(tx *gorm.DB) error { - // 新增素材记录 - materialInfo := gmodel.FsUserMaterial{ - Module: &module, - UserId: &userId, - GuestId: &guestId, - ResourceId: &uploadRes.ResourceId, - ResourceUrl: &uploadRes.ResourceUrl, - Metadata: &resultStrB, - Ctime: &nowTime, - } resCreate := tx.Create(&materialInfo) err = resCreate.Error if err != nil { logc.Errorf(l.ctx, "FsUserInfo First err:%+v", err) return err } - // 更新用户信息 - var module = "profile" - userInfoGorm := tx.Where("module = ?", module) - userInfo := gmodel.FsUserInfo{} - if userId > 0 { - userInfoGorm.Where("user_id = ?", userId) - userInfo.UserId = &userId - } else { - userInfoGorm.Where("guest_id = ?", guestId) - userInfo.GuestId = &guestId - } - resFirst := userInfoGorm.First(&userInfo) - err = resFirst.Error - if err != nil { - if err != gorm.ErrRecordNotFound { - logc.Errorf(l.ctx, "FsUserInfo First err:%+v", err) - return err - } - } - var metadataMap map[string]interface{} - var metadataMapOld map[string]interface{} - if userInfo.Id > 0 { - err = json.Unmarshal(*userInfo.Metadata, &metadataMapOld) - if err != nil { - logc.Errorf(l.ctx, "userInfo.Metadata Unmarshal err:%+v", err) - return err - } - } - var metadataChild = make(map[string]interface{}, 1) - metadataChild["logo_selected_id"] = materialInfo.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 - } - userInfo.Metadata = &metadataB - if userInfo.Id > 0 { - userInfo.Utime = &nowTime - resUpdates := tx.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 - } - } - } else { - var nowTime = time.Now().UTC() - userInfo.Module = &module - userInfo.Ctime = &nowTime - userInfo.Utime = &nowTime - resCreate := tx.Create(&userInfo) - err = resCreate.Error - if err != nil { - if err != gorm.ErrRecordNotFound { - logc.Errorf(l.ctx, "FsUserInfo Create err:%+v", err) - return err - } - } - } return nil }) @@ -284,6 +217,7 @@ func (l *UploadLogoLogic) UploadLogo(req *types.UploadLogoReq, userinfo *auth.Us return resp.SetStatus(basic.CodeOK, map[string]interface{}{ "upload_data": UploadUrl{ Status: 1, + LogoId: materialInfo.Id, ResourceId: uploadRes.ResourceId, ResourceUrl: uploadRes.ResourceUrl, }, diff --git a/server_api/home-user-auth.api b/server_api/home-user-auth.api index d97db2ca..65fb4fd0 100644 --- a/server_api/home-user-auth.api +++ b/server_api/home-user-auth.api @@ -67,8 +67,19 @@ service home-user-auth { // 保存商户信息 @handler UserInfoSetHandler post /api/user/set_user_info (UserInfoSetReq) returns (response); + + // 用户logo设置当前 + @handler UserLogoSetHandler + get /api/user/logo-set (UserLogoSetReq) returns (response); } +type ( + UserLogoSetReq { + LogoSelectedId int64 `form:"logo_selected_id"` + CategoryId int64 `form:"category_id,optional"` + } +) + type ( UserInfoSetReq { Module string `form:"module,options=[merchant_category,logo_merchant_category,profile]"` // json格式字符串 From 7543f99f8b16e68f3f56a01232535c1dec439a9e Mon Sep 17 00:00:00 2001 From: momo <1012651275@qq.com> Date: Fri, 8 Sep 2023 11:47:53 +0800 Subject: [PATCH 02/14] =?UTF-8?q?fix:=E8=AE=BE=E7=BD=AE=E5=BD=93=E5=89=8Dl?= =?UTF-8?q?ogo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- model/gmodel/fs_user_material_logic.go | 9 ++ .../home-user-auth/internal/handler/routes.go | 2 +- .../internal/logic/userlogosetlogic.go | 144 +++++++++--------- server/home-user-auth/internal/types/types.go | 6 +- server_api/home-user-auth.api | 8 +- utils/basic/basic.go | 1 + 6 files changed, 96 insertions(+), 74 deletions(-) diff --git a/model/gmodel/fs_user_material_logic.go b/model/gmodel/fs_user_material_logic.go index c353b9ad..ebe8cb9d 100644 --- a/model/gmodel/fs_user_material_logic.go +++ b/model/gmodel/fs_user_material_logic.go @@ -52,6 +52,15 @@ func (m *FsUserMaterialModel) FindAll(ctx context.Context, rowBuilder *gorm.DB, return resp, nil } } +func (m *FsUserMaterialModel) FindOne(ctx context.Context, rowBuilder *gorm.DB) (*FsUserMaterial, error) { + var resp *FsUserMaterial + result := rowBuilder.WithContext(ctx).First(&resp) + if result.Error != nil { + return nil, result.Error + } else { + return resp, nil + } +} func (m *FsUserMaterialModel) FindList(ctx context.Context, rowBuilder *gorm.DB, filterMap map[string]string, orderBy string) ([]*RelaFsUserMaterial, error) { var resp []*RelaFsUserMaterial diff --git a/server/home-user-auth/internal/handler/routes.go b/server/home-user-auth/internal/handler/routes.go index 60b66955..1116922b 100644 --- a/server/home-user-auth/internal/handler/routes.go +++ b/server/home-user-auth/internal/handler/routes.go @@ -88,7 +88,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { Handler: UserInfoSetHandler(serverCtx), }, { - Method: http.MethodGet, + Method: http.MethodPost, Path: "/api/user/logo-set", Handler: UserLogoSetHandler(serverCtx), }, diff --git a/server/home-user-auth/internal/logic/userlogosetlogic.go b/server/home-user-auth/internal/logic/userlogosetlogic.go index 91b93fb0..99f1e04d 100644 --- a/server/home-user-auth/internal/logic/userlogosetlogic.go +++ b/server/home-user-auth/internal/logic/userlogosetlogic.go @@ -45,101 +45,110 @@ func (l *UserLogoSetLogic) UserLogoSet(req *types.UserLogoSetReq, userinfo *auth // 如果是,返回未授权的错误码 return resp.SetStatus(basic.CodeUnAuth) } + if req.LogoSelectedId == 0 { + return resp.SetStatus(basic.CodeLogoSetCategory, "logo logo_selected_id not null") + } + if req.SetLogoCategory == 1 && req.CategoryId == 0 { + return resp.SetStatus(basic.CodeLogoSetCategory, "logo category_id not null") + } var userId int64 var guestId int64 + NewFsUserMaterialModel := gmodel.NewFsUserMaterialModel(l.svcCtx.MysqlConn) + NewFsUserMaterialModelRow := NewFsUserMaterialModel.RowSelectBuilder(nil).Where("id = ?", req.LogoSelectedId) - // 检查用户是否是游客 if userinfo.IsGuest() { // 如果是,使用游客ID和游客键名格式 guestId = userinfo.GuestId + NewFsUserMaterialModelRow.Where("guest_id = ?", guestId) } else { // 否则,使用用户ID和用户键名格式 userId = userinfo.UserId + NewFsUserMaterialModelRow.Where("user_id = ?", userId) } - var userInfo = &gmodel.FsUserInfo{} - fsUserInfoModel := gmodel.NewFsUserInfoModel(l.svcCtx.MysqlConn) - BuilderDB := fsUserInfoModel.BuilderDB(l.ctx, nil).Model(&gmodel.FsUserInfo{}).Where("module = ?", "profile") - if userId > 0 { - BuilderDB.Where("user_id=?", userId) - } else { - BuilderDB.Where("guest_id=?", guestId) - } - userInfo, err := fsUserInfoModel.FindOne(BuilderDB, nil) + userMaterialInfo, err := NewFsUserMaterialModel.FindOne(l.ctx, NewFsUserMaterialModelRow.Model(&gmodel.FsUserMaterial{})) if err != nil { - if errors.Is(err, gorm.ErrRecordNotFound) { - logx.Error(err) - return resp.SetStatus(basic.CodeDbSqlErr, "UserInfoSet error system failed") - } + logc.Errorf(l.ctx, "FsUserMaterial FindOne err:%+v", err) + return resp.SetStatus(basic.CodeLogoSetCategory, "logo not find") } var nowTime = time.Now().UTC() - - var metadataMap map[string]interface{} err = l.svcCtx.MysqlConn.WithContext(l.ctx).Transaction(func(tx *gorm.DB) error { - if userInfo.Id != 0 { - var metadataMapOld map[string]interface{} - json.Unmarshal(*userInfo.Metadata, &metadataMapOld) - } // 更新merchant_category - if req.Module == "merchant_category" { - logoSelectedId, isEx := metadataMapOld["logo_selected_id"] - if isEx { - var materialId int64 = int64(logoSelectedId.(float64)) + if req.SetLogoCategory == 1 { - var userMaterialInfo gmodel.FsUserMaterial - userMaterialGorm := tx.Where("id = ?", materialId) - resUserMaterialInfo := userMaterialGorm.First(&userMaterialInfo) - err = resUserMaterialInfo.Error + var metadataMapOldUserMaterial map[string]interface{} + if userMaterialInfo.Metadata != nil { + err = json.Unmarshal(*userMaterialInfo.Metadata, &metadataMapOldUserMaterial) if err != nil { - logc.Errorf(l.ctx, "FsUserMaterial First err:%+v", err) + logc.Errorf(l.ctx, "userMaterialInfo Metadata Unmarshal err:%+v", err) return err } - 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 - } - } } - } else { - var metadataChild = make(map[string]interface{}, 1) - metadataChild["logo_selected_id"] = reqMetadata["logo_selected_id"] - metadataMap, err = metadata.SetMetadata(metadataChild, metadataMapOld) + var metadataChildUserMaterial = make(map[string]interface{}, 1) + metadataChildUserMaterial["merchant_category"] = req.CategoryId + metadataMapUserMaterial, err := metadata.SetMetadata(metadataChildUserMaterial, metadataMapOldUserMaterial) if err != nil { - logc.Errorf(l.ctx, "metadata SetMetadata err:%+v", err) + logc.Errorf(l.ctx, "userMaterialInfo Metadata SetMetadata err:%+v", err) return err } - metadataB, err := json.Marshal(metadataMap) + metadataBUserMaterial, err := json.Marshal(metadataMapUserMaterial) if err != nil { - logc.Errorf(l.ctx, "metadata marshal err:%+v", err) + logc.Errorf(l.ctx, "userMaterialInfo Metadata err:%+v", err) return err } - userInfo.Metadata = &metadataB + userMaterialInfo.Metadata = &metadataBUserMaterial + resUpdates := tx.Select("metadata").Where("id = ?", req.LogoSelectedId).Updates(&userMaterialInfo) + err = resUpdates.Error + if err != nil { + if err != gorm.ErrRecordNotFound { + logc.Errorf(l.ctx, "userMaterialInfo Updates err:%+v", err) + return err + } + } + + } + + if req.SetLogoSelected == 1 { + + var userInfo = &gmodel.FsUserInfo{} + BuilderDB := tx.Model(&gmodel.FsUserInfo{}).Where("module = ?", "profile") + if userId > 0 { + BuilderDB.Where("user_id=?", userId) + } else { + BuilderDB.Where("guest_id=?", guestId) + } + userInfoFirstRes := BuilderDB.First(userInfo) + err = userInfoFirstRes.Error + if err != nil { + if errors.Is(err, gorm.ErrRecordNotFound) { + logc.Errorf(l.ctx, "userInfo First err:%+v", err) + return err + } + } + var metadataMapOldUserInfo map[string]interface{} + if userInfo.Metadata != nil { + err = json.Unmarshal(*userInfo.Metadata, &metadataMapOldUserInfo) + if err != nil { + logc.Errorf(l.ctx, "userInfo Metadata Unmarshal err:%+v", err) + return err + } + } + + var metadataChildUserInfo = make(map[string]interface{}, 1) + metadataChildUserInfo["logo_selected_id"] = req.LogoSelectedId + metadataMapUserInfo, err := metadata.SetMetadata(metadataChildUserInfo, metadataMapOldUserInfo) + if err != nil { + logc.Errorf(l.ctx, "userInfo Metadata SetMetadata err:%+v", err) + return err + } + metadataBUserInfo, err := json.Marshal(metadataMapUserInfo) + if err != nil { + logc.Errorf(l.ctx, "userInfo Metadata marshal err:%+v", err) + return err + } + userInfo.Metadata = &metadataBUserInfo userInfo.Utime = &nowTime resUpdates := tx.Model(&userInfo).Select("metadata").Where("id = ?", userInfo.Id).Updates(&userInfo) err = resUpdates.Error @@ -150,12 +159,11 @@ func (l *UserLogoSetLogic) UserLogoSet(req *types.UserLogoSetReq, userinfo *auth } } } - return nil }) if err != nil { logx.Error(err) - return resp.SetStatus(basic.CodeDbSqlErr, "service fail") + return resp.SetStatus(basic.CodeDbSqlErr, "set logo fail") } return resp.SetStatus(basic.CodeOK) } diff --git a/server/home-user-auth/internal/types/types.go b/server/home-user-auth/internal/types/types.go index 763ebe23..0ec0cfaa 100644 --- a/server/home-user-auth/internal/types/types.go +++ b/server/home-user-auth/internal/types/types.go @@ -6,8 +6,10 @@ import ( ) type UserLogoSetReq struct { - LogoSelectedId int64 `form:"logo_selected_id"` - CategoryId int64 `form:"category_id,optional"` + SetLogoSelected int64 `form:"set_logo_selected"` + LogoSelectedId int64 `form:"logo_selected_id"` + SetLogoCategory int64 `form:"set_logo_category"` + CategoryId int64 `form:"category_id"` } type UserInfoSetReq struct { diff --git a/server_api/home-user-auth.api b/server_api/home-user-auth.api index 65fb4fd0..2b030c28 100644 --- a/server_api/home-user-auth.api +++ b/server_api/home-user-auth.api @@ -70,13 +70,15 @@ service home-user-auth { // 用户logo设置当前 @handler UserLogoSetHandler - get /api/user/logo-set (UserLogoSetReq) returns (response); + post /api/user/logo-set (UserLogoSetReq) returns (response); } type ( UserLogoSetReq { - LogoSelectedId int64 `form:"logo_selected_id"` - CategoryId int64 `form:"category_id,optional"` + SetLogoSelected int64 `form:"set_logo_selected"` + LogoSelectedId int64 `form:"logo_selected_id"` + SetLogoCategory int64 `form:"set_logo_category"` + CategoryId int64 `form:"category_id"` } ) diff --git a/utils/basic/basic.go b/utils/basic/basic.go index afce9235..35f17a2b 100644 --- a/utils/basic/basic.go +++ b/utils/basic/basic.go @@ -95,6 +95,7 @@ var ( CodeFileUploadLogoErrType = &StatusResponse{5111, "logo upload err file is not image"} // 用户上位LOGO失败"} CodeFileLogoCombineErr = &StatusResponse{5112, "logo upload err"} // 用户合图失败 CodeFileNoFoundErr = &StatusResponse{5113, "file not found err"} // 文件不存在 + CodeLogoSetCategory = &StatusResponse{5114, "logo set category fail"} // 文件不存在 ) type Response struct { From ae020a8b788a0174c984ea83dddbd77c81e0dc64 Mon Sep 17 00:00:00 2001 From: momo <1012651275@qq.com> Date: Fri, 8 Sep 2023 11:49:10 +0800 Subject: [PATCH 03/14] =?UTF-8?q?fix:=E8=AE=BE=E7=BD=AE=E5=BD=93=E5=89=8Dl?= =?UTF-8?q?ogo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go.mod | 1 - go.sum | 2 -- 2 files changed, 3 deletions(-) diff --git a/go.mod b/go.mod index 069b20a9..01c94f65 100644 --- a/go.mod +++ b/go.mod @@ -123,5 +123,4 @@ require ( google.golang.org/grpc v1.56.2 // indirect google.golang.org/protobuf v1.31.0 // indirect gopkg.in/yaml.v2 v2.4.0 - gorm.io/datatypes v1.2.0 ) diff --git a/go.sum b/go.sum index cabd1d03..67d9f1b0 100644 --- a/go.sum +++ b/go.sum @@ -986,8 +986,6 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gorm.io/datatypes v1.2.0 h1:5YT+eokWdIxhJgWHdrb2zYUimyk0+TaFth+7a0ybzco= -gorm.io/datatypes v1.2.0/go.mod h1:o1dh0ZvjIjhH/bngTpypG6lVRJ5chTBxE09FH/71k04= gorm.io/driver/mysql v1.5.1 h1:WUEH5VF9obL/lTtzjmML/5e6VfFR/788coz2uaVCAZw= gorm.io/driver/mysql v1.5.1/go.mod h1:Jo3Xu7mMhCyj8dlrb3WoCaRd1FhsVh+yMXb1jUInf5o= gorm.io/gorm v1.25.1 h1:nsSALe5Pr+cM3V1qwwQ7rOkw+6UeLrX5O4v3llhHa64= From d6c43e3e94ee6631a1ef212e2ca061f5147bf432 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Fri, 8 Sep 2023 14:23:34 +0800 Subject: [PATCH 04/14] fix --- .../internal/logic/ws_render_image.go | 34 +++++++------------ 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/server/websocket/internal/logic/ws_render_image.go b/server/websocket/internal/logic/ws_render_image.go index 26976272..167d3831 100644 --- a/server/websocket/internal/logic/ws_render_image.go +++ b/server/websocket/internal/logic/ws_render_image.go @@ -110,29 +110,21 @@ func (w *wsConnectItem) renderImage(data []byte) { w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "该产品不可定制", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0) return } - //获取上传最近的logo - userMaterial, err := w.logic.svcCtx.AllModels.FsUserMaterial.FindLatestOne(w.logic.ctx, w.userId, w.guestId) + //获取用户需要渲染logo + logoInfo, err := w.logic.svcCtx.Repositories.ImageHandle.LogoInfo(w.logic.ctx, &repositories.LogoInfoReq{ + UserId: w.userId, + GuestId: w.guestId, + }) if err != nil { - if !errors.Is(err, gorm.ErrRecordNotFound) { - w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "获取用户上传logo素材失败", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0) - logx.Error("failed to get user logo") - return - } - //使用默认logo(id=0) - userMaterialDefault, err := w.logic.svcCtx.AllModels.FsUserMaterial.FindOneById(w.logic.ctx, 0) - if err != nil { - if errors.Is(err, gorm.ErrRecordNotFound) { - w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "默认logo不存在", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0) - return - } - w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "获取默认logo失败", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0) - logx.Error("default logo is not exists") - return - } - renderImageData.RenderData.Logo = *userMaterialDefault.ResourceUrl - } else { - renderImageData.RenderData.Logo = *userMaterial.ResourceUrl + w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "获取用户logo素材错误", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0) + logx.Error(err) + return } + if logoInfo == nil || logoInfo.LogoUrl == nil { + w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "用户logo素材url是空的", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0) + return + } + renderImageData.RenderData.Logo = *logoInfo.LogoUrl //用户id赋值 renderImageData.RenderData.UserId = w.userId renderImageData.RenderData.GuestId = w.guestId From b7882ef06f450f2431215b03b512e58aa9a98936 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Fri, 8 Sep 2023 14:25:47 +0800 Subject: [PATCH 05/14] fix --- model/gmodel/fs_product_logic.go | 8 ++++++-- server/websocket/internal/logic/ws_render_image.go | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/model/gmodel/fs_product_logic.go b/model/gmodel/fs_product_logic.go index 95c301ce..8e7cca3c 100755 --- a/model/gmodel/fs_product_logic.go +++ b/model/gmodel/fs_product_logic.go @@ -2,8 +2,12 @@ package gmodel import "context" -func (p *FsProductModel) FindOne(ctx context.Context, id int64) (resp *FsProduct, err error) { - err = p.db.WithContext(ctx).Model(&FsProduct{}).Where("`id` = ? ", id).First(&resp).Error +func (p *FsProductModel) FindOne(ctx context.Context, id int64, fields ...string) (resp *FsProduct, err error) { + db := p.db.WithContext(ctx).Model(&FsProduct{}).Where("`id` = ? ", id) + if len(fields) != 0 { + db = db.Select(fields[0]) + } + err = db.Take(&resp).Error return resp, err } func (p *FsProductModel) FindOneBySn(ctx context.Context, sn string, fields ...string) (resp *FsProduct, err error) { diff --git a/server/websocket/internal/logic/ws_render_image.go b/server/websocket/internal/logic/ws_render_image.go index 167d3831..84f858df 100644 --- a/server/websocket/internal/logic/ws_render_image.go +++ b/server/websocket/internal/logic/ws_render_image.go @@ -94,8 +94,8 @@ func (w *wsConnectItem) renderImage(data []byte) { logx.Error("invalid format of websocket render image message", err) return } - //获取产品信息 - productInfo, err := w.logic.svcCtx.AllModels.FsProduct.FindOne(w.logic.ctx, renderImageData.RenderData.ProductId) + //获取产品信息(部分字段) + productInfo, err := w.logic.svcCtx.AllModels.FsProduct.FindOne(w.logic.ctx, renderImageData.RenderData.ProductId, "id,is_customization") if err != nil { if errors.Is(err, gorm.ErrRecordNotFound) { w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "该产品不存在", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0) From 62256cdde99fb94cf31987627adfc01a91d4c79d Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Fri, 8 Sep 2023 16:57:32 +0800 Subject: [PATCH 06/14] fix --- server/websocket/internal/logic/datatransferlogic.go | 1 + server/websocket/internal/logic/ws_render_image.go | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/server/websocket/internal/logic/datatransferlogic.go b/server/websocket/internal/logic/datatransferlogic.go index a01a9970..19f3704d 100644 --- a/server/websocket/internal/logic/datatransferlogic.go +++ b/server/websocket/internal/logic/datatransferlogic.go @@ -195,6 +195,7 @@ func (l *DataTransferLogic) setConnPool(conn *websocket.Conn, userInfo *auth.Use renderImageTask: make(map[string]*renderTask), renderImageTaskCtlChan: make(chan renderImageControlChanItem, renderImageTaskCtlChanLen), renderChan: make(chan []byte, renderChanLen), + renderConsumeTickTime: 1, //默认1纳秒,后面需要根据不同用户不同触发速度 }, } //保存连接 diff --git a/server/websocket/internal/logic/ws_render_image.go b/server/websocket/internal/logic/ws_render_image.go index 84f858df..d1cc0405 100644 --- a/server/websocket/internal/logic/ws_render_image.go +++ b/server/websocket/internal/logic/ws_render_image.go @@ -35,6 +35,7 @@ type extendRenderProperty struct { renderImageTask map[string]*renderTask //需要渲染的图片任务 key是taskId val 是renderId renderImageTaskCtlChan chan renderImageControlChanItem //渲染任务新增/回调结果移除任务/更新渲染耗时属性的控制通道(由于任务map无法读写并发) renderChan chan []byte //渲染消息入口的缓冲队列 + renderConsumeTickTime time.Duration //消费渲染消息时钟间隔(纳秒),用于后期控制不同类型用户渲染速度限制 } // 渲染任务新增移除的控制通道的数据 @@ -74,15 +75,15 @@ func (w *wsConnectItem) consumeRenderImageData() { logx.Error("func renderImage err:", err) } }() + tick := time.Tick(w.extendRenderProperty.renderConsumeTickTime) for { select { case <-w.closeChan: //已关闭 return - case data := <-w.extendRenderProperty.renderChan: - w.renderImage(data) + case <-tick: //消费数据 + w.renderImage(<-w.extendRenderProperty.renderChan) } } - } // 执行渲染任务 From c006cdc9b967f2bfab998dbeb63e953203fb9bd2 Mon Sep 17 00:00:00 2001 From: momo <1012651275@qq.com> Date: Fri, 8 Sep 2023 17:36:11 +0800 Subject: [PATCH 07/14] =?UTF-8?q?fix:=E8=AE=BE=E7=BD=AE=E5=BD=93=E5=89=8Dl?= =?UTF-8?q?ogo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- model/gmodel/fs_user_material_logic.go | 10 +++ .../internal/logic/userlogolistlogic.go | 74 ++++++++++++++++++- .../internal/logic/logoresizelogic.go | 3 +- 3 files changed, 82 insertions(+), 5 deletions(-) diff --git a/model/gmodel/fs_user_material_logic.go b/model/gmodel/fs_user_material_logic.go index ebe8cb9d..77ae2736 100644 --- a/model/gmodel/fs_user_material_logic.go +++ b/model/gmodel/fs_user_material_logic.go @@ -62,6 +62,16 @@ func (m *FsUserMaterialModel) FindOne(ctx context.Context, rowBuilder *gorm.DB) } } +func (m *FsUserMaterialModel) FindOneData(ctx context.Context, rowBuilder *gorm.DB) (*RelaFsUserMaterial, error) { + var resp *RelaFsUserMaterial + result := rowBuilder.WithContext(ctx).First(&resp) + if result.Error != nil { + return nil, result.Error + } else { + return resp, nil + } +} + func (m *FsUserMaterialModel) FindList(ctx context.Context, rowBuilder *gorm.DB, filterMap map[string]string, orderBy string) ([]*RelaFsUserMaterial, error) { var resp []*RelaFsUserMaterial // 过滤 diff --git a/server/home-user-auth/internal/logic/userlogolistlogic.go b/server/home-user-auth/internal/logic/userlogolistlogic.go index 033fd0ed..24e6b179 100644 --- a/server/home-user-auth/internal/logic/userlogolistlogic.go +++ b/server/home-user-auth/internal/logic/userlogolistlogic.go @@ -12,6 +12,7 @@ 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" ) @@ -46,19 +47,76 @@ func (l *UserLogoListLogic) UserLogoList(req *types.UserLogoListReq, userinfo *a var userId int64 var guestId int64 + if userinfo.IsOnlooker() { + // 如果是,返回未授权的错误码 + return resp.SetStatus(basic.CodeUnAuth) + } + + // 用户信息 + NewFsUserInfoModel := gmodel.NewFsUserInfoModel(l.svcCtx.MysqlConn) + userInfoGorm := NewFsUserInfoModel.BuilderDB(l.ctx, nil).Where("module = ?", "profile") + userInfo := gmodel.FsUserInfo{} + // 检查用户是否是游客 if userinfo.IsGuest() { // 如果是,使用游客ID和游客键名格式 guestId = userinfo.GuestId + userInfoGorm.Where("guest_id = ?", guestId) } else { // 否则,使用用户ID和用户键名格式 userId = userinfo.UserId + userInfoGorm.Where("user_id = ?", userId) + } + var merchantCategoryIds []int64 + var logoSelectedIdd int64 + var userMaterialInfo *gmodel.RelaFsUserMaterial + userMaterialModel := gmodel.NewFsUserMaterialModel(l.svcCtx.MysqlConn) + resFirst := userInfoGorm.First(&userInfo) + err := resFirst.Error + if err != nil { + if err != gorm.ErrRecordNotFound { + logc.Errorf(l.ctx, "FsUserInfo First err:%+v", err) + return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "data not found") + } + } + if userInfo.Id != 0 && userInfo.Metadata != nil { + var metadata map[string]interface{} + err = json.Unmarshal([]byte(*userInfo.Metadata), &metadata) + if err != nil { + logc.Errorf(l.ctx, "userInfo.Metadata Unmarshal err:%+v", err) + return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get data list") + } + logoSelectedId, isEx := metadata["logo_selected_id"] + if isEx { + logoSelectedIdd = int64(logoSelectedId.(float64)) + userMaterialRSB1 := userMaterialModel.RowSelectBuilder(nil).Preload("ResourceInfo", func(dbPreload *gorm.DB) *gorm.DB { + return dbPreload.Table(gmodel.NewFsResourceModel(l.svcCtx.MysqlConn).TableName()) + }).Where("module = ?", "logo").Where("id = ?", logoSelectedIdd) + userMaterialInfo, err = userMaterialModel.FindOneData(l.ctx, userMaterialRSB1) + if err != nil { + if err != gorm.ErrRecordNotFound { + logc.Errorf(l.ctx, "FsUserInfo First err:%+v", err) + return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get data list") + } + } + var metadataMapuserMaterialInfo map[string]interface{} + if userMaterialInfo.Metadata != nil { + json.Unmarshal(*userMaterialInfo.Metadata, &metadataMapuserMaterialInfo) + merchantCategoryuserMaterialInfo, merchantCategoryEixuserMaterialInfo := metadataMapuserMaterialInfo["merchant_category"] + if merchantCategoryEixuserMaterialInfo { + merchantCategoryIduserMaterialInfo := int64(merchantCategoryuserMaterialInfo.(float64)) + merchantCategoryIds = append(merchantCategoryIds, merchantCategoryIduserMaterialInfo) + } + } + userMaterialInfo.MetaDataMap = metadataMapuserMaterialInfo + } } - userMaterialModel := gmodel.NewFsUserMaterialModel(l.svcCtx.MysqlConn) + // 历史列表 + 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) + }).Where("module = ?", "logo").Order("id desc").Limit(5) if userId != 0 { userMaterialRSB.Where("user_id = ?", userId) } else { @@ -72,8 +130,8 @@ func (l *UserLogoListLogic) UserLogoList(req *types.UserLogoListReq, userinfo *a logx.Error(err) return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get data list") } + var isDefaul bool = false if len(list) > 0 { - var merchantCategoryIds []int64 for _, v := range list { var metadataMap map[string]interface{} if v.Metadata != nil { @@ -95,6 +153,10 @@ func (l *UserLogoListLogic) UserLogoList(req *types.UserLogoListReq, userinfo *a v.ResourceInfo.MetaDataMap = resourceMetadata } } + + if logoSelectedIdd == v.Id { + isDefaul = true + } } if len(merchantCategoryIds) > 0 { newFsMerchantCategoryModel := gmodel.NewFsMerchantCategoryModel(l.svcCtx.MysqlConn) @@ -111,7 +173,10 @@ func (l *UserLogoListLogic) UserLogoList(req *types.UserLogoListReq, userinfo *a merchantCategoryData[v.Id] = v } } - for _, v := range list { + for k, v := range list { + if !isDefaul && k == 4 && userMaterialInfo != nil { + v = userMaterialInfo + } if v.MetaDataMap != nil { merchantCategory1, merchantCategoryEix1 := v.MetaDataMap["merchant_category"] if merchantCategoryEix1 { @@ -121,6 +186,7 @@ func (l *UserLogoListLogic) UserLogoList(req *types.UserLogoListReq, userinfo *a v.MetaDataMap["merchant_category_info"] = nil } } + list[k] = v } } } diff --git a/server/resource/internal/logic/logoresizelogic.go b/server/resource/internal/logic/logoresizelogic.go index c405915d..47526031 100644 --- a/server/resource/internal/logic/logoresizelogic.go +++ b/server/resource/internal/logic/logoresizelogic.go @@ -98,7 +98,7 @@ func (l *LogoResizeLogic) LogoResize(req *types.LogoResizeReq, userinfo *auth.Us hashKeyDataB, _ := json.Marshal(req) json.Unmarshal(hashKeyDataB, &hashKeyDataMap) var resourceId string = hash.JsonHashKey(hashKeyDataMap) - fmt.Println(resourceId) + //fmt.Println(resourceId) // 上传文件 var upload = file.Upload{ @@ -107,6 +107,7 @@ func (l *LogoResizeLogic) LogoResize(req *types.LogoResizeReq, userinfo *auth.Us AwsSession: l.svcCtx.AwsSession, } uploadRes, err := upload.UploadFileByByte(&file.UploadBaseReq{ + Refresh: 1, FileHash: resourceId, FileByte: emptyBuff.Bytes(), UploadBucket: 1, From a5b5dff4d2626ea4775f4767f9017dabd1adc37a Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Fri, 8 Sep 2023 17:54:57 +0800 Subject: [PATCH 08/14] fix --- server/product/internal/logic/getrecommandproductlistlogic.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/product/internal/logic/getrecommandproductlistlogic.go b/server/product/internal/logic/getrecommandproductlistlogic.go index 1f3d2326..c708f8f9 100644 --- a/server/product/internal/logic/getrecommandproductlistlogic.go +++ b/server/product/internal/logic/getrecommandproductlistlogic.go @@ -193,7 +193,7 @@ func (l *GetRecommandProductListLogic) GetRecommandProductList(req *types.GetRec Intro: *v.Intro, IsRecommend: isRecommend, MinPrice: minPrice, - IsCustomization: *productInfo.IsCustomization, + IsCustomization: *v.IsCustomization, } if _, ok := mapTagProp[productInfo.Id]; ok { item.CoverDefault = mapTagProp[productInfo.Id] From b329034cfc86f1cb200a13d25ec7526716f6d7fa Mon Sep 17 00:00:00 2001 From: momo <1012651275@qq.com> Date: Fri, 8 Sep 2023 18:16:19 +0800 Subject: [PATCH 09/14] =?UTF-8?q?fix:=E8=AE=BE=E7=BD=AE=E5=BD=93=E5=89=8Dl?= =?UTF-8?q?ogo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/home-user-auth/internal/logic/userlogolistlogic.go | 7 +++---- server/home-user-auth/internal/logic/userlogosetlogic.go | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/server/home-user-auth/internal/logic/userlogolistlogic.go b/server/home-user-auth/internal/logic/userlogolistlogic.go index 24e6b179..c77cdb85 100644 --- a/server/home-user-auth/internal/logic/userlogolistlogic.go +++ b/server/home-user-auth/internal/logic/userlogolistlogic.go @@ -124,11 +124,10 @@ func (l *UserLogoListLogic) UserLogoList(req *types.UserLogoListReq, userinfo *a } 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") + if !errors.Is(err, gorm.ErrRecordNotFound) { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get data list") } - logx.Error(err) - return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get data list") } var isDefaul bool = false if len(list) > 0 { diff --git a/server/home-user-auth/internal/logic/userlogosetlogic.go b/server/home-user-auth/internal/logic/userlogosetlogic.go index 99f1e04d..45d5dbf7 100644 --- a/server/home-user-auth/internal/logic/userlogosetlogic.go +++ b/server/home-user-auth/internal/logic/userlogosetlogic.go @@ -122,7 +122,7 @@ func (l *UserLogoSetLogic) UserLogoSet(req *types.UserLogoSetReq, userinfo *auth userInfoFirstRes := BuilderDB.First(userInfo) err = userInfoFirstRes.Error if err != nil { - if errors.Is(err, gorm.ErrRecordNotFound) { + if !errors.Is(err, gorm.ErrRecordNotFound) { logc.Errorf(l.ctx, "userInfo First err:%+v", err) return err } From 7abcfadd9388dce9cd8a538b347ddecc60818239 Mon Sep 17 00:00:00 2001 From: momo <1012651275@qq.com> Date: Fri, 8 Sep 2023 18:19:24 +0800 Subject: [PATCH 10/14] =?UTF-8?q?fix:=E8=AE=BE=E7=BD=AE=E5=BD=93=E5=89=8Dl?= =?UTF-8?q?ogo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../internal/logic/userlogosetlogic.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/server/home-user-auth/internal/logic/userlogosetlogic.go b/server/home-user-auth/internal/logic/userlogosetlogic.go index 45d5dbf7..cca077ca 100644 --- a/server/home-user-auth/internal/logic/userlogosetlogic.go +++ b/server/home-user-auth/internal/logic/userlogosetlogic.go @@ -150,8 +150,16 @@ func (l *UserLogoSetLogic) UserLogoSet(req *types.UserLogoSetReq, userinfo *auth } userInfo.Metadata = &metadataBUserInfo userInfo.Utime = &nowTime - resUpdates := tx.Model(&userInfo).Select("metadata").Where("id = ?", userInfo.Id).Updates(&userInfo) - err = resUpdates.Error + if userInfo.Id == 0 { + // 新增 + resCreate := tx.Model(&userInfo).Create(&userInfo) + err = resCreate.Error + } else { + // 更新 + 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) From bf9c6c9386cf79929b793daea2caf2eb20bfd721 Mon Sep 17 00:00:00 2001 From: momo <1012651275@qq.com> Date: Fri, 8 Sep 2023 18:22:44 +0800 Subject: [PATCH 11/14] =?UTF-8?q?fix:=E8=AE=BE=E7=BD=AE=E5=BD=93=E5=89=8Dl?= =?UTF-8?q?ogo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/home-user-auth/internal/logic/userlogosetlogic.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/server/home-user-auth/internal/logic/userlogosetlogic.go b/server/home-user-auth/internal/logic/userlogosetlogic.go index cca077ca..74ee1e6a 100644 --- a/server/home-user-auth/internal/logic/userlogosetlogic.go +++ b/server/home-user-auth/internal/logic/userlogosetlogic.go @@ -109,11 +109,11 @@ func (l *UserLogoSetLogic) UserLogoSet(req *types.UserLogoSetReq, userinfo *auth } } - + var module = "profile" if req.SetLogoSelected == 1 { var userInfo = &gmodel.FsUserInfo{} - BuilderDB := tx.Model(&gmodel.FsUserInfo{}).Where("module = ?", "profile") + BuilderDB := tx.Model(&gmodel.FsUserInfo{}).Where("module = ?", module) if userId > 0 { BuilderDB.Where("user_id=?", userId) } else { @@ -152,6 +152,7 @@ func (l *UserLogoSetLogic) UserLogoSet(req *types.UserLogoSetReq, userinfo *auth userInfo.Utime = &nowTime if userInfo.Id == 0 { // 新增 + userInfo.Module = &module resCreate := tx.Model(&userInfo).Create(&userInfo) err = resCreate.Error } else { From 37e0d03de197bc260ba766550574166a2f43e4e2 Mon Sep 17 00:00:00 2001 From: momo <1012651275@qq.com> Date: Fri, 8 Sep 2023 18:26:23 +0800 Subject: [PATCH 12/14] =?UTF-8?q?fix:=E8=AE=BE=E7=BD=AE=E5=BD=93=E5=89=8Dl?= =?UTF-8?q?ogo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/home-user-auth/internal/logic/userlogosetlogic.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/server/home-user-auth/internal/logic/userlogosetlogic.go b/server/home-user-auth/internal/logic/userlogosetlogic.go index 74ee1e6a..230b2af1 100644 --- a/server/home-user-auth/internal/logic/userlogosetlogic.go +++ b/server/home-user-auth/internal/logic/userlogosetlogic.go @@ -149,14 +149,19 @@ func (l *UserLogoSetLogic) UserLogoSet(req *types.UserLogoSetReq, userinfo *auth return err } userInfo.Metadata = &metadataBUserInfo - userInfo.Utime = &nowTime + if userInfo.Id == 0 { // 新增 userInfo.Module = &module + userInfo.Ctime = &nowTime + userInfo.Utime = &nowTime + userInfo.UserId = &userId + userInfo.GuestId = &guestId resCreate := tx.Model(&userInfo).Create(&userInfo) err = resCreate.Error } else { // 更新 + userInfo.Utime = &nowTime resUpdates := tx.Model(&userInfo).Select("metadata").Where("id = ?", userInfo.Id).Updates(&userInfo) err = resUpdates.Error } From 1f28a644425dc6f7fd777103d5f049860f63d115 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Fri, 8 Sep 2023 18:49:56 +0800 Subject: [PATCH 13/14] fix --- model/gmodel/fs_product_template_v2_logic.go | 2 +- server/websocket/internal/logic/ws_render_image.go | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/model/gmodel/fs_product_template_v2_logic.go b/model/gmodel/fs_product_template_v2_logic.go index c99314d1..bb657017 100755 --- a/model/gmodel/fs_product_template_v2_logic.go +++ b/model/gmodel/fs_product_template_v2_logic.go @@ -116,7 +116,7 @@ func (t *FsProductTemplateV2Model) GetProductTemplateListByParams(ctx context.Co // 获取开启云渲染模板 func (t *FsProductTemplateV2Model) FindOneCloudRenderByProductIdModelIdTemplateTag(ctx context.Context, productId, modelId int64, templateTag string) (resp *FsProductTemplateV2, err error) { err = t.db.WithContext(ctx).Model(&FsProductTemplateV2{}). - Where("product_id = ? and model_id = ? and template_tag = ? and element_model_id > ? ", productId, modelId, templateTag, 0). + Where("product_id = ? and model_id = ? and template_tag = ? ", productId, modelId, templateTag). Where("status = ? and is_del = ?", 1, 0). Order("sort ASC"). Take(&resp).Error diff --git a/server/websocket/internal/logic/ws_render_image.go b/server/websocket/internal/logic/ws_render_image.go index d1cc0405..1b47d116 100644 --- a/server/websocket/internal/logic/ws_render_image.go +++ b/server/websocket/internal/logic/ws_render_image.go @@ -278,7 +278,7 @@ func (w *wsConnectItem) getProductRelateionInfo(renderImageData websocket_data.R productTemplate, err = w.logic.svcCtx.AllModels.FsProductTemplateV2.FindOneCloudRenderByProductIdModelIdTemplateTag(w.logic.ctx, renderImageData.RenderData.ProductId, model3d.Id, renderImageData.RenderData.TemplateTag) if err != nil { if errors.Is(err, gorm.ErrRecordNotFound) { - w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "找不到对应开启云渲染的模板", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, model3d.Id, productSize.Id, 0) + w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "找不到对应的模板", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, model3d.Id, productSize.Id, 0) logx.Error("template info is not found") return nil, nil, nil, err } @@ -286,6 +286,10 @@ func (w *wsConnectItem) getProductRelateionInfo(renderImageData websocket_data.R logx.Error("failed to get template info:", err) return nil, nil, nil, err } + if *productTemplate.ElementModelId <= 0 { + w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "模板未开启云渲染", renderImageData.RenderData.ProductId, w.userId, w.guestId, productTemplate.Id, model3d.Id, productSize.Id, 0) + return nil, nil, nil, errors.New("模板未开启云渲染") + } if productTemplate.TemplateInfo == nil || *productTemplate.TemplateInfo == "" { w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "渲染模板的json设计信息是空的", renderImageData.RenderData.ProductId, w.userId, w.guestId, productTemplate.Id, model3d.Id, productSize.Id, 0) return nil, nil, nil, errors.New("渲染模板的json设计信息是空的") From e6c0558679bcba0c0d76a33fa2c63802de49d4da Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Fri, 8 Sep 2023 18:52:57 +0800 Subject: [PATCH 14/14] fix --- model/gmodel/fs_product_template_v2_logic.go | 2 +- server/websocket/internal/logic/ws_render_image.go | 6 +----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/model/gmodel/fs_product_template_v2_logic.go b/model/gmodel/fs_product_template_v2_logic.go index bb657017..c99314d1 100755 --- a/model/gmodel/fs_product_template_v2_logic.go +++ b/model/gmodel/fs_product_template_v2_logic.go @@ -116,7 +116,7 @@ func (t *FsProductTemplateV2Model) GetProductTemplateListByParams(ctx context.Co // 获取开启云渲染模板 func (t *FsProductTemplateV2Model) FindOneCloudRenderByProductIdModelIdTemplateTag(ctx context.Context, productId, modelId int64, templateTag string) (resp *FsProductTemplateV2, err error) { err = t.db.WithContext(ctx).Model(&FsProductTemplateV2{}). - Where("product_id = ? and model_id = ? and template_tag = ? ", productId, modelId, templateTag). + Where("product_id = ? and model_id = ? and template_tag = ? and element_model_id > ? ", productId, modelId, templateTag, 0). Where("status = ? and is_del = ?", 1, 0). Order("sort ASC"). Take(&resp).Error diff --git a/server/websocket/internal/logic/ws_render_image.go b/server/websocket/internal/logic/ws_render_image.go index 1b47d116..d1cc0405 100644 --- a/server/websocket/internal/logic/ws_render_image.go +++ b/server/websocket/internal/logic/ws_render_image.go @@ -278,7 +278,7 @@ func (w *wsConnectItem) getProductRelateionInfo(renderImageData websocket_data.R productTemplate, err = w.logic.svcCtx.AllModels.FsProductTemplateV2.FindOneCloudRenderByProductIdModelIdTemplateTag(w.logic.ctx, renderImageData.RenderData.ProductId, model3d.Id, renderImageData.RenderData.TemplateTag) if err != nil { if errors.Is(err, gorm.ErrRecordNotFound) { - w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "找不到对应的模板", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, model3d.Id, productSize.Id, 0) + w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "找不到对应开启云渲染的模板", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, model3d.Id, productSize.Id, 0) logx.Error("template info is not found") return nil, nil, nil, err } @@ -286,10 +286,6 @@ func (w *wsConnectItem) getProductRelateionInfo(renderImageData websocket_data.R logx.Error("failed to get template info:", err) return nil, nil, nil, err } - if *productTemplate.ElementModelId <= 0 { - w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "模板未开启云渲染", renderImageData.RenderData.ProductId, w.userId, w.guestId, productTemplate.Id, model3d.Id, productSize.Id, 0) - return nil, nil, nil, errors.New("模板未开启云渲染") - } if productTemplate.TemplateInfo == nil || *productTemplate.TemplateInfo == "" { w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "渲染模板的json设计信息是空的", renderImageData.RenderData.ProductId, w.userId, w.guestId, productTemplate.Id, model3d.Id, productSize.Id, 0) return nil, nil, nil, errors.New("渲染模板的json设计信息是空的")