Commit 8d492956 authored by chenweijian's avatar chenweijian

家族

parent e0ecdb1b
......@@ -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
}
......@@ -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 {
......
......@@ -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) {
......
......@@ -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
}
......@@ -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
}
......@@ -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
}
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