diff --git a/domain/model/groupPower_m/group_rank.go b/domain/model/groupPower_m/group_rank.go index be056dc96cd0860e01fa631662cd33bf031df6a4..9ebcfd53251c9d17e8e6dfd403a0ad6eb18a719b 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 5d27b92d8bcda9ef5d8db3c7061346c2e0e56a97..898fd8e3b8ab9beae51b7f28a3f1c2832079856b 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 }