diff --git a/common/utils.go b/common/utils.go index 9d7420ef3b1a7098c1772985d005b61265af9d7c..fe1faa14d3a49500b19aca241e892094d533aedf 100755 --- a/common/utils.go +++ b/common/utils.go @@ -30,3 +30,13 @@ func MakeFullUrl(url string) string { return url } } + +func PageNext(total int64, pageIndex, pageSize int) (int, bool) { + var nextIdx int + var hasNext bool + if total > int64(pageIndex*pageSize) { + hasNext = true + nextIdx = pageIndex + 1 + } + return nextIdx, hasNext +} diff --git a/cv/group_power_cv/groupPower.go b/cv/group_power_cv/groupPower.go index 1d1583f525f7b29b05167ed57d5ad4c9bc284142..87cdf0957b95e39680d3522a41c8914a2b56c65d 100644 --- a/cv/group_power_cv/groupPower.go +++ b/cv/group_power_cv/groupPower.go @@ -642,9 +642,22 @@ func GetAllPowerDiamond(period string) (map[string]string, error) { } type GroupPowerInfo struct { - Info *groupPower_m.GroupPower `json:"info"` - Members []*GroupPowerUser `json:"members"` - Stars []*user_m.UserTiny `json:"stars"` + Info *GroupPower `json:"info"` + Members []*GroupPowerUser `json:"members"` + Stars []*GroupPowerStart `json:"stars"` +} + +type GroupPower struct { + Id uint64 `json:"id"` + Name mysql.Str `json:"name"` + Nameplate mysql.Str `json:"nameplate"` // 铭牌 + Declaration mysql.Str `json:"declaration"` // 宣言 + Icon mysql.Str `json:"icon"` // 头像 + Grade mysql.Num `json:"grade" gorm:"-"` // 等级 + Exp mysql.Num `json:"exp" gorm:"-"` // 当前经验值 + NextExp mysql.Num `json:"nextExp" gorm:"-"` // 升到下一级需要的经验值 + GradeName mysql.Str `json:"gradeName"` // 等级称号 + GradeMedal mysql.Str `json:"gradeMedal"` // 等级勋章图片 } type GroupPowerUser struct { diff --git a/domain/model/groupPower_m/family.go b/domain/model/groupPower_m/family.go index 97d416ce8b616632c5f84efd78f0d5fa4b2788e5..1a590792eb9571d4fc18120cb5501d423537e21e 100644 --- a/domain/model/groupPower_m/family.go +++ b/domain/model/groupPower_m/family.go @@ -4,6 +4,7 @@ import ( "git.hilo.cn/hilo-common/domain" "git.hilo.cn/hilo-common/resource/mysql" "gorm.io/gorm" + "hilo-group/common" "hilo-group/common/utime" "time" ) @@ -37,13 +38,20 @@ func (this *GroupPower) Get(model *domain.Model) (*GroupPower, error) { return group, nil } -func (gpu *GroupPowerUser) GetBy(model *domain.Model, pageSize, pageIndex int) ([]*GroupPowerUser, error) { +func (gpu *GroupPowerUser) GetBy(model *domain.Model, pageSize, pageIndex int) ([]*GroupPowerUser, int, bool, error) { rows := make([]*GroupPowerUser, 0) - err := model.Db.Where(gpu).Order("field(`role`, 2, 3, 1)").Limit(pageSize).Offset(pageIndex - 1).Find(&rows).Error + db := model.Db.Where(gpu).Order("field(`role`, 2, 3, 1)") + var count int64 + err := db.Count(&count).Error if err != nil { - return nil, err + return nil, 0, false, err + } + err = db.Limit(pageSize).Offset(pageIndex - 1).Find(&rows).Error + if err != nil { + return nil, 0, false, err } - return rows, nil + nextPageIndex, hasNextPage := common.PageNext(count, pageIndex, pageSize) + return rows, nextPageIndex, hasNextPage, nil } func (gpu *GroupPowerUser) GetGroupPowerUser(model *domain.Model) (*GroupPowerUser, error) { diff --git a/domain/model/groupPower_m/group_power_apply.go b/domain/model/groupPower_m/group_power_apply.go index 1ada06d5c1e194b1c6831b43032816e873c93c10..1d91cc7249984d6e59ae4214e6c6a16dfd08ffcd 100644 --- a/domain/model/groupPower_m/group_power_apply.go +++ b/domain/model/groupPower_m/group_power_apply.go @@ -3,6 +3,7 @@ package groupPower_m import ( "git.hilo.cn/hilo-common/domain" "gorm.io/gorm" + "hilo-group/common" "hilo-group/myerr" "hilo-group/myerr/bizerr" "time" @@ -60,12 +61,18 @@ func AcceptGroupPowerApplyJoin(model *domain.Model, userId, familyId uint64) err return nil } -func OptGroupPowerApplyList(model *domain.Model, familyId uint64, pageSize, pageIndex int) ([]*GroupPowerApplyJoin, error) { +func OptGroupPowerApplyList(model *domain.Model, familyId uint64, pageSize, pageIndex int) ([]*GroupPowerApplyJoin, int, bool, error) { rows := make([]*GroupPowerApplyJoin, 0) - err := model.Db.Model(GroupPowerApplyJoin{}).Where("group_power_id = ?", familyId). - Order("is_accept, created_time desc").Limit(pageSize).Offset(pageIndex - 1).Find(&rows).Error + db := model.Db.Model(GroupPowerApplyJoin{}).Where("group_power_id = ?", familyId).Order("is_accept, created_time desc") + var count int64 + err := db.Count(&count).Error if err != nil { - return nil, err + return nil, 0, false, err } - return rows, nil + err = db.Limit(pageSize).Offset(pageIndex - 1).Find(&rows).Error + if err != nil { + return nil, 0, false, err + } + nextIdx, hasNext := common.PageNext(count, pageIndex, pageSize) + return rows, nextIdx, hasNext, nil } diff --git a/domain/model/group_m/groupInfo.go b/domain/model/group_m/groupInfo.go index ea1a92bd59b72b1928669aaf4985227d9f95369b..b9f0ff9b63effa78d4bbe20bdaa2366674bef36c 100644 --- a/domain/model/group_m/groupInfo.go +++ b/domain/model/group_m/groupInfo.go @@ -515,12 +515,23 @@ func GetLatestGroupInfos(model *domain.Model, limit, lastId int, groupIds []stri return } -func GetFamilyRooms(model *domain.Model, familyId uint64, pageSize, pageIndex int) ([]*GroupInfo, error) { +func GetFamilyRooms(model *domain.Model, familyId uint64, pageSize, pageIndex int) ([]*GroupInfo, int, bool, error) { rows := make([]*GroupInfo, 0) - 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). - Limit(pageSize).Offset((pageIndex - 1) * pageSize).Find(&rows).Error + db := 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) + var count int64 + err := db.Count(&count).Error if err != nil { - return nil, err + return nil, 0, false, err } - return rows, nil + err = db.Limit(pageSize).Offset((pageIndex - 1) * pageSize).Find(&rows).Error + if err != nil { + return nil, 0, false, err + } + var nextIdx int + var hasNext bool + if count > int64(pageIndex*pageSize) { + hasNext = true + nextIdx = pageIndex + 1 + } + return rows, nextIdx, hasNext, nil } diff --git a/route/group_power_r/group_power.go b/route/group_power_r/group_power.go index 6a2e8856152ff5d08a969191bb28a2ce99fd89cd..be271377f7526a158b698f181ff049e4fa36d8e2 100644 --- a/route/group_power_r/group_power.go +++ b/route/group_power_r/group_power.go @@ -717,7 +717,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, 0) + members, _, _, err := gpU.GetBy(model, 5, 0) if err != nil { return myContext, err } @@ -735,7 +735,11 @@ func GroupPowerInfo(c *gin.Context) (*mycontext.MyContext, error) { for _, v := range members { resMembers = append(resMembers, &group_power_cv.GroupPowerUser{User: userMap[v.UserId], Role: v.Role}) } - res := group_power_cv.GroupPowerInfo{Info: gpInfo, Members: resMembers} + info := &group_power_cv.GroupPower{ + Id: gpInfo.ID, Name: gpInfo.Name, Nameplate: gpInfo.Nameplate, Declaration: gpInfo.Declaration, Icon: gpInfo.Icon, + Grade: gpInfo.Grade, Exp: gpInfo.Exp, NextExp: gpInfo.NextExp, GradeName: gpInfo.GradeName, GradeMedal: gpInfo.GradeMedal, + } + res := group_power_cv.GroupPowerInfo{Info: info, Members: resMembers} resp.ResponseOk(c, res) return myContext, nil @@ -767,7 +771,7 @@ func GroupPowerRooms(c *gin.Context) (*mycontext.MyContext, error) { return myContext, err } model := domain.CreateModelContext(myContext) - rooms, err := group_m.GetFamilyRooms(model, familyId, pageSize, pageIndex) + rooms, nextPageIndex, hasNextPage, err := group_m.GetFamilyRooms(model, familyId, pageSize, pageIndex) if err != nil { return myContext, err } @@ -776,7 +780,7 @@ func GroupPowerRooms(c *gin.Context) (*mycontext.MyContext, error) { return myContext, err } - resp.ResponseOk(c, resRooms) + resp.ResponsePageBaseOk(c, resRooms, nextPageIndex, hasNextPage) return myContext, nil } @@ -820,7 +824,7 @@ func GroupPowerMembers(c *gin.Context) (*mycontext.MyContext, error) { } } - members, err := gpU.GetBy(model, pageSize, pageIndex) + members, nextPageIndex, hasNextPage, err := gpU.GetBy(model, pageSize, pageIndex) if err != nil { return myContext, err } @@ -845,7 +849,7 @@ func GroupPowerMembers(c *gin.Context) (*mycontext.MyContext, error) { } } - resp.ResponseOk(c, result) + resp.ResponsePageBaseOk(c, result, nextPageIndex, hasNextPage) return myContext, nil } @@ -1009,7 +1013,7 @@ func GroupPowerApplyList(c *gin.Context) (*mycontext.MyContext, error) { return myContext, bizerr.GroupPowerHaveNoPower } // 申请列表 - rows, err := groupPower_m.OptGroupPowerApplyList(model, myGroupPUser.GroupPowerId, pageSize, pageIndex) + rows, nextPageIndex, hasNextPage, err := groupPower_m.OptGroupPowerApplyList(model, myGroupPUser.GroupPowerId, pageSize, pageIndex) if err != nil { return myContext, err } @@ -1027,6 +1031,6 @@ func GroupPowerApplyList(c *gin.Context) (*mycontext.MyContext, error) { result = append(result, &group_power_cv.FamilyApplyList{User: userMap[v.UserId], Time: v.CreatedTime, Status: v.IsAccept, MgrName: userMap[v.MgrId].Nick}) } - resp.ResponseOk(c, result) + resp.ResponsePageBaseOk(c, result, nextPageIndex, hasNextPage) return myContext, nil }