118 lines
3.2 KiB
Go
118 lines
3.2 KiB
Go
package main
|
|
|
|
import (
|
|
"mongo.games.com/game/model"
|
|
"mongo.games.com/goserver/core/basic"
|
|
"mongo.games.com/goserver/core/logger"
|
|
"mongo.games.com/goserver/core/task"
|
|
"time"
|
|
|
|
"mongo.games.com/goserver/core/module"
|
|
)
|
|
|
|
type AwardLogManager struct {
|
|
BaseClockSinker
|
|
AwardMap map[int32]map[int32]int32 //key1:1话费 2实物 key2 itemId value:数量
|
|
AnnouncerLog map[int32][]model.AnnouncerLog //key:1话费 2实物
|
|
}
|
|
|
|
var AwardLogMgr = &AwardLogManager{}
|
|
|
|
func (this *AwardLogManager) ModuleName() string {
|
|
return "AwardLogManager"
|
|
}
|
|
|
|
func (this *AwardLogManager) GetAwardLog(typeId int32) map[int32]int32 {
|
|
return this.AwardMap[typeId]
|
|
}
|
|
|
|
func (this *AwardLogManager) GetAnnouncerLog(typeId int32) []model.AnnouncerLog {
|
|
log := this.AnnouncerLog[typeId]
|
|
if len(log) > 100 {
|
|
return log[len(log)-100:]
|
|
}
|
|
return this.AnnouncerLog[typeId]
|
|
}
|
|
|
|
// 已兑换数据
|
|
func (this *AwardLogManager) UpdateAwardLog(itemId, num, itemType int32) {
|
|
typeID := int32(1)
|
|
if itemType == 16 {
|
|
typeID = 2
|
|
}
|
|
if this.AwardMap == nil {
|
|
this.AwardMap = make(map[int32]map[int32]int32)
|
|
}
|
|
if this.AwardMap[typeID] == nil {
|
|
this.AwardMap[typeID] = make(map[int32]int32)
|
|
}
|
|
|
|
this.AwardMap[typeID][itemId] += num
|
|
logger.Logger.Trace("更新已兑换数据数据 this.AwardMap = ", this.AwardMap)
|
|
this.Save()
|
|
}
|
|
|
|
// 实时播报数据
|
|
func (this *AwardLogManager) UpdateAnnouncerLog(data model.AnnouncerLog) {
|
|
if this.AnnouncerLog == nil {
|
|
this.AnnouncerLog = make(map[int32][]model.AnnouncerLog)
|
|
}
|
|
this.AnnouncerLog[data.TypeId] = append(this.AnnouncerLog[data.TypeId], data)
|
|
logger.Logger.Trace("更新实时播报数据 this.AnnouncerLog = ", this.AnnouncerLog)
|
|
err := model.InsertAnnouncerLog(&data)
|
|
if err != nil {
|
|
logger.Logger.Error("UpdateAnnouncerLog InsertAnnouncerLog err :", err)
|
|
}
|
|
}
|
|
|
|
func (this *AwardLogManager) Init() {
|
|
//初始化数据
|
|
this.AwardMap = make(map[int32]map[int32]int32)
|
|
this.AnnouncerLog = make(map[int32][]model.AnnouncerLog)
|
|
AwardMap, err := model.FetchAwardLog("1")
|
|
if err == nil {
|
|
for _, log := range AwardMap {
|
|
this.AwardMap = log.AwardMap
|
|
}
|
|
}
|
|
AnnouncerLog, err := model.FetchAnnouncerLog("1")
|
|
if err == nil {
|
|
for _, log := range AnnouncerLog {
|
|
this.AnnouncerLog[log.TypeId] = append(this.AnnouncerLog[log.TypeId], log)
|
|
}
|
|
}
|
|
logger.Logger.Tracef("AwardLog初始化数据 this.AwardMap = %v,this.AnnouncerLog = %v", this.AwardMap, this.AnnouncerLog)
|
|
}
|
|
|
|
func (this *AwardLogManager) Update() {
|
|
}
|
|
|
|
func (this *AwardLogManager) Shutdown() {
|
|
this.Save()
|
|
}
|
|
|
|
func (this *AwardLogManager) OnHourTimer() {
|
|
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
|
|
awardData := &model.AwardLog{}
|
|
awardData.Platform = "1"
|
|
awardData.AwardMap = this.AwardMap
|
|
awardData.Ts = time.Now()
|
|
model.UpsertAwardLog("1", awardData)
|
|
return nil
|
|
}), task.CompleteNotifyWrapper(func(data interface{}, tt task.Task) {
|
|
})).StartByFixExecutor("AwardLogTask")
|
|
}
|
|
|
|
func (this *AwardLogManager) Save() {
|
|
awardData := &model.AwardLog{}
|
|
awardData.Platform = "1"
|
|
awardData.AwardMap = this.AwardMap
|
|
awardData.Ts = time.Now()
|
|
model.UpsertAwardLog("1", awardData)
|
|
}
|
|
|
|
func init() {
|
|
module.RegisteModule(AwardLogMgr, time.Minute*3, 0)
|
|
ClockMgrSington.RegisteSinker(AwardLogMgr)
|
|
}
|