Commit 711aa915 authored by chenweijian's avatar chenweijian

家族月度活动

parent 8dcec28d
...@@ -15,4 +15,5 @@ func Init() { ...@@ -15,4 +15,5 @@ func Init() {
gift_cron.GiftRemark() // 礼物消息补偿 gift_cron.GiftRemark() // 礼物消息补偿
mic_cron.OnMicCheck() // 检查上麦 mic_cron.OnMicCheck() // 检查上麦
group_cron.GroupPowerExpClear() // 清理家族经验/等级 group_cron.GroupPowerExpClear() // 清理家族经验/等级
group_cron.GroupPowerMonthRankAct()
} }
package group_cron
import (
"git.hilo.cn/hilo-common/domain"
"github.com/robfig/cron"
"hilo-group/domain/service/group_power_s"
)
// 家族贡献月度排行榜发奖
func GroupPowerMonthRankAct() {
c := cron.New()
// 每月1号0:01结算发奖
spec := "0 1 0 1 * ?"
_ = c.AddFunc(spec, func() {
var model = domain.CreateModelNil()
if err := group_power_s.CalcGroupPowerMonthRankAct(model); err != nil {
model.Log.Errorf("GroupPowerMonthRankAct fail:%v", err)
}
})
c.Start()
}
...@@ -40,10 +40,20 @@ type CvGroupPowerRank struct { ...@@ -40,10 +40,20 @@ type CvGroupPowerRank struct {
Items []CvGroupPowerRankData `json:"items"` // 列表 Items []CvGroupPowerRankData `json:"items"` // 列表
} }
// 家族月度排行活动榜单
type CvGroupPowerRankMontAct struct {
MyGroupPower *CvGroupPowerRankData `json:"myGroupPower"` // 我的家族排名
Items []CvGroupPowerRankData `json:"items"` // 列表
MyGroupPowerLast *CvGroupPowerRankData `json:"myGroupPowerLast"` // 我的家族排名(上月)
ItemsLast []CvGroupPowerRankData `json:"itemsLast"` // 列表(上月)
LeftSecond int64 `json:"leftSecond"` // 活动倒计时
}
type CvGroupPowerRankData struct { type CvGroupPowerRankData struct {
CvGroupPowerBase `json:",inline"` CvGroupPowerBase `json:",inline"`
CvGroupPowerGrade `json:",inline"` CvGroupPowerGrade `json:",inline"`
Rank int `json:"rank"` // 排名 Rank int `json:"rank"` // 排名
StarList []*CvGroupPowerStarData `json:"starList"` // 家族贡献top10
} }
// 家族之星 // 家族之星
...@@ -108,6 +118,6 @@ var GroupPowerGradePrivilegeNum = map[groupPower_e.GroupPowerGrade][]CvPrivilege ...@@ -108,6 +118,6 @@ var GroupPowerGradePrivilegeNum = map[groupPower_e.GroupPowerGrade][]CvPrivilege
{groupPower_e.GroupPowerPrivilegeNameplate, 1, "https://image.whoisamy.shop/hilo/resource/family/nameplate_yellow.png"}, {groupPower_e.GroupPowerPrivilegeNameplate, 1, "https://image.whoisamy.shop/hilo/resource/family/nameplate_yellow.png"},
{groupPower_e.GroupPowerPrivilegeMedal, 1, "https://image.whoisamy.shop/hilo/resource/family/privilege_yellow.png"}, {groupPower_e.GroupPowerPrivilegeMedal, 1, "https://image.whoisamy.shop/hilo/resource/family/privilege_yellow.png"},
{groupPower_e.GroupPowerPrivilegeNameplateEdit, 1, "https://image.whoisamy.shop/hilo/resource/family/edit_yellow.png"}, {groupPower_e.GroupPowerPrivilegeNameplateEdit, 1, "https://image.whoisamy.shop/hilo/resource/family/edit_yellow.png"},
{groupPower_e.GroupPowerPrivilegeNameplateHeadwear, 1,"https://image.whoisamy.shop/hilo/resource/family/headwear_yellow.png"}, {groupPower_e.GroupPowerPrivilegeNameplateHeadwear, 1, "https://image.whoisamy.shop/hilo/resource/family/headwear_yellow.png"},
}, },
} }
...@@ -43,6 +43,16 @@ type GroupPowerUser struct { ...@@ -43,6 +43,16 @@ type GroupPowerUser struct {
Role groupPower_e.GroupPowerUserRole Role groupPower_e.GroupPowerUserRole
} }
type ActFamilyMonthRankLog struct {
Id uint64 `json:"id"`
Period string `json:"period"`
FamilyId uint64 `json:"family_id"`
RankFamily int `json:"rank_family"`
RankUser int `json:"rank_user"`
UserId uint64 `json:"user_id"`
Award string `json:"award"`
}
func (gpu *GroupPowerUser) Get(db *gorm.DB) ([]GroupPowerUser, error) { func (gpu *GroupPowerUser) Get(db *gorm.DB) ([]GroupPowerUser, error) {
rows := make([]GroupPowerUser, 0) rows := make([]GroupPowerUser, 0)
err := db.Where(gpu).Find(&rows).Error err := db.Where(gpu).Find(&rows).Error
...@@ -64,6 +74,22 @@ func GetPowerOwner(db *gorm.DB, powerId uint64) (uint64, error) { ...@@ -64,6 +74,22 @@ func GetPowerOwner(db *gorm.DB, powerId uint64) (uint64, error) {
return records[0].UserId, nil return records[0].UserId, nil
} }
func GetPowerOwnerMap(model *domain.Model, powerIds []uint64) (map[uint64]uint64, error) {
rows := make([]GroupPowerUser, 0)
if len(powerIds) > 0 {
if err := model.DB().Model(&GroupPowerUser{}).
Where("group_power_id IN ? and role = ?", powerIds, groupPower_e.GroupPowerUserRoleMgr).
Find(&rows).Error; err != nil {
return nil, err
}
}
result := make(map[uint64]uint64, 0)
for _, i := range rows {
result[i.GroupPowerId] = i.UserId
}
return result, nil
}
func GetMyPowerId(db *gorm.DB, userId uint64) (uint64, error) { func GetMyPowerId(db *gorm.DB, userId uint64) (uint64, error) {
gpu := GroupPowerUser{UserId: userId, Role: groupPower_e.GroupPowerUserRoleMgr} gpu := GroupPowerUser{UserId: userId, Role: groupPower_e.GroupPowerUserRoleMgr}
records, err := gpu.Get(db) records, err := gpu.Get(db)
...@@ -707,3 +733,7 @@ func BatchGetGroupPowerUser(model *domain.Model, userIds []mysql.ID) (map[mysql. ...@@ -707,3 +733,7 @@ func BatchGetGroupPowerUser(model *domain.Model, userIds []mysql.ID) (map[mysql.
} }
return res, nil return res, nil
} }
func CreateActFamilyMonthRankLog(model *domain.Model, list []*ActFamilyMonthRankLog) error {
return model.DB().CreateInBatches(&list, 50).Error
}
...@@ -4,6 +4,7 @@ import ( ...@@ -4,6 +4,7 @@ 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" "gorm.io/gorm"
"hilo-group/_const/enum/groupPower_e"
) )
type GroupPowerExpRank struct { type GroupPowerExpRank struct {
...@@ -14,10 +15,14 @@ type GroupPowerExpRank struct { ...@@ -14,10 +15,14 @@ type GroupPowerExpRank struct {
// 获取家族经验排行榜 // 获取家族经验排行榜
// param limit: 排行榜人数 // 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 var res []GroupPowerExpRank
if err := model.DB().Table("group_power_day_exp").Select("group_power_id,SUM(exp) as exp"). db := model.DB().Table("group_power_day_exp gpd").Select("gpd.group_power_id,SUM(gpd.exp) as exp").
Where("date BETWEEN ? AND ?", beginDate, endDate).Group("group_power_id").Order("exp DESC").Limit(limit).Find(&res).Error; err != nil { 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) model.Log.Errorf("GetGroupPowerExpRank fail:%v", err)
return res, err return res, err
} }
......
...@@ -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)
......
package group_power_s package group_power_s
import ( import (
"encoding/json"
"git.hilo.cn/hilo-common/_const/enum/diamond_e"
"git.hilo.cn/hilo-common/domain" "git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/mycontext" "git.hilo.cn/hilo-common/mycontext"
"git.hilo.cn/hilo-common/resource/mysql" "git.hilo.cn/hilo-common/resource/mysql"
"git.hilo.cn/hilo-common/txop/award_tx"
"git.hilo.cn/hilo-common/utils"
"github.com/jinzhu/now"
"hilo-group/_const/enum/groupPower_e"
"hilo-group/_const/enum/msg_e"
"hilo-group/cv/group_power_cv"
"hilo-group/cv/user_cv"
"hilo-group/domain/event/group_power_ev" "hilo-group/domain/event/group_power_ev"
"hilo-group/domain/model/groupPower_m" "hilo-group/domain/model/groupPower_m"
"hilo-group/domain/model/user_m"
"hilo-group/myerr/bizerr"
"time"
) )
type GroupPowerService struct { type GroupPowerService struct {
...@@ -66,3 +78,278 @@ func (s *GroupPowerService) GroupPowerUserLeave(groupPowerId mysql.ID, userId my ...@@ -66,3 +78,278 @@ func (s *GroupPowerService) GroupPowerUserLeave(groupPowerId mysql.ID, userId my
}) })
return remainSeconds, err return remainSeconds, err
} }
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
}
var ids []mysql.ID
for _, g := range rank {
ids = append(ids, g.GroupPowerId)
}
var myGroupPower *groupPower_m.GroupPowerUser
if userId > 0 {
myGroupPower, err = groupPower_m.GetGroupPowerUserOrNil(model, userId)
if err != nil {
return
}
}
if myGroupPower != nil {
ids = append(ids, myGroupPower.GroupPowerId)
}
grades, err := groupPower_m.MGetGroupPowerGrade(model, ids)
if err != nil {
return
}
groupPowers, err := groupPower_m.MGetGroupPowerInfoMap(model, ids)
if err != nil {
return
}
if myGroupPower != nil {
myGroupPowerRank, err := groupPower_m.GetMyGroupPowerExpRank(model, beginDate, endDate, myGroupPower.GroupPowerId)
if err != nil {
return response, 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 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{
Id: v.GroupPowerId,
Icon: groupPowers[v.GroupPowerId].Icon,
Name: groupPowers[v.GroupPowerId].Name,
Nameplate: groupPowers[v.GroupPowerId].Nameplate,
},
CvGroupPowerGrade: group_power_cv.CvGroupPowerGrade{
Grade: grades[v.GroupPowerId].Grade,
Exp: v.Exp,
},
Rank: v.Rank,
})
}
if response.MyGroupPower != nil && response.MyGroupPower.Rank == 0 {
response.MyGroupPower.Rank = 31 // 客户端统一显示30+
}
return response, nil
}
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
}
//var response []group_power_cv.CvGroupPowerStarData
response := make([]*group_power_cv.CvGroupPowerStarData, 0)
var userIds []mysql.ID
for _, row := range rank {
userIds = append(userIds, row.UserId)
}
users, err := user_m.GetUserMapByIds(model, userIds)
for _, row := range rank {
user := users[row.UserId]
score := row.Score
if _type == groupPower_e.GroupPowerStarTypeActive {
score = score / 60
}
if score <= 0 {
continue
}
response = append(response, &group_power_cv.CvGroupPowerStarData{
User: user_cv.CvUserTiny{
Id: user.ID,
ExternalId: user.ExternalId,
Code: user.Code,
Nick: user.Nick,
Avatar: user.Avatar,
},
Score: score,
})
}
return response, nil
}
func CalcGroupPowerMonthRankAct(model *domain.Model) error {
lastDayTime := time.Now().AddDate(0, 0, -1)
_now := now.New(lastDayTime)
calcMonth := _now.BeginningOfMonth().Format(utils.MONTH_FORMAT)
beginDate, endDate := _now.BeginningOfMonth().Format("2006-01-02"), _now.EndOfMonth().Format("2006-01-02")
return DoCalcGroupPowerMonthRankAct(model, calcMonth, beginDate, endDate)
}
func DoCalcGroupPowerMonthRankAct(model *domain.Model, calcMonth, beginDate, endDate string) error {
// 计算获奖
response, err := GetGroupPowerRankResp(model, beginDate, endDate, 0, groupPower_e.GroupPowerUserHas)
if err != nil {
return err
}
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, time.Now().Format(utils.COMPACT_MONTH_FORMAT))
if err != nil {
return err
}
}
// 奖励、日志
awardList, logList, err := getAwardAndLogList(model, powerIds, response.Items, calcMonth)
if err != nil {
return err
}
return model.Transaction(func(model *domain.Model) error {
// log
err = groupPower_m.CreateActFamilyMonthRankLog(model, logList)
if err != nil {
model.Log.Errorf("CalcGroupPowerMonthRankAct err:%+v", err)
return err
}
// award
for _, v := range awardList {
err = award_tx.SendUserAward(model, v, diamond_e.GeneralActivity, msg_e.MgrSendDiamondProperty)
if err != nil {
model.Log.Errorf("CalcGroupPowerMonthRankAct award:%+v, err:%+v", v, err)
return err
}
}
return nil
})
}
func getAwardAndLogList(model *domain.Model, powerIds []uint64, items []group_power_cv.CvGroupPowerRankData, calcMonth string) ([]*award_tx.UserAward, []*groupPower_m.ActFamilyMonthRankLog, error) {
// 读奖励配置
confMap := CalcGroupPowerMonthRankActConf()
awardList := make([]*award_tx.UserAward, 0, 50) // 奖励
ownerMap, err := groupPower_m.GetPowerOwnerMap(model, powerIds)
if err != nil {
return nil, nil, err
}
// log list
logList := make([]*groupPower_m.ActFamilyMonthRankLog, 0, 50)
for _, v := range items {
teamRank := 0
if v.Rank >= 1 && v.Rank <= 3 {
teamRank = v.Rank
} else if v.Rank >= 4 && v.Rank <= 10 {
teamRank = 4
} else {
break
}
ownerId, ok := ownerMap[v.Id]
if !ok || ownerId <= 0 {
model.Log.Errorf("CalcGroupPowerMonthRankAct 获取势力主错误 familyId:%d", v.Id)
return nil, nil, bizerr.InvalidParameter
}
uRankConfMap, tCOk := confMap[teamRank]
if !tCOk {
break
}
// 家族长奖励
oAward, aOk := uRankConfMap[0]
if !aOk {
model.Log.Errorf("CalcGroupPowerMonthRankAct 配置错误:%v", confMap)
return nil, nil, bizerr.InvalidParameter
}
oAwardJ, _ := json.Marshal(oAward)
logList = append(logList, &groupPower_m.ActFamilyMonthRankLog{
Period: calcMonth,
FamilyId: v.Id,
RankFamily: v.Rank,
RankUser: 0,
UserId: ownerId,
Award: string(oAwardJ),
})
awardList = append(awardList, &award_tx.UserAward{
UserId: ownerId,
MedalId: oAward.MedalId,
MedalDuration: oAward.MedalDay,
Diamond: oAward.Diamond,
NobleLevel: oAward.Noble,
NobleDuration: oAward.NobleDay,
HeaddressId: oAward.HeaddressId,
HeaddressDuration: oAward.HeaddressDay})
// 家族成员奖励
for i, m := range v.StarList {
uRank := i + 1
confIdx := 9
if uRank >= 1 && uRank <= 3 {
confIdx = 1
} else if uRank >= 4 && uRank <= 10 {
confIdx = 4
}
mAward, aOk := uRankConfMap[confIdx]
if !aOk {
break
}
mAwardJ, _ := json.Marshal(mAward)
logList = append(logList, &groupPower_m.ActFamilyMonthRankLog{
Period: calcMonth,
FamilyId: v.Id,
RankFamily: v.Rank,
RankUser: uRank,
UserId: m.User.Id,
Award: string(mAwardJ),
})
awardList = append(awardList, &award_tx.UserAward{
UserId: m.User.Id,
MedalId: mAward.MedalId,
MedalDuration: mAward.MedalDay,
Diamond: mAward.Diamond,
NobleLevel: mAward.Noble,
NobleDuration: mAward.NobleDay,
HeaddressId: mAward.HeaddressId,
HeaddressDuration: mAward.HeaddressDay})
}
}
return awardList, logList, nil
}
// 奖励配置
type awardConf struct {
MedalId uint64
MedalDay uint32
Diamond uint32
Noble uint32
NobleDay uint32
HeaddressId uint64
HeaddressDay int
}
func CalcGroupPowerMonthRankActConf() map[int]map[int]*awardConf {
return map[int]map[int]*awardConf{
1: {
0: {MedalId: 5211, MedalDay: 30, Diamond: 320000, Noble: 5, NobleDay: 15},
1: {MedalId: 5251, MedalDay: 30, Diamond: 120000, Noble: 5, NobleDay: 7, HeaddressId: 2121, HeaddressDay: 30},
4: {HeaddressId: 2121, HeaddressDay: 30},
},
2: {
0: {MedalId: 5221, MedalDay: 30, Diamond: 220000, Noble: 4, NobleDay: 15},
1: {MedalId: 5261, MedalDay: 30, Diamond: 100000, Noble: 4, NobleDay: 7, HeaddressId: 2131, HeaddressDay: 30},
4: {HeaddressId: 2131, HeaddressDay: 30},
},
3: {
0: {MedalId: 5231, MedalDay: 30, Diamond: 120000, Noble: 5, NobleDay: 5},
1: {MedalId: 5271, MedalDay: 30, Diamond: 70000, HeaddressId: 2141, HeaddressDay: 30},
4: {HeaddressId: 2141, HeaddressDay: 30},
},
4: {
0: {MedalId: 5241, MedalDay: 30},
1: {MedalId: 5281, MedalDay: 30, HeaddressId: 2151, HeaddressDay: 30},
},
}
}
CREATE TABLE `act_family_month_rank_log` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id',
`period` varchar(20) NOT NULL DEFAULT '' COMMENT '月份',
`family_id` bigint unsigned NOT NULL COMMENT '家族id',
`rank_family` int unsigned NOT NULL DEFAULT '0' COMMENT '家族排名',
`rank_user` int unsigned NOT NULL DEFAULT '0' COMMENT '用户在家族中的家族排名',
`user_id` bigint unsigned NOT NULL COMMENT 'id',
`award` varchar(500) NOT NULL DEFAULT '' COMMENT '获得的奖励',
`created_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
UNIQUE KEY `period` (`period`,`family_id`,`rank_user`),
KEY `user_idx` (`user_id`) USING BTREE,
KEY `created_time` (`created_time`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='家族月度排行发奖日志';
\ No newline at end of file
...@@ -12,6 +12,7 @@ import ( ...@@ -12,6 +12,7 @@ import (
"hilo-group/cv/user_cv" "hilo-group/cv/user_cv"
"hilo-group/domain/model/groupPower_m" "hilo-group/domain/model/groupPower_m"
"hilo-group/domain/model/user_m" "hilo-group/domain/model/user_m"
"hilo-group/domain/service/group_power_s"
"hilo-group/myerr/bizerr" "hilo-group/myerr/bizerr"
"hilo-group/req" "hilo-group/req"
"hilo-group/resp" "hilo-group/resp"
...@@ -46,72 +47,69 @@ func GroupPowerRank(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -46,72 +47,69 @@ func GroupPowerRank(c *gin.Context) (*mycontext.MyContext, error) {
beginDate, endDate = now.BeginningOfMonth().Format("2006-01-02"), now.EndOfMonth().Format("2006-01-02") beginDate, endDate = now.BeginningOfMonth().Format("2006-01-02"), now.EndOfMonth().Format("2006-01-02")
} }
var model = domain.CreateModelContext(myContext) var model = domain.CreateModelContext(myContext)
rank, err := groupPower_m.GetGroupPowerExpRank(model, beginDate, endDate, 30) response, err := group_power_s.GetGroupPowerRankResp(model, beginDate, endDate, userId, 0)
if err != nil { if err != nil {
return myContext, err return myContext, err
} }
var ids []mysql.ID resp.ResponseOk(c, response)
for _, g := range rank { return myContext, nil
ids = append(ids, g.GroupPowerId) }
}
response := group_power_cv.CvGroupPowerRank{} // @Tags 国家势力
myGroupPower, err := groupPower_m.GetGroupPowerUserOrNil(model, userId) // @Summary 家族榜单-活动
// @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)
userId, err := req.GetUserId(c)
if err != nil { if err != nil {
return myContext, err return myContext, err
} }
if myGroupPower != nil { var model = domain.CreateModelContext(myContext)
ids = append(ids, myGroupPower.GroupPowerId) // 这个月
} beginDate, endDate := now.BeginningOfMonth().Format(utils.DATE_FORMAT), now.EndOfMonth().Format(utils.DATE_FORMAT)
grades, err := groupPower_m.MGetGroupPowerGrade(model, ids) response, err := GroupPowerMonthRankActByMonth(model, userId, beginDate, endDate, time.Now().Format(utils.COMPACT_MONTH_FORMAT))
if err != nil { if err != nil {
return myContext, err return myContext, err
} }
groupPowers, err := groupPower_m.MGetGroupPowerInfoMap(model, ids) // 上月
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
} }
if myGroupPower != nil {
myGroupPowerRank, err := groupPower_m.GetMyGroupPowerExpRank(model, beginDate, endDate, myGroupPower.GroupPowerId) res := &group_power_cv.CvGroupPowerRankMontAct{
MyGroupPower: response.MyGroupPower,
Items: response.Items,
MyGroupPowerLast: responseLast.MyGroupPower,
ItemsLast: responseLast.Items,
LeftSecond: now.EndOfMonth().Unix() - time.Now().Unix(),
}
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, groupPower_e.GroupPowerUserHas)
if err != nil { if err != nil {
return myContext, err return response, 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,
} }
if response.MyGroupPower != nil {
response.MyGroupPower.StarList, err = group_power_s.GetGroupPowerStar(model, response.MyGroupPower.Id, groupPower_e.GroupPowerStarTypeFamous, 0, 10, month)
} }
for _, v := range rank { if err != nil {
if response.MyGroupPower != nil && v.GroupPowerId == response.MyGroupPower.Id { return response, err
response.MyGroupPower.Rank = v.Rank
} }
response.Items = append(response.Items, group_power_cv.CvGroupPowerRankData{ for i, v := range response.Items {
CvGroupPowerBase: group_power_cv.CvGroupPowerBase{ response.Items[i].StarList, err = group_power_s.GetGroupPowerStar(model, v.Id, groupPower_e.GroupPowerStarTypeFamous, 0, 10, month)
Id: v.GroupPowerId, if err != nil {
Icon: groupPowers[v.GroupPowerId].Icon, return response, err
Name: groupPowers[v.GroupPowerId].Name,
Nameplate: groupPowers[v.GroupPowerId].Nameplate,
},
CvGroupPowerGrade: group_power_cv.CvGroupPowerGrade{
Grade: grades[v.GroupPowerId].Grade,
Exp: v.Exp,
},
Rank: v.Rank,
})
} }
if response.MyGroupPower != nil && response.MyGroupPower.Rank == 0 {
response.MyGroupPower.Rank = 31 // 客户端统一显示30+
} }
resp.ResponseOk(c, response) return response, nil
return myContext, nil
} }
// @Tags 国家势力 // @Tags 国家势力
...@@ -135,7 +133,7 @@ func GroupPowerRankTop(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -135,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") beginDate, endDate = now.BeginningOfMonth().Format("2006-01-02"), now.EndOfMonth().Format("2006-01-02")
} }
var model = domain.CreateModelContext(myContext) 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 { if err != nil {
return myContext, err return myContext, err
} }
...@@ -201,38 +199,12 @@ func GroupPowerStar(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -201,38 +199,12 @@ func GroupPowerStar(c *gin.Context) (*mycontext.MyContext, error) {
if param.PageSize <= 0 { if param.PageSize <= 0 {
param.PageSize = 30 param.PageSize = 30
} }
var model = domain.CreateModelContext(myContext)
offset, limit := (param.PageIndex-1)*param.PageSize, param.PageSize offset, limit := (param.PageIndex-1)*param.PageSize, param.PageSize
rank, err := groupPower_m.GetGroupPowerMonthStarRank(model, param.GroupPowerId, param.Type, offset, limit) var model = domain.CreateModelContext(myContext)
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
} }
var response []group_power_cv.CvGroupPowerStarData
var userIds []mysql.ID
for _, row := range rank {
userIds = append(userIds, row.UserId)
}
users, err := user_m.GetUserMapByIds(model, userIds)
for _, row := range rank {
user := users[row.UserId]
score := row.Score
if param.Type == groupPower_e.GroupPowerStarTypeActive {
score = score / 60
}
if score <= 0 {
continue
}
response = append(response, group_power_cv.CvGroupPowerStarData{
User: user_cv.CvUserTiny{
Id: user.ID,
ExternalId: user.ExternalId,
Code: user.Code,
Nick: user.Nick,
Avatar: user.Avatar,
},
Score: score,
})
}
resp.ResponsePageBaseOk(c, response, 0, false) resp.ResponsePageBaseOk(c, response, 0, false)
return myContext, nil return myContext, nil
} }
......
...@@ -146,6 +146,7 @@ func InitRouter() *gin.Engine { ...@@ -146,6 +146,7 @@ func InitRouter() *gin.Engine {
h5GroupPower := v1.Group("/h5/groupPower") h5GroupPower := v1.Group("/h5/groupPower")
{ {
h5GroupPower.GET("/grade/detail", wrapper(group_power_r.GroupPowerGradeDetail)) h5GroupPower.GET("/grade/detail", wrapper(group_power_r.GroupPowerGradeDetail))
h5GroupPower.GET("/rank/month", wrapper(group_power_r.GroupPowerMonthRankAct))
} }
charge := v1.Group("/charge") charge := v1.Group("/charge")
......
...@@ -3,9 +3,13 @@ package test ...@@ -3,9 +3,13 @@ package test
import ( import (
"fmt" "fmt"
"git.hilo.cn/hilo-common/domain" "git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/utils"
"github.com/jinzhu/now"
"hilo-group/domain/model/groupPower_m" "hilo-group/domain/model/groupPower_m"
"hilo-group/domain/model/group_m" "hilo-group/domain/model/group_m"
"hilo-group/domain/service/group_power_s"
"testing" "testing"
"time"
) )
func TestGetAllGroupPowerOwner(t *testing.T) { func TestGetAllGroupPowerOwner(t *testing.T) {
...@@ -23,3 +27,11 @@ func TestIsUseTRTC(t *testing.T) { ...@@ -23,3 +27,11 @@ func TestIsUseTRTC(t *testing.T) {
fmt.Println("true--------------") fmt.Println("true--------------")
} }
} }
func TestDoCalcGroupPowerMonthRankAct(t *testing.T) {
lastDayTime := time.Now().AddDate(0, 0, -1)
_now := now.New(lastDayTime)
calcMonth := _now.BeginningOfMonth().Format(utils.MONTH_FORMAT)
beginDate, endDate := _now.BeginningOfMonth().Format("2006-01-02"), _now.EndOfMonth().Format("2006-01-02")
_ = group_power_s.DoCalcGroupPowerMonthRankAct(domain.CreateModelNil(), calcMonth, beginDate, endDate)
}
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