Commit bc331065 authored by chenweijian's avatar chenweijian

家族成员列表

parent a677f328
......@@ -656,3 +656,8 @@ type GroupPowerStart struct {
User *user_m.UserTiny `json:"user"`
RankingType groupPower_e.GroupPowerRankType `json:"rankingType"`
}
type FamilyMemberDetail struct {
user_cv.CvUserExtend
Role groupPower_e.GroupPowerUserRole `json:"role"`
}
......@@ -37,9 +37,9 @@ func (this *GroupPower) Get(model *domain.Model) (*GroupPower, error) {
return group, nil
}
func (gpu *GroupPowerUser) GetBy(model *domain.Model, limit int) ([]*GroupPowerUser, error) {
func (gpu *GroupPowerUser) GetBy(model *domain.Model, pageSize, pageIndex int) ([]*GroupPowerUser, error) {
rows := make([]*GroupPowerUser, 0)
err := model.Db.Where(gpu).Order("field(`role`, 2, 3, 1)").Limit(limit).Find(&rows).Error
err := model.Db.Where(gpu).Order("field(`role`, 2, 3, 1)").Limit(pageSize).Offset(pageIndex - 1).Find(&rows).Error
if err != nil {
return nil, err
}
......
......@@ -716,7 +716,7 @@ func GroupPowerInfo(c *gin.Context) (*mycontext.MyContext, error) {
return myContext, err
}
gpU := &groupPower_m.GroupPowerUser{GroupPowerId: gpInfo.ID}
members, err := gpU.GetBy(model, 5)
members, err := gpU.GetBy(model, 5, 0)
if err != nil {
return myContext, err
}
......@@ -778,3 +778,60 @@ func GroupPowerRooms(c *gin.Context) (*mycontext.MyContext, error) {
resp.ResponseOk(c, resRooms)
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_power_cv.FamilyMemberDetail
// @Router /v1/groupPower/members [get]
func GroupPowerMembers(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)
gpU := &groupPower_m.GroupPowerUser{GroupPowerId: familyId}
members, err := gpU.GetBy(model, pageSize, pageIndex)
if err != nil {
return myContext, err
}
userIds := make([]uint64, 0)
for _, v := range members {
userIds = append(userIds, v.UserId)
}
result := make([]group_power_cv.FamilyMemberDetail, 0)
if len(userIds) > 0 {
users, err := user_cv.BatchGetUserExtend(model, userIds, userId)
if err != nil {
return myContext, err
}
for _, v := range members {
result = append(result, group_power_cv.FamilyMemberDetail{
CvUserExtend: users[v.UserId],
Role: v.Role,
})
}
}
resp.ResponseOk(c, result)
return myContext, nil
}
......@@ -128,6 +128,7 @@ func InitRouter() *gin.Engine {
groupPower.GET("/billboard/owner/week", wrapper(group_power_r.GroupPowerBillboardOwnerWeek))
groupPower.GET("/info", wrapper(group_power_r.GroupPowerInfo))
groupPower.GET("/rooms", wrapper(group_power_r.GroupPowerRooms))
groupPower.GET("/members", wrapper(group_power_r.GroupPowerMembers))
}
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