game_sync/ranksrv/rank/invitelog.go

63 lines
1.7 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/rand"
"mongo.games.com/game/common"
"mongo.games.com/game/model"
"mongo.games.com/game/ranksrv/com"
"mongo.games.com/goserver/core/basic"
"mongo.games.com/goserver/core/logger"
"mongo.games.com/goserver/core/task"
"time"
)
var InviteLogMgrInstance = com.NewListMgr[*model.InviteInfo](
func() int64 {
return 5 // 缓存5秒
},
func(platform string, index int32) ([]*model.InviteInfo, error) {
logger.Logger.Tracef("load invitelog platform:%s snid:%d", platform, index)
ret, err := model.GetInviteList(platform, index)
if err != nil {
logger.Logger.Errorf("load invitelog err:%s", err.Error())
return nil, err
}
return ret, nil
})
func RobotRandon() {
//机器人随机
robotNum := rand.Intn(21) + 10
accounts := model.GetRobotAccounts(200)
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
for i := 0; i < robotNum; i++ {
//随机机器人
snId := accounts[rand.Intn(len(accounts))].SnId
data := model.RankInvite{
Platform: "1",
SnId: snId,
Num: int64(rand.Intn(4) + 2),
Score: int64(rand.Intn(901) + 100),
Ts: time.Now().Unix(),
Week: common.GetWeekStartTs(time.Now().Unix()),
}
err := model.SaveRankInvite(&data)
if err != nil {
logger.Logger.Error("SaveRankInviteTask error %v", err)
return err
}
}
return nil
}), task.CompleteNotifyWrapper(func(data interface{}, tt task.Task) {
InviteLogMgrInstance.UpdateCache("1", 2)
})).StartByFixExecutor("SaveRankInviteTask")
}
func init() {
common.RegisterClockFunc(&common.ClockFunc{
OnDayTimerFunc: func() {
RobotRandon()
logger.Logger.Trace("邀请积分排行榜0点机器人随机完成")
},
})
}