上传代码

This commit is contained in:
liwei1dao 2023-12-28 14:08:55 +08:00
parent 583975ff70
commit 32682eb3fc
15 changed files with 52 additions and 58 deletions

View File

@ -24,7 +24,7 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.CaravanGetListRe
return // 参数校验失败直接返回 return // 参数校验失败直接返回
} }
list, _ := this.module.modelCaravan.getCaravanList(session.GetUserId()) list, _ := this.module.modelCaravan.getCaravanList(session.GetUserId())
endtime := utils.WeekIntervalTime() endtime := utils.WeekIntervalTime(configure.Now().Unix())
if list.Resettime != endtime { // 初始化门票和虚拟币 if list.Resettime != endtime { // 初始化门票和虚拟币
this.module.ModuleUser.CleanUserMerchantmoney(session) this.module.ModuleUser.CleanUserMerchantmoney(session)
if conf, err := this.module.configure.GetCaravanLv(list.Lv); err == nil { if conf, err := this.module.configure.GetCaravanLv(list.Lv); err == nil {

View File

@ -38,7 +38,7 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.EntertainGetList
update["touxiang"] = list.Touxiang // 每天投降次数清0 update["touxiang"] = list.Touxiang // 每天投降次数清0
update["rtime"] = list.Rtime update["rtime"] = list.Rtime
update["playtype"] = list.Playtype update["playtype"] = list.Playtype
_, endSeasonTime := utils.GetMonthStartEnd() endSeasonTime := utils.GetMonthEnd(configure.Now().Unix())
if list.Etime > endSeasonTime { if list.Etime > endSeasonTime {
list.Etime = endSeasonTime list.Etime = endSeasonTime
update["etime"] = list.Etime update["etime"] = list.Etime

View File

@ -6,6 +6,7 @@ import (
"go_dreamfactory/lego/sys/mgo" "go_dreamfactory/lego/sys/mgo"
"go_dreamfactory/modules" "go_dreamfactory/modules"
"go_dreamfactory/pb" "go_dreamfactory/pb"
"go_dreamfactory/sys/configure"
"go_dreamfactory/utils" "go_dreamfactory/utils"
"go.mongodb.org/mongo-driver/bson/primitive" "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.Uid = uid
result.Reward = make(map[int32]int32) result.Reward = make(map[int32]int32)
result.Card = make(map[string]int32) result.Card = make(map[string]int32)
_, endSeasonTime := utils.GetMonthStartEnd() endSeasonTime := utils.GetMonthEnd(configure.Now().Unix())
result.Etime = endSeasonTime result.Etime = endSeasonTime
// 初始化默认获得类型为1的卡片 // 初始化默认获得类型为1的卡片

View File

@ -8,6 +8,7 @@ import (
"go_dreamfactory/lego/sys/redis/pipe" "go_dreamfactory/lego/sys/redis/pipe"
"go_dreamfactory/modules" "go_dreamfactory/modules"
"go_dreamfactory/pb" "go_dreamfactory/pb"
"go_dreamfactory/sys/configure"
cfg "go_dreamfactory/sys/configure/structs" cfg "go_dreamfactory/sys/configure/structs"
"go_dreamfactory/utils" "go_dreamfactory/utils"
"sync" "sync"
@ -62,7 +63,7 @@ func (this *modelRank) updateRank(guilds ...*pb.DBGuildGve) (err error) {
) )
menbers = make([]*redis.Z, len(guilds)) menbers = make([]*redis.Z, len(guilds))
for i, v := range 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) start := time.Unix(v.Lastkilltime, 0)
seconds := endtime.Sub(start).Seconds() seconds := endtime.Sub(start).Seconds()
Integral := float64(v.Kills)*float64(10000000000) + seconds Integral := float64(v.Kills)*float64(10000000000) + seconds

View File

@ -188,7 +188,7 @@ func Test_Main(t *testing.T) {
hero := &pb.DBHero{} hero := &pb.DBHero{}
value, err := strconv.Atoi("944005411") 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) ids := utils.RandomNumbers(0, 10, 5)
for _, v := range ids { for _, v := range ids {
fmt.Printf("%d", v) fmt.Printf("%d", v)

View File

@ -34,7 +34,7 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.JielongGetListRe
} }
if list.Lasttime < configure.Now().Unix() { if list.Lasttime < configure.Now().Unix() {
update := make(map[string]interface{}, 0) update := make(map[string]interface{}, 0)
list.Lasttime = utils.WeekIntervalTime() list.Lasttime = utils.WeekIntervalTime(configure.Now().Unix())
list.Curwin = 0 // 本周连胜 list.Curwin = 0 // 本周连胜
list.Weekmax = 0 // 本周最大连胜 list.Weekmax = 0 // 本周最大连胜
list.Reward = map[int32]int32{} list.Reward = map[int32]int32{}

View File

@ -6,6 +6,7 @@ import (
"go_dreamfactory/lego/sys/mgo" "go_dreamfactory/lego/sys/mgo"
"go_dreamfactory/modules" "go_dreamfactory/modules"
"go_dreamfactory/pb" "go_dreamfactory/pb"
"go_dreamfactory/sys/configure"
"go_dreamfactory/utils" "go_dreamfactory/utils"
"go.mongodb.org/mongo-driver/bson/primitive" "go.mongodb.org/mongo-driver/bson/primitive"
@ -40,7 +41,7 @@ func (this *ModelJielong) getUserJielongData(uid string) (results *pb.DBJielongD
Uid: uid, Uid: uid,
Reward: map[int32]int32{}, Reward: map[int32]int32{},
Gotarr: map[int32]int32{}, Gotarr: map[int32]int32{},
Lasttime: utils.WeekIntervalTime(), Lasttime: utils.WeekIntervalTime(configure.Now().Unix()),
} }
err = this.Add(uid, results) err = this.Add(uid, results)
} }

View File

@ -235,7 +235,7 @@ func (this *Pagoda) Rpc_ModuleSeasonPagodaReward(ctx context.Context, args *pb.E
func (this *Pagoda) GetSeasonData() (endSeasonTime int64) { 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 return endSeasonTime
} }

View File

@ -6,6 +6,7 @@ import (
"go_dreamfactory/pb" "go_dreamfactory/pb"
"go_dreamfactory/sys/configure" "go_dreamfactory/sys/configure"
cfg "go_dreamfactory/sys/configure/structs" cfg "go_dreamfactory/sys/configure/structs"
"go_dreamfactory/utils"
"time" "time"
) )
@ -31,8 +32,6 @@ func (this *apiComp) Getlist(session comm.IUserSession, req *pb.ShopGetListReq)
sdata *pb.UserShopData sdata *pb.UserShopData
items []*cfg.GameShopitemData items []*cfg.GameShopitemData
goods []*pb.ShopItem goods []*pb.ShopItem
tdata time.Duration
ltime time.Duration
equiconf *cfg.GameEquipData equiconf *cfg.GameEquipData
equibuyconf *cfg.GameShopBuyequiCosData equibuyconf *cfg.GameShopBuyequiCosData
leftrefnum int32 leftrefnum int32
@ -81,23 +80,6 @@ func (this *apiComp) Getlist(session comm.IUserSession, req *pb.ShopGetListReq)
leftrefnum = shopconf.Rnum 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 { //可以手动刷新 if req.IsManualRefresh && shopconf.Rnum > 0 { //可以手动刷新
isrefresh := false isrefresh := false
if refresh > 0 { // 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)) 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}) this.module.modelShop.Change(session.GetUserId(), map[string]interface{}{"refreshnumgoldShop": shopData.RefreshnumgoldShop, "refreshtimegoldShop": shopData.RefreshtimegoldShop, "shops": shopData.Shops})
} else if !req.IsManualRefresh { } else if !req.IsManualRefresh {
// refresh := int(this.module.privilege.GetCountByPrivilegeId(session.GetUserId(), comm.PrivilegeType2)) isrefresh := configure.Now().After((time.Unix(sdata.LastRefreshTime, 0)))
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
}
// }
if isrefresh { 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 var _items []*cfg.GameShopitemData
for _, v := range shopconf.Shopitem { for _, v := range shopconf.Shopitem {
if _items, err = this.module.configure.GetShopItemsConfigureByGroups(v, udata); err != nil || len(_items) == 0 { 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)) items = append(items, randomGoods(_items))
} }
sdata.LastRefreshTime = configure.Now().Unix()
sdata.Items = make([]*pb.UserShopGood, len(items)) sdata.Items = make([]*pb.UserShopGood, len(items))
sdata.Preview = make(map[int32]*pb.UserShopDataEx) sdata.Preview = make(map[int32]*pb.UserShopDataEx)
for i, v := range items { for i, v := range items {

View File

@ -50,7 +50,7 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.StonehengeGetLis
update["hero"] = stone.Hero update["hero"] = stone.Hero
stone.Addweight = make(map[int32]int32, 0) stone.Addweight = make(map[int32]int32, 0)
update["addweight"] = stone.Addweight update["addweight"] = stone.Addweight
stone.Etime = utils.WeekIntervalTime() stone.Etime = utils.WeekIntervalTime(configure.Now().Unix())
update["etime"] = stone.Etime update["etime"] = stone.Etime
stone.Integral = 0 stone.Integral = 0
update["integral"] = stone.Integral update["integral"] = stone.Integral

View File

@ -7,6 +7,7 @@ import (
"go_dreamfactory/lego/sys/mgo" "go_dreamfactory/lego/sys/mgo"
"go_dreamfactory/modules" "go_dreamfactory/modules"
"go_dreamfactory/pb" "go_dreamfactory/pb"
"go_dreamfactory/sys/configure"
"go_dreamfactory/utils" "go_dreamfactory/utils"
"sync" "sync"
@ -63,7 +64,7 @@ func (this *MStonehenge) GetStonehengeData(uid string) (info *pb.DBStonehenge, e
Userbuff: make(map[int32]int32), Userbuff: make(map[int32]int32),
Reward: make(map[int32]bool), Reward: make(map[int32]bool),
Addweight: make(map[int32]int32), Addweight: make(map[int32]int32),
Etime: utils.WeekIntervalTime(), Etime: utils.WeekIntervalTime(configure.Now().Unix()),
Hero: make(map[string]*pb.BattleRole), Hero: make(map[string]*pb.BattleRole),
Talent: make(map[int32]bool), Talent: make(map[int32]bool),
Talentproperty: make(map[string]int32), Talentproperty: make(map[string]int32),
@ -92,10 +93,10 @@ func (this *MStonehenge) reLoadStoneBoos() (err error) {
this.lock.Lock() this.lock.Lock()
this.bossStage = this.module.configure.CheckStage() this.bossStage = this.module.configure.CheckStage()
this.lock.Unlock() 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{}{ this.module.ModuleTools.UpdateGlobalData(StoneBossKey, map[string]interface{}{
"BossStage": this.bossStage, "BossStage": this.bossStage,
"rtime": utils.WeekIntervalTime(), "rtime": utils.WeekIntervalTime(configure.Now().Unix()),
}) })
} else { } else {
this.lock.Lock() this.lock.Lock()

View File

@ -83,7 +83,7 @@ func (this *CaravanRank) Start() (err error) {
} }
func (this *CaravanRank) TimerSeason() { 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()) this.module.Debugf("TimerSeason end: %d,cur time:%d", endTime, configure.Now().Unix())
if err := this.service.RpcCall( if err := this.service.RpcCall(

View File

@ -89,7 +89,7 @@ func (this *ModelSign) UserSign(session comm.IUserSession) {
lastSignTime = sign.SignTime lastSignTime = sign.SignTime
sign.SignTime = configure.Now().Unix() sign.SignTime = configure.Now().Unix()
start, _ := utils.GetMonthStartEnd() start := utils.GetMonthStart()
iDay := (configure.Now().Unix() - start) / (24 * 3600) iDay := (configure.Now().Unix() - start) / (24 * 3600)
if sign.SignTime < start { // 重置 if sign.SignTime < start { // 重置
sign.SignCount = 1 sign.SignCount = 1

View File

@ -138,17 +138,15 @@ func GetMonthStart() int64 {
return _d1 return _d1
} }
// 获取本月的开始和结束的时间戳 // 获取本月的结束的时间戳
func GetMonthStartEnd() (int64, int64) { func GetMonthEnd(curTime int64) int64 {
t := configure.Now() t := time.Unix(curTime, 0)
monthStartDay := t.AddDate(0, 0, -t.Day()+1) monthStartDay := t.AddDate(0, 0, -t.Day()+1)
monthStartTime := time.Date(monthStartDay.Year(), monthStartDay.Month(), monthStartDay.Day(), 0, 0, 0, 0, t.Location()) monthStartTime := time.Date(monthStartDay.Year(), monthStartDay.Month(), monthStartDay.Day(), 0, 0, 0, 0, t.Location())
monthEndDay := monthStartTime.AddDate(0, 1, -1) monthEndDay := monthStartTime.AddDate(0, 1, -1)
monthEndTime := time.Date(monthEndDay.Year(), monthEndDay.Month(), monthEndDay.Day(), 23, 59, 59, 0, t.Location()) monthEndTime := time.Date(monthEndDay.Year(), monthEndDay.Month(), monthEndDay.Day(), 23, 59, 59, 0, t.Location())
_d1 := monthStartTime.Unix()
_d2 := monthEndTime.Unix() _d2 := monthEndTime.Unix()
fmt.Printf("%d,%d", _d1, _d2) return _d2
return _d1, _d2
} }
// 获取今天零点时间戳 // 获取今天零点时间戳
@ -186,8 +184,8 @@ func DiffDays(t1, t2 int64) int {
return diffDays return diffDays
} }
func WeekIntervalTime() (endTime int64) { func WeekIntervalTime(curTime int64) (endTime int64) {
now := time.Now() now := time.Unix(curTime, 0)
offset := int(time.Monday - now.Weekday()) offset := int(time.Monday - now.Weekday())
//周日做特殊判断 因为time.Monday = 0 //周日做特殊判断 因为time.Monday = 0
if offset > 0 { if offset > 0 {

View File

@ -119,9 +119,16 @@ func TestIsSameWeek(t *testing.T) {
} }
func TestWeekIntervalTime(t *testing.T) { func TestWeekIntervalTime(t *testing.T) {
ti := utils.WeekIntervalTime() ti := utils.WeekIntervalTime(time.Now().Unix())
format := "2006-01-02 15:04:05" format := "2006-01-02 15:04:05"
formattedTime := time.Unix(ti, 0).Format(format) formattedTime := time.Unix(ti, 0).Format(format)
fmt.Println(formattedTime) 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)
}