From e4ce8b28dcc3f498747dfc0cfcb8d9a8e1753f7d Mon Sep 17 00:00:00 2001 From: chenweijian <820961417@qq.com> Date: Wed, 26 Jul 2023 14:36:18 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cv/cp_cv/rank.go | 12 ++++++------ cv/user_cv/user.go | 20 ++++++++++++++++++++ route/cp_r/rank.go | 16 ++++++++-------- 3 files changed, 34 insertions(+), 14 deletions(-) diff --git a/cv/cp_cv/rank.go b/cv/cp_cv/rank.go index f03c1f3..0e13eed 100644 --- a/cv/cp_cv/rank.go +++ b/cv/cp_cv/rank.go @@ -6,12 +6,12 @@ import ( ) type CvCpRank struct { - CpId uint64 `json:"cpId"` // cpId - User1 *user_cv.CvUserBase `json:"user1"` // user1 - User2 *user_cv.CvUserBase `json:"user2,omitempty"` // user2 - Score uint32 `json:"score"` // 分值 - CpLevel CvCpLevel `json:"cpLevel"` // cp等级 - Ranking string `json:"ranking"` // 排名 + CpId uint64 `json:"cpId"` // cpId + User1 *user_cv.CvUserLittle `json:"user1"` // user1 + User2 *user_cv.CvUserLittle `json:"user2,omitempty"` // user2 + Score uint32 `json:"score"` // 分值 + CpLevel CvCpLevel `json:"cpLevel"` // cp等级 + Ranking string `json:"ranking"` // 排名 } type CvCpAchievement struct { diff --git a/cv/user_cv/user.go b/cv/user_cv/user.go index 82e053d..6dc2378 100644 --- a/cv/user_cv/user.go +++ b/cv/user_cv/user.go @@ -111,6 +111,17 @@ type CvUserBase struct { GroupRole common.GroupRoleType `json:"groupRole"` // 在群组的角色 } +type CvUserLittle struct { + //不会有返回值 + Id *mysql.ID `json:"id,omitempty"` + //头像,不存在为nil + Avatar *string `json:"avatar"` + //用户对外ID + ExternalId *string `json:"externalId"` + //昵称,不存在为nil + Nick *string `json:"nick"` +} + //批量获取用户基本信息 func GetUserBases(userIds []mysql.ID, myUserId mysql.ID) ([]*CvUserBase, error) { if len(userIds) == 0 { @@ -516,3 +527,12 @@ type CvCpLevel struct { type CvPrivilege struct { Type cp_e.CpPrivilege `json:"type"` // 特权id 1:空间 2:横幅 3:等级勋章 4:证书 5:进场特效 6:头像头饰 7:动态资料卡 8:麦位特效 } + +func UserBaseToUserLittle(base *CvUserBase) *CvUserLittle { + return &CvUserLittle{ + Id: base.Id, + Avatar: base.Avatar, + ExternalId: base.ExternalId, + Nick: base.Nick, + } +} diff --git a/route/cp_r/rank.go b/route/cp_r/rank.go index 22fdc19..2a2caaf 100644 --- a/route/cp_r/rank.go +++ b/route/cp_r/rank.go @@ -81,8 +81,8 @@ func CpRank(c *gin.Context) (*mycontext.MyContext, error) { for i, rank := range ranks { response = append(response, cp_cv.CvCpRank{ CpId: rank.CpId, - User1: userBase[rank.UserId1], - User2: userBase[rank.UserId2], + User1: user_cv.UserBaseToUserLittle(userBase[rank.UserId1]), + User2: user_cv.UserBaseToUserLittle(userBase[rank.UserId2]), Score: rank.Score, Ranking: fmt.Sprintf("%d", i+1+offset), CpLevel: cp_cv.CvCpLevel{ @@ -143,8 +143,8 @@ func CpTop3(c *gin.Context) (*mycontext.MyContext, error) { if queryType == "day" { response.Day = append(response.Day, cp_cv.CvCpRank{ CpId: rank.CpId, - User1: userBase[rank.UserId1], - User2: userBase[rank.UserId2], + User1: user_cv.UserBaseToUserLittle(userBase[rank.UserId1]), + User2: user_cv.UserBaseToUserLittle(userBase[rank.UserId2]), Score: rank.Score, Ranking: fmt.Sprintf("%d", i+1+offset), CpLevel: cp_cv.CvCpLevel{ @@ -154,8 +154,8 @@ func CpTop3(c *gin.Context) (*mycontext.MyContext, error) { } else { response.Week = append(response.Week, cp_cv.CvCpRank{ CpId: rank.CpId, - User1: userBase[rank.UserId1], - User2: userBase[rank.UserId2], + User1: user_cv.UserBaseToUserLittle(userBase[rank.UserId1]), + User2: user_cv.UserBaseToUserLittle(userBase[rank.UserId2]), Score: rank.Score, Ranking: fmt.Sprintf("%d", i+1+offset), CpLevel: cp_cv.CvCpLevel{ @@ -224,10 +224,10 @@ func CpMy(c *gin.Context) (*mycontext.MyContext, error) { Score: scores, } if relation.UserId1 > 0 { - response.User1 = userBases[relation.UserId1] + response.User1 = user_cv.UserBaseToUserLittle(userBases[relation.UserId1]) } if relation.UserId2 > 0 { - response.User2 = userBases[relation.UserId2] + response.User2 = user_cv.UserBaseToUserLittle(userBases[relation.UserId2]) response.Ranking = "30+" ranks := cp_m.PageCpDayRank(model, beginDate, endDate, 0, 30) for i, rank := range ranks { -- 2.22.0 From 3b73212b822773b902f7ef8e16b882f1cabba6c9 Mon Sep 17 00:00:00 2001 From: chenweijian <820961417@qq.com> Date: Wed, 26 Jul 2023 16:17:34 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cv/user_cv/user.go | 51 ++++++++++++++++++++++++++++++++++++ route/router.go | 1 + route/user_r/user.go | 62 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 114 insertions(+) diff --git a/cv/user_cv/user.go b/cv/user_cv/user.go index 6dc2378..5aeee0c 100644 --- a/cv/user_cv/user.go +++ b/cv/user_cv/user.go @@ -1,6 +1,7 @@ package user_cv import ( + "encoding/json" "git.hilo.cn/hilo-common/_const/common" "git.hilo.cn/hilo-common/domain" "git.hilo.cn/hilo-common/mylogrus" @@ -493,6 +494,49 @@ type CvUserDetail struct { Cp *CvCp `json:"cp,omitempty"` // cp信息 } +//用户详细信息-在房间里面时需要的 +type CvUserDetailRoom struct { //不会有返回值 + //不会有返回值 + Id *mysql.ID `json:"id,omitempty"` + //头像,不存在为nil + Avatar *string `json:"avatar"` + //是否默认头像 true:是 false:不是 + DefaultAvatar *bool `json:"defaultAvatar"` + //用户对外ID + ExternalId *string `json:"externalId"` + //昵称,不存在为nil + Nick *string `json:"nick"` + //性别 1:男 2:女,不存在为nil + Sex *uint8 `json:"sex"` + //国家,不存在为nil + Country *string `json:"country"` + //国旗图标,不存在为nil + CountryIcon *string `json:"countryIcon"` + //邀请码 + Code *string `json:"code"` + IsPrettyCode bool `json:"isPrettyCode"` // 是否靓号 + //生日,如果是其它人用户信息,年龄则按照是否展示显示,如果是本人,年龄则按照是否存在展示 + Birthday *uint64 `json:"birthday"` + //是否展示年龄, 是本人才有数据,看其他用户均为nil + IsShowAge *uint8 `json:"isShowAge"` + //是否VIP用户 + IsVip bool `json:"isVip"` + Svip rpc.CvSvip `json:"svip"` // svip结构,等级+权限 + Medals []uint32 `json:"medals"` // 勋章列表 + Noble noble_cv.CvNoble `json:"noble"` // 当前的 + CountryManager *CVCountryManager `json:"countryManager,omitempty"` // 国家管理员 + Headwear *headwear_cv.CvHeadwear `json:"headwear"` // 当前使用的头饰 + WealthUserGrade uint32 `json:"wealthUserGrade"` //财富等级 + CharmUserGrade uint32 `json:"charmUserGrade"` //魅力等级 + ActivityUserGrade uint32 `json:"activityUserGrade"` //活跃等级 + GroupPower rpc.CvGroupPowerInfo `json:"groupPower"` // 家族 + //是否喜欢(本人没有数据,//20210205 已废弃nil,产品说:可以自己喜欢自己) + IsLike *bool `json:"isLike"` + //别人是否喜欢我,自己本人没有数据 (20210205 已废弃nil,产品说:可以自己喜欢自己) + IsLikeMe *bool `json:"isLikeMe"` + Cp *CvCp `json:"cp,omitempty"` // cp信息 +} + // cv国家管理人员 type CVCountryManager struct { Country string `json:"country"` // 国家name @@ -536,3 +580,10 @@ func UserBaseToUserLittle(base *CvUserBase) *CvUserLittle { Nick: base.Nick, } } + +func CvUserDetailToCvUserDetailRoom(info *CvUserDetail) *CvUserDetailRoom { + res := new(CvUserDetailRoom) + jData, _ := json.Marshal(info) + _ = json.Unmarshal(jData, &res) + return res +} diff --git a/route/router.go b/route/router.go index 81cfcb8..080a5d6 100644 --- a/route/router.go +++ b/route/router.go @@ -32,6 +32,7 @@ func InitRouter() *gin.Engine { user.GET("/bag/:resType", wrapper(user_r.UserBag)) user.GET("/detail", EncryptHandle, wrapper(user_r.UserDetail)) user.GET("/detail/:userExternalId", EncryptHandle, wrapper(user_r.UserDetailByExternalId)) + user.GET("/detail/room/:userExternalId", EncryptHandle, wrapper(user_r.GetUserDetailInRoom)) } cp := v2.Group("/cp") { diff --git a/route/user_r/user.go b/route/user_r/user.go index 87cf5cf..30c5fe2 100644 --- a/route/user_r/user.go +++ b/route/user_r/user.go @@ -7,6 +7,7 @@ import ( "git.hilo.cn/hilo-common/resource/redisCli" "github.com/gin-gonic/gin" "hilo-user/_const/redis_key/user_k" + "hilo-user/cv/user_cv" "hilo-user/domain/model/group_m" "hilo-user/domain/model/tim_m" "hilo-user/domain/service/user_s" @@ -106,3 +107,64 @@ func UserDetailByExternalId(c *gin.Context) (*mycontext.MyContext, error) { resp.ResponseOk(c, cvUserDetail) return myContext, nil } + +// @Tags 用户 +// @Summary 房间内获取用户信息 +// @Param userExternalId path string true "userExternalId" +// @Param groupId query string false "群组id,当传了该id,则返回该用户在该群组的身份" +// @Success 200 {object} user_cv.CvUserDetail +// @Router /v1/user/detail/room/{userExternalId} [get] +func GetUserDetailInRoom(c *gin.Context) (*mycontext.MyContext, error) { + myContext := mycontext.CreateMyContext(c.Keys) + userId, lang, err := req.GetUserIdLang(c, myContext) + if err != nil { + return myContext, err + } + otherUserId, err := req.ToUserId(myContext, mysql.Str(c.Param("userExternalId"))) + if err != nil { + return nil, err + } + model := domain.CreateModelContext(myContext) + + imGroupId := c.Query("groupId") + if imGroupId != "" { + imGroupId, err = group_m.ToImGroupId(model, imGroupId) + if err != nil { + return myContext, err + } + } + + cvUserDetail, err := user_s.NewUserService(myContext).GetUserDetail(otherUserId, userId, lang) + if err != nil { + return myContext, err + } + if imGroupId != "" { + cvUserDetail.GroupRole, err = group_m.GetGroupRoleById(model, imGroupId, otherUserId) + if err != nil { + return myContext, err + } + } + + if cvUserDetail != nil { + // 检查是否需要同步 + if n, err := redisCli.GetRedis().Exists(model, user_k.GetKeySyncTimHilo(userId)).Result(); err == nil { + if n == 0 { + // FIXME:转异步执行 + err = tim_m.FlushHiloInfo(*cvUserDetail.ExternalId, cvUserDetail.IsVip, cvUserDetail.IsPrettyCode, + cvUserDetail.Medals, cvUserDetail.MyGroupPowerName, cvUserDetail.Noble.Level) + if err == nil { + redisCli.GetRedis().Set(model, user_k.GetKeySyncTimHilo(userId), "1", time.Minute) + } else { + model.Log.Info("UserBaseByExternalId, FlushHiloInfo failed: ", err) + } + } else { + model.Log.Info("UserDetailByExternalId, no need to sync yet: ", userId) + } + } else { + model.Log.Info("UserDetailByExternalId, check KeySyncTimHilo failed", err) + } + } + + resp.ResponseOk(c, user_cv.CvUserDetailToCvUserDetailRoom(cvUserDetail)) + return myContext, nil +} -- 2.22.0 From a829b62a389bc08dcffad162603327c6b996d03b Mon Sep 17 00:00:00 2001 From: chenweijian <820961417@qq.com> Date: Wed, 26 Jul 2023 16:30:59 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- route/router.go | 2 +- route/user_r/user.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/route/router.go b/route/router.go index 080a5d6..e46b610 100644 --- a/route/router.go +++ b/route/router.go @@ -32,7 +32,7 @@ func InitRouter() *gin.Engine { user.GET("/bag/:resType", wrapper(user_r.UserBag)) user.GET("/detail", EncryptHandle, wrapper(user_r.UserDetail)) user.GET("/detail/:userExternalId", EncryptHandle, wrapper(user_r.UserDetailByExternalId)) - user.GET("/detail/room/:userExternalId", EncryptHandle, wrapper(user_r.GetUserDetailInRoom)) + user.GET("/detail/room", EncryptHandle, wrapper(user_r.GetUserDetailInRoom)) } cp := v2.Group("/cp") { diff --git a/route/user_r/user.go b/route/user_r/user.go index 30c5fe2..f3049ba 100644 --- a/route/user_r/user.go +++ b/route/user_r/user.go @@ -110,17 +110,17 @@ func UserDetailByExternalId(c *gin.Context) (*mycontext.MyContext, error) { // @Tags 用户 // @Summary 房间内获取用户信息 -// @Param userExternalId path string true "userExternalId" +// @Param userExternalId query string true "userExternalId" // @Param groupId query string false "群组id,当传了该id,则返回该用户在该群组的身份" // @Success 200 {object} user_cv.CvUserDetail -// @Router /v1/user/detail/room/{userExternalId} [get] +// @Router /v1/user/detail/room [get] func GetUserDetailInRoom(c *gin.Context) (*mycontext.MyContext, error) { myContext := mycontext.CreateMyContext(c.Keys) userId, lang, err := req.GetUserIdLang(c, myContext) if err != nil { return myContext, err } - otherUserId, err := req.ToUserId(myContext, mysql.Str(c.Param("userExternalId"))) + otherUserId, err := req.ToUserId(myContext, c.Query("userExternalId")) if err != nil { return nil, err } -- 2.22.0 From 35c773377376db3c4880a66f55decc681d4b493c Mon Sep 17 00:00:00 2001 From: chenweijian <820961417@qq.com> Date: Wed, 26 Jul 2023 16:34:05 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- route/router.go | 2 +- route/user_r/user.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/route/router.go b/route/router.go index e46b610..11d8437 100644 --- a/route/router.go +++ b/route/router.go @@ -32,7 +32,6 @@ func InitRouter() *gin.Engine { user.GET("/bag/:resType", wrapper(user_r.UserBag)) user.GET("/detail", EncryptHandle, wrapper(user_r.UserDetail)) user.GET("/detail/:userExternalId", EncryptHandle, wrapper(user_r.UserDetailByExternalId)) - user.GET("/detail/room", EncryptHandle, wrapper(user_r.GetUserDetailInRoom)) } cp := v2.Group("/cp") { @@ -66,6 +65,7 @@ func InitRouter() *gin.Engine { userV2.GET("/invite/apply", wrapper(invite_r.InviteApplyList)) userV2.GET("/invite/platform", wrapper(invite_r.PromotionPlatform)) userV2.GET("/invite/period", wrapper(invite_r.AgentPeriod)) + userV2.GET("/detail/room", EncryptHandle, wrapper(user_r.GetUserDetailInRoom)) } inner := r.Group("/inner") inner.Use(ExceptionHandle, LoggerHandle) diff --git a/route/user_r/user.go b/route/user_r/user.go index f3049ba..2684af6 100644 --- a/route/user_r/user.go +++ b/route/user_r/user.go @@ -113,7 +113,7 @@ func UserDetailByExternalId(c *gin.Context) (*mycontext.MyContext, error) { // @Param userExternalId query string true "userExternalId" // @Param groupId query string false "群组id,当传了该id,则返回该用户在该群组的身份" // @Success 200 {object} user_cv.CvUserDetail -// @Router /v1/user/detail/room [get] +// @Router /v2/user/detail/room [get] func GetUserDetailInRoom(c *gin.Context) (*mycontext.MyContext, error) { myContext := mycontext.CreateMyContext(c.Keys) userId, lang, err := req.GetUserIdLang(c, myContext) -- 2.22.0 From ae0fe89f47df77dc6635808cb5d2ed93007328b2 Mon Sep 17 00:00:00 2001 From: chenweijian <820961417@qq.com> Date: Wed, 26 Jul 2023 16:43:59 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cv/user_cv/user.go | 31 +++++++++++++++++++++++++++++-- route/user_r/user.go | 2 +- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/cv/user_cv/user.go b/cv/user_cv/user.go index 5aeee0c..b64e447 100644 --- a/cv/user_cv/user.go +++ b/cv/user_cv/user.go @@ -533,8 +533,8 @@ type CvUserDetailRoom struct { //不会有返回值 //是否喜欢(本人没有数据,//20210205 已废弃nil,产品说:可以自己喜欢自己) IsLike *bool `json:"isLike"` //别人是否喜欢我,自己本人没有数据 (20210205 已废弃nil,产品说:可以自己喜欢自己) - IsLikeMe *bool `json:"isLikeMe"` - Cp *CvCp `json:"cp,omitempty"` // cp信息 + IsLikeMe *bool `json:"isLikeMe"` + Cp *CvCpTiny `json:"cp,omitempty"` // cp信息 } // cv国家管理人员 @@ -552,6 +552,33 @@ type CvCp struct { CpDays int `json:"cpDays"` // cp天数 } +// cp信息 +type CvCpTiny struct { + CpUserInfo *CvCpUser `json:"cpUserInfo"` // cp用户信息 + CpLevel CvCpLevel `json:"cpLevel"` // cp等级 + MyPrivilegeList []CvPrivilege `json:"myPrivilegeList"` // 等级特权 + CreatedUnix int64 `json:"createdUnix"` // cp创建时间 + CpDays int `json:"cpDays"` // cp天数 +} + +type CvCpUser struct { + //不会有返回值 + Id *mysql.ID `json:"id,omitempty"` + //头像,不存在为nil + Avatar *string `json:"avatar"` + //用户对外ID + ExternalId *string `json:"externalId"` + //昵称,不存在为nil + Nick *string `json:"nick"` + //性别 1:男 2:女,不存在为nil + Sex *uint8 `json:"sex"` + //邀请码 + Code *string `json:"code"` + Headwear *headwear_cv.CvHeadwear `json:"headwear"` // 当前使用的头饰 + Svip rpc.CvSvip `json:"svip"` // svip结构,等级+权限 + Noble noble_cv.CvNoble `json:"noble"` // 当前的 +} + // cp关系 type CvCpRelation struct { CpId uint64 `json:"cpId"` diff --git a/route/user_r/user.go b/route/user_r/user.go index 2684af6..0b55220 100644 --- a/route/user_r/user.go +++ b/route/user_r/user.go @@ -112,7 +112,7 @@ func UserDetailByExternalId(c *gin.Context) (*mycontext.MyContext, error) { // @Summary 房间内获取用户信息 // @Param userExternalId query string true "userExternalId" // @Param groupId query string false "群组id,当传了该id,则返回该用户在该群组的身份" -// @Success 200 {object} user_cv.CvUserDetail +// @Success 200 {object} user_cv.CvUserDetailRoom // @Router /v2/user/detail/room [get] func GetUserDetailInRoom(c *gin.Context) (*mycontext.MyContext, error) { myContext := mycontext.CreateMyContext(c.Keys) -- 2.22.0 From 5a3b75bb2bc8991a2478e108dcea612e37e096a2 Mon Sep 17 00:00:00 2001 From: chenweijian <820961417@qq.com> Date: Thu, 27 Jul 2023 15:21:27 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cv/user_cv/user.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cv/user_cv/user.go b/cv/user_cv/user.go index b64e447..9c653c4 100644 --- a/cv/user_cv/user.go +++ b/cv/user_cv/user.go @@ -533,8 +533,9 @@ type CvUserDetailRoom struct { //不会有返回值 //是否喜欢(本人没有数据,//20210205 已废弃nil,产品说:可以自己喜欢自己) IsLike *bool `json:"isLike"` //别人是否喜欢我,自己本人没有数据 (20210205 已废弃nil,产品说:可以自己喜欢自己) - IsLikeMe *bool `json:"isLikeMe"` - Cp *CvCpTiny `json:"cp,omitempty"` // cp信息 + IsLikeMe *bool `json:"isLikeMe"` + Cp *CvCpTiny `json:"cp,omitempty"` // cp信息 + GroupRole common.GroupRoleType `json:"groupRole"` // 在群组的角色 } // cv国家管理人员 -- 2.22.0