Commit 387ff1df authored by chenweijian's avatar chenweijian

家族信息接口

parent f2d5e210
...@@ -43,12 +43,12 @@ type GroupBasicInfo struct { ...@@ -43,12 +43,12 @@ type GroupBasicInfo struct {
//1:5人 2:10人 //1:5人 2:10人
MicNumType int `json:"micNumType"` MicNumType int `json:"micNumType"`
// N天内的进入用户数量(重复进入去重,实时) // N天内的进入用户数量(重复进入去重,实时)
GroupInUserDuration int64 `json:"groupInUserDuration"` GroupInUserDuration int64 `json:"groupInUserDuration"` // 群热度
GroupMedals []medal_cv.PicElement `json:"groupMedals"` // 群勋章 GroupMedals []medal_cv.PicElement `json:"groupMedals"` // 群勋章
TouristMic uint8 `json:"touristMic"` // 游客是否能上麦 TouristMic uint8 `json:"touristMic"` // 游客是否能上麦
TouristSendMsg uint8 `json:"touristSendMsg"` // 游客是否能发言 TouristSendMsg uint8 `json:"touristSendMsg"` // 游客是否能发言
TouristSendPic uint8 `json:"touristSendPic"` // 游客是否能发图片 TouristSendPic uint8 `json:"touristSendPic"` // 游客是否能发图片
MemberFee uint64 `json:"memberFee"` // 加入群组会员需要的黄钻 MemberFee uint64 `json:"memberFee"` // 加入群组会员需要的黄钻
} }
type MemberListInfo struct { type MemberListInfo struct {
...@@ -404,6 +404,168 @@ func BuildJoinedGroupInfo(myService *domain.Service, myUserId uint64, groupIds [ ...@@ -404,6 +404,168 @@ func BuildJoinedGroupInfo(myService *domain.Service, myUserId uint64, groupIds [
return result, len(groupInfo), nil return result, len(groupInfo), nil
} }
func BuildPopularGroupInfo(model *domain.Model, myUserId uint64, groupInfo []*group_m.GroupInfo) ([]*PopularGroupInfo, error) {
groupIds := make([]string, 0, len(groupInfo))
for _, v := range groupInfo {
groupIds = append(groupIds, v.ImGroupId)
}
// roomMicUserMap不影响排序
roomMicUserMap, err := group_m.BatchGetAllMicUser(model, groupIds)
if err != nil {
return nil, err
}
uids := make([]uint64, 0)
micUsersMap := make(map[string][]uint64, 0)
for _, v := range groupInfo {
micUsersMap[v.ImGroupId] = make([]uint64, 0)
if len(v.Password) <= 0 {
// 密码群不显示麦上头像
u := roomMicUserMap[v.ImGroupId]
if len(u) >= 4 {
micUsersMap[v.ImGroupId] = u[0:4]
} else if len(u) > 0 {
micUsersMap[v.ImGroupId] = u
}
uids = append(uids, micUsersMap[v.ImGroupId]...)
}
}
uids = utils.UniqueSliceUInt64(uids)
userTiny, err := user_cv.GetUserTinyMap(uids)
if err != nil {
return nil, err
}
roomCount, err := group_m.BatchGetRoomCount(model, groupIds)
if err != nil {
return nil, err
}
countryInfo, err := res_c.GetCountryIconMap(model)
if err != nil {
return nil, err
}
supportLevels, err := group_s.NewGroupService(model.MyContext).GetWeekMaxSupportLevelMap()
if err != nil {
return nil, err
}
visitCount, err := group_m.BatchGetRoomVisitCount(model.Log, groupIds)
if err != nil {
return nil, err
}
roomEnterTime, err := room_c.GetUserRoomVisit(myUserId)
if err != nil {
return nil, err
}
model.Log.Infof("BuildPopularGroupInfo, roomEnterTime: %v", roomEnterTime)
// 排序优先级V8.0版本
sort.Slice(groupIds, func(i, j int) bool {
gi := groupIds[i]
gj := groupIds[j]
return roomEnterTime[gi] > roomEnterTime[gj] ||
roomEnterTime[gi] == roomEnterTime[gj] && visitCount[gj] > visitCount[gj] ||
roomEnterTime[gi] == roomEnterTime[gj] && visitCount[gj] == visitCount[gj] && i >= j
})
result := make([]*PopularGroupInfo, 0)
owners := make([]uint64, 0)
for _, v := range groupInfo {
owners = append(owners, v.Owner)
}
powerIds, powerNames, err := group_power_cv.BatchGetGroupPower(model.Db, owners)
if err != nil {
return nil, err
}
groupMedals, err := group_m.BatchGetMedals(model.Db, groupIds)
if err != nil {
return nil, err
}
resMedal, err := res_m.MedalGetAllMap(model.Db)
if err != nil {
return nil, err
}
rr := rocket_m.RocketResult{}
maxStageMap, err := rr.GetMaxStage(model.Db, groupIds)
if err != nil {
return nil, err
}
// 正在进行的游戏
games := game_m.GetNotEndGamesMap(model)
for _, v := range groupInfo {
g := v
i := v.ImGroupId
micUsers := make([]user_cv.CvUserTiny, 0)
for _, j := range micUsersMap[i] {
micUsers = append(micUsers, userTiny[j])
}
var maxStage *uint16 = nil
if s, ok := maxStageMap[i]; ok {
maxStage = &s
}
medals := make([]medal_cv.PicElement, 0)
if m, ok := groupMedals[i]; ok {
for _, j := range m {
mId := uint32(j)
if e, ok := resMedal[mId]; ok {
medals = append(medals, medal_cv.PicElement{
PicUrl: e.PicUrl,
})
}
}
}
// 补上房间流水勋章
var pe *medal_cv.PicElement
_, pe, err = medal_cv.GetGroupConsumeMedal(model, i)
if err != nil {
model.Log.Infof("BuildPopularGroupInfo: GetGroupConsumeMedal: %s", err.Error())
} else if pe != nil {
medals = append(medals, medal_cv.PicElement{PicUrl: pe.PicUrl})
}
var password *string = nil
if len(g.Password) > 0 && g.Owner != myUserId {
emptyStr := ""
password = &emptyStr
}
result = append(result, &PopularGroupInfo{
GroupInfo: GroupInfo{
GroupBasicInfo: GroupBasicInfo{
GroupId: g.TxGroupId,
Name: g.Name,
Notification: g.Notification,
Introduction: g.Introduction,
FaceUrl: g.FaceUrl,
Code: g.Code,
CountryIcon: countryInfo[g.Country],
Password: password,
SupportLevel: supportLevels[i],
GroupInUserDuration: visitCount[i],
MicNumType: int(g.MicNumType),
GroupMedals: medals,
},
HasOnMic: len(micUsers) > 0,
GroupPowerId: powerIds[g.Owner],
GroupPowerName: powerNames[g.Owner],
},
MicUsers: micUsers,
RoomUserCount: uint(roomCount[i]),
MaxStage: maxStage,
GameTypes: games[g.TxGroupId],
})
}
return result, nil
}
//检查群组中是否有有人在麦上,返回存在的Set[imGroupId] //检查群组中是否有有人在麦上,返回存在的Set[imGroupId]
func CheckMicHasUserByGroup(groupIds []string) (map[string]struct{}, error) { func CheckMicHasUserByGroup(groupIds []string) (map[string]struct{}, error) {
groupMap := map[string]struct{}{} groupMap := map[string]struct{}{}
......
...@@ -515,29 +515,12 @@ func GetLatestGroupInfos(model *domain.Model, limit, lastId int, groupIds []stri ...@@ -515,29 +515,12 @@ func GetLatestGroupInfos(model *domain.Model, limit, lastId int, groupIds []stri
return return
} }
//func init() { func GetFamilyRooms(model *domain.Model, familyId uint64, pageSize, pageIndex int) ([]*GroupInfo, error) {
// // 初始化官方群组 rows := make([]*GroupInfo, 0)
// strGroupIds := strings.Split(config.GetConfigApp().OFFICIAL_GROUP, ",") err := model.Db.Model(GroupInfo{}).Where("owner in (select user_id from group_power_user where group_power_id=? order by field(`role`, 2, 3, 1))", familyId).
// for _, i := range strGroupIds { Limit(pageSize).Offset((pageIndex - 1) * pageSize).Find(&rows).Error
// if len(i) > 0 { if err != nil {
// officialGroup = append(officialGroup, i) return nil, err
// } }
// } return rows, nil
// mylogrus.MyLog.Info("Official groups: ", officialGroup) }
//
// event.AddUserInfoUpdate(func(model *domain.Model, e interface{}) error {
// event := e.(*event.UserInfoUpdateEvent)
// if event.Country == nil {
// return nil
// } else {
// // v2.3需求:同步更新群组country
// model.Log.Infof("Receive userInfoUpdate: user %d, country %s", event.UserId, *event.Country)
// return UpdateCountryByOwner(model, *event.Country, event.UserId)
// }
// })
// event.AddMgrUserCountryUpdateAsync(func(model *domain.Model, event *event.MgrUserCountryUpdateEvent) error {
// // v2.3需求:同步更新群组country
// model.Log.Infof("Receive MgrUserCountryUpdate: user %d, from %s to %s", event.UserId, event.OldCountry, event.NewCountry)
// return UpdateCountryByOwner(model, event.NewCountry, event.UserId)
// })
//}
...@@ -739,3 +739,42 @@ func GroupPowerInfo(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -739,3 +739,42 @@ func GroupPowerInfo(c *gin.Context) (*mycontext.MyContext, error) {
resp.ResponseOk(c, res) resp.ResponseOk(c, res)
return myContext, nil return myContext, nil
} }
// @Tags 家族
// @Summary 获取某个家族房间列表
// @Param id query int true "家族id"
// @Param pageSize query int true "分页大小 默认:10" default(10)
// @Param pageIndex query int true "第几个分页,从1开始 默认:1" default(1)
// @Success 200 {object} []group_cv.PopularGroupInfo
// @Router /v1/groupPower/rooms [get]
func GroupPowerRooms(c *gin.Context) (*mycontext.MyContext, error) {
myContext := mycontext.CreateMyContext(c.Keys)
userId, err := req.GetUserId(c)
if err != nil {
return myContext, err
}
familyId, err := strconv.ParseUint(c.Query("id"), 10, 64)
if err != nil {
return myContext, err
}
pageSize, err := strconv.Atoi(c.Query("pageSize"))
if err != nil {
return myContext, err
}
pageIndex, err := strconv.Atoi(c.Query("pageIndex"))
if err != nil {
return myContext, err
}
model := domain.CreateModelContext(myContext)
rooms, err := group_m.GetFamilyRooms(model, familyId, pageSize, pageIndex)
if err != nil {
return myContext, err
}
resRooms, err := group_cv.BuildPopularGroupInfo(model, userId, rooms)
if err != nil {
return myContext, err
}
resp.ResponseOk(c, resRooms)
return myContext, nil
}
...@@ -127,6 +127,7 @@ func InitRouter() *gin.Engine { ...@@ -127,6 +127,7 @@ func InitRouter() *gin.Engine {
groupPower.GET("/billboard/week", wrapper(group_power_r.GroupPowerBillboardWeek)) groupPower.GET("/billboard/week", wrapper(group_power_r.GroupPowerBillboardWeek))
groupPower.GET("/billboard/owner/week", wrapper(group_power_r.GroupPowerBillboardOwnerWeek)) groupPower.GET("/billboard/owner/week", wrapper(group_power_r.GroupPowerBillboardOwnerWeek))
groupPower.GET("/info", wrapper(group_power_r.GroupPowerInfo)) groupPower.GET("/info", wrapper(group_power_r.GroupPowerInfo))
groupPower.GET("/rooms", wrapper(group_power_r.GroupPowerRooms))
} }
charge := v1.Group("/charge") charge := v1.Group("/charge")
......
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