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 +}