From b9dde787aa4b03ada4d1546f2ee104e9be644cbe Mon Sep 17 00:00:00 2001 From: chenweijian <820961417@qq.com> Date: Mon, 1 May 2023 15:00:43 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=B6=E6=97=8F=E6=8E=92=E8=A1=8C=E5=A5=96?= =?UTF-8?q?=E5=8A=B1=E8=A1=A5=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cron/cron.go | 1 + cron/group_cron/group_power_month_act.go | 13 ++ domain/service/group_power_s/group_power.go | 168 +++++++++++++++++++- test/group_power_test.go | 11 +- 4 files changed, 187 insertions(+), 6 deletions(-) diff --git a/cron/cron.go b/cron/cron.go index 181ba0b..4f1b9bf 100644 --- a/cron/cron.go +++ b/cron/cron.go @@ -16,4 +16,5 @@ func Init() { mic_cron.OnMicCheck() // 检查上麦 group_cron.GroupPowerExpClear() // 清理家族经验/等级 group_cron.GroupPowerMonthRankAct() + group_cron.BufaGroupPowerMonthRankAct() } diff --git a/cron/group_cron/group_power_month_act.go b/cron/group_cron/group_power_month_act.go index 82edee6..0156e6b 100644 --- a/cron/group_cron/group_power_month_act.go +++ b/cron/group_cron/group_power_month_act.go @@ -20,3 +20,16 @@ func GroupPowerMonthRankAct() { c.Start() } + +func BufaGroupPowerMonthRankAct() { + c := cron.New() + spec := "0 4 15 1 * ?" + _ = c.AddFunc(spec, func() { + var model = domain.CreateModelNil() + if err := group_power_s.BufaCalcGroupPowerMonthRankAct(model); err != nil { + model.Log.Errorf("BufaGroupPowerMonthRankAct fail:%v", err) + } + }) + + c.Start() +} diff --git a/domain/service/group_power_s/group_power.go b/domain/service/group_power_s/group_power.go index 9e4bcd3..1770221 100644 --- a/domain/service/group_power_s/group_power.go +++ b/domain/service/group_power_s/group_power.go @@ -16,11 +16,11 @@ import ( "hilo-group/domain/cache/user_c" "hilo-group/domain/event/group_power_ev" "hilo-group/domain/model/groupPower_m" - "time" "hilo-group/domain/model/msg_m" "hilo-group/domain/model/noble_m" "hilo-group/domain/model/user_m" "hilo-group/myerr/bizerr" + "time" ) type GroupPowerService struct { @@ -193,11 +193,21 @@ func CalcGroupPowerMonthRankAct(model *domain.Model) error { lastDayTime := time.Now().AddDate(0, 0, -1) _now := now.New(lastDayTime) calcMonth := _now.BeginningOfMonth().Format(utils.MONTH_FORMAT) + starDate := _now.BeginningOfMonth().Format(utils.COMPACT_MONTH_FORMAT) + beginDate, endDate := _now.BeginningOfMonth().Format("2006-01-02"), _now.EndOfMonth().Format("2006-01-02") + return DoCalcGroupPowerMonthRankAct(model, calcMonth, beginDate, endDate, starDate) +} + +func BufaCalcGroupPowerMonthRankAct(model *domain.Model) error { + lastDayTime := time.Now().AddDate(0, 0, -1) + _now := now.New(lastDayTime) + calcMonth := _now.BeginningOfMonth().Format(utils.MONTH_FORMAT) + starDate := _now.BeginningOfMonth().Format(utils.COMPACT_MONTH_FORMAT) beginDate, endDate := _now.BeginningOfMonth().Format("2006-01-02"), _now.EndOfMonth().Format("2006-01-02") - return DoCalcGroupPowerMonthRankAct(model, calcMonth, beginDate, endDate) + return BufaDoCalcGroupPowerMonthRankAct(model, calcMonth, beginDate, endDate, starDate) } -func DoCalcGroupPowerMonthRankAct(model *domain.Model, calcMonth, beginDate, endDate string) error { +func DoCalcGroupPowerMonthRankAct(model *domain.Model, calcMonth, beginDate, endDate, starDate string) error { areaList := []int{1, 2} for _, area := range areaList { // 计算获奖 model := domain.CreateModelContext(model.MyContext) @@ -208,7 +218,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, time.Now().Format(utils.COMPACT_MONTH_FORMAT)) + response.Items[i].StarList, err = GetGroupPowerStar(model, v.Id, groupPower_e.GroupPowerStarTypeFamous, 0, 10, starDate) if err != nil { return err } @@ -244,10 +254,65 @@ func DoCalcGroupPowerMonthRankAct(model *domain.Model, calcMonth, beginDate, end return nil } +func BufaDoCalcGroupPowerMonthRankAct(model *domain.Model, calcMonth, beginDate, endDate, starDate string) error { + 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 + } + 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, starDate) + if err != nil { + return err + } + } + // 奖励、日志 + awardList, logList, err := bufaGetAwardAndLogList(model, powerIds, response.Items, calcMonth, area) + if err != nil { + return err + } + + //if area == 1 { + // for _, v := range logList { + // if v.RankUser == 1 { + // model.Log.Infof("bufajiangli award:%+v", v) + // } + // } + //} + + err = model.Transaction(func(model *domain.Model) error { + // log + err = groupPower_m.CreateActFamilyMonthRankLog(model, logList) + if err != nil { + 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 +} + 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) // 奖励 + awardList := make([]*award_tx.UserAward, 0, 120) // 奖励 ownerMap, err := groupPower_m.GetPowerOwnerMap(model, powerIds) if err != nil { return nil, nil, err @@ -334,6 +399,99 @@ func getAwardAndLogList(model *domain.Model, powerIds []uint64, items []group_po return awardList, logList, nil } +func bufaGetAwardAndLogList(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, 120) // 奖励 + 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), + // Area: area, + //}) + //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 { + if m.User.Id == 5343751 || m.User.Id == 1180791 { + continue + } + 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), + Area: area, + }) + 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 diff --git a/test/group_power_test.go b/test/group_power_test.go index a659a3a..54c80d0 100644 --- a/test/group_power_test.go +++ b/test/group_power_test.go @@ -38,5 +38,14 @@ func TestDoCalcGroupPowerMonthRankAct(t *testing.T) { _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) + _ = group_power_s.DoCalcGroupPowerMonthRankAct(domain.CreateModelNil(), calcMonth, beginDate, endDate, "") +} + +func TestDoCalcGroupPowerMonthRankActbufa(t *testing.T) { + lastDayTime := time.Now().AddDate(0, 0, -1) + _now := now.New(lastDayTime) + calcMonth := _now.BeginningOfMonth().Format(utils.MONTH_FORMAT) + starDate := _now.BeginningOfMonth().Format(utils.COMPACT_MONTH_FORMAT) + beginDate, endDate := _now.BeginningOfMonth().Format("2006-01-02"), _now.EndOfMonth().Format("2006-01-02") + _ = group_power_s.BufaDoCalcGroupPowerMonthRankAct(domain.CreateModelNil(), calcMonth, beginDate, endDate, starDate) } -- 2.22.0