Commit 06790632 authored by hujiebin's avatar hujiebin

fix:补全myGroupOPwer

parent fdf023a0
......@@ -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
......
......@@ -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{
......
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