Commit 569fbe66 authored by chenweijian's avatar chenweijian

月度排行发奖

parent 67817eb2
......@@ -4,6 +4,7 @@ import (
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/resource/mysql"
"gorm.io/gorm"
"hilo-group/_const/enum/groupPower_e"
)
type GroupPowerExpRank struct {
......@@ -14,10 +15,14 @@ type GroupPowerExpRank struct {
// 获取家族经验排行榜
// param limit: 排行榜人数
func GetGroupPowerExpRank(model *domain.Model, beginDate, endDate string, limit int) ([]GroupPowerExpRank, error) {
func GetGroupPowerExpRank(model *domain.Model, beginDate, endDate string, limit int, gpStatus groupPower_e.GroupPowerStatus) ([]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").Order("exp DESC").Limit(limit).Find(&res).Error; err != nil {
db := model.DB().Table("group_power_day_exp gpd").Select("gpd.group_power_id,SUM(gpd.exp) as exp").
Where("gpd.date BETWEEN ? AND ?", beginDate, endDate)
if gpStatus > 0 {
db = db.Joins("left join group_power gp on gpd.group_power_id = gp.id").Where("status = ?", gpStatus)
}
if err := db.Group("gpd.group_power_id").Order("exp DESC").Limit(limit).Find(&res).Error; err != nil {
model.Log.Errorf("GetGroupPowerExpRank fail:%v", err)
return res, err
}
......
......@@ -79,8 +79,8 @@ func (s *GroupPowerService) GroupPowerUserLeave(groupPowerId mysql.ID, userId my
return remainSeconds, err
}
func GetGroupPowerRankResp(model *domain.Model, beginDate, endDate string, userId uint64) (response group_power_cv.CvGroupPowerRank, err error) {
rank, err := groupPower_m.GetGroupPowerExpRank(model, beginDate, endDate, 30)
func GetGroupPowerRankResp(model *domain.Model, beginDate, endDate string, userId uint64, gpStatus groupPower_e.GroupPowerStatus) (response group_power_cv.CvGroupPowerRank, err error) {
rank, err := groupPower_m.GetGroupPowerExpRank(model, beginDate, endDate, 30, gpStatus)
if err != nil {
return
}
......@@ -194,7 +194,7 @@ func CalcGroupPowerMonthRankAct(model *domain.Model) error {
func DoCalcGroupPowerMonthRankAct(model *domain.Model, calcMonth, beginDate, endDate string) error {
// 计算获奖
response, err := GetGroupPowerRankResp(model, beginDate, endDate, 0)
response, err := GetGroupPowerRankResp(model, beginDate, endDate, 0, groupPower_e.GroupPowerUserHas)
if err != nil {
return err
}
......
......@@ -47,7 +47,7 @@ func GroupPowerRank(c *gin.Context) (*mycontext.MyContext, error) {
beginDate, endDate = now.BeginningOfMonth().Format("2006-01-02"), now.EndOfMonth().Format("2006-01-02")
}
var model = domain.CreateModelContext(myContext)
response, err := group_power_s.GetGroupPowerRankResp(model, beginDate, endDate, userId)
response, err := group_power_s.GetGroupPowerRankResp(model, beginDate, endDate, userId, 0)
if err != nil {
return myContext, err
}
......@@ -93,7 +93,7 @@ func GroupPowerMonthRankAct(c *gin.Context) (*mycontext.MyContext, error) {
}
func GroupPowerMonthRankActByMonth(model *domain.Model, userId uint64, beginDate, endDate, month string) (response group_power_cv.CvGroupPowerRank, err error) {
response, err = group_power_s.GetGroupPowerRankResp(model, beginDate, endDate, userId)
response, err = group_power_s.GetGroupPowerRankResp(model, beginDate, endDate, userId, groupPower_e.GroupPowerUserHas)
if err != nil {
return response, err
}
......@@ -133,7 +133,7 @@ func GroupPowerRankTop(c *gin.Context) (*mycontext.MyContext, error) {
beginDate, endDate = now.BeginningOfMonth().Format("2006-01-02"), now.EndOfMonth().Format("2006-01-02")
}
var model = domain.CreateModelContext(myContext)
rank, err := groupPower_m.GetGroupPowerExpRank(model, beginDate, endDate, 3)
rank, err := groupPower_m.GetGroupPowerExpRank(model, beginDate, endDate, 3, 0)
if err != nil {
return myContext, err
}
......
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