92 lines
2.4 KiB
Go
92 lines
2.4 KiB
Go
package main
|
|
|
|
import (
|
|
"mongo.games.com/goserver/core/basic"
|
|
"mongo.games.com/goserver/core/logger"
|
|
"mongo.games.com/goserver/core/netlib"
|
|
"mongo.games.com/goserver/core/task"
|
|
|
|
"mongo.games.com/game/common"
|
|
"mongo.games.com/game/model"
|
|
"mongo.games.com/game/protocol/welfare"
|
|
)
|
|
|
|
func init() {
|
|
common.Register(int(welfare.SPacketID_PACKET_CSLotteryInfo), &welfare.CSLotteryInfo{}, CSLotteryInfoHandler)
|
|
}
|
|
|
|
func CSLotteryInfoHandler(s *netlib.Session, packetid int, data interface{}, sid int64) error {
|
|
logger.Logger.Tracef("CSLotteryInfo Process recv %v", data)
|
|
_, ok := data.(*welfare.CSLotteryInfo)
|
|
if !ok {
|
|
return nil
|
|
}
|
|
|
|
p := PlayerMgrSington.GetPlayer(sid)
|
|
if p == nil {
|
|
return nil
|
|
}
|
|
|
|
pack := &welfare.SCLotteryInfo{}
|
|
|
|
var list []*welfare.LotteryInfo
|
|
cfg := PlatformMgrSingleton.GetConfig(p.Platform).LotteryConfig
|
|
if cfg != nil {
|
|
list = LotteryMgrInst.GetList(p.Platform)
|
|
pack.Info = list
|
|
}
|
|
// player lottery info
|
|
info := PlayerInfoMgrSingle.Players[p.SnId]
|
|
if info != nil {
|
|
// 当前开启中的抽奖活动id
|
|
for _, v := range list {
|
|
playerLottery := info.Lottery[v.GetId()]
|
|
if playerLottery != nil && playerLottery.StartTs == v.GetStartTs() {
|
|
v.CostRoomCard = playerLottery.CostCard
|
|
v.Codes = playerLottery.Code
|
|
}
|
|
}
|
|
}
|
|
// 查询上期中奖信息
|
|
var last []*model.LotteryLog
|
|
var err error
|
|
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
|
|
last, err = model.GetLotteryLogs(p.Platform, 1)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}), task.CompleteNotifyWrapper(func(i interface{}, t task.Task) {
|
|
if err != nil {
|
|
logger.Logger.Errorf("get_last_lottery_info err:%s", err.Error())
|
|
return
|
|
}
|
|
if len(last) > 0 {
|
|
var award []*welfare.PropInfo
|
|
for _, v := range last[0].Award {
|
|
award = append(award, &welfare.PropInfo{
|
|
ItemId: int32(v.Id),
|
|
ItemNum: v.N,
|
|
})
|
|
}
|
|
pack.Last = &welfare.LotteryInfo{
|
|
Id: last[0].CId,
|
|
StartTs: last[0].CTime.Unix(),
|
|
WinTs: last[0].Ts,
|
|
Award: award,
|
|
WinCode: last[0].Code,
|
|
SnId: last[0].SnId,
|
|
Name: last[0].Name,
|
|
RoleId: last[0].RoleId,
|
|
Index: last[0].Num,
|
|
Price: last[0].Price,
|
|
ImageURL: last[0].ImageURL,
|
|
}
|
|
}
|
|
p.SendToClient(int(welfare.SPacketID_PACKET_SCLotteryInfo), pack)
|
|
logger.Logger.Tracef("SCLotteryInfo: %v", pack)
|
|
}), "get_last_lottery_info").Start()
|
|
|
|
return nil
|
|
}
|