diff --git a/rpc/user.go b/rpc/user.go index bed7df43b90141e2205f53f810eb8dd6d77615de..e447fb292ca592474f8b726dd6a0104e1c129018 100644 --- a/rpc/user.go +++ b/rpc/user.go @@ -4,6 +4,7 @@ import ( "encoding/json" "errors" "fmt" + "git.hilo.cn/hilo-common/_const/common" "git.hilo.cn/hilo-common/domain" "git.hilo.cn/hilo-common/mylogrus" "git.hilo.cn/hilo-common/resource/consul" @@ -241,39 +242,6 @@ func SendUserRide(model *domain.Model, userId mysql.ID, rideId mysql.ID, day mys return nil } -// cp关系 -type CvCpRelation struct { - CpId uint64 `json:"cpId"` - UserId uint64 `json:"userId"` - CpUserId uint64 `json:"cpUserId"` -} - -// 获取用户cp关系 -func GetUserCpRelation(model *domain.Model, userId mysql.ID) (*CvCpRelation, error) { - type Response struct { - Code int `json:"code"` - Message string `json:"message"` - Data *CvCpRelation `json:"data"` - } - _url := fmt.Sprintf("%v://%v/inner/user/cpRelation", defaultUserServerScheme, getUserHost()) - resp, err := HttpGet(model, _url, nil, map[string][]string{ - "id": {fmt.Sprintf("%d", userId)}, - }) - if err != nil { - model.Log.Errorf("GetUserCpRelation fail:%v", err) - return nil, err - } - response := new(Response) - if err = json.Unmarshal(resp, response); err != nil { - model.Log.Errorf("GetUserCpRelation json fail:%v", err) - return nil, err - } - if response.Data != nil && response.Data.CpUserId > 0 { - return response.Data, nil - } - return nil, nil -} - // 获取指定cp对 func MGetUserCpPairs(model *domain.Model, userIds []mysql.ID) ([][2]mysql.ID, error) { type Response struct { @@ -313,3 +281,175 @@ func getUserHost() string { mylogrus.MyLog.Infof("getHostUser:%v---%v", r, UserServerHost[r]) return UserServerHost[r] } + +// cp关系 +type CvCpRelation struct { + CpId uint64 `json:"cpId"` + UserId uint64 `json:"userId"` + CpUserId uint64 `json:"cpUserId"` + CpUserAvatar string `json:"cpUserAvatar"` +} + +// 批量获取用户cpRelation +func MGetUserCpRelations(model *domain.Model, userIds []mysql.ID) (map[mysql.ID]CvCpRelation, error) { + type Response struct { + Code int `json:"code"` + Message string `json:"message"` + Data map[mysql.ID]CvCpRelation + } + var res = make(map[mysql.ID]CvCpRelation) + if len(userIds) <= 0 { + return res, nil + } + var userIdsStr []string + for _, userId := range userIds { + userIdsStr = append(userIdsStr, fmt.Sprintf("%d", userId)) + } + _url := fmt.Sprintf("%v://%v/inner/user/cpRelations", defaultUserServerScheme, getUserHost()) + resp, err := HttpGet(model, _url, nil, map[string][]string{ + "ids": userIdsStr, + }) + if err != nil { + model.Log.Errorf("MGetUserSvip fail:%v", err) + return res, err + } + response := new(Response) + if err = json.Unmarshal(resp, response); err != nil { + model.Log.Errorf("MGetUserSvip json fail:%v", err) + return res, err + } + return res, nil +} + +// 获取用户cpRelation +func GetUserCpRelation(model *domain.Model, userId mysql.ID) (CvCpRelation, error) { + res, err := MGetUserCpRelations(model, []uint64{userId}) + if err != nil { + return CvCpRelation{}, err + } + return res[userId], nil +} + +type CvCp struct { + CpUserInfo *CvUserBase `json:"cpUserInfo"` // cp用户信息 + CpLevel CvCpLevel `json:"cpLevel"` // cp等级 + MyPrivilegeList []CvPrivilege `json:"myPrivilegeList"` // 等级特权 + CreatedUnix int64 `json:"createdUnix"` // cp创建时间 + CpDays int `json:"cpDays"` // cp天数 +} + +// cp等级 +type CvCpLevel struct { + Level int `json:"level"` // 等级 0:无称号 1:恋爱CP 2:甜蜜CP 3:忠诚CP 4:炽热CP 5:荣耀CP + Points uint32 `json:"points"` // CP值 + Title string `json:"title"` +} + +// 特权信息 +type CvPrivilege struct { + Type int `json:"type"` // 特权id 1:空间 2:横幅 3:等级勋章 4:证书 5:进场特效 6:头像头饰 7:动态资料卡 8:麦位特效 +} + +//用户基本信息 +type CvUserBase 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"` + //签名,不存在为nil + Description *string `json:"description"` + //性别 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"` // 是否靓号 + IsLogout bool `json:"isLogout"` //是否注销 + //生日,如果是其它人用户信息,年龄则按照是否展示显示,如果是本人,年龄则按照是否存在展示 + Birthday *uint64 `json:"birthday"` + //是否展示年龄, 是本人才有数据,看其他用户均为nil + IsShowAge *uint8 `json:"isShowAge"` + //是否工会成员, 只有是自己查自己,这个才有值,其它全为nil, 20220329 数据开放:原因:产品1对1视频聊天中,公会用户视频需要送礼物。改为: 全部人可以知道是否是公会用户。 + IsTradeUnion *bool `json:"isTradeUnion"` + //是否代理管理员, 只有自己查自己的时候才有值,其他情况为nil + IsAgentMgr *bool `json:"isAgentMgr"` + //工会成员,是否开启了,匹配通知,只有 isTradeUnion值为true,这里才有值, + IsTradeUnionMatchNotification *bool `json:"isTradeUnionMatchNotification"` + //是否VIP用户 + IsVip bool `json:"isVip"` + //是否是官方人员 + IsOfficialStaff bool `json:"isOfficialStaff"` + //VIP用户过期时间(只有自己查询自己,才返回) + VipExpireTime *int64 `json:"vipExpireTime"` + Svip CvSvip `json:"svip"` // svip结构,等级+权限 + Medals []uint32 `json:"medals"` // 勋章列表 TODO: 删除 + MedalInfo []CvMedal `json:"medalInfo"` // 勋章列表 + Headwear *CvHeadwear `json:"headwear"` // 当前使用的头饰 + Ride CvProperty `json:"ride"` // 当前使用的座驾 + Noble CvNoble `json:"noble"` // 当前的 + GroupRole common.GroupRoleType `json:"groupRole"` // 在群组的角色 +} + +type CvMedal struct { + Id uint32 `json:"id"` + PicUrl mysql.Str `json:"picUrl"` + EffectUrl mysql.Str `json:"effectUrl"` +} + +type CvHeadwear struct { + Id uint64 `json:"id"` + Using bool `json:"using"` + PicUrl mysql.Str `json:"picUrl"` + EffectUrl mysql.Str `json:"effectUrl"` + TimeLeft int64 `json:"timeLeft"` // 离到期还有多少秒(过期则是负数) +} + +type CvProperty struct { + Id uint64 `json:"id"` + PicUrl mysql.Str `json:"picUrl"` + EffectUrl mysql.Str `json:"effectUrl"` + Using bool `json:"using"` + TimeLeft int64 `json:"timeLeft"` // 离到期还有多少秒(过期则是负数) + SenderAvatar string `json:"senderAvatar"` + ReceiverAvatar string `json:"receiverAvatar"` +} + +type CvNoble struct { + Level uint16 `json:"level"` + EndTime int64 `json:"endTime"` +} + +// 获取用户cp +func GetUserCp(model *domain.Model, userId mysql.ID) (*CvCp, error) { + type Response struct { + Code int `json:"code"` + Message string `json:"message"` + Data *CvCp `json:"data"` + } + _url := fmt.Sprintf("%v://%v/inner/user/cp", defaultUserServerScheme, getUserHost()) + resp, err := HttpGet(model, _url, nil, map[string][]string{ + "id": {fmt.Sprintf("%d", userId)}, + }) + if err != nil { + model.Log.Errorf("GetUserCp fail:%v", err) + return nil, err + } + response := new(Response) + if err = json.Unmarshal(resp, response); err != nil { + model.Log.Errorf("GetUserCp json fail:%v", err) + return nil, err + } + if response.Data != nil && response.Data.CpUserInfo != nil { + return response.Data, nil + } + return nil, nil +}