From ef0d3aed4752dd8de99ef9b621e1705f329eb67f Mon Sep 17 00:00:00 2001 From: chenweijian <820961417@qq.com> Date: Mon, 20 Mar 2023 15:57:57 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=B6=E6=97=8F=E6=9C=88=E6=8E=92=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cv/group_power_cv/groupPower.go | 1 + domain/model/groupPower_m/group_rank.go | 20 ++++++++++++++++++++ route/group_power_r/group_power.go | 7 +++++++ 3 files changed, 28 insertions(+) diff --git a/cv/group_power_cv/groupPower.go b/cv/group_power_cv/groupPower.go index cf4996d..4c9522d 100644 --- a/cv/group_power_cv/groupPower.go +++ b/cv/group_power_cv/groupPower.go @@ -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 { diff --git a/domain/model/groupPower_m/group_rank.go b/domain/model/groupPower_m/group_rank.go index 9ebcfd5..78287bd 100644 --- a/domain/model/groupPower_m/group_rank.go +++ b/domain/model/groupPower_m/group_rank.go @@ -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 +} diff --git a/route/group_power_r/group_power.go b/route/group_power_r/group_power.go index 2174fc9..1d11c61 100644 --- a/route/group_power_r/group_power.go +++ b/route/group_power_r/group_power.go @@ -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) -- 2.22.0