diff --git a/modules/caravan/api_getlist.go b/modules/caravan/api_getlist.go index b95eb636b..0bd44d6b2 100644 --- a/modules/caravan/api_getlist.go +++ b/modules/caravan/api_getlist.go @@ -24,7 +24,7 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.CaravanGetListRe return // 参数校验失败直接返回 } list, _ := this.module.modelCaravan.getCaravanList(session.GetUserId()) - endtime := utils.WeekIntervalTime() + endtime := utils.WeekIntervalTime(configure.Now().Unix()) if list.Resettime != endtime { // 初始化门票和虚拟币 this.module.ModuleUser.CleanUserMerchantmoney(session) if conf, err := this.module.configure.GetCaravanLv(list.Lv); err == nil { diff --git a/modules/entertainment/api_getlist.go b/modules/entertainment/api_getlist.go index 02a39109b..332b1cb91 100644 --- a/modules/entertainment/api_getlist.go +++ b/modules/entertainment/api_getlist.go @@ -38,7 +38,7 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.EntertainGetList update["touxiang"] = list.Touxiang // 每天投降次数清0 update["rtime"] = list.Rtime update["playtype"] = list.Playtype - _, endSeasonTime := utils.GetMonthStartEnd() + endSeasonTime := utils.GetMonthEnd(configure.Now().Unix()) if list.Etime > endSeasonTime { list.Etime = endSeasonTime update["etime"] = list.Etime diff --git a/modules/entertainment/model.go b/modules/entertainment/model.go index de967d964..a26a8b1f5 100644 --- a/modules/entertainment/model.go +++ b/modules/entertainment/model.go @@ -6,6 +6,7 @@ import ( "go_dreamfactory/lego/sys/mgo" "go_dreamfactory/modules" "go_dreamfactory/pb" + "go_dreamfactory/sys/configure" "go_dreamfactory/utils" "go.mongodb.org/mongo-driver/bson/primitive" @@ -53,7 +54,7 @@ func (this *modelComp) getEntertainmList(uid string) (result *pb.DBXXLData, err result.Uid = uid result.Reward = make(map[int32]int32) result.Card = make(map[string]int32) - _, endSeasonTime := utils.GetMonthStartEnd() + endSeasonTime := utils.GetMonthEnd(configure.Now().Unix()) result.Etime = endSeasonTime // 初始化默认获得类型为1的卡片 diff --git a/modules/guildgve/modelrank.go b/modules/guildgve/modelrank.go index 1f5440583..4262d1199 100644 --- a/modules/guildgve/modelrank.go +++ b/modules/guildgve/modelrank.go @@ -8,6 +8,7 @@ import ( "go_dreamfactory/lego/sys/redis/pipe" "go_dreamfactory/modules" "go_dreamfactory/pb" + "go_dreamfactory/sys/configure" cfg "go_dreamfactory/sys/configure/structs" "go_dreamfactory/utils" "sync" @@ -62,7 +63,7 @@ func (this *modelRank) updateRank(guilds ...*pb.DBGuildGve) (err error) { ) menbers = make([]*redis.Z, len(guilds)) for i, v := range guilds { - endtime := time.Unix(utils.WeekIntervalTime(), 0) + endtime := time.Unix(utils.WeekIntervalTime(configure.Now().Unix()), 0) start := time.Unix(v.Lastkilltime, 0) seconds := endtime.Sub(start).Seconds() Integral := float64(v.Kills)*float64(10000000000) + seconds diff --git a/modules/hero/hero_test.go b/modules/hero/hero_test.go index 2ec0ef297..c21f2aa01 100644 --- a/modules/hero/hero_test.go +++ b/modules/hero/hero_test.go @@ -188,7 +188,7 @@ func Test_Main(t *testing.T) { hero := &pb.DBHero{} value, err := strconv.Atoi("944005411") - fmt.Printf("%v,%v,%d,%v,%v", value, err, utils.WeekIntervalTime(), sz, hero) + fmt.Printf("%v,%v,%d,%v,%v", value, err, utils.WeekIntervalTime(configure.Now().Unix()), sz, hero) ids := utils.RandomNumbers(0, 10, 5) for _, v := range ids { fmt.Printf("%d", v) diff --git a/modules/jielong/api_lvlist.go b/modules/jielong/api_lvlist.go index a73093dc1..c7d408644 100644 --- a/modules/jielong/api_lvlist.go +++ b/modules/jielong/api_lvlist.go @@ -34,7 +34,7 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.JielongGetListRe } if list.Lasttime < configure.Now().Unix() { update := make(map[string]interface{}, 0) - list.Lasttime = utils.WeekIntervalTime() + list.Lasttime = utils.WeekIntervalTime(configure.Now().Unix()) list.Curwin = 0 // 本周连胜 list.Weekmax = 0 // 本周最大连胜 list.Reward = map[int32]int32{} diff --git a/modules/jielong/mode_jielong.go b/modules/jielong/mode_jielong.go index b16354934..4902dd2fa 100644 --- a/modules/jielong/mode_jielong.go +++ b/modules/jielong/mode_jielong.go @@ -6,6 +6,7 @@ import ( "go_dreamfactory/lego/sys/mgo" "go_dreamfactory/modules" "go_dreamfactory/pb" + "go_dreamfactory/sys/configure" "go_dreamfactory/utils" "go.mongodb.org/mongo-driver/bson/primitive" @@ -40,7 +41,7 @@ func (this *ModelJielong) getUserJielongData(uid string) (results *pb.DBJielongD Uid: uid, Reward: map[int32]int32{}, Gotarr: map[int32]int32{}, - Lasttime: utils.WeekIntervalTime(), + Lasttime: utils.WeekIntervalTime(configure.Now().Unix()), } err = this.Add(uid, results) } diff --git a/modules/pagoda/module.go b/modules/pagoda/module.go index 95457809e..f911ed3eb 100644 --- a/modules/pagoda/module.go +++ b/modules/pagoda/module.go @@ -235,7 +235,7 @@ func (this *Pagoda) Rpc_ModuleSeasonPagodaReward(ctx context.Context, args *pb.E func (this *Pagoda) GetSeasonData() (endSeasonTime int64) { - _, endSeasonTime = utils.GetMonthStartEnd() //+ int64((6-d)*3600*24) + endSeasonTime = utils.GetMonthEnd(configure.Now().Unix()) //+ int64((6-d)*3600*24) return endSeasonTime } diff --git a/modules/shop/api_getlist.go b/modules/shop/api_getlist.go index d36c6adc8..394089d7c 100644 --- a/modules/shop/api_getlist.go +++ b/modules/shop/api_getlist.go @@ -6,6 +6,7 @@ import ( "go_dreamfactory/pb" "go_dreamfactory/sys/configure" cfg "go_dreamfactory/sys/configure/structs" + "go_dreamfactory/utils" "time" ) @@ -31,8 +32,6 @@ func (this *apiComp) Getlist(session comm.IUserSession, req *pb.ShopGetListReq) sdata *pb.UserShopData items []*cfg.GameShopitemData goods []*pb.ShopItem - tdata time.Duration - ltime time.Duration equiconf *cfg.GameEquipData equibuyconf *cfg.GameShopBuyequiCosData leftrefnum int32 @@ -81,23 +80,6 @@ func (this *apiComp) Getlist(session comm.IUserSession, req *pb.ShopGetListReq) leftrefnum = shopconf.Rnum } - tdata = configure.Now().Sub((time.Unix(sdata.LastRefreshTime, 0))) - switch shopconf.Rtype { - case -1: //一百年不刷新 - ltime = 365 * 20 * 24 * time.Hour - case 1: - ltime = time.Hour * time.Duration(shopconf.Rtime) - break - case 2: - ltime = 24 * time.Hour * time.Duration(shopconf.Rtime) - break - case 3: - ltime = 7 * 24 * time.Hour * time.Duration(shopconf.Rtime) - break - case 4: - ltime = 30 * 7 * 24 * time.Hour * time.Duration(shopconf.Rtime) - break - } if req.IsManualRefresh && shopconf.Rnum > 0 { //可以手动刷新 isrefresh := false if refresh > 0 { // @@ -192,22 +174,26 @@ func (this *apiComp) Getlist(session comm.IUserSession, req *pb.ShopGetListReq) tasks = append(tasks, comm.GetBuriedParam(comm.Rtype105, 1)) this.module.modelShop.Change(session.GetUserId(), map[string]interface{}{"refreshnumgoldShop": shopData.RefreshnumgoldShop, "refreshtimegoldShop": shopData.RefreshtimegoldShop, "shops": shopData.Shops}) } else if !req.IsManualRefresh { - // refresh := int(this.module.privilege.GetCountByPrivilegeId(session.GetUserId(), comm.PrivilegeType2)) - isrefresh := false - // if refresh > 0 { // - // if time.Unix(shopData.RefreshtimegoldShop, 0).Day() < configure.Now().Day() { - // shopData.RefreshtimegoldShop = configure.Now().Unix() - // shopData.RefreshnumgoldShop = 0 - // } - // if int(shopData.RefreshnumgoldShop) < refresh { - // isrefresh = true - // } - // } else { - if tdata > ltime { //达到刷新时间 可以刷新商品列表 - isrefresh = true - } - // } + isrefresh := configure.Now().After((time.Unix(sdata.LastRefreshTime, 0))) if isrefresh { + //重新计算刷新时间点 + switch shopconf.Rtype { + case -1: //一百年不刷新 + sdata.LastRefreshTime = -1 + case 1: + sdata.LastRefreshTime = configure.Now().Add(time.Hour * time.Duration(shopconf.Rtime)).Unix() + break + case 2: + sdata.LastRefreshTime = utils.GetTodayZeroTime(configure.Now().Unix()) + break + case 3: + sdata.LastRefreshTime = utils.WeekIntervalTime(configure.Now().Unix()) + break + case 4: + sdata.LastRefreshTime = utils.GetMonthEnd(configure.Now().Unix()) + break + } + var _items []*cfg.GameShopitemData for _, v := range shopconf.Shopitem { if _items, err = this.module.configure.GetShopItemsConfigureByGroups(v, udata); err != nil || len(_items) == 0 { @@ -221,7 +207,6 @@ func (this *apiComp) Getlist(session comm.IUserSession, req *pb.ShopGetListReq) } items = append(items, randomGoods(_items)) } - sdata.LastRefreshTime = configure.Now().Unix() sdata.Items = make([]*pb.UserShopGood, len(items)) sdata.Preview = make(map[int32]*pb.UserShopDataEx) for i, v := range items { diff --git a/modules/stonehenge/api_getlist.go b/modules/stonehenge/api_getlist.go index 6360c8436..6f28e2ed6 100644 --- a/modules/stonehenge/api_getlist.go +++ b/modules/stonehenge/api_getlist.go @@ -50,7 +50,7 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.StonehengeGetLis update["hero"] = stone.Hero stone.Addweight = make(map[int32]int32, 0) update["addweight"] = stone.Addweight - stone.Etime = utils.WeekIntervalTime() + stone.Etime = utils.WeekIntervalTime(configure.Now().Unix()) update["etime"] = stone.Etime stone.Integral = 0 update["integral"] = stone.Integral diff --git a/modules/stonehenge/modelStonehenge.go b/modules/stonehenge/modelStonehenge.go index a3a298e14..0333c2307 100644 --- a/modules/stonehenge/modelStonehenge.go +++ b/modules/stonehenge/modelStonehenge.go @@ -7,6 +7,7 @@ import ( "go_dreamfactory/lego/sys/mgo" "go_dreamfactory/modules" "go_dreamfactory/pb" + "go_dreamfactory/sys/configure" "go_dreamfactory/utils" "sync" @@ -63,7 +64,7 @@ func (this *MStonehenge) GetStonehengeData(uid string) (info *pb.DBStonehenge, e Userbuff: make(map[int32]int32), Reward: make(map[int32]bool), Addweight: make(map[int32]int32), - Etime: utils.WeekIntervalTime(), + Etime: utils.WeekIntervalTime(configure.Now().Unix()), Hero: make(map[string]*pb.BattleRole), Talent: make(map[int32]bool), Talentproperty: make(map[string]int32), @@ -92,10 +93,10 @@ func (this *MStonehenge) reLoadStoneBoos() (err error) { this.lock.Lock() this.bossStage = this.module.configure.CheckStage() this.lock.Unlock() - if len(s.Bossstage) != len(this.bossStage) || utils.WeekIntervalTime() != s.Rtime { + if len(s.Bossstage) != len(this.bossStage) || utils.WeekIntervalTime(configure.Now().Unix()) != s.Rtime { this.module.ModuleTools.UpdateGlobalData(StoneBossKey, map[string]interface{}{ "BossStage": this.bossStage, - "rtime": utils.WeekIntervalTime(), + "rtime": utils.WeekIntervalTime(configure.Now().Unix()), }) } else { this.lock.Lock() diff --git a/modules/timer/caravanrank.go b/modules/timer/caravanrank.go index eb84e5da0..34b7e886c 100644 --- a/modules/timer/caravanrank.go +++ b/modules/timer/caravanrank.go @@ -83,7 +83,7 @@ func (this *CaravanRank) Start() (err error) { } func (this *CaravanRank) TimerSeason() { - endTime := utils.WeekIntervalTime() + endTime := utils.WeekIntervalTime(configure.Now().Unix()) this.module.Debugf("TimerSeason end: %d,cur time:%d", endTime, configure.Now().Unix()) if err := this.service.RpcCall( diff --git a/modules/user/model_sign.go b/modules/user/model_sign.go index c6331fea8..44e60bca8 100644 --- a/modules/user/model_sign.go +++ b/modules/user/model_sign.go @@ -89,7 +89,7 @@ func (this *ModelSign) UserSign(session comm.IUserSession) { lastSignTime = sign.SignTime sign.SignTime = configure.Now().Unix() - start, _ := utils.GetMonthStartEnd() + start := utils.GetMonthStart() iDay := (configure.Now().Unix() - start) / (24 * 3600) if sign.SignTime < start { // 重置 sign.SignCount = 1 diff --git a/utils/time.go b/utils/time.go index 73b7ef2aa..447b97f7c 100644 --- a/utils/time.go +++ b/utils/time.go @@ -138,17 +138,15 @@ func GetMonthStart() int64 { return _d1 } -// 获取本月的开始和结束的时间戳 -func GetMonthStartEnd() (int64, int64) { - t := configure.Now() +// 获取本月的结束的时间戳 +func GetMonthEnd(curTime int64) int64 { + t := time.Unix(curTime, 0) monthStartDay := t.AddDate(0, 0, -t.Day()+1) monthStartTime := time.Date(monthStartDay.Year(), monthStartDay.Month(), monthStartDay.Day(), 0, 0, 0, 0, t.Location()) monthEndDay := monthStartTime.AddDate(0, 1, -1) monthEndTime := time.Date(monthEndDay.Year(), monthEndDay.Month(), monthEndDay.Day(), 23, 59, 59, 0, t.Location()) - _d1 := monthStartTime.Unix() _d2 := monthEndTime.Unix() - fmt.Printf("%d,%d", _d1, _d2) - return _d1, _d2 + return _d2 } // 获取今天零点时间戳 @@ -186,8 +184,8 @@ func DiffDays(t1, t2 int64) int { return diffDays } -func WeekIntervalTime() (endTime int64) { - now := time.Now() +func WeekIntervalTime(curTime int64) (endTime int64) { + now := time.Unix(curTime, 0) offset := int(time.Monday - now.Weekday()) //周日做特殊判断 因为time.Monday = 0 if offset > 0 { diff --git a/utils/utils_test.go b/utils/utils_test.go index f2347e901..c47b11fa5 100644 --- a/utils/utils_test.go +++ b/utils/utils_test.go @@ -119,9 +119,16 @@ func TestIsSameWeek(t *testing.T) { } func TestWeekIntervalTime(t *testing.T) { - ti := utils.WeekIntervalTime() + ti := utils.WeekIntervalTime(time.Now().Unix()) format := "2006-01-02 15:04:05" formattedTime := time.Unix(ti, 0).Format(format) fmt.Println(formattedTime) } + +func TestGetZeroTime(t *testing.T) { + ti := utils.GetMonthEnd(time.Now().Unix()) + format := "2006-01-02 15:04:05" + formattedTime := time.Unix(ti, 0).Format(format) + fmt.Println(formattedTime) +}