diff --git a/cron/cron.go b/cron/cron.go index eeef2b4a420c0a1b6d4b82eb61d2dfb1bcd99752..69f5de9f440c6c9f02ed2f43c3618c69035208d6 100644 --- a/cron/cron.go +++ b/cron/cron.go @@ -4,14 +4,17 @@ import ( "git.hilo.cn/hilo-common/resource/config" "hilo-user/cron/cp_cron" "hilo-user/cron/gift_cron" + "hilo-user/cron/user_cron" ) func Init() { + user_cron.SyncGiftRecommendUsers() // 同步送礼推荐用户,多进程都需要执行 if !config.IsMaster() { return } - gift_cron.SendGiftEventInit() // 礼物消息 - gift_cron.GiftRemark() // 礼物消息补偿 + //gift_cron.SendGiftEventInit() // 礼物消息 + //gift_cron.GiftRemark() // 礼物消息补偿 + gift_cron.SendGiftEvent() // 送礼事件 cp_cron.ClearCpExpire() // 清理过期cp cp_cron.CpAnniversaryNotice() // cp纪念日 cp_cron.CpInviteCancelInit() // cp邀请、解除到期结算 diff --git a/cron/gift_cron/send_gift_redis.go b/cron/gift_cron/send_gift_redis.go new file mode 100644 index 0000000000000000000000000000000000000000..f4ee273a63fec047d9b74a49999f4e37a19f891f --- /dev/null +++ b/cron/gift_cron/send_gift_redis.go @@ -0,0 +1,79 @@ +package gift_cron + +import ( + "git.hilo.cn/hilo-common/domain" + "github.com/jinzhu/now" + "hilo-user/_const/enum/cp_e" + "hilo-user/domain/cache/gift_c" + "hilo-user/domain/event/gift_ev" + "hilo-user/domain/model/cp_m" + "time" +) + +// 送礼事件 +func SendGiftEvent() { + //if !config.IsMaster() { + // return + //} + go func() { + for true { + model := domain.CreateModelNil() + if sendGiftEvent := gift_c.BLPopQueueSendGift(model); sendGiftEvent != nil { + cpGiftEvent(model, sendGiftEvent) // cp送礼 + } + } + }() +} + +// 送礼增加cp等级 +// 送礼增加cp排行榜 +func cpGiftEvent(model *domain.Model, sendGiftEvent *gift_ev.SendGiftEvent) { + // 只处理cp礼物 + if !sendGiftEvent.ResGift.Cp { + return + } + for _, receiverUid := range sendGiftEvent.ReceiveUserIds { + diamonds := sendGiftEvent.GiftN * sendGiftEvent.ResGift.DiamondNum + // 有cp关系 + if cpRelation, exits := cp_m.GetCpRelationPair(model, sendGiftEvent.SendUserId, receiverUid); exits { + if err := cp_m.AddCpLevelPoints(model, cpRelation, diamonds, sendGiftEvent.SceneType, sendGiftEvent.SceneUid); err != nil { + model.Log.Errorf("AddCpLevelPoints fail:%v", err) + } + if err := cp_m.AddCpDayRank(model, cpRelation, diamonds); err != nil { + model.Log.Errorf("AddCpDayRank fail:%v", err) + } + // 检查最新的等级 + if cpLevel := cp_m.GetCpLevel(model, cpRelation.Id); cpLevel.CpId >= 0 { + points := cpLevel.Points + cp_e.CpLevelPoints[cpLevel.Level] + if err := cp_m.UpdateCpAchievement(model, cpLevel.CpId, cpRelation.UserId1, cpRelation.UserId2, cp_e.CpAchievementLevel, points); err != nil { + model.Log.Errorf("UpdateCpAchievement fail:%v", err) + } + } + // 检查最高的分数 + for _, queryType := range []string{"day", "week", "month"} { + var beginDate, endDate string + var cpAchievementType cp_e.CpAchievement + switch queryType { + case "day": + beginDate, endDate = time.Now().Format("2006-01-02"), time.Now().Format("2006-01-02") + cpAchievementType = cp_e.CpAchievementDayRank + case "week": + beginDate = now.BeginningOfWeek().Format("2006-01-02") + endDate = now.EndOfWeek().Format("2006-01-02") + cpAchievementType = cp_e.CpAchievementWeekRank + case "month": + beginDate = now.BeginningOfMonth().Format("2006-01-02") + endDate = now.EndOfMonth().Format("2006-01-02") + cpAchievementType = cp_e.CpAchievementMonthRank + } + if data := cp_m.GetCpDayRank(model, beginDate, endDate, cpRelation.Id); data.Score > 0 { + if err := cp_m.UpdateCpAchievement(model, cpRelation.Id, cpRelation.UserId1, cpRelation.UserId2, cpAchievementType, data.Score); err != nil { + model.Log.Errorf("UpdateCpAchievement fail:%v", err) + } + } + } + // 检查最新日周月榜单 + return // 业务场景允许提前break(cp是唯一的) + } + } +} diff --git a/cron/user_cron/gift_user.go b/cron/user_cron/gift_user.go new file mode 100644 index 0000000000000000000000000000000000000000..3a4c72665f03fdc8e3edf97a5276d63a037c1cc5 --- /dev/null +++ b/cron/user_cron/gift_user.go @@ -0,0 +1,20 @@ +package user_cron + +import ( + "git.hilo.cn/hilo-common/domain" + "github.com/robfig/cron" + "hilo-user/domain/model/recommend_m" +) + +// 定期同步礼物推荐用户 +func SyncGiftRecommendUsers() { + go recommend_m.SyncPastTop50SendGiftUsers(domain.CreateModelNil()) // 启动先同步一次 + + c := cron.New() + spec := "0 */5 * * * ?" + _ = c.AddFunc(spec, func() { + var model = domain.CreateModelNil() + recommend_m.SyncPastTop50SendGiftUsers(model) + }) + c.Start() +} diff --git a/cv/cp_cv/rank.go b/cv/cp_cv/rank.go index f03c1f38ece55d78b679367f4bccf57a4539f24f..0e13eed96206b5f23b742932433d46901c3bc382 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 82e053d1963ad14ed7b1d33f16bc7cfdb50e3a26..9c653c4373ef6690ff67cccbfab4724895c02212 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" @@ -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 +} diff --git a/domain/cache/gift_c/gift_event.go b/domain/cache/gift_c/gift_event.go new file mode 100644 index 0000000000000000000000000000000000000000..c6710004b1df5690f1b6064ac5444004d0288c08 --- /dev/null +++ b/domain/cache/gift_c/gift_event.go @@ -0,0 +1,34 @@ +package gift_c + +import ( + "encoding/json" + "git.hilo.cn/hilo-common/domain" + "github.com/go-redis/redis/v8" + "hilo-user/domain/event/gift_ev" + "time" +) + +const EventSendGiftHiloUserQueue = "send:gift:queue:hilo_user" + +// redis pop event sendGift +func BLPopQueueSendGift(model *domain.Model) *gift_ev.SendGiftEvent { + var res *gift_ev.SendGiftEvent + queue := EventSendGiftHiloUserQueue + strs, err := model.Redis.BLPop(model, time.Second, queue).Result() + if err != nil { + if err != redis.Nil { + model.Log.Errorf("BLPopQueueSendGift fail:%v", err) + } + return nil + } + if len(strs) >= 2 { + content := strs[1] + res = new(gift_ev.SendGiftEvent) + if err := json.Unmarshal([]byte(content), res); err != nil { + model.Log.Errorf("BLPopQueueSendGift json fail:%v", err) + return nil + } + return res + } + return nil +} diff --git a/domain/model/cp_m/rank.go b/domain/model/cp_m/rank.go index 915587cb7deec21c379c1001e0520e582d9605ad..36370841bc4f7f8fa935ade019941e3cc1eaa367 100644 --- a/domain/model/cp_m/rank.go +++ b/domain/model/cp_m/rank.go @@ -41,7 +41,9 @@ func AddCpDayRank(model *domain.Model, cpRelation CpRelation, score mysql.Num) ( func PageCpDayRank(model *domain.Model, beginDate, endDate string, offset, limit int) []CpDayRank { var ranks []CpDayRank if err := model.DB().Table("cp_day_rank r").Joins("INNER JOIN cp_relation c ON c.id = r.cp_id"). - Where("r.date BETWEEN ? AND ?", beginDate, endDate).Group("cp_id").Select("cp_id,r.user_id1,r.user_id2,SUM(r.score) score"). + Where("r.date BETWEEN ? AND ?", beginDate, endDate). + Where("cp_id not in (1581, 12651, 5171, 9191, 39131, 28801, 181, 35221)"). + Group("cp_id").Select("cp_id,r.user_id1,r.user_id2,SUM(r.score) score"). Order("score DESC").Offset(offset).Limit(limit).Find(&ranks).Error; err != nil { model.Log.Errorf("PageCpDayRank fail:%v", err) } diff --git a/domain/model/diamond_m/diamond.go b/domain/model/diamond_m/diamond.go index 22b63b09cd28aa404b98abfea955265d4b46d48e..26b9ff9dbc47111131ff0b101700d77ab9981d8c 100644 --- a/domain/model/diamond_m/diamond.go +++ b/domain/model/diamond_m/diamond.go @@ -1,6 +1,7 @@ package diamond_m import ( + "fmt" "git.hilo.cn/hilo-common/_const/enum/diamond_e" "git.hilo.cn/hilo-common/domain" "git.hilo.cn/hilo-common/resource/mysql" @@ -37,6 +38,11 @@ type DiamondAccountDetail struct { diamondAccount *DiamondAccount `gorm:"-"` } +func (DiamondAccountDetail) TableName() string { + month := time.Now().Format("200601") + return fmt.Sprintf("diamond_account_detail_%s", month) +} + // 粉钻详情 type DiamondPinkAccountDetail struct { mysql.Entity @@ -107,7 +113,7 @@ func (diamondAccount *DiamondAccount) addDiamondAccountDetail(operateType diamon var count int64 if diamondOperateSet.FrequencyDay == -1 { if diamondOperateSet.FrequencyNum != -1 { - diamondAccount.Db.Model(&DiamondAccountDetail{}).Where(&DiamondAccountDetail{ + diamondAccount.DB().Table(DiamondAccountDetail{}.TableName()).Where(&DiamondAccountDetail{ UserId: diamondAccount.UserId, OperateType: operateType, }).Count(&count) @@ -122,7 +128,7 @@ func (diamondAccount *DiamondAccount) addDiamondAccountDetail(operateType diamon return nil, myerr.WrapErr(err) } //一天的次数 - diamondAccount.Db.Model(&DiamondAccountDetail{}).Where(&DiamondAccountDetail{ + diamondAccount.DB().Table(DiamondAccountDetail{}.TableName()).Where(&DiamondAccountDetail{ UserId: diamondAccount.UserId, OperateType: operateType, }).Where("created_time >= ? ", beginTime).Count(&count) @@ -130,7 +136,7 @@ func (diamondAccount *DiamondAccount) addDiamondAccountDetail(operateType diamon return nil, bizerr.DiamondFrequency } //终极拦截,利用 - diamondAccount.SetCheckUpdateCondition(" EXISTS (SELECT * from (SELECT COUNT(1) as n from diamond_account_detail d where d.user_id = " + strconv.FormatUint(diamondAccount.UserId, 10) + " and d.operate_type = " + strconv.FormatUint(uint64(operateType), 10) + " and d.created_time >= from_unixtime(" + strconv.FormatInt(utils.GetZeroTime(time.Now()).Unix(), 10) + ")) t where t.n < " + strconv.Itoa(diamondOperateSet.FrequencyNum) + " )") + diamondAccount.SetCheckUpdateCondition(" EXISTS (SELECT * from (SELECT COUNT(1) as n from " + DiamondAccountDetail{}.TableName() + " d where d.user_id = " + strconv.FormatUint(diamondAccount.UserId, 10) + " and d.operate_type = " + strconv.FormatUint(uint64(operateType), 10) + " and d.created_time >= from_unixtime(" + strconv.FormatInt(utils.GetZeroTime(time.Now()).Unix(), 10) + ")) t where t.n < " + strconv.Itoa(diamondOperateSet.FrequencyNum) + " )") } //-1,代表值无效,由参数给与 diff --git a/domain/model/diamond_m/repo.go b/domain/model/diamond_m/repo.go index 7b48c1552015245e4cd901f46563f4ac861f1645..76816cd5135e93c5273488bf025f8e06bdbe8ed7 100755 --- a/domain/model/diamond_m/repo.go +++ b/domain/model/diamond_m/repo.go @@ -3,7 +3,6 @@ package diamond_m import ( "git.hilo.cn/hilo-common/resource/mysql" "gorm.io/gorm" - "hilo-user/domain/model" "hilo-user/myerr" "strconv" ) @@ -32,7 +31,10 @@ func (diamondAccountDetail *DiamondAccountDetail) PersistentNoInTransactional() } //持久化diamondAccountDetail - if err := model.Persistent(diamondAccountDetail.Db, diamondAccountDetail); err != nil { + //if err := model.Persistent(diamondAccountDetail.Db, diamondAccountDetail); err != nil { + // return myerr.WrapErr(err) + //} + if err := diamondAccountDetail.DB().Table(diamondAccountDetail.TableName()).Save(diamondAccountDetail).Error; err != nil { return myerr.WrapErr(err) } //改变diamondAccount值 diff --git a/domain/model/group_m/room.go b/domain/model/group_m/room.go index 12319ada23e8b5f085e06610e18d095222a6b456..f23e5d0f7bd33339f21feb1b43f6bc413eb7a08d 100644 --- a/domain/model/group_m/room.go +++ b/domain/model/group_m/room.go @@ -12,7 +12,8 @@ import ( "time" ) -const expireMinute = 60 * 60 * 12 +// 3天 +const expireMinute = 60 * 60 * 24 * 3 //获取在房间的用户 返回值:map,key:userId, value:groupUuid func RoomLivingUserIdFilter(model *domain.Model, userIds []mysql.ID) (map[mysql.ID]string, error) { diff --git a/domain/model/promotion_m/promotion_info.go b/domain/model/promotion_m/promotion_info.go index 8389284ee47ba9acfbe0c0403e976ac6ba779183..6a8d1e3d3ae3d8e2583b9beb621c418ef389dee4 100644 --- a/domain/model/promotion_m/promotion_info.go +++ b/domain/model/promotion_m/promotion_info.go @@ -9,7 +9,7 @@ import ( // 获取推广员平台 func GetPromotionPlatforms(model *domain.Model) []string { return []string{"Falla", "Yalla", "Whisper", "Ahlan", "Mashi", "YoYo", "Yoho", "Echo", "Hawa", "Yalla Ludo", "Hafla", - "Imo", "Ola Party", "ShareChat", "Viya", "Hello Yo", "Bigo Live", "Hago"} + "Imo", "Ola Party", "ShareChat", "Viya", "Hello Yo", "Bigo Live", "Hago", "Oye Talk", "Tiktok", "Bigo", "Mr7ba"} } // 检查是否推广员 diff --git a/domain/model/recommend_m/gift.go b/domain/model/recommend_m/gift.go index 01cf680d9fa901b0b387b3db3f77d79f20fc2e49..fae95a8b29acac6ebe1906ded1a35f86d596b211 100644 --- a/domain/model/recommend_m/gift.go +++ b/domain/model/recommend_m/gift.go @@ -17,23 +17,26 @@ var recommendUserGiftKey = "recommendUserGiftKey" var recommendUserGiftCache = gcache.New(1).LRU().Build() // 推荐最近送礼的50人,最近12小时赠送礼物大于100k的用户 -// 先lru cache,后db -// ttl: 5min -func GetPastTop50SendGiftUsers(model *domain.Model) []recommendUserGift { - if data, err := recommendUserGiftCache.Get(recommendUserGiftKey); err == nil { - return data.([]recommendUserGift) - } +func SyncPastTop50SendGiftUsers(model *domain.Model) { limitUserIds, _ := GetBillboardLimitUserList(model) var res []recommendUserGift - if err := model.DB().Table("gift_operate").Select("send_user_id,SUM(send_user_diamond) send_user_diamond"). - Where("created_time >= ?", time.Now().Add(-time.Hour*12)). + if err := model.DB().Table("gift_operate g").Joins("INNER JOIN user u ON u.id = g.send_user_id").Select("send_user_id,SUM(send_user_diamond) send_user_diamond"). + Where("u.avatar <> ''"). + Where("g.created_time >= ?", time.Now().Add(-time.Hour*12)). Where("send_user_id NOT in ?", limitUserIds). Group("send_user_id"). Having("send_user_diamond > 100000").Order("send_user_diamond DESC").Limit(34).Find(&res).Error; err != nil { model.Log.Errorf("GetPastTop50SendGiftUsers fail:%v", err) } - recommendUserGiftCache.SetWithExpire(recommendUserGiftKey, res, time.Minute*5) - return res + _ = recommendUserGiftCache.Set(recommendUserGiftKey, res) +} + +// 只从缓存中拿 +func GetPastTop50SendGiftUsers(model *domain.Model) []recommendUserGift { + if data, err := recommendUserGiftCache.Get(recommendUserGiftKey); err == nil { + return data.([]recommendUserGift) + } + return []recommendUserGift{} } // 榜单黑名单 diff --git a/domain/service/event_s/cp_level.go b/domain/service/event_s/cp_level.go index 4d172e8d3851bc249bc8419945158fa286156cc2..98a7b3571651091c315d888f8c875784fc990448 100644 --- a/domain/service/event_s/cp_level.go +++ b/domain/service/event_s/cp_level.go @@ -1,166 +1,154 @@ package event_s -import ( - "git.hilo.cn/hilo-common/domain" - "git.hilo.cn/hilo-common/resource/config" - "git.hilo.cn/hilo-common/resource/redisCli" - "github.com/jinzhu/now" - "hilo-user/_const/enum/cp_e" - "hilo-user/_const/enum/gift_e" - "hilo-user/domain/event/gift_ev" - "hilo-user/domain/model/cp_m" - "time" -) - // 送礼增加cp等级 // 送礼增加cp排行榜 -func CpGiftEvent() { - gift_ev.AddSendGiftEventSync(func(model *domain.Model, event interface{}) error { - sendGiftEvent, ok := event.(*gift_ev.SendGiftEvent) - if !ok { - model.Log.Errorf("AddSendGiftEventAsync event type err") - return nil - } - // 只处理cp礼物 - if !sendGiftEvent.ResGift.Cp { - return nil - } - for _, receiverUid := range sendGiftEvent.ReceiveUserIds { - diamonds := sendGiftEvent.GiftN * sendGiftEvent.ResGift.DiamondNum - // 有cp关系 - if cpRelation, exits := cp_m.GetCpRelationPair(model, sendGiftEvent.SendUserId, receiverUid); exits { - if err := cp_m.AddCpLevelPoints(model, cpRelation, diamonds, sendGiftEvent.SceneType, sendGiftEvent.SceneUid); err != nil { - model.Log.Errorf("AddCpLevelPoints fail:%v", err) - } - if err := cp_m.AddCpDayRank(model, cpRelation, diamonds); err != nil { - model.Log.Errorf("AddCpDayRank fail:%v", err) - } - // 检查最新的等级 - if cpLevel := cp_m.GetCpLevel(model, cpRelation.Id); cpLevel.CpId >= 0 { - points := cpLevel.Points + cp_e.CpLevelPoints[cpLevel.Level] - if err := cp_m.UpdateCpAchievement(model, cpLevel.CpId, cpRelation.UserId1, cpRelation.UserId2, cp_e.CpAchievementLevel, points); err != nil { - model.Log.Errorf("UpdateCpAchievement fail:%v", err) - } - } - // 检查最高的分数 - for _, queryType := range []string{"day", "week", "month"} { - var beginDate, endDate string - var cpAchievementType cp_e.CpAchievement - switch queryType { - case "day": - beginDate, endDate = time.Now().Format("2006-01-02"), time.Now().Format("2006-01-02") - cpAchievementType = cp_e.CpAchievementDayRank - case "week": - beginDate = now.BeginningOfWeek().Format("2006-01-02") - endDate = now.EndOfWeek().Format("2006-01-02") - cpAchievementType = cp_e.CpAchievementWeekRank - case "month": - beginDate = now.BeginningOfMonth().Format("2006-01-02") - endDate = now.EndOfMonth().Format("2006-01-02") - cpAchievementType = cp_e.CpAchievementMonthRank - } - if data := cp_m.GetCpDayRank(model, beginDate, endDate, cpRelation.Id); data.Score > 0 { - if err := cp_m.UpdateCpAchievement(model, cpRelation.Id, cpRelation.UserId1, cpRelation.UserId2, cpAchievementType, data.Score); err != nil { - model.Log.Errorf("UpdateCpAchievement fail:%v", err) - } - } - } - // 检查最新日周月榜单 - return nil // 业务场景允许提前break(cp是唯一的) - } - } - return nil - }) -} +//func CpGiftEvent() { +// gift_ev.AddSendGiftEventSync(func(model *domain.Model, event interface{}) error { +// sendGiftEvent, ok := event.(*gift_ev.SendGiftEvent) +// if !ok { +// model.Log.Errorf("AddSendGiftEventAsync event type err") +// return nil +// } +// // 只处理cp礼物 +// if !sendGiftEvent.ResGift.Cp { +// return nil +// } +// for _, receiverUid := range sendGiftEvent.ReceiveUserIds { +// diamonds := sendGiftEvent.GiftN * sendGiftEvent.ResGift.DiamondNum +// // 有cp关系 +// if cpRelation, exits := cp_m.GetCpRelationPair(model, sendGiftEvent.SendUserId, receiverUid); exits { +// if err := cp_m.AddCpLevelPoints(model, cpRelation, diamonds, sendGiftEvent.SceneType, sendGiftEvent.SceneUid); err != nil { +// model.Log.Errorf("AddCpLevelPoints fail:%v", err) +// } +// if err := cp_m.AddCpDayRank(model, cpRelation, diamonds); err != nil { +// model.Log.Errorf("AddCpDayRank fail:%v", err) +// } +// // 检查最新的等级 +// if cpLevel := cp_m.GetCpLevel(model, cpRelation.Id); cpLevel.CpId >= 0 { +// points := cpLevel.Points + cp_e.CpLevelPoints[cpLevel.Level] +// if err := cp_m.UpdateCpAchievement(model, cpLevel.CpId, cpRelation.UserId1, cpRelation.UserId2, cp_e.CpAchievementLevel, points); err != nil { +// model.Log.Errorf("UpdateCpAchievement fail:%v", err) +// } +// } +// // 检查最高的分数 +// for _, queryType := range []string{"day", "week", "month"} { +// var beginDate, endDate string +// var cpAchievementType cp_e.CpAchievement +// switch queryType { +// case "day": +// beginDate, endDate = time.Now().Format("2006-01-02"), time.Now().Format("2006-01-02") +// cpAchievementType = cp_e.CpAchievementDayRank +// case "week": +// beginDate = now.BeginningOfWeek().Format("2006-01-02") +// endDate = now.EndOfWeek().Format("2006-01-02") +// cpAchievementType = cp_e.CpAchievementWeekRank +// case "month": +// beginDate = now.BeginningOfMonth().Format("2006-01-02") +// endDate = now.EndOfMonth().Format("2006-01-02") +// cpAchievementType = cp_e.CpAchievementMonthRank +// } +// if data := cp_m.GetCpDayRank(model, beginDate, endDate, cpRelation.Id); data.Score > 0 { +// if err := cp_m.UpdateCpAchievement(model, cpRelation.Id, cpRelation.UserId1, cpRelation.UserId2, cpAchievementType, data.Score); err != nil { +// model.Log.Errorf("UpdateCpAchievement fail:%v", err) +// } +// } +// } +// // 检查最新日周月榜单 +// return nil // 业务场景允许提前break(cp是唯一的) +// } +// } +// return nil +// }) +//} // 漏掉加分数的送礼记录,补上cp增加分数 // 送礼增加cp等级 // 送礼增加cp排行榜 -func CompensateCpScore() { - if !config.IsMaster() { - return - } - model := domain.CreateModelNil() - num, err := redisCli.IncrNumExpire("scirpt:compensateCpScore", 1, time.Hour*999) - if err != nil { - model.Log.Errorf("CompensateCpScore err:%v", err) - } - if num > 1 { - model.Log.Errorf("CompensateCpScore 执行过了,退出") - return - } - // 查找需要补分的送礼记录 - type GiftOperate struct { - Id uint64 `json:"id"` - ResGiftId uint64 `json:"res_gift_id"` - GiftN int32 `json:"gift_n"` - SendUserId uint64 `json:"send_user_id"` - ReceiveUserId uint64 `json:"receive_user_id"` - SendUserDiamond uint32 `json:"send_user_diamond"` - SceneType int8 `json:"scene_type"` - SceneUid string `json:"scene_uid"` - CreatedTime time.Time `json:"created_time"` - } - rows := make([]*GiftOperate, 0) - err = model.DB().Model(GiftOperate{}). - Where("created_time < ?", "2023-06-22 11:20:15"). - Where("res_gift_id in (?)", - []int{3561, 3571, 3581, 3591, 3601, 3611, 3621, 3631, 3641, 3651, 3661, 3671, 3681, 3691, 3701, 3711}). - Find(&rows).Error - if err != nil { - model.Log.Errorf("CompensateCpScore err:%v", err) - return - } - model.Log.Infof("CompensateCpScore len(rows):%v", len(rows)) - - for idx, r := range rows { - diamonds := r.SendUserDiamond - // 有cp关系 - if cpRelation, exits := cp_m.GetCpRelationPair(model, r.SendUserId, r.ReceiveUserId); exits { - if err := cp_m.AddCpLevelPoints(model, cpRelation, diamonds, gift_e.GiftOperateSceneType(r.SceneType), r.SceneUid); err != nil { - model.Log.Errorf("CompensateCpScore AddCpLevelPoints fail:%v", err) - return - } - if err := cp_m.AddCpDayRank(model, cpRelation, diamonds); err != nil { - model.Log.Errorf("CompensateCpScore AddCpDayRank fail:%v", err) - return - } - // 检查最新的等级 - if cpLevel := cp_m.GetCpLevel(model, cpRelation.Id); cpLevel.CpId >= 0 { - points := cpLevel.Points + cp_e.CpLevelPoints[cpLevel.Level] - if err := cp_m.UpdateCpAchievement(model, cpLevel.CpId, cpRelation.UserId1, cpRelation.UserId2, cp_e.CpAchievementLevel, points); err != nil { - model.Log.Errorf("CompensateCpScore UpdateCpAchievement fail:%v", err) - } - } - // 检查最高的分数 - for _, queryType := range []string{"day", "week", "month"} { - var beginDate, endDate string - var cpAchievementType cp_e.CpAchievement - switch queryType { - case "day": - beginDate, endDate = r.CreatedTime.Format("2006-01-02"), r.CreatedTime.Format("2006-01-02") - cpAchievementType = cp_e.CpAchievementDayRank - case "week": - beginDate = now.With(r.CreatedTime).BeginningOfWeek().Format("2006-01-02") - endDate = now.With(r.CreatedTime).EndOfWeek().Format("2006-01-02") - cpAchievementType = cp_e.CpAchievementWeekRank - case "month": - beginDate = now.BeginningOfMonth().Format("2006-01-02") - endDate = now.EndOfMonth().Format("2006-01-02") - cpAchievementType = cp_e.CpAchievementMonthRank - } - if data := cp_m.GetCpDayRank(model, beginDate, endDate, cpRelation.Id); data.Score > 0 { - if err := cp_m.UpdateCpAchievement(model, cpRelation.Id, cpRelation.UserId1, cpRelation.UserId2, cpAchievementType, data.Score); err != nil { - model.Log.Errorf("CompensateCpScore UpdateCpAchievement fail:%v", err) - } - } - } - } - model.Log.Infof("CompensateCpScore idx:%v", idx) - if idx%1000 == 0 { - time.Sleep(time.Millisecond * 100) - } - } - - model.Log.Infof("CompensateCpScore 补偿完毕") -} +//func CompensateCpScore() { +// if !config.IsMaster() { +// return +// } +// model := domain.CreateModelNil() +// num, err := redisCli.IncrNumExpire("scirpt:compensateCpScore", 1, time.Hour*999) +// if err != nil { +// model.Log.Errorf("CompensateCpScore err:%v", err) +// } +// if num > 1 { +// model.Log.Errorf("CompensateCpScore 执行过了,退出") +// return +// } +// // 查找需要补分的送礼记录 +// type GiftOperate struct { +// Id uint64 `json:"id"` +// ResGiftId uint64 `json:"res_gift_id"` +// GiftN int32 `json:"gift_n"` +// SendUserId uint64 `json:"send_user_id"` +// ReceiveUserId uint64 `json:"receive_user_id"` +// SendUserDiamond uint32 `json:"send_user_diamond"` +// SceneType int8 `json:"scene_type"` +// SceneUid string `json:"scene_uid"` +// CreatedTime time.Time `json:"created_time"` +// } +// rows := make([]*GiftOperate, 0) +// err = model.DB().Model(GiftOperate{}). +// Where("created_time < ?", "2023-06-22 11:20:15"). +// Where("res_gift_id in (?)", +// []int{3561, 3571, 3581, 3591, 3601, 3611, 3621, 3631, 3641, 3651, 3661, 3671, 3681, 3691, 3701, 3711}). +// Find(&rows).Error +// if err != nil { +// model.Log.Errorf("CompensateCpScore err:%v", err) +// return +// } +// model.Log.Infof("CompensateCpScore len(rows):%v", len(rows)) +// +// for idx, r := range rows { +// diamonds := r.SendUserDiamond +// // 有cp关系 +// if cpRelation, exits := cp_m.GetCpRelationPair(model, r.SendUserId, r.ReceiveUserId); exits { +// if err := cp_m.AddCpLevelPoints(model, cpRelation, diamonds, gift_e.GiftOperateSceneType(r.SceneType), r.SceneUid); err != nil { +// model.Log.Errorf("CompensateCpScore AddCpLevelPoints fail:%v", err) +// return +// } +// if err := cp_m.AddCpDayRank(model, cpRelation, diamonds); err != nil { +// model.Log.Errorf("CompensateCpScore AddCpDayRank fail:%v", err) +// return +// } +// // 检查最新的等级 +// if cpLevel := cp_m.GetCpLevel(model, cpRelation.Id); cpLevel.CpId >= 0 { +// points := cpLevel.Points + cp_e.CpLevelPoints[cpLevel.Level] +// if err := cp_m.UpdateCpAchievement(model, cpLevel.CpId, cpRelation.UserId1, cpRelation.UserId2, cp_e.CpAchievementLevel, points); err != nil { +// model.Log.Errorf("CompensateCpScore UpdateCpAchievement fail:%v", err) +// } +// } +// // 检查最高的分数 +// for _, queryType := range []string{"day", "week", "month"} { +// var beginDate, endDate string +// var cpAchievementType cp_e.CpAchievement +// switch queryType { +// case "day": +// beginDate, endDate = r.CreatedTime.Format("2006-01-02"), r.CreatedTime.Format("2006-01-02") +// cpAchievementType = cp_e.CpAchievementDayRank +// case "week": +// beginDate = now.With(r.CreatedTime).BeginningOfWeek().Format("2006-01-02") +// endDate = now.With(r.CreatedTime).EndOfWeek().Format("2006-01-02") +// cpAchievementType = cp_e.CpAchievementWeekRank +// case "month": +// beginDate = now.BeginningOfMonth().Format("2006-01-02") +// endDate = now.EndOfMonth().Format("2006-01-02") +// cpAchievementType = cp_e.CpAchievementMonthRank +// } +// if data := cp_m.GetCpDayRank(model, beginDate, endDate, cpRelation.Id); data.Score > 0 { +// if err := cp_m.UpdateCpAchievement(model, cpRelation.Id, cpRelation.UserId1, cpRelation.UserId2, cpAchievementType, data.Score); err != nil { +// model.Log.Errorf("CompensateCpScore UpdateCpAchievement fail:%v", err) +// } +// } +// } +// } +// model.Log.Infof("CompensateCpScore idx:%v", idx) +// if idx%1000 == 0 { +// time.Sleep(time.Millisecond * 100) +// } +// } +// +// model.Log.Infof("CompensateCpScore 补偿完毕") +//} diff --git a/domain/service/event_s/event_init.go b/domain/service/event_s/event_init.go index 14d10791780e443bedaaa10727789f7c96e8e1f0..652f70910d7673c50b26244ac5351f4ca62ae46f 100644 --- a/domain/service/event_s/event_init.go +++ b/domain/service/event_s/event_init.go @@ -14,7 +14,7 @@ import ( func EventInit() { UserBagSendEvent() - CpGiftEvent() + //CpGiftEvent() CpSpaceVisitEvent() } diff --git a/release.ini b/release.ini index 4e7a5683fa44b5826e694d59900842d12ea88a86..ac53e28c474d0e243bcf2d27950064f5452785c9 100755 --- a/release.ini +++ b/release.ini @@ -1,6 +1,6 @@ [DATABASE] MYSQL_HOST=ua4papc3hmgqf351pbej-rw4rm.rwlb.dubai.rds.aliyuncs.com -MYSQL_USERNAME=nextvideo +MYSQL_USERNAME=hilo_user MYSQL_PASSWORD=ihlUwI4nhi9W88MI MYSQL_DB=hilo [DATABASECODE] diff --git a/route/cp_r/rank.go b/route/cp_r/rank.go index 22fdc1994f2c9aa853620870b008866662858e7d..2a2caafd3e810315f7eda178c5cca5f7a00867a0 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 { diff --git a/route/invite_r/party_invite.go b/route/invite_r/party_invite.go index d1b167a46f868d789040b7cfe88cd3f6d505f7a8..5ddff63cfc1c5ee7c1bd1098c5546d0302f5d51a 100644 --- a/route/invite_r/party_invite.go +++ b/route/invite_r/party_invite.go @@ -231,7 +231,7 @@ func InviteApplyList(c *gin.Context) (*mycontext.MyContext, error) { func PromotionPlatform(c *gin.Context) (*mycontext.MyContext, error) { myCtx := mycontext.CreateMyContext(c.Keys) resp.ResponseOk(c, []string{"Falla", "Yalla", "Whisper", "Ahlan", "Mashi", "YoYo", "Yoho", "Echo", "Hawa", - "Yalla Ludo", "Hafla", "Imo", "Ola Party", "ShareChat", "Viya", "Hello Yo", "Bigo Live", "Hago"}) + "Yalla Ludo", "Hafla", "Imo", "Ola Party", "ShareChat", "Viya", "Hello Yo", "Bigo Live", "Hago", "Oye Talk", "Tiktok", "Bigo", "Mr7ba"}) return myCtx, nil } diff --git a/route/router.go b/route/router.go index 81cfcb81908701fe13f28b7e193e0d4114387659..ef4619ca97427047027b40a019169d2d4a651eec 100644 --- a/route/router.go +++ b/route/router.go @@ -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) @@ -75,7 +76,8 @@ func InitRouter() *gin.Engine { innerUser.GET("/cp", wrapper(user_r.GetUserCp)) innerUser.GET("/cpRelations", wrapper(user_r.MGetUserCpRelation)) innerUser.GET("/cp/pair", wrapper(user_r.GetUserCpPair)) - innerUser.GET("/cp/entryEffect", wrapper(user_r.GetUserCpEntryEffect)) // 获取cp进场特效信息,高频接口,需要额外处理 + innerUser.GET("/cp/entryEffect", wrapper(user_r.GetUserCpEntryEffect)) // 获取cp进场特效信息,高频接口,需要额外处理 + innerUser.GET("/svipNobleLevel", wrapper(user_r.MGetUserSvipNobleLevel)) // 获取用户svip/noble/level等信息 } // 道具相关 innerProp := inner.Group("/prop") diff --git a/route/user_r/inner.go b/route/user_r/inner.go index b2422f9b50c897648461837fd3d20f2f117476d5..1d66443988624c333b17ebcdab99c3b2e26029f1 100644 --- a/route/user_r/inner.go +++ b/route/user_r/inner.go @@ -4,9 +4,11 @@ import ( "git.hilo.cn/hilo-common/domain" "git.hilo.cn/hilo-common/mycontext" "git.hilo.cn/hilo-common/resource/mysql" + "git.hilo.cn/hilo-common/rpc" "github.com/gin-gonic/gin" "hilo-user/_const/enum/cp_e" "hilo-user/cv/cp_cv" + "hilo-user/cv/noble_cv" "hilo-user/cv/user_cv" "hilo-user/domain/cache/user_c" "hilo-user/domain/model/bag_m" @@ -56,6 +58,62 @@ func MGetUserLevels(c *gin.Context) (*mycontext.MyContext, error) { return myCtx, nil } +type MGetUserSvipVipLevelReq struct { + Ids []mysql.ID `form:"ids" binding:"required"` +} + +// @Tags 用户-内部 +// @Summary 批量获取用户等级 +// @Param ids query string true "用户id,如:ids=1&ids=2&ids=3" +// @Success 200 {object} user_cv.CvUserDetail +// @Router /inner/user/svipNobleLevel [get] +func MGetUserSvipNobleLevel(c *gin.Context) (*mycontext.MyContext, error) { + myCtx := mycontext.CreateMyContext(c.Keys) + var model = domain.CreateModelContext(myCtx) + var req MGetUserLevelReq + if err := c.ShouldBindQuery(&req); err != nil { + return myCtx, err + } + wealthGrade, err := user_m.MGetWealthGrade(model, req.Ids) + if err != nil { + return myCtx, err + } + charmGrade, err := user_m.MGetCharmGrade(model, req.Ids) + activeGrade, err := user_m.MGetActiveGrade(model, req.Ids) + nobleLevel, err := noble_m.BatchGetNobleLevel(model, req.Ids) + svip, err := rpc.MGetUserSvip(model, req.Ids) + users, err := user_m.GetUserMapByIds(model, req.Ids) + response := make(map[uint64]user_cv.CvUserDetail) + for _, userId := range req.Ids { + user := users[userId] + response[userId] = user_cv.CvUserDetail{ + CvUserBase: user_cv.CvUserBase{ + Id: &user.ID, + Avatar: &user.Avatar, + ExternalId: &user.ExternalId, + Nick: &user.Nick, + Sex: &user.Sex, + Country: &user.Country, + CountryIcon: &user.CountryIcon, + Code: &user.Code, + Birthday: &user.Birthday, + Svip: rpc.CvSvip{ + SvipLevel: svip[userId].SvipLevel, + }, + Noble: noble_cv.CvNoble{ + Level: nobleLevel[userId], + }, + }, + WealthUserGrade: wealthGrade[userId], + CharmUserGrade: charmGrade[userId], + ActivityUserGrade: activeGrade[userId], + } + } + + resp.ResponseOk(c, response) + return myCtx, nil +} + type GetUserBagReq struct { BagId mysql.ID `form:"bagId" binding:"required"` } diff --git a/route/user_r/user.go b/route/user_r/user.go index 87cf5cf326d298e13e4651265e22c6d94280057e..0b55220399f6cef10c714438690bbc9a019cb486 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 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 +}