Commit 06790632 authored by hujiebin's avatar hujiebin

fix:补全myGroupOPwer

parent fdf023a0
...@@ -3,6 +3,7 @@ package groupPower_m ...@@ -3,6 +3,7 @@ package groupPower_m
import ( import (
"git.hilo.cn/hilo-common/domain" "git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/resource/mysql" "git.hilo.cn/hilo-common/resource/mysql"
"gorm.io/gorm"
) )
type GroupPowerExpRank struct { type GroupPowerExpRank struct {
...@@ -26,6 +27,20 @@ func GetGroupPowerExpRank(model *domain.Model, beginDate, endDate string, limit ...@@ -26,6 +27,20 @@ func GetGroupPowerExpRank(model *domain.Model, beginDate, endDate string, limit
return res, nil 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 // 获取我的家族月排名是多少,超过30则返回31
func GetGroupPowerExpRankById(model *domain.Model, beginDate, endDate string, limit int, groupPowerId uint64) (int, error) { func GetGroupPowerExpRankById(model *domain.Model, beginDate, endDate string, limit int, groupPowerId uint64) (int, error) {
var res []GroupPowerExpRank var res []GroupPowerExpRank
......
...@@ -70,8 +70,11 @@ func GroupPowerRank(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -70,8 +70,11 @@ func GroupPowerRank(c *gin.Context) (*mycontext.MyContext, error) {
if err != nil { if err != nil {
return myContext, err return myContext, err
} }
for _, v := range rank { if myGroupPower != nil && myGroupPower.Role == groupPower_e.GroupPowerUserRoleMgr {
if myGroupPower != nil && v.GroupPowerId == myGroupPower.GroupPowerId && 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{ response.MyGroupPower = &group_power_cv.CvGroupPowerRankData{
CvGroupPowerBase: group_power_cv.CvGroupPowerBase{ CvGroupPowerBase: group_power_cv.CvGroupPowerBase{
Id: myGroupPower.GroupPowerId, Id: myGroupPower.GroupPowerId,
...@@ -81,11 +84,15 @@ func GroupPowerRank(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -81,11 +84,15 @@ func GroupPowerRank(c *gin.Context) (*mycontext.MyContext, error) {
}, },
CvGroupPowerGrade: group_power_cv.CvGroupPowerGrade{ CvGroupPowerGrade: group_power_cv.CvGroupPowerGrade{
Grade: grades[myGroupPower.GroupPowerId].Grade, Grade: grades[myGroupPower.GroupPowerId].Grade,
Exp: v.Exp, Exp: myGroupPowerRank.Exp,
}, },
Rank: v.Rank, Rank: 0,
} }
} }
for _, v := range rank {
if response.MyGroupPower != nil && v.GroupPowerId == response.MyGroupPower.Id {
response.MyGroupPower.Rank = v.Rank
}
response.Items = append(response.Items, group_power_cv.CvGroupPowerRankData{ response.Items = append(response.Items, group_power_cv.CvGroupPowerRankData{
CvGroupPowerBase: group_power_cv.CvGroupPowerBase{ CvGroupPowerBase: group_power_cv.CvGroupPowerBase{
Id: v.GroupPowerId, Id: v.GroupPowerId,
......
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