修复竞技馆抽奖活动问题

This commit is contained in:
sk 2024-10-24 11:59:46 +08:00
parent 7e52629091
commit 900a54d64d
4 changed files with 46 additions and 28 deletions

View File

@ -88,7 +88,7 @@ func (svc *LotteryLogSvc) UpdateMedia(req *model.UpdateLotteryMediaReq, ret *boo
if clog == nil { if clog == nil {
return LotteryLogDBErr return LotteryLogDBErr
} }
err := clog.Update(bson.M{"_id": req.LogId}, bson.M{"$set": bson.M{"media": req.Media}}) err := clog.Update(bson.M{"_id": bson.ObjectIdHex(req.LogId)}, bson.M{"$set": bson.M{"media": req.Media}})
if err != nil && !errors.Is(err, mgo.ErrNotFound) { if err != nil && !errors.Is(err, mgo.ErrNotFound) {
return err return err
} }

View File

@ -46,10 +46,12 @@ func InitHandler() {
}) })
} }
pack := &rankproto.UserAward{ pack := &rankproto.UserAward{
Snid: log.SnId, Snid: log.SnId,
Name: log.Name, Name: log.Name,
Awards: awards, Awards: awards,
Ts: log.EndTs, Ts: log.EndTs,
Price: log.Price,
ImageURL: log.ImageURL,
} }
action.BroadcastMessage(common.GetSelfAreaId(), srvlib.GateServerType, int(rankproto.Rank_PACKET_SCRoomAwardOne), pack, nil) action.BroadcastMessage(common.GetSelfAreaId(), srvlib.GateServerType, int(rankproto.Rank_PACKET_SCRoomAwardOne), pack, nil)
logger.Logger.Tracef("SCRoomAwardOne %v", pack) logger.Logger.Tracef("SCRoomAwardOne %v", pack)

View File

@ -87,6 +87,11 @@ func CSUpBagInfo(s *netlib.Session, packetid int, data interface{}, sid int64) e
Operator: "system", Operator: "system",
Remark: "测试", Remark: "测试",
}) })
for _, v := range items {
if v.ItemId == common.ItemIDRoomCard && v.ItemNum < 0 {
LotteryMgrInst.AddCostRoomCard(p.Platform, p.SnId, -v.ItemNum)
}
}
return nil return nil
} }
} }

View File

