抽奖活动日志

This commit is contained in:
sk 2024-10-30 16:16:58 +08:00
parent 995a9e010a
commit 505b0f01ef
3 changed files with 17 additions and 11 deletions

View File

@ -41,8 +41,6 @@ func init() {
if err = svc.InsertLotteryLogs(log.Platform, log); err != nil {
logger.Logger.Errorf("InsertLotteryLogs error: %v", err)
}
mq.Write(&model.LotteryLog{Platform: log.Platform}, mq.RankLotteryLog)
return
},
})

View File

@ -69,7 +69,8 @@ func GetLotteryLogs(plt string, count int) (ret []*model.LotteryLog, err error)
if clog == nil {
return nil, LotteryLogDBErr
}
err = clog.Find(bson.M{"ts": bson.M{"$lt": time.Now().Unix()}}).Sort("-ts").Limit(count).All(&ret)
now := time.Now().Unix()
err = clog.Find(bson.M{"ts": bson.M{"$lt": now}}).Sort("-ts").Limit(count).All(&ret)
if err != nil && !errors.Is(err, mgo.ErrNotFound) {
return nil, err
}

View File

@ -104,6 +104,7 @@ func (l *LotteryData) Reset() {
l.CostCard = 0
l.RobotCodeCount = 0
l.PlayerNum = 0
logger.Logger.Tracef("LotteryData Reset: %v", l.CId)
}
// GetCode 获取抽奖码
@ -143,8 +144,8 @@ func (l *LotteryData) GetRemainCode() int {
}
// 发奖
func (l *LotteryData) sendAward() {
if l.isDone {
func (l *LotteryData) sendAward(must bool) {
if l.isDone || !must {
return
}
@ -153,6 +154,7 @@ func (l *LotteryData) sendAward() {
return
}
l.IsSend = true
mq.Write(&model.LotteryLog{Platform: l.Platform}, mq.RankLotteryLog)
var lotteryAward []*welfare.PropInfo
for _, v := range l.Reward {
@ -218,6 +220,7 @@ func (l *LotteryData) Done() {
return
}
l.isDone = true
logger.Logger.Tracef("LotteryData Done1: cid:%v wincode:%v snid:%v", l.CId, l.WinCode, l.SnId)
now := time.Now()
if l.EndTs <= 0 || l.EndTs >= now.Unix() || l.SnId > 0 || now.Unix()-l.EndTs > 5*60 {
@ -415,11 +418,12 @@ func (l *LotteryData) Done() {
Ts: l.WinTs,
}
mq.Write(lotteryLog)
logger.Logger.Tracef("LotteryData 抽奖中奖记录: %+v", *lotteryLog)
logger.Logger.Tracef("LotteryData 抽奖中奖记录: %+v %p", *lotteryLog, l)
logger.Logger.Tracef("LotteryData Done2: cid:%v wincode:%v snid:%v", l.CId, l.WinCode, l.SnId)
// 开始发奖
l.sendAward()
l.sendAward(true)
}
}), "LotterySendAward").Start()
})).StartByExecutor(fmt.Sprintf("LotterySendAward_%s_%d", l.Platform, l.CId))
}
type LotteryConfig struct {
@ -463,8 +467,9 @@ func (l *LotteryMgr) Init() {
}
func (l *LotteryMgr) Update() {
for _, v := range l.Data {
for _, d := range v {
for i := range l.Data {
for k := range l.Data[i] {
d := l.Data[i][k]
if d == nil {
continue
}
@ -475,9 +480,11 @@ func (l *LotteryMgr) Update() {
// 随机给机器人发放抽奖码
d.sendRobotCode(1, 5)
// 活动结束,开始抽奖
logger.Logger.Tracef("Done1 cid:%v wincode:%v %p", d.CId, d.WinCode, d)
d.Done()
logger.Logger.Tracef("Done2 cid:%v wincode:%v %p", d.CId, d.WinCode, d)
// 开始发奖
d.sendAward()
d.sendAward(false)
}
}
}