Commit c09b7ca3 authored by hujiebin's avatar hujiebin

feat:修复排名

parent 359a3eb9
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
}
......@@ -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
}
......
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