Commit e3429dc5 authored by chenweijian's avatar chenweijian

获取上个月开始时间

parent 97beeb3a
...@@ -40,6 +40,14 @@ type CvGroupPowerRank struct { ...@@ -40,6 +40,14 @@ type CvGroupPowerRank struct {
Items []CvGroupPowerRankData `json:"items"` // 列表 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 { type CvGroupPowerRankData struct {
CvGroupPowerBase `json:",inline"` CvGroupPowerBase `json:",inline"`
CvGroupPowerGrade `json:",inline"` CvGroupPowerGrade `json:",inline"`
......
...@@ -104,9 +104,9 @@ func GetGroupPowerMonthStar(model *domain.Model, groupPowerId, userId mysql.ID, ...@@ -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 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). 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 { Order("score desc").Offset(offset).Limit(limit).Find(&res).Error; err != nil {
model.Log.Errorf("GetGroupPowerMonthStarRank fail:%v", err) model.Log.Errorf("GetGroupPowerMonthStarRank fail:%v", err)
......
...@@ -149,8 +149,8 @@ func GetGroupPowerRankResp(model *domain.Model, beginDate, endDate string, userI ...@@ -149,8 +149,8 @@ func GetGroupPowerRankResp(model *domain.Model, beginDate, endDate string, userI
return response, nil return response, nil
} }
func GetGroupPowerStar(model *domain.Model, groupPowerId mysql.ID, _type groupPower_e.GroupPowerStarType, offset, limit int) ([]*group_power_cv.CvGroupPowerStarData, error) { 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) rank, err := groupPower_m.GetGroupPowerMonthStarRank(model, groupPowerId, _type, offset, limit, month)
if err != nil { if err != nil {
return nil, err return nil, err
} }
...@@ -201,7 +201,7 @@ func DoCalcGroupPowerMonthRankAct(model *domain.Model, calcMonth, beginDate, end ...@@ -201,7 +201,7 @@ func DoCalcGroupPowerMonthRankAct(model *domain.Model, calcMonth, beginDate, end
powerIds := make([]uint64, 0, len(response.Items)) powerIds := make([]uint64, 0, len(response.Items))
for i, v := range response.Items { for i, v := range response.Items {
powerIds = append(powerIds, v.Id) 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 { if err != nil {
return err return err
} }
......
...@@ -57,7 +57,7 @@ func GroupPowerRank(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -57,7 +57,7 @@ func GroupPowerRank(c *gin.Context) (*mycontext.MyContext, error) {
// @Tags 国家势力 // @Tags 国家势力
// @Summary 家族榜单-活动 // @Summary 家族榜单-活动
// @Success 200 {object} []group_power_cv.CvGroupPowerRank // @Success 200 {object} group_power_cv.CvGroupPowerRankMontAct
// @Router /v1/h5/groupPower/rank/month [get] // @Router /v1/h5/groupPower/rank/month [get]
func GroupPowerMonthRankAct(c *gin.Context) (*mycontext.MyContext, error) { func GroupPowerMonthRankAct(c *gin.Context) (*mycontext.MyContext, error) {
myContext := mycontext.CreateMyContext(c.Keys) myContext := mycontext.CreateMyContext(c.Keys)
...@@ -65,26 +65,50 @@ func GroupPowerMonthRankAct(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -65,26 +65,50 @@ func GroupPowerMonthRankAct(c *gin.Context) (*mycontext.MyContext, error) {
if err != nil { if err != nil {
return myContext, err return myContext, err
} }
beginDate, endDate := now.BeginningOfMonth().Format("2006-01-02"), now.EndOfMonth().Format("2006-01-02")
var model = domain.CreateModelContext(myContext) 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 { if err != nil {
return myContext, err 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 { 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 { if err != nil {
return myContext, err return response, err
} }
for i, v := range response.Items { 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 { if err != nil {
return myContext, err return response, err
} }
} }
resp.ResponseOk(c, response) return response, nil
return myContext, nil
} }
// @Tags 国家势力 // @Tags 国家势力
...@@ -176,7 +200,7 @@ func GroupPowerStar(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -176,7 +200,7 @@ func GroupPowerStar(c *gin.Context) (*mycontext.MyContext, error) {
} }
offset, limit := (param.PageIndex-1)*param.PageSize, param.PageSize offset, limit := (param.PageIndex-1)*param.PageSize, param.PageSize
var model = domain.CreateModelContext(myContext) 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 { if err != nil {
return myContext, err 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