Commit c835a8d9 authored by chenweijian's avatar chenweijian

家族月度排行活动

parent 8330b0ff
......@@ -51,6 +51,7 @@ type ActFamilyMonthRankLog struct {
RankUser int `json:"rank_user"`
UserId uint64 `json:"user_id"`
Award string `json:"award"`
Area int `json:"area"`
}
func (gpu *GroupPowerUser) Get(db *gorm.DB) ([]GroupPowerUser, error) {
......
......@@ -15,12 +15,16 @@ type GroupPowerExpRank struct {
// 获取家族经验排行榜
// param limit: 排行榜人数
func GetGroupPowerExpRank(model *domain.Model, beginDate, endDate string, limit int, gpStatus groupPower_e.GroupPowerStatus) ([]GroupPowerExpRank, error) {
func GetGroupPowerExpRank(model *domain.Model, beginDate, endDate string, limit int, gpStatus groupPower_e.GroupPowerStatus, area int) ([]GroupPowerExpRank, error) {
var res []GroupPowerExpRank
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 area > 0 {
db = db.Joins("left join group_info gi on gp.group_uid = gi.im_group_id left join res_country rs on gi.country = rs.name").
Where("rs.area = ?", area)
}
}
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)
......
......@@ -79,8 +79,9 @@ func (s *GroupPowerService) GroupPowerUserLeave(groupPowerId mysql.ID, userId my
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)
func GetGroupPowerRankResp(model *domain.Model, beginDate, endDate string, userId uint64, gpStatus groupPower_e.GroupPowerStatus,
area int) (response group_power_cv.CvGroupPowerRank, err error) {
rank, err := groupPower_m.GetGroupPowerExpRank(model, beginDate, endDate, 30, gpStatus, area)
if err != nil {
return
}
......@@ -193,45 +194,48 @@ func CalcGroupPowerMonthRankAct(model *domain.Model) error {
}
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))
areaList := []int{1, 2}
for _, area := range areaList { // 计算获奖
response, err := GetGroupPowerRankResp(model, beginDate, endDate, 0, groupPower_e.GroupPowerUserHas, area)
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)
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, area)
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)
return model.Transaction(func(model *domain.Model) error {
// log
err = groupPower_m.CreateActFamilyMonthRankLog(model, logList)
if err != nil {
model.Log.Errorf("CalcGroupPowerMonthRankAct award:%+v, err:%+v", v, err)
model.Log.Errorf("CalcGroupPowerMonthRankAct err:%+v", err)
return err
}
}
return nil
})
// 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
})
}
return nil
}
func getAwardAndLogList(model *domain.Model, powerIds []uint64, items []group_power_cv.CvGroupPowerRankData, calcMonth string) ([]*award_tx.UserAward, []*groupPower_m.ActFamilyMonthRankLog, error) {
func getAwardAndLogList(model *domain.Model, powerIds []uint64, items []group_power_cv.CvGroupPowerRankData, calcMonth string, area int) ([]*award_tx.UserAward, []*groupPower_m.ActFamilyMonthRankLog, error) {
// 读奖励配置
confMap := CalcGroupPowerMonthRankActConf()
awardList := make([]*award_tx.UserAward, 0, 50) // 奖励
......@@ -273,6 +277,7 @@ func getAwardAndLogList(model *domain.Model, powerIds []uint64, items []group_po
RankUser: 0,
UserId: ownerId,
Award: string(oAwardJ),
Area: area,
})
awardList = append(awardList, &award_tx.UserAward{
UserId: ownerId,
......@@ -304,6 +309,7 @@ func getAwardAndLogList(model *domain.Model, powerIds []uint64, items []group_po
RankUser: uRank,
UserId: m.User.Id,
Award: string(mAwardJ),
Area: area,
})
awardList = append(awardList, &award_tx.UserAward{
UserId: m.User.Id,
......
......@@ -12,4 +12,6 @@ CREATE TABLE `act_family_month_rank_log` (
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
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='家族月度排行发奖日志';
ALTER TABLE hilo.act_family_month_rank_log ADD area TINYINT DEFAULT 0 NOT NULL COMMENT '区域1.阿语区2.非阿语区';
......@@ -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, 0)
response, err := group_power_s.GetGroupPowerRankResp(model, beginDate, endDate, userId, 0, 0)
if err != nil {
return myContext, err
}
......@@ -66,9 +66,15 @@ func GroupPowerMonthRankAct(c *gin.Context) (*mycontext.MyContext, error) {
return myContext, err
}
var model = domain.CreateModelContext(myContext)
// 国家区域
_, area, err := user_m.GetUserCountryArea(model, userId)
if err != nil {
model.Log.Errorf("GroupPowerMonthRankAct 获取国家资源错误 userId:%d, err:%v", userId, err)
return myContext, err
}
// 这个月
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))
response, err := GroupPowerMonthRankActByMonth(model, userId, beginDate, endDate, time.Now().Format(utils.COMPACT_MONTH_FORMAT), area)
if err != nil {
return myContext, err
}
......@@ -76,7 +82,7 @@ func GroupPowerMonthRankAct(c *gin.Context) (*mycontext.MyContext, error) {
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))
responseLast, err := GroupPowerMonthRankActByMonth(model, userId, beginDateLast, endDateLast, lastMonthStart.Format(utils.COMPACT_MONTH_FORMAT), area)
if err != nil {
return myContext, err
}
......@@ -92,8 +98,8 @@ func GroupPowerMonthRankAct(c *gin.Context) (*mycontext.MyContext, error) {
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)
func GroupPowerMonthRankActByMonth(model *domain.Model, userId uint64, beginDate, endDate, month string, area int) (response group_power_cv.CvGroupPowerRank, err error) {
response, err = group_power_s.GetGroupPowerRankResp(model, beginDate, endDate, userId, groupPower_e.GroupPowerUserHas, area)
if err != nil {
return response, err
}
......@@ -133,7 +139,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, 0)
rank, err := groupPower_m.GetGroupPowerExpRank(model, beginDate, endDate, 3, 0, 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