From e3429dc5c75d73e9dd67bf6372372a49260228d7 Mon Sep 17 00:00:00 2001 From: chenweijian <820961417@qq.com> Date: Thu, 20 Apr 2023 12:02:20 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8E=B7=E5=8F=96=E4=B8=8A=E4=B8=AA=E6=9C=88?= =?UTF-8?q?=E5=BC=80=E5=A7=8B=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cv/group_power_cv/group_rank.go | 8 ++++ domain/model/groupPower_m/group_star.go | 4 +- domain/service/group_power_s/group_power.go | 6 +-- route/group_power_r/group_rank.go | 44 ++++++++++++++++----- 4 files changed, 47 insertions(+), 15 deletions(-) diff --git a/cv/group_power_cv/group_rank.go b/cv/group_power_cv/group_rank.go index 0a3bef1..d4f089f 100644 --- a/cv/group_power_cv/group_rank.go +++ b/cv/group_power_cv/group_rank.go @@ -40,6 +40,14 @@ type CvGroupPowerRank struct { Items []CvGroupPowerRankData `json:"items"` // 列表 } +// 家族月度排行活动榜单 +type CvGroupPowerRankMontAct struct { + MyGroupPower *CvGroupPowerRankData `json:"myGroupPower,omitempty"` // 我的家族排名 + Items []CvGroupPowerRankData `json:"items"` // 列表 + MyGroupPowerLast *CvGroupPowerRankData `json:"myGroupPowerLast"` // 我的家族排名(上月) + ItemsLast []CvGroupPowerRankData `json:"itemsLast"` // 列表(上月) +} + type CvGroupPowerRankData struct { CvGroupPowerBase `json:",inline"` CvGroupPowerGrade `json:",inline"` diff --git a/domain/model/groupPower_m/group_star.go b/domain/model/groupPower_m/group_star.go index 1929399..ee52a2b 100644 --- a/domain/model/groupPower_m/group_star.go +++ b/domain/model/groupPower_m/group_star.go @@ -104,9 +104,9 @@ func GetGroupPowerMonthStar(model *domain.Model, groupPowerId, userId mysql.ID, } // 获取家族之星排行 -func GetGroupPowerMonthStarRank(model *domain.Model, groupPowerId mysql.ID, _type groupPower_e.GroupPowerStarType, offset, limit int) ([]*GroupPowerMonthStar, error) { +func GetGroupPowerMonthStarRank(model *domain.Model, groupPowerId mysql.ID, _type groupPower_e.GroupPowerStarType, offset, limit int, month string) ([]*GroupPowerMonthStar, error) { var res []*GroupPowerMonthStar - month := time.Now().Format("200601") + //month := time.Now().Format("200601") if err := model.DB().Model(GroupPowerMonthStar{}).Where("month = ? AND group_power_id = ? AND `type` = ?", month, groupPowerId, _type). Order("score desc").Offset(offset).Limit(limit).Find(&res).Error; err != nil { model.Log.Errorf("GetGroupPowerMonthStarRank fail:%v", err) diff --git a/domain/service/group_power_s/group_power.go b/domain/service/group_power_s/group_power.go index 74809d2..f44aa10 100644 --- a/domain/service/group_power_s/group_power.go +++ b/domain/service/group_power_s/group_power.go @@ -149,8 +149,8 @@ func GetGroupPowerRankResp(model *domain.Model, beginDate, endDate string, userI return response, nil } -func GetGroupPowerStar(model *domain.Model, groupPowerId mysql.ID, _type groupPower_e.GroupPowerStarType, offset, limit int) ([]*group_power_cv.CvGroupPowerStarData, error) { - rank, err := groupPower_m.GetGroupPowerMonthStarRank(model, groupPowerId, _type, offset, limit) +func GetGroupPowerStar(model *domain.Model, groupPowerId mysql.ID, _type groupPower_e.GroupPowerStarType, offset, limit int, month string) ([]*group_power_cv.CvGroupPowerStarData, error) { + rank, err := groupPower_m.GetGroupPowerMonthStarRank(model, groupPowerId, _type, offset, limit, month) if err != nil { return nil, err } @@ -201,7 +201,7 @@ func DoCalcGroupPowerMonthRankAct(model *domain.Model, calcMonth, beginDate, end powerIds := make([]uint64, 0, len(response.Items)) for i, v := range response.Items { powerIds = append(powerIds, v.Id) - response.Items[i].StarList, err = GetGroupPowerStar(model, v.Id, groupPower_e.GroupPowerStarTypeFamous, 0, 10) + response.Items[i].StarList, err = GetGroupPowerStar(model, v.Id, groupPower_e.GroupPowerStarTypeFamous, 0, 10, time.Now().Format(utils.COMPACT_MONTH_FORMAT)) if err != nil { return err } diff --git a/route/group_power_r/group_rank.go b/route/group_power_r/group_rank.go index ff41b55..a601e78 100644 --- a/route/group_power_r/group_rank.go +++ b/route/group_power_r/group_rank.go @@ -57,7 +57,7 @@ func GroupPowerRank(c *gin.Context) (*mycontext.MyContext, error) { // @Tags 国家势力 // @Summary 家族榜单-活动 -// @Success 200 {object} []group_power_cv.CvGroupPowerRank +// @Success 200 {object} group_power_cv.CvGroupPowerRankMontAct // @Router /v1/h5/groupPower/rank/month [get] func GroupPowerMonthRankAct(c *gin.Context) (*mycontext.MyContext, error) { myContext := mycontext.CreateMyContext(c.Keys) @@ -65,26 +65,50 @@ func GroupPowerMonthRankAct(c *gin.Context) (*mycontext.MyContext, error) { if err != nil { return myContext, err } - 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) + // 这个月 + beginDate, endDate := now.BeginningOfMonth().Format(utils.DATE_FORMAT), now.EndOfMonth().Format(utils.DATE_FORMAT) + response, err := GroupPowerMonthRankActByMonth(model, userId, beginDate, endDate, time.Now().Format(utils.COMPACT_MONTH_FORMAT)) + if err != nil { + return myContext, err + } + // 上月 + lastMonthStart := utils.GetLastMonthStart(time.Now()) + lastTime := now.New(lastMonthStart) + beginDateLast, endDateLast := lastTime.BeginningOfMonth().Format(utils.DATE_FORMAT), lastTime.EndOfMonth().Format(utils.DATE_FORMAT) + responseLast, err := GroupPowerMonthRankActByMonth(model, userId, beginDateLast, endDateLast, lastMonthStart.Format(utils.COMPACT_MONTH_FORMAT)) if err != nil { return myContext, err } + + res := &group_power_cv.CvGroupPowerRankMontAct{ + MyGroupPower: response.MyGroupPower, + Items: response.Items, + MyGroupPowerLast: responseLast.MyGroupPower, + ItemsLast: responseLast.Items, + } + resp.ResponseOk(c, res) + return myContext, nil +} + +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) + if err != nil { + return response, err + } if response.MyGroupPower != nil { - response.MyGroupPower.StarList, err = group_power_s.GetGroupPowerStar(model, response.MyGroupPower.Id, groupPower_e.GroupPowerStarTypeFamous, 0, 10) + response.MyGroupPower.StarList, err = group_power_s.GetGroupPowerStar(model, response.MyGroupPower.Id, groupPower_e.GroupPowerStarTypeFamous, 0, 10, month) } if err != nil { - return myContext, err + return response, err } for i, v := range response.Items { - response.Items[i].StarList, err = group_power_s.GetGroupPowerStar(model, v.Id, groupPower_e.GroupPowerStarTypeFamous, 0, 10) + response.Items[i].StarList, err = group_power_s.GetGroupPowerStar(model, v.Id, groupPower_e.GroupPowerStarTypeFamous, 0, 10, month) if err != nil { - return myContext, err + return response, err } } - resp.ResponseOk(c, response) - return myContext, nil + return response, nil } // @Tags 国家势力 @@ -176,7 +200,7 @@ func GroupPowerStar(c *gin.Context) (*mycontext.MyContext, error) { } offset, limit := (param.PageIndex-1)*param.PageSize, param.PageSize var model = domain.CreateModelContext(myContext) - response, err := group_power_s.GetGroupPowerStar(model, param.GroupPowerId, param.Type, offset, limit) + response, err := group_power_s.GetGroupPowerStar(model, param.GroupPowerId, param.Type, offset, limit, time.Now().Format(utils.COMPACT_MONTH_FORMAT)) if err != nil { return myContext, err } -- 2.22.0