game_sync/ranksrv/rank/wincoin.go

70 lines
1.6 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package rank
import (
"math"
"time"
"mongo.games.com/goserver/core/logger"
"mongo.games.com/goserver/core/module"
"mongo.games.com/game/model"
"mongo.games.com/game/ranksrv/com"
)
var WinCoinMgrInstance = com.NewListMgr[*model.WinCoinInfo](
func() int64 {
return math.MaxInt32
},
func(platform string, index int32) ([]*model.WinCoinInfo, error) {
// 每天21点刷新获取前一天的排行
startTs, endTs := StartEndTs()
logger.Logger.Tracef("load wincoin platform:%s startTs:%v endTs:%v", platform, startTs, endTs)
ret, err := model.FindWinCoinListTienlen(&model.FindWinCoinListArgs{
Platform: platform,
StartTs: startTs,
EndTs: endTs,
})
return ret.List, err
})
func StartEndTs() (startTs int64, endTs int64) {
now := time.Now()
year, month, day := now.Date()
lastTs := time.Date(year, month, day, model.GameParamData.WinCoinUpdateTime, 0, 0, 0, now.Location())
if now.Before(lastTs) {
lastTs = lastTs.AddDate(0, 0, -1)
}
endTs = lastTs.Unix()
return endTs - 24*int64(time.Hour.Seconds()), endTs
}
type WinCoinMgr struct {
}
func (w *WinCoinMgr) ModuleName() string {
return "WinCoinMgr"
}
func (w *WinCoinMgr) Init() {
for k := range com.PlatformConfigSingleton.Platforms {
WinCoinMgrInstance.UpdateCache(k, 0)
}
}
func (w *WinCoinMgr) Update() {
h := time.Now().Hour()
if h == model.GameParamData.WinCoinUpdateTime {
for k := range com.PlatformConfigSingleton.Platforms {
WinCoinMgrInstance.UpdateCache(k, 0)
}
}
}
func (w *WinCoinMgr) Shutdown() {
module.UnregisteModule(w)
}
func init() {
module.RegisteModule(new(WinCoinMgr), time.Hour, 0)
}