diff --git a/domain/model/groupPower_m/group_rank.go b/domain/model/groupPower_m/group_rank.go index 78287bd3ba8098366c5e5762b959abfaf3ab437b..1d18512a80da2324532546bf3a2263da65378b8e 100644 --- a/domain/model/groupPower_m/group_rank.go +++ b/domain/model/groupPower_m/group_rank.go @@ -3,6 +3,7 @@ package groupPower_m import ( "git.hilo.cn/hilo-common/domain" "git.hilo.cn/hilo-common/resource/mysql" + "gorm.io/gorm" ) type GroupPowerExpRank struct { @@ -26,6 +27,20 @@ func GetGroupPowerExpRank(model *domain.Model, beginDate, endDate string, limit return res, nil } +// 获取我的家族经验排行榜 +func GetMyGroupPowerExpRank(model *domain.Model, beginDate, endDate string, groupPowerId uint64) (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 ? AND group_power_id = ?", beginDate, endDate, groupPowerId).Group("group_power_id").First(&res).Error; err != nil { + if err != gorm.ErrRecordNotFound { + model.Log.Errorf("GetMyGroupPowerExpRank fail:%v", err) + return res, err + } + return res, nil + } + return res, nil +} + // 获取我的家族月排名是多少,超过30则返回31 func GetGroupPowerExpRankById(model *domain.Model, beginDate, endDate string, limit int, groupPowerId uint64) (int, error) { var res []GroupPowerExpRank diff --git a/route/group_power_r/group_rank.go b/route/group_power_r/group_rank.go index 7c665f1ad215efdc27ba45f8a6fbcf59ef34e280..6aebe500b80a8d155a43d9065c2bafd03e61a150 100644 --- a/route/group_power_r/group_rank.go +++ b/route/group_power_r/group_rank.go @@ -70,21 +70,28 @@ 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.GetMyGroupPowerExpRank(model, beginDate, endDate, myGroupPower.GroupPowerId) + if err != nil { + return myContext, err + } + response.MyGroupPower = &group_power_cv.CvGroupPowerRankData{ + CvGroupPowerBase: group_power_cv.CvGroupPowerBase{ + Id: 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: 0, + } + } 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{ - Id: 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, - } + if response.MyGroupPower != nil && v.GroupPowerId == response.MyGroupPower.Id { + response.MyGroupPower.Rank = v.Rank } response.Items = append(response.Items, group_power_cv.CvGroupPowerRankData{ CvGroupPowerBase: group_power_cv.CvGroupPowerBase{