From f7dbcd42bc9dd48fc9a47c733da078afff293cbb Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Wed, 12 Jul 2023 09:46:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9A=E6=97=B6=E5=99=A8=20=E6=AF=8F?= =?UTF-8?q?=E5=A4=A90=E7=82=B9=20=E6=A0=A1=E9=AA=8C=E6=98=AF=E5=90=A6=20?= =?UTF-8?q?=E6=9C=89=E7=BB=93=E7=AE=97=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/caravan/module.go | 4 ++-- modules/timer/caravanrank.go | 40 ++++++++++++++++++------------------ utils/time.go | 16 +++++++++++++++ 3 files changed, 38 insertions(+), 22 deletions(-) diff --git a/modules/caravan/module.go b/modules/caravan/module.go index 9e1db69ad..0800972bf 100644 --- a/modules/caravan/module.go +++ b/modules/caravan/module.go @@ -368,7 +368,7 @@ func (this *Caravan) CheckOverweight(data *pb.DBCaravan) (b bool) { var weight int32 for k, v := range data.Items { - if d, err := this.configure.GetCaravanGoods(k); err != nil { + if d, err := this.configure.GetCaravanGoods(k); err == nil { weight += d.Weight * v.Count if weight > data.Baglimit { return true @@ -376,7 +376,7 @@ func (this *Caravan) CheckOverweight(data *pb.DBCaravan) (b bool) { } } - return true + return false } // 获得利润判断是否能提升商队等级 diff --git a/modules/timer/caravanrank.go b/modules/timer/caravanrank.go index b08f6eb8a..f8dc61faa 100644 --- a/modules/timer/caravanrank.go +++ b/modules/timer/caravanrank.go @@ -2,7 +2,6 @@ package timer import ( "context" - "fmt" "go_dreamfactory/comm" "go_dreamfactory/lego/base" "go_dreamfactory/lego/core" @@ -15,7 +14,7 @@ import ( "go_dreamfactory/sys/configure" cfg "go_dreamfactory/sys/configure/structs" "go_dreamfactory/sys/db" - "time" + "go_dreamfactory/utils" ) // 此组件废弃 @@ -77,28 +76,29 @@ func (this *CaravanRank) Start() (err error) { if configure.Now().Unix() < opentime { // 开服时间是未来可能存在问题 return } - //获取时分秒 - currentTime := time.Unix(opentime, 0) - m := currentTime.Minute() - s := currentTime.Second() - h := currentTime.Hour() - day := this.GetGlobalConf().BusinessRewardday - cronStr := fmt.Sprintf("%d %d %d */%d * ?", m, s, h, day) // - this.module.Debugf("cron start: %s", cronStr) - cron.AddFunc(cronStr, this.TimerSeason) + _, end := utils.WeekIntervalTime(0) + this.module.Errorf("%v", end) + + cron.AddFunc("0,0,0,*,*,*", this.TimerSeason) + this.module.Debugf("cron start: %s", configure.Now().Unix()) //this.TimerSeason() return } func (this *CaravanRank) TimerSeason() { - this.module.Debugf("TimerSeason start: %d", configure.Now().Unix()) - if err := this.service.RpcCall( - context.Background(), - comm.Service_Worker, - string(comm.Rpc_ModuleCaravanSettlement), - pb.EmptyReq{}, - nil, - ); err != nil { - this.module.Errorln(err) + _, end := utils.WeekIntervalTime(0) + this.module.Debugf("TimerSeason end: %d,cur time:%d", end, configure.Now().Unix()) + if configure.Now().Unix()-end < 5 { + this.module.Debugf("TimerSeason start: %d", configure.Now().Unix()) + if err := this.service.RpcCall( + context.Background(), + comm.Service_Worker, + string(comm.Rpc_ModuleCaravanSettlement), + pb.EmptyReq{}, + nil, + ); err != nil { + this.module.Errorln(err) + } } + } diff --git a/utils/time.go b/utils/time.go index e06c19155..f213c1060 100644 --- a/utils/time.go +++ b/utils/time.go @@ -164,3 +164,19 @@ func DiffDays(t1, t2 int64) int { } return diffDays } + +func WeekIntervalTime(week int) (startTime, endTime int64) { + now := time.Now() + offset := int(time.Monday - now.Weekday()) + //周日做特殊判断 因为time.Monday = 0 + if offset > 0 { + offset = -6 + } + + year, month, day := now.Date() + thisWeek := time.Date(year, month, day, 0, 0, 0, 0, time.Local) + startTime = thisWeek.AddDate(0, 0, offset+7*week).Unix() + endTime = thisWeek.AddDate(0, 0, offset+6+7*week).Unix() + + return startTime, endTime +}