diff --git a/dbproxy/svc/l_lotterylog.go b/dbproxy/svc/l_lotterylog.go index b3af2bd..bc6e298 100644 --- a/dbproxy/svc/l_lotterylog.go +++ b/dbproxy/svc/l_lotterylog.go @@ -88,7 +88,7 @@ func (svc *LotteryLogSvc) UpdateMedia(req *model.UpdateLotteryMediaReq, ret *boo if clog == nil { 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) { return err } diff --git a/ranksrv/mq/init.go b/ranksrv/mq/init.go index be5bde8..fbafc3e 100644 --- a/ranksrv/mq/init.go +++ b/ranksrv/mq/init.go @@ -46,10 +46,12 @@ func InitHandler() { }) } pack := &rankproto.UserAward{ - Snid: log.SnId, - Name: log.Name, - Awards: awards, - Ts: log.EndTs, + Snid: log.SnId, + Name: log.Name, + Awards: awards, + Ts: log.EndTs, + Price: log.Price, + ImageURL: log.ImageURL, } action.BroadcastMessage(common.GetSelfAreaId(), srvlib.GateServerType, int(rankproto.Rank_PACKET_SCRoomAwardOne), pack, nil) logger.Logger.Tracef("SCRoomAwardOne %v", pack) diff --git a/worldsrv/action_bag.go b/worldsrv/action_bag.go index 95b2249..61b4d8f 100644 --- a/worldsrv/action_bag.go +++ b/worldsrv/action_bag.go @@ -87,6 +87,11 @@ func CSUpBagInfo(s *netlib.Session, packetid int, data interface{}, sid int64) e Operator: "system", Remark: "测试", }) + for _, v := range items { + if v.ItemId == common.ItemIDRoomCard && v.ItemNum < 0 { + LotteryMgrInst.AddCostRoomCard(p.Platform, p.SnId, -v.ItemNum) + } + } return nil } } diff --git a/worldsrv/lotterymgr.go b/worldsrv/lotterymgr.go index a98b740..fb5da86 100644 --- a/worldsrv/lotterymgr.go +++ b/worldsrv/lotterymgr.go @@ -38,12 +38,6 @@ func init() { if v.IsCycle { // 每天重置抽奖数据 LotteryMgrInst.Reset() - // 重置抽奖期数 - for _, v := range LotteryMgrInst.PlatformConfig { - if v != nil { - v.Num = 0 - } - } // 重置玩家抽奖数据 for _, v := range PlayerInfoMgrSingle.Players { v.Lottery = make(map[int64]*model.Lottery) @@ -138,7 +132,7 @@ func (l *LotteryData) GetRemainCode() int { // 发奖 func (l *LotteryData) sendAward() { 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 } l.IsSend = true @@ -220,7 +214,7 @@ func (l *LotteryData) sendRobotCode(a, b int) { // Done 抽奖 func (l *LotteryData) Done() { 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 } @@ -271,6 +265,7 @@ func (l *LotteryData) Done() { index = common.RandInt(1, l.RobotIndex) awardPlayer.SnId = v.GetSnId() 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 } } @@ -291,6 +286,8 @@ func (l *LotteryData) Done() { tp = 3 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{} { @@ -367,7 +364,7 @@ func (l *LotteryData) Done() { // 记录中奖结果 if awardPlayer != nil { - l.Num = int(LotteryMgrInst.GetNum(l.Platform)) + l.Num = LotteryMgrInst.GetIndex(l.Platform, l.CId) l.SnId = awardPlayer.SnId l.Name = awardPlayer.Name l.WinCostCard = costCard @@ -400,6 +397,7 @@ func (l *LotteryData) Done() { Ts: l.WinTs, } mq.Write(lotteryLog) + logger.Logger.Tracef("LotteryData 抽奖中奖记录: %+v", *lotteryLog) // 开始发奖 l.sendAward() } @@ -408,7 +406,6 @@ func (l *LotteryData) Done() { type LotteryConfig struct { IsCycle bool - Num int64 } // LotteryMgr 抽奖管理 @@ -547,16 +544,28 @@ func (l *LotteryMgr) GetData(plt string, cid int64) *LotteryData { return l.Data[plt][cid] } -// GetNum 获取抽奖第几期 -// 当前抽奖是第几期 -func (l *LotteryMgr) GetNum(plt string) int64 { - p := l.GetConfig(plt) - if p.Num == 0 { - p.Num = 1 - return 1 +func (l *LotteryMgr) GetIndex(plt string, cid int64) int { + var arr []*LotteryData + for _, d := range l.Data[plt] { + lc := PlatformMgrSingleton.GetLotteryConfig(d.Platform, d.CId) + if lc == nil || lc.GetOn() != common.On { + continue + } + arr = append(arr, d) } - p.Num += 1 - return p.Num + sort.Slice(arr, func(i, j int) bool { + 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 获取抽奖列表 @@ -606,6 +615,8 @@ func (l *LotteryMgr) GetList(plt string) []*welfare.LotteryInfo { WinCode: d.WinCode, SnId: d.SnId, Name: d.Name, + Index: int32(d.Num), + Price: d.Price, NeedRoomCard: LotteryRoomCard, ImageURL: d.ImageURL, }) @@ -613,7 +624,7 @@ func (l *LotteryMgr) GetList(plt string) []*welfare.LotteryInfo { sort.Slice(ret, func(i, j int) bool { 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 }) @@ -645,9 +656,6 @@ func (l *LotteryMgr) AddCostRoomCard(plt string, snid int32, n int64) { if v == nil || v.GetState() != common.LotteryStateRun { continue } - if v.GetRemainCode() <= 0 { - continue - } playerLottery := info.Lottery[v.GetId()] if playerLottery == nil || playerLottery.StartTs != v.GetStartTs() { playerLottery = &model.Lottery{ @@ -667,6 +675,9 @@ func (l *LotteryMgr) AddCostRoomCard(plt string, snid int32, n int64) { n = int64(int(n) + playerLottery.ReCostCard) playerLottery.ReCostCard = int(n % LotteryRoomCard) for i := 0; i < int(n)/LotteryRoomCard; i++ { + if v.GetRemainCode() <= 0 { + break + } code, b := lotteryData.GetCode() if b { intCode, _ := strconv.Atoi(code)