定时器 每天0点 校验是否 有结算任务
This commit is contained in:
parent
7424b5c57b
commit
f7dbcd42bc
@ -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
|
||||
}
|
||||
|
||||
// 获得利润判断是否能提升商队等级
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user