Commit 6d902bd7 authored by chenweijian's avatar chenweijian Committed by hujiebin

4.0.5 接口优化

parent c08701f9
......@@ -7,8 +7,8 @@ import (
type CvCpRank struct {
CpId uint64 `json:"cpId"` // cpId
User1 *user_cv.CvUserBase `json:"user1"` // user1
User2 *user_cv.CvUserBase `json:"user2,omitempty"` // user2
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"` // 排名
......
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"
......@@ -111,6 +112,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 {
......@@ -482,6 +494,50 @@ 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 *CvCpTiny `json:"cp,omitempty"` // cp信息
GroupRole common.GroupRoleType `json:"groupRole"` // 在群组的角色
}
// cv国家管理人员
type CVCountryManager struct {
Country string `json:"country"` // 国家name
......@@ -497,6 +553,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"`
......@@ -516,3 +599,19 @@ 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,
}
}
func CvUserDetailToCvUserDetailRoom(info *CvUserDetail) *CvUserDetailRoom {
res := new(CvUserDetailRoom)
jData, _ := json.Marshal(info)
_ = json.Unmarshal(jData, &res)
return res
}
......@@ -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 {
......
......@@ -65,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)
......
......@@ -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 query string true "userExternalId"
// @Param groupId query string false "群组id,当传了该id,则返回该用户在该群组的身份"
// @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)
userId, lang, err := req.GetUserIdLang(c, myContext)
if err != nil {
return myContext, err
}
otherUserId, err := req.ToUserId(myContext, c.Query("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
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment