Commit ef0d3aed authored by chenweijian's avatar chenweijian

家族月排名

parent 5935a3fb
......@@ -671,6 +671,7 @@ type GroupPower struct {
MemberMax mysql.Num `json:"memberMax" gorm:"-"` // 最大人数
Role int `json:"role" gorm:"-"` // 我在此家族中的角色 0.路人 1.成员 2.家族长 3.管理员
IsApply bool `json:"isApply" gorm:"-"` // 最大人数
MonthRank int `json:"monthRank" gorm:"-"` // 家族月排名
}
type GroupPowerUser struct {
......
......@@ -25,3 +25,23 @@ func GetGroupPowerExpRank(model *domain.Model, beginDate, endDate string, limit
}
return res, nil
}
// 获取我的家族月排名是多少,超过30则返回31
func GetGroupPowerExpRankById(model *domain.Model, beginDate, endDate string, limit int, groupPowerId uint64) (int, error) {
var res []GroupPowerExpRank
if err := model.DB().Table("group_power_day_exp").Select("group_power_id,SUM(exp) as exp").
Where("date BETWEEN ? AND ?", beginDate, endDate).Group("group_power_id").Order("exp DESC").Limit(limit).Find(&res).Error; err != nil {
model.Log.Errorf("GetMyGroupPowerExpRank fail:%v", err)
return 0, err
}
for i := range res {
res[i].Rank = i + 1
}
myRank := 31
for _, v := range res {
if v.GroupPowerId == groupPowerId {
myRank = v.Rank
}
}
return myRank, nil
}
......@@ -9,6 +9,7 @@ import (
"git.hilo.cn/hilo-common/resource/redisCli"
"git.hilo.cn/hilo-common/utils"
"github.com/gin-gonic/gin"
"github.com/jinzhu/now"
"hilo-group/_const/enum/groupPower_e"
"hilo-group/_const/enum/group_e"
"hilo-group/_const/enum/msg_e"
......@@ -760,6 +761,12 @@ func GroupPowerInfo(c *gin.Context) (*mycontext.MyContext, error) {
info.Nameplate = groupInfo.Name
}
}
// 家族月排名
beginDate, endDate := now.BeginningOfMonth().Format("2006-01-02"), now.EndOfMonth().Format("2006-01-02")
info.MonthRank, err = groupPower_m.GetGroupPowerExpRankById(model, beginDate, endDate, 30, info.Id)
if err != nil {
return myContext, err
}
// 我在该家族中的角色
myPU := groupPower_m.GroupPowerUser{UserId: myUserId}
myGroupPUser, err := myPU.GetGroupPowerUser(model)
......
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