From 124073a198f364b8065d6ee76f7b1bfa098b660b Mon Sep 17 00:00:00 2001 From: chenweijian <820961417@qq.com> Date: Tue, 25 Apr 2023 10:05:52 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=B6=E6=97=8F=E6=9C=88=E5=BA=A6=E6=8E=92?= =?UTF-8?q?=E8=A1=8C=E6=B4=BB=E5=8A=A8=E5=88=86=E5=8C=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- domain/model/groupPower_m/groupPower.go | 1 + domain/model/groupPower_m/group_rank.go | 8 ++- domain/service/group_power_s/group_power.go | 69 ++++++++++++--------- mysql/group_power_month_act.sql | 4 +- route/group_power_r/group_rank.go | 38 ++++++++++-- 5 files changed, 82 insertions(+), 38 deletions(-) diff --git a/domain/model/groupPower_m/groupPower.go b/domain/model/groupPower_m/groupPower.go index d78decb..86aab07 100644 --- a/domain/model/groupPower_m/groupPower.go +++ b/domain/model/groupPower_m/groupPower.go @@ -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) { diff --git a/domain/model/groupPower_m/group_rank.go b/domain/model/groupPower_m/group_rank.go index 2185357..00aa8da 100644 --- a/domain/model/groupPower_m/group_rank.go +++ b/domain/model/groupPower_m/group_rank.go @@ -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) + db = db.Joins("left join group_power gp on gpd.group_power_id = gp.id").Where("gp.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) diff --git a/domain/service/group_power_s/group_power.go b/domain/service/group_power_s/group_power.go index fc8f7f3..42e2d4e 100644 --- a/domain/service/group_power_s/group_power.go +++ b/domain/service/group_power_s/group_power.go @@ -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,53 @@ 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 { // 计算获奖 + model := domain.CreateModelContext(model.MyContext) + 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) + + err = 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 area:%d, err:%+v", area, 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 + }) + if err != nil { + model.Log.Errorf("CalcGroupPowerMonthRankAct area:%d, err:%+v", area, 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 +282,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 +314,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, diff --git a/mysql/group_power_month_act.sql b/mysql/group_power_month_act.sql index 3722131..531c5a4 100644 --- a/mysql/group_power_month_act.sql +++ b/mysql/group_power_month_act.sql @@ -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.非阿语区'; diff --git a/route/group_power_r/group_rank.go b/route/group_power_r/group_rank.go index 555b98e..d431b3e 100644 --- a/route/group_power_r/group_rank.go +++ b/route/group_power_r/group_rank.go @@ -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,35 @@ func GroupPowerMonthRankAct(c *gin.Context) (*mycontext.MyContext, error) { return myContext, err } var model = domain.CreateModelContext(myContext) + // 国家区域 + var area int + // 我的家族 + myGroupPower, err := groupPower_m.GetGroupPowerUserOrNil(model, userId) + if err != nil { + return myContext, err + } + if myGroupPower != nil && myGroupPower.GroupPowerId > 0 { + //获取势力主 + mgrUserId, err := groupPower_m.GetGroupPowerMgr(model, myGroupPower.GroupPowerId) + if err != nil { + return myContext, err + } + _, area, err = user_m.GetUserCountryArea(model, mgrUserId) + if err != nil { + model.Log.Errorf("GroupPowerMonthRankAct 获取国家资源错误 userId:%d, err:%v", userId, err) + return myContext, err + } + } + if area == 0 { + _, 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 +102,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 +118,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 +159,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 } -- 2.22.0