diff --git a/cv/group_power_cv/groupPower.go b/cv/group_power_cv/groupPower.go index 3ebcf6518de9fadff7e1ba0de2d53a761b5cdf22..dc54f16418cc973857dad0390d308cdad4139451 100644 --- a/cv/group_power_cv/groupPower.go +++ b/cv/group_power_cv/groupPower.go @@ -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"` +} diff --git a/domain/model/groupPower_m/family.go b/domain/model/groupPower_m/family.go index 2925d49e156e21c7ac4f23faff21cb90fa890670..d274e3661530b6d5f8a8ad21c00c25513f09b957 100644 --- a/domain/model/groupPower_m/family.go +++ b/domain/model/groupPower_m/family.go @@ -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 } diff --git a/route/group_power_r/group_power.go b/route/group_power_r/group_power.go index 1c075aeafeb4c458c4a0312bb4883d47c8b502b4..4a69c17026c91b6ff389c07852f7f43d2a1c6370 100644 --- a/route/group_power_r/group_power.go +++ b/route/group_power_r/group_power.go @@ -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 +} diff --git a/route/router.go b/route/router.go index fb65e8dca0d308d0f01f05bfc34f8f47b3605498..d4df17479dd5aca27f07b39194a728911a181633 100644 --- a/route/router.go +++ b/route/router.go @@ -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")