@ -38,12 +38,6 @@ func init() {
if v.IsCycle { if v.IsCycle {
// 每天重置抽奖数据 // 每天重置抽奖数据
LotteryMgrInst.Reset() LotteryMgrInst.Reset()
// 重置抽奖期数
for _, v := range LotteryMgrInst.PlatformConfig {
if v != nil {
v.Num = 0
}
}
// 重置玩家抽奖数据 // 重置玩家抽奖数据
for _, v := range PlayerInfoMgrSingle.Players { for _, v := range PlayerInfoMgrSingle.Players {
v.Lottery = make(map[int64]*model.Lottery) v.Lottery = make(map[int64]*model.Lottery)
@ -138,7 +132,7 @@ func (l *LotteryData) GetRemainCode() int {
// 发奖 // 发奖
func (l *LotteryData) sendAward() { func (l *LotteryData) sendAward() {
now := time.Now() now := time.Now()
if l.WinTs <= 0 || l.WinTs >= now.Unix() || l.IsSend || l.WinCode == "" || l.SnId == 0 { if l.WinTs <= 0 || l.WinTs >= now.Unix() || l.IsSend || l.WinCode == "" || l.SnId == 0 || now.Unix()-l.WinTs > 5*60 {
return return
} }
l.IsSend = true l.IsSend = true
@ -220,7 +214,7 @@ func (l *LotteryData) sendRobotCode(a, b int) {
// Done 抽奖 // Done 抽奖
func (l *LotteryData) Done() { func (l *LotteryData) Done() {
now := time.Now() now := time.Now()
if l.EndTs <= 0 || l.EndTs >= now.Unix() || l.SnId > 0 { if l.EndTs <= 0 || l.EndTs >= now.Unix() || l.SnId > 0 || now.Unix()-l.EndTs > 5*60 {
return return
} }
@ -271,6 +265,7 @@ func (l *LotteryData) Done() {
index = common.RandInt(1, l.RobotIndex) index = common.RandInt(1, l.RobotIndex)
awardPlayer.SnId = v.GetSnId() awardPlayer.SnId = v.GetSnId()
awardPlayer.IsRob = false awardPlayer.IsRob = false
logger.Logger.Tracef("LotteryData 抽奖 isMust:%v tp:%v index:%v RobotIndex:%v awardPlayer:%v", isMust, tp, index, l.RobotIndex, awardPlayer.SnId)
break break
} }
} }
@ -291,6 +286,8 @@ func (l *LotteryData) Done() {
tp = 3 tp = 3
index = common.RandInt(1, l.PlayerIndex) index = common.RandInt(1, l.PlayerIndex)
} }
logger.Logger.Tracef("LotteryData 抽奖 value:%v tp:%v index:%v RobotIndex:%v Code:%v PlayerIndex:%v Cid:%v",
value, tp, index, l.RobotIndex, l.Code, l.PlayerIndex, l.CId)
} }
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} { task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
@ -367,7 +364,7 @@ func (l *LotteryData) Done() {
// 记录中奖结果 // 记录中奖结果
if awardPlayer != nil { if awardPlayer != nil {
l.Num = int(LotteryMgrInst.GetNum(l.Platform)) l.Num = LotteryMgrInst.GetIndex(l.Platform, l.CId)
l.SnId = awardPlayer.SnId l.SnId = awardPlayer.SnId
l.Name = awardPlayer.Name l.Name = awardPlayer.Name
l.WinCostCard = costCard l.WinCostCard = costCard
@ -400,6 +397,7 @@ func (l *LotteryData) Done() {
Ts: l.WinTs, Ts: l.WinTs,
} }
mq.Write(lotteryLog) mq.Write(lotteryLog)
logger.Logger.Tracef("LotteryData 抽奖中奖记录: %+v", *lotteryLog)
// 开始发奖 // 开始发奖
l.sendAward() l.sendAward()
} }
@ -408,7 +406,6 @@ func (l *LotteryData) Done() {
type LotteryConfig struct { type LotteryConfig struct {
IsCycle bool IsCycle bool
Num int64
} }
// LotteryMgr 抽奖管理 // LotteryMgr 抽奖管理
@ -547,16 +544,28 @@ func (l *LotteryMgr) GetData(plt string, cid int64) *LotteryData {
return l.Data[plt][cid] return l.Data[plt][cid]
} }
// GetNum 获取抽奖第几期 func (l *LotteryMgr) GetIndex(plt string, cid int64) int {
// 当前抽奖是第几期 var arr []*LotteryData
func (l *LotteryMgr) GetNum(plt string) int64 { for _, d := range l.Data[plt] {
p := l.GetConfig(plt) lc := PlatformMgrSingleton.GetLotteryConfig(d.Platform, d.CId)
if p.Num == 0 { if lc == nil || lc.GetOn() != common.On {
p.Num = 1 continue
return 1 }
arr = append(arr, d)
} }
p.Num += 1 sort.Slice(arr, func(i, j int) bool {
return p.Num if arr[i].StartTs == arr[j].StartTs {
return arr[i].EndTs < arr[j].EndTs
}
return arr[i].StartTs < arr[j].StartTs
})
for k, v := range arr {
if v.CId == cid {
return k + 1
}
}
return 0
} }
// GetList 获取抽奖列表 // GetList 获取抽奖列表
@ -606,6 +615,8 @@ func (l *LotteryMgr) GetList(plt string) []*welfare.LotteryInfo {
WinCode: d.WinCode, WinCode: d.WinCode,
SnId: d.SnId, SnId: d.SnId,
Name: d.Name, Name: d.Name,
Index: int32(d.Num),
Price: d.Price,
NeedRoomCard: LotteryRoomCard, NeedRoomCard: LotteryRoomCard,
ImageURL: d.ImageURL, ImageURL: d.ImageURL,
}) })
@ -613,7 +624,7 @@ func (l *LotteryMgr) GetList(plt string) []*welfare.LotteryInfo {
sort.Slice(ret, func(i, j int) bool { sort.Slice(ret, func(i, j int) bool {
if ret[i].StartTs == ret[j].StartTs { if ret[i].StartTs == ret[j].StartTs {
return ret[i].Index < ret[j].Index return ret[i].EndTs < ret[j].EndTs
} }
return ret[i].StartTs < ret[j].StartTs return ret[i].StartTs < ret[j].StartTs
}) })
@ -645,9 +656,6 @@ func (l *LotteryMgr) AddCostRoomCard(plt string, snid int32, n int64) {
if v == nil || v.GetState() != common.LotteryStateRun { if v == nil || v.GetState() != common.LotteryStateRun {
continue continue
} }
if v.GetRemainCode() <= 0 {
continue
}
playerLottery := info.Lottery[v.GetId()] playerLottery := info.Lottery[v.GetId()]
if playerLottery == nil || playerLottery.StartTs != v.GetStartTs() { if playerLottery == nil || playerLottery.StartTs != v.GetStartTs() {
playerLottery = &model.Lottery{ playerLottery = &model.Lottery{
@ -667,6 +675,9 @@ func (l *LotteryMgr) AddCostRoomCard(plt string, snid int32, n int64) {
n = int64(int(n) + playerLottery.ReCostCard) n = int64(int(n) + playerLottery.ReCostCard)
playerLottery.ReCostCard = int(n % LotteryRoomCard) playerLottery.ReCostCard = int(n % LotteryRoomCard)
for i := 0; i < int(n)/LotteryRoomCard; i++ { for i := 0; i < int(n)/LotteryRoomCard; i++ {
if v.GetRemainCode() <= 0 {
break
}
code, b := lotteryData.GetCode() code, b := lotteryData.GetCode()
if b { if b {
intCode, _ := strconv.Atoi(code) intCode, _ := strconv.Atoi(code)