From c09b7ca3c3ddc840843f1b2e0c8a0e3450917798 Mon Sep 17 00:00:00 2001 From: hujiebin Date: Mon, 13 Mar 2023 14:13:34 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E4=BF=AE=E5=A4=8D=E6=8E=92=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- domain/model/groupPower_m/group_rank.go | 19 +++---------- route/group_power_r/group_rank.go | 37 ++++++++++++------------- 2 files changed, 22 insertions(+), 34 deletions(-) diff --git a/domain/model/groupPower_m/group_rank.go b/domain/model/groupPower_m/group_rank.go index be056dc..9ebcfd5 100644 --- a/domain/model/groupPower_m/group_rank.go +++ b/domain/model/groupPower_m/group_rank.go @@ -1,7 +1,6 @@ package groupPower_m import ( - "fmt" "git.hilo.cn/hilo-common/domain" "git.hilo.cn/hilo-common/resource/mysql" ) @@ -16,23 +15,13 @@ type GroupPowerExpRank struct { // param limit: 排行榜人数 func GetGroupPowerExpRank(model *domain.Model, beginDate, endDate string, limit int) ([]GroupPowerExpRank, 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") - if err := model.DB().Table("group_power_day_exp p").Joins(",(SELECT @curRank := 0) p").Where("date BETWEEN ? AND ?", beginDate, endDate). - Select("group_power_id,SUM(exp) as exp,@curRank := @curRank + 1 `rank`"). - Group("group_power_id").Order("exp DESC").Limit(limit).Find(&res).Error; err != nil { + 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("GetGroupPowerExpRank fail:%v", err) return res, err } - return res, nil -} - -// 获取我的家族排行 -func GetGroupPowerExpMyRank(model *domain.Model, beginDate, endDate string, groupPowerId mysql.ID) (GroupPowerExpRank, error) { - table := fmt.Sprintf("(select group_power_id,SUM(exp) as exp,@curRank := @curRank + 1 `rank` from group_power_day_exp p,(SELECT @curRank := 0) tmp"+ - " WHERE `date` BETWEEN '%s' AND '%s' group BY group_power_id ORDER BY exp DESC ) t", beginDate, endDate) - var res GroupPowerExpRank - if err := model.DB().Table(table).Select("t.group_power_id,t.exp,t.`rank`").Where("t.group_power_id = ?", groupPowerId).Scan(&res).Error; err != nil { - return res, err + for i := range res { + res[i].Rank = i + 1 } return res, nil } diff --git a/route/group_power_r/group_rank.go b/route/group_power_r/group_rank.go index 5d27b92..898fd8e 100644 --- a/route/group_power_r/group_rank.go +++ b/route/group_power_r/group_rank.go @@ -70,26 +70,22 @@ func GroupPowerRank(c *gin.Context) (*mycontext.MyContext, error) { if err != nil { return myContext, err } - if myGroupPower != nil && myGroupPower.Role == groupPower_e.GroupPowerUserRoleMgr { - myGroupPowerRank, err := groupPower_m.GetGroupPowerExpMyRank(model, beginDate, endDate, myGroupPower.GroupPowerId) - if err != nil { - return myContext, err - } - response.MyGroupPower = &group_power_cv.CvGroupPowerRankData{ - CvGroupPowerBase: group_power_cv.CvGroupPowerBase{ - GroupPowerId: myGroupPower.GroupPowerId, - Icon: groupPowers[myGroupPower.GroupPowerId].Icon, - Name: groupPowers[myGroupPower.GroupPowerId].Name, - Nameplate: groupPowers[myGroupPower.GroupPowerId].Nameplate, - }, - CvGroupPowerGrade: group_power_cv.CvGroupPowerGrade{ - Grade: grades[myGroupPower.GroupPowerId].Grade, - Exp: myGroupPowerRank.Exp, - }, - Rank: myGroupPowerRank.Rank, - } - } for _, v := range rank { + if myGroupPower != nil && v.GroupPowerId == myGroupPower.GroupPowerId && myGroupPower.Role == groupPower_e.GroupPowerUserRoleMgr { + response.MyGroupPower = &group_power_cv.CvGroupPowerRankData{ + CvGroupPowerBase: group_power_cv.CvGroupPowerBase{ + GroupPowerId: myGroupPower.GroupPowerId, + Icon: groupPowers[myGroupPower.GroupPowerId].Icon, + Name: groupPowers[myGroupPower.GroupPowerId].Name, + Nameplate: groupPowers[myGroupPower.GroupPowerId].Nameplate, + }, + CvGroupPowerGrade: group_power_cv.CvGroupPowerGrade{ + Grade: grades[myGroupPower.GroupPowerId].Grade, + Exp: v.Exp, + }, + Rank: v.Rank, + } + } response.Items = append(response.Items, group_power_cv.CvGroupPowerRankData{ CvGroupPowerBase: group_power_cv.CvGroupPowerBase{ GroupPowerId: v.GroupPowerId, @@ -104,6 +100,9 @@ func GroupPowerRank(c *gin.Context) (*mycontext.MyContext, error) { Rank: v.Rank, }) } + if response.MyGroupPower != nil && response.MyGroupPower.Rank == 0 { + response.MyGroupPower.Rank = 31 // 客户端统一显示30+ + } resp.ResponseOk(c, response) return myContext, nil } -- 2.22.0