示例#1
0
    def notifyMatchStart(self, player):
        '''
        通知用户比赛开始了
        '''
        try:
            ftlog.info('MatchPlayerNotifierDizhu.notifyMatchStart matchId=',
                       player.matchInst.matchId, 'signinParams=',
                       player.signinParams, 'instId=', player.matchInst.instId,
                       'userId=', player.userId)
            mo = MsgPack()
            mo.setCmd('m_start')
            mo.setResult('gameId', self._room.gameId)
            mo.setResult('roomId', self._room.bigRoomId)
            router.sendToUser(mo, player.userId)

            mo = MsgPack()
            mo.setCmd('m_play_animation')
            mo.setResult('gameId', self._room.gameId)
            mo.setResult('roomId', self._room.bigRoomId)
            mo.setResult('type', AnimationType.ASSIGN_TABLE)
            router.sendToUser(mo, player.userId)

            sequence = int(player.matchInst.instId.split('.')[1])
            matchutil.report_bi_game_event(
                'MATCH_START', player.userId, self._room.bigRoomId, 0,
                sequence, 0, 0, 0,
                [int(player.mixId) if player.mixId else 255], 'match_start')

            # 保存用户折扣次数
            roomDiscountConf = match_signin_discount.getRoomDiscountConf(
                player.mixId if player.mixId else self._room.bigRoomId)
            if roomDiscountConf and player._paidFee:
                ret, _, _ = match_signin_discount.canMatchDiscount(
                    player.userId,
                    player.mixId if player.mixId else self._room.bigRoomId,
                    player.paidFee.assetKindId)
                if ret:
                    match_signin_discount.saveUserMatchDiscountCount(
                        player.userId,
                        player.mixId if player.mixId else self._room.bigRoomId,
                        player._paidFee.assetKindId)
        except:
            ftlog.error()
示例#2
0
    def buildGetRewardResponse(cls, userId, rewardId):
        ''' 返回客户端消息 mo '''
        ret = cls.getRewardByRewardId(userId, rewardId)
        if ret:
            rewards = ret['rewards']
            rewardType = ret['type']
            # 给用户发奖
            contentItems = TYContentItem.decodeList(rewards)
            if rewardType == REWARD_ASYNC_TYPE_AS_ARENA_MATCH:
                matchId = ret.get('params', {}).get('matchId', 0)
                mixId = ret.get('params', {}).get('mixId', 0)
                rank = ret.get('params', {}).get('rank', 0)
                sequence = ret.get('params', {}).get('sequence', 0)
                roomName = ret.get('params', {}).get('roomName', '红包赛')

                mail = '红包赛奖励#恭喜您在%s' % roomName + '中, 获得${rewardContent}。'
                dizhu_util.sendRewardItems(
                    userId, contentItems, mail, 'MATCH_REWARD',
                    ret.get('params', {}).get('matchId', 0))
                for reward in rewards:
                    chipType = matchutil.getBiChipType(reward['itemId'])
                    kindId = 0
                    if chipType == daoconst.CHIP_TYPE_ITEM:
                        kindId = reward['itemId'].strip('item:')
                    matchutil.report_bi_game_event(
                        'MATCH_REWARD', userId, matchId, 0, sequence, 0, 0, 0,
                        [
                            chipType, reward['count'], kindId, rank, mixId,
                            len(rewards)
                        ], 'match_reward')
            elif rewardType == REWARD_ASYNC_TYPE_AS_WINSTREAK:
                winStreak = ret.get('params', {}).get('winStreak', 0)
                dizhu_util.sendRewardItems(userId, contentItems, None,
                                           'DIZHU_SEGMENT_MATCH_WINSTREAK',
                                           winStreak)

            # 如果是奖券则广播奖券事件
            for reward in rewards:
                if reward['itemId'] == 'user:coupon':
                    if rewardType == REWARD_ASYNC_TYPE_AS_ARENA_MATCH:
                        from hall.game import TGHall
                        TGHall.getEventBus().publishEvent(
                            UserCouponReceiveEvent(
                                HALL_GAMEID, userId, reward['count'],
                                user_coupon_details.
                                USER_COUPON_SOURCE_MATCH_ARENA))

                    elif rewardType == REWARD_ASYNC_TYPE_AS_WINSTREAK:
                        from hall.game import TGHall
                        TGHall.getEventBus().publishEvent(
                            UserCouponReceiveEvent(
                                HALL_GAMEID, userId, reward['count'],
                                user_coupon_details.
                                USER_COUPON_SOURCE_SEGMENT_WINSTREAK_TASK))
        mo = MsgPack()
        mo.setCmd('dizhu')
        mo.setResult('action', 'get_reward_async')
        mo.setResult('gameId', DIZHU_GAMEID)
        mo.setResult('userId', userId)
        mo.setResult('rewardInfo', ret)
        return mo
示例#3
0
    def _do_room__revival(self, msg):
        userId = msg.getParam('userId')
        isOK = msg.getParam('isOk', 0)
        player = self.match.findPlayer(userId)
        reviveCondition = player.stage.stageConf.reviveCondition
        if player and reviveCondition:
            itemId = reviveCondition.get('fee', {}).get('itemId')
            count = reviveCondition.get('fee', {}).get('count')
            if itemId and count and isOK:
                userAssets = hallitem.itemSystem.loadUserAssets(player.userId)
                timestamp = pktimestamp.getCurrentTimestamp()
                balance = userAssets.balance(HALL_GAMEID, itemId, timestamp)
                if balance and balance >= count:
                    _, consumeCount, _ = userAssets.consumeAsset(DIZHU_GAMEID, itemId, count, timestamp, 'MATCH_REVIVE', 0)
                    if consumeCount == count:
                        # 消费成功, 考虑锁的关系,时间竞争
                        ret = self.match.currentInstance.doUserRevive(player, True)
                        if not ret:
                            # 退费
                            userAssets.addAsset(DIZHU_GAMEID, itemId, count, timestamp, 'MATCH_REVIVE', 0)
                            ftlog.info('DizhuCtrlRoomArenaMatch._do_room__m_revive returnFee',
                                       'gameId=', self.gameId,
                                       'roomId=', self.roomId,
                                       'userId=', userId,
                                       'stageIndex=', player.stage.index,
                                       'reviveCondition=', reviveCondition)
                        if ret:
                            # 日志记录
                            try:
                                sequence = int(player.matchInst.instId.split('.')[1])
                                matchutil.report_bi_game_event('MATCH_REVIVE', player.userId, player.matchInst.matchId, 0, sequence, 0, 0, 0,
                                                               [int(player.mixId) if player.mixId else 0, player.stage.index, count], 'match_revive')

                                ftlog.info('DizhuCtrlRoomArenaMatch._do_room__m_revive success',
                                           'gameId=', self.gameId,
                                           'roomId=', self.roomId,
                                           'userId=', userId,
                                           'stageIndex=', player.stage.index,
                                           'reviveCondition=', reviveCondition)
                            except Exception, e:
                                ftlog.error('DizhuCtrlRoomArenaMatch._do_room__m_revive',
                                            'gameId=', self.gameId,
                                            'userId=', userId,
                                            'err=', e.message)

                else:
                    # 发送不够的todotask
                    payOrder = reviveCondition.get('fee', {}).get('params', {}).get('payOrder')
                    failure = reviveCondition.get('fee', {}).get('params', {}).get('failure')
                    mo = TodoTaskHelper.makeTodoTaskMsg(self.gameId, player.userId, TodoTaskShowInfo(failure))
                    if payOrder:
                        clientId = sessiondata.getClientId(player.userId)
                        product, _shelves = hallstore.findProductByPayOrder(self.gameId, player.userId, clientId, payOrder)
                        if product:
                            orderShow = TodoTaskOrderShow.makeByProduct(failure, '', product, 'charge', reviveCondition.get('fee', {}).get('count', 0), reviveCondition.get('fee', {}).get('itemId', ''))
                            orderShow.setParam('sub_action_btn_text', '购买')
                            mo = TodoTaskHelper.makeTodoTaskMsg(self.gameId, player.userId, orderShow)
                    router.sendToUser(mo, userId)

            else:
                self.match.currentInstance.doUserRevive(player, False)
def notifyMatchOver(self, player, reason, rankRewards):
    '''
    通知用户比赛结束了
    '''
    try:
        ftlog.info('MatchPlayerNotifierDizhu.notifyMatchOver matchId=',
                   player.matchInst.matchId, 'instId=',
                   player.matchInst.instId, 'userId=', player.userId,
                   'signinParams=', player.signinParams, 'stageIndex=',
                   player.stage.index, 'rank=', player.rank, 'reason=', reason,
                   'rankRewards=', rankRewards)

        if (reason == MatchFinishReason.USER_WIN
                or reason == MatchFinishReason.USER_LOSER):
            try:
                if player.isQuit:
                    rankRewards = None
                event_remote.publishMatchWinloseEvent(
                    self._room.gameId, player.userId, self._room.match.matchId,
                    reason == MatchFinishReason.USER_WIN, player.rank,
                    player.matchInst.matchConf.stages[0].totalUserCount,
                    rankRewards.conf if rankRewards else None)

                tempGameResult = 1 if reason == MatchFinishReason.USER_WIN else -1
                hall51event.sendToHall51MatchOverEvent(player.userId,
                                                       self._room.gameId,
                                                       self._room.bigRoomId,
                                                       tempGameResult, -1, -1)

                from dizhu.entity.matchhistory import MatchHistoryHandler
                MatchHistoryHandler.onMatchOver(
                    player.userId, player.matchInst.matchConf.recordId,
                    player.rank, reason == MatchFinishReason.USER_WIN,
                    rankRewards.conf if rankRewards else None, False,
                    player.mixId)

                if not rankRewards:
                    matchutil.report_bi_game_event(
                        'MATCH_REWARD', player.userId,
                        player.matchInst.matchId, 0,
                        int(player.matchInst.instId.split('.')[1]), 0, 0, 0, [
                            0, 0, 0, player.rank,
                            int(player.mixId) if player.mixId else 0, 0
                        ], 'match_reward')

            except:
                ftlog.error()

            # 比赛记录保存
            try:
                event = {
                    'gameId': self._room.gameId,
                    'userId': player.userId,
                    'matchId': self._room.match.matchId,
                    'rank': player.rank,
                    'isGroup': 0,
                    'mixId': player.mixId
                }
                MatchRecord.updateAndSaveRecord(event)
            except:
                ftlog.error()

        msg = MsgPack()
        msg.setCmd('m_over')
        msg.setResult('mixId', player.mixId)
        msg.setResult('gameId', self._room.gameId)
        msg.setResult('roomId', self._room.bigRoomId)
        msg.setResult('userId', player.userId)
        msg.setResult('reason', reason)
        msg.setResult('rank', player.rank)

        if rankRewards:
            msg.setResult('info', self.buildWinInfo(player, rankRewards))
        else:
            msg.setResult('info', self.buildLoserInfo(player))
        msg.setResult('mucount',
                      player.matchInst.matchConf.stages[0].totalUserCount)
        msg.setResult('date', str(datetime.now().date().today()))
        msg.setResult('time',
                      time.strftime('%H:%M', time.localtime(time.time())))
        msg.setResult('addInfo', '')
        rewardDesc = ''
        if rankRewards:
            msg.setResult('reward', matchutil.buildRewards(rankRewards))
            rewardDesc = matchutil.buildRewardsDesc(rankRewards)
            if rewardDesc:
                msg.setResult('rewardDesc', rewardDesc)

        roomName = player.matchInst.matchConf.getRoomName(player.mixId)
        arenaContent = dizhuhallinfo.getArenaMatchProvinceContent(
            player.userId,
            int(player.mixId) if player.mixId else self._room.bigRoomId, None)
        if arenaContent:
            roomName = arenaContent.get('showName') or roomName
        msg.setResult('mname', roomName)

        shareInfo = matchutil.buildShareInfo(
            self._room.gameId, sessiondata.getClientId(player.userId))
        msg.setResult('shareInfo',
                      {'erweima': shareInfo['erweima'] if shareInfo else {}})

        try:
            msg.setResult('beatDownUser', player.beatDownUserName)
            if rankRewards and rankRewards.todotask:
                msg.setResult('todotask', rankRewards.todotask)
            # 设置奖状分享的todotask diplomaShare
            shareTodoTask = dizhudiplomashare.buildDiplomaShare(
                player.userName, roomName, player.rank, rewardDesc,
                player.userId)
            if shareTodoTask:
                msg.setResult('shareTodoTask', shareTodoTask)

            if rankRewards:
                bigImg = rankRewards.conf.get('bigImg', '')
                if bigImg:
                    msg.setResult('bidImg', bigImg)

                if ftlog.is_debug():
                    ftlog.debug(
                        'MatchPlayerNotifierDizhu.notifyMatchOver userId=',
                        player.userId, 'roomId=', self._room.roomId, 'bigImg=',
                        bigImg, 'rank=', player.rank, 'rankRewards.conf=',
                        rankRewards.conf)
        except:
            ftlog.debug('NobeatDownUser arena match')
            ftlog.exception()

        # 冠军触发抽奖逻辑
        try:
            from dizhu.games.matchutil import MatchLottery
            match_lottery = MatchLottery()
            ret = match_lottery.checkMatchRank(player.userId,
                                               self._room.match.matchId,
                                               player.rank)
            if ret:
                msg.setResult('match_lottery', 1)
        except:
            ftlog.debug('MatchLottery arena match')
            ftlog.exception()
        ###########################

        # 玩家红包记录
        try:
            from dizhu.entity import dizhushare
            shareInfoConf = rankRewards.conf.get('shareInfo',
                                                 {}) if rankRewards else {}
            rewardType = shareInfoConf.get('type', '') if shareInfoConf else ''

            shareNum, shareTotalNum = dizhushare.arenaMatchRewardRecord(
                player.userId, shareInfoConf)

            # 常规配置
            championRewards = player.matchInst.matchConf.feeRewardList
            championShareInfo = championRewards[0].rankRewardsList[0].conf.get(
                'shareInfo', {})
            if arenaContent:
                # 分ip奖励配置
                championRewards = arenaContent.get('rank.rewards', [])
                if championRewards and championRewards[0].get(
                        'ranking', {}).get('start', 0) == 1:
                    championShareInfo = championRewards[0].get('shareInfo', {})

            rmb = 0
            matchShareType = 0
            if championShareInfo and championShareInfo.get(
                    'type', '') == MATCH_REWARD_REDENVELOPE:
                # 冠军奖励金额
                rmb = championShareInfo.get('rmb', 0)
                matchShareType = 1

            if shareInfoConf and str(rewardType) == MATCH_REWARD_REDENVELOPE:
                rmb = shareInfoConf.get('rmb', 0)

            shareInfoNew = {
                "matchShareType": matchShareType,
                "shareNum": shareNum if shareNum else 0,
                "shareTotalNum": shareTotalNum if shareTotalNum else 0,
                "get": 1 if str(rewardType) == MATCH_REWARD_REDENVELOPE else 0,
                "rmb": '{0:.2f}'.format(rmb)
            }
            msg.setResult('shareInfoNew', shareInfoNew)
        except Exception, e:
            ftlog.error('MatchPlayerNotifierDizhu.notifyMatchOver', 'gameId=',
                        self._room.gameId, 'userId=', player.userId, 'roomId=',
                        self._room.roomId, 'matchId=',
                        self._room.match.matchId, 'err=', e.message)
        ###########################

        record = MatchRecord.loadRecord(self._room.gameId, player.userId,
                                        self._room.match.matchId)
        if record:
            msg.setResult(
                'mrecord', {
                    'bestRank': record.bestRank,
                    'bestRankDate': record.bestRankDate,
                    'isGroup': record.isGroup,
                    'crownCount': record.crownCount,
                    'playCount': record.playCount
                })
        else:
            from dizhu.activities.toolbox import Tool
            msg.setResult(
                'mrecord', {
                    'bestRank': player.rank,
                    'bestRankDate': Tool.datetimeToTimestamp(datetime.now()),
                    'isGroup': 0,
                    'crownCount': 1 if player.rank == 1 else 0,
                    'playCount': 1
                })

        if not player.isQuit:
            router.sendToUser(msg, player.userId)

        # 混房冠军LED
        mixId = player.mixId
        if mixId:
            mixConf = MatchPlayerNotifierDizhu.getArenaMixConf(
                self._room.roomConf, mixId)
            if player.rank == 1 and mixConf.get('championLed'):
                clientId = sessiondata.getClientId(player.userId)
                arenaContent = dizhuhallinfo.getArenaMatchProvinceContent(
                    player.userId,
                    int(mixId) if mixId else self._room.roomId, clientId)
                if ftlog.is_debug():
                    ftlog.debug('MatchPlayerNotifierDizhu.notifyMatchOver',
                                'userId=', player.userId, 'roomId=',
                                self._room.roomId, 'mixId=', mixId, 'roomName',
                                mixConf.get('roomName'), 'rewardShow=',
                                mixConf.get('rewardShow',
                                            rewardDesc), 'mixConf=', mixConf)
                # 冠军发送Led通知所有其他玩家
                ledtext = dizhuled._mk_match_champion_rich_text(
                    player.userName,
                    arenaContent.get('name')
                    if arenaContent else mixConf.get('roomName'),
                    arenaContent.get('rewardShow')
                    if arenaContent else mixConf.get('rewardShow', rewardDesc))
                LedUtil.sendLed(ledtext, 'global')
        else:
            if player.rank == 1 and self._room.roomConf.get(
                    'championLed') and not player.isQuit:
                clientId = sessiondata.getClientId(player.userId)
                arenaContent = dizhuhallinfo.getArenaMatchProvinceContent(
                    player.userId,
                    int(mixId) if mixId else self._room.roomId, clientId)
                # 冠军发送Led通知所有其他玩家
                ledtext = dizhuled._mk_match_champion_rich_text(
                    player.userName,
                    arenaContent.get('name') if arenaContent else roomName,
                    arenaContent.get('rewardShow') if arenaContent else
                    self._room.roomConf.get('rewardShow', rewardDesc))
                LedUtil.sendLed(ledtext, 'global')

        sequence = int(player.matchInst.instId.split('.')[1])
        matchutil.report_bi_game_event(
            'MATCH_FINISH', player.userId, player.matchInst.matchId, 0,
            sequence, 0, 0, 0, [int(player.mixId) if player.mixId else 255],
            'match_end')
示例#5
0
    def sendRankRewards(self, player, rankRewards):
        '''
        给用户发奖
        '''
        conf = configure.getGameJson(DIZHU_GAMEID, 'wx.share.control', {})
        matchRewardSwitch = conf.get('matchRewardSwitch')
        if matchRewardSwitch:
            return
        try:
            ftlog.info('MatchRankRewardsSenderDizhu.sendRankRewards matchId=',
                       player.matchInst.matchId, 'instId=',
                       player.matchInst.instId, 'userId=', player.userId,
                       'rank=', player.rank, 'signinParams=',
                       player.signinParams, 'rewards=', rankRewards.rewards)
            playerMixId = int(player.mixId) if player.mixId else None
            user_remote.addAssets(self._room.gameId, player.userId,
                                  rankRewards.rewards, 'MATCH_REWARD',
                                  playerMixId or player.matchInst.matchId)

            from dizhu.game import TGDizhu
            from dizhu.entity.common.events import ActiveEvent
            TGDizhu.getEventBus().publishEvent(
                ActiveEvent(DIZHU_GAMEID, player.userId, 'redEnvelope'))

            if rankRewards:
                # 发邮件
                rewardDesc = matchutil.buildRewardsDesc(rankRewards)
                roomName = player.matchInst.matchConf.getRoomName(player.mixId)
                mailstr = '红包赛奖励#恭喜您在%s' % roomName + '中, 获得%s。' % rewardDesc
                message.send(DIZHU_GAMEID, message.MESSAGE_TYPE_SYSTEM,
                             player.userId, mailstr)

            if rankRewards.message:
                pkmessage.sendPrivate(self._room.gameId, player.userId, 0,
                                      rankRewards.message)
                datachangenotify.sendDataChangeNotify(self._room.gameId,
                                                      player.userId, 'message')

            sequence = int(player.matchInst.instId.split('.')[1])
            rewardsLen = len(rankRewards.rewards)
            for reward in rankRewards.rewards:
                # 如果是红包券则广播红包券事件
                if reward['itemId'] == 'user:coupon':
                    from hall.game import TGHall
                    TGHall.getEventBus().publishEvent(
                        UserCouponReceiveEvent(
                            HALL_GAMEID, player.userId, reward['count'],
                            user_coupon_details.USER_COUPON_SOURCE_MATCH_ARENA)
                    )

                chipType = matchutil.getBiChipType(reward['itemId'])
                kindId = 0
                if chipType == daoconst.CHIP_TYPE_ITEM:
                    kindId = reward['itemId'].strip('item:')
                matchutil.report_bi_game_event(
                    'MATCH_REWARD', player.userId, player.matchInst.matchId, 0,
                    sequence, 0, 0, 0, [
                        chipType, reward['count'], kindId, player.rank,
                        int(player.mixId) if player.mixId else 0, rewardsLen
                    ], 'match_reward')
        except:
            ftlog.error()
示例#6
0
    def notifyMatchOver(self, player, reason, rankRewards):
        '''
        通知用户比赛结束了
        '''
        try:
            exchangeMoney = rankRewards.conf.get('exchangeMoney',
                                                 None) if rankRewards else None
            exchangeCode = None
            if exchangeMoney:
                exchangeCode = RedEnvelopeHelper.getRedEnvelopeCode(
                    player.userId, self._room.gameId, exchangeMoney,
                    self._room.roomId, self._room.match.matchId, player.rank)

            ftlog.info('MatchPlayerNotifierDizhu.notifyMatchOver matchId=',
                       player.matchInst.matchId, 'instId=',
                       player.matchInst.instId, 'userId=', player.userId,
                       'signinParams=', player.signinParams, 'stageIndex=',
                       player.stage.index, 'rank=', player.rank, 'reason=',
                       reason, 'rankRewards=', rankRewards, 'exchangeCode=',
                       exchangeCode)

            lastBestRank = None
            record = MatchRecord.loadRecord(self._room.gameId, player.userId,
                                            self._room.match.matchId)
            if record:
                lastBestRank = record.bestRank

            # 获取房间名
            roomName = player.matchInst.matchConf.getRoomName(player.mixId)
            arenaContent = dizhuhallinfo.getArenaMatchProvinceContent(
                player.userId,
                int(player.mixId) if player.mixId else self._room.bigRoomId,
                None)
            if arenaContent:
                roomName = arenaContent.get('showName') or roomName

            rewardId = None
            if (reason == MatchFinishReason.USER_WIN
                    or reason == MatchFinishReason.USER_LOSER):
                try:
                    if player.isQuit:
                        rankRewards = None
                    event_remote.publishMatchWinloseEvent(
                        self._room.gameId, player.userId,
                        self._room.match.matchId,
                        reason == MatchFinishReason.USER_WIN, player.rank,
                        player.matchInst.matchConf.stages[0].totalUserCount,
                        rankRewards.conf if rankRewards else None)

                    tempGameResult = 1 if reason == MatchFinishReason.USER_WIN else -1
                    hall51event.sendToHall51MatchOverEvent(
                        player.userId, self._room.gameId, self._room.bigRoomId,
                        tempGameResult, -1, -1)

                    if rankRewards:
                        from dizhu.entity.matchhistory import MatchHistoryHandler
                        MatchHistoryHandler.onMatchOver(
                            player.userId,
                            player.matchInst.matchConf.recordId,
                            player.rank,
                            reason == MatchFinishReason.USER_WIN,
                            rankRewards.conf if rankRewards else None,
                            False,
                            player.mixId,
                            exchangeCode=exchangeCode)

                        matchRewardSwitch = WxShareControlHelper.getMatchRewardSwitch(
                        )
                        if matchRewardSwitch:
                            from dizhu.game import TGDizhu
                            rewardId = RewardAsyncHelper.genRewardId()
                            rewards = []
                            for rewardInfo in rankRewards.rewards:
                                rewards.append({
                                    'itemId': rewardInfo['itemId'],
                                    'count': rewardInfo['count']
                                })
                            playerMixId = int(
                                player.mixId) if player.mixId else None
                            TGDizhu.getEventBus().publishEvent(
                                UserRewardAsyncEvent(
                                    DIZHU_GAMEID,
                                    player.userId,
                                    REWARD_ASYNC_TYPE_AS_ARENA_MATCH,
                                    rewardId,
                                    rewards,
                                    matchId=playerMixId
                                    or player.matchInst.matchId,
                                    mixId=playerMixId or 0,
                                    rank=player.rank,
                                    sequence=int(
                                        player.matchInst.instId.split('.')[1]),
                                    roomName=roomName))

                    if not rankRewards:
                        matchutil.report_bi_game_event(
                            'MATCH_REWARD', player.userId,
                            player.matchInst.matchId, 0,
                            int(player.matchInst.instId.split('.')[1]), 0, 0,
                            0, [
                                0, 0, 0, player.rank,
                                int(player.mixId) if player.mixId else 0, 0
                            ], 'match_reward')

                except:
                    ftlog.error()

                # 比赛记录保存
                try:
                    event = {
                        'gameId': self._room.gameId,
                        'userId': player.userId,
                        'matchId': self._room.match.matchId,
                        'rank': player.rank,
                        'isGroup': 0,
                        'mixId': player.mixId
                    }
                    MatchRecord.updateAndSaveRecord(event)
                except:
                    ftlog.error()

            msg = MsgPack()
            msg.setCmd('m_over')
            msg.setResult('rewardId', rewardId)
            msg.setResult('mixId', player.mixId)
            msg.setResult('gameId', self._room.gameId)
            msg.setResult('roomId', self._room.bigRoomId)
            msg.setResult('userId', player.userId)
            msg.setResult('reason', reason)
            msg.setResult('rank', player.rank)
            msg.setResult('exchangeCode', exchangeCode)

            if rankRewards:
                msg.setResult('info', self.buildWinInfo(player, rankRewards))
            else:
                msg.setResult('info', self.buildLoserInfo(player))
            msg.setResult('mucount',
                          player.matchInst.matchConf.stages[0].totalUserCount)
            msg.setResult('date', str(datetime.now().date().today()))
            msg.setResult('time',
                          time.strftime('%H:%M', time.localtime(time.time())))
            msg.setResult('addInfo', '')
            rewardDesc = ''
            if rankRewards:
                msg.setResult('reward', matchutil.buildRewards(rankRewards))
                rewardDesc = matchutil.buildRewardsDesc(rankRewards)
                if rewardDesc:
                    msg.setResult('rewardDesc', rewardDesc)

            msg.setResult('mname', roomName)

            clientId = sessiondata.getClientId(player.userId)

            # 微信分享
            money = 0
            if rankRewards:
                for r in rankRewards.rewards:
                    if r['itemId'] == 'user:coupon':
                        assetKind = hallitem.itemSystem.findAssetKind(
                            'user:coupon')
                        displayRate = assetKind.displayRate
                        money = round(r['count'] * 1.0 / displayRate, 2)
            kwargs = {'matchRank': {'money': money % 100, 'stop': player.rank}}

            shareInfo = commconf.getNewShareInfoByCondiction(
                self._room.gameId, clientId)
            msg.setResult(
                'shareInfo',
                {'erweima': shareInfo['erweima'] if shareInfo else {}})

            try:
                # 玩家红包记录
                dizhushare.addMatchHistoryCount(self._room.bigRoomId,
                                                player.rank)
                userShareInfo = rankRewards.conf.get(
                    'shareInfo', {}) if rankRewards else {}
                rewardType, shareInfoNew = dizhushare.getArenaShareInfoNew(
                    player.userId, player.matchInst.matchConf.feeRewardList,
                    arenaContent, userShareInfo)
                if shareInfoNew:
                    msg.setResult('shareInfoNew', shareInfoNew)

                # 设置奖状分享的todotask diplomaShare
                matchShareType = 'arena' if rewardType == 'redEnvelope' else 'group'
                shareTodoTask = commconf.getMatchShareInfo(
                    player.userName, roomName, player.rank, rewardDesc,
                    player.userId, matchShareType, clientId)
                if shareTodoTask:
                    msg.setResult('shareTodoTask', shareTodoTask)

                if rankRewards:
                    bigImg = rankRewards.conf.get('bigImg', '')
                    if bigImg:
                        msg.setResult('bidImg', bigImg)

                msg.setResult('beatDownUser', player.beatDownUserName)
                if rankRewards and rankRewards.todotask:
                    msg.setResult('todotask', rankRewards.todotask)

                # 微信公众号消息
                if player.rank == 1:
                    from hall.game import TGHall
                    msgParams = {'reward': rewardDesc, 'roomName': roomName}
                    TGHall.getEventBus().publishEvent(
                        OfficialMessageEvent(DIZHU_GAMEID,
                                             player.userId,
                                             RED_ENVELOPE,
                                             msgParams,
                                             mixId=player.mixId))
                    if ftlog.is_debug():
                        ftlog.debug(
                            'MatchPlayerNotifierDizhu.notifyMatchOver.redEnvelopeEvent userId=',
                            player.userId, 'reward=', rewardDesc, 'rank=',
                            player.rank, 'roomName=', roomName)

                # 冠军触发抽奖逻辑
                match_lottery = MatchLottery()
                ret = match_lottery.checkMatchRank(player.userId,
                                                   self._room.match.matchId,
                                                   player.rank)
                if ret:
                    msg.setResult('match_lottery', 1)

                # 局间奖励总数
                if player.stageRewardTotal:
                    msg.setResult('stageReward',
                                  {'count': player.stageRewardTotal})

                if ftlog.is_debug():
                    ftlog.debug(
                        'MatchPlayerNotifierDizhu.notifyMatchOver userId=',
                        player.userId, 'roomId=', self._room.roomId, 'rank=',
                        player.rank, 'player=', player, 'stageRewardTotal=',
                        player.stageRewardTotal)

            except Exception, e:
                ftlog.error('notifyMatchOver.getArenaShareInfoNew', 'userId=',
                            player.userId, 'matchId=',
                            self._room.match.matchId, 'err=', e.message)

            record = MatchRecord.loadRecord(self._room.gameId, player.userId,
                                            self._room.match.matchId)
            if record:
                msg.setResult(
                    'mrecord', {
                        'bestRank': record.bestRank,
                        'lastBestRank': lastBestRank,
                        'bestRankDate': record.bestRankDate,
                        'isGroup': record.isGroup,
                        'crownCount': record.crownCount,
                        'playCount': record.playCount
                    })
            else:
                from dizhu.activities.toolbox import Tool
                msg.setResult(
                    'mrecord', {
                        'bestRank': player.rank,
                        'lastBestRank': lastBestRank,
                        'bestRankDate': Tool.datetimeToTimestamp(
                            datetime.now()),
                        'isGroup': 0,
                        'crownCount': 1 if player.rank == 1 else 0,
                        'playCount': 1
                    })

            if not player.isQuit:
                router.sendToUser(msg, player.userId)

            # 混房冠军LED
            mixId = player.mixId
            if mixId:
                mixConf = MatchPlayerNotifierDizhu.getArenaMixConf(
                    self._room.roomConf, mixId)
                if player.rank == 1 and mixConf.get('championLed'):
                    arenaContent = dizhuhallinfo.getArenaMatchProvinceContent(
                        player.userId,
                        int(mixId) if mixId else self._room.roomId, clientId)
                    if ftlog.is_debug():
                        ftlog.debug('MatchPlayerNotifierDizhu.notifyMatchOver',
                                    'userId=', player.userId, 'roomId=',
                                    self._room.roomId,
                                    'mixId=', mixId, 'roomName',
                                    mixConf.get('roomName'), 'rewardShow=',
                                    mixConf.get('rewardShow', rewardDesc),
                                    'mixConf=', mixConf)
                    # 冠军发送Led通知所有其他玩家
                    ledtext = dizhuled._mk_match_champion_rich_text(
                        player.userName,
                        arenaContent.get('name')
                        if arenaContent else mixConf.get('roomName'),
                        arenaContent.get('rewardShow') if arenaContent else
                        mixConf.get('rewardShow', rewardDesc))
                    LedUtil.sendLed(ledtext, 'global')
            else:
                if player.rank == 1 and self._room.roomConf.get(
                        'championLed') and not player.isQuit:
                    arenaContent = dizhuhallinfo.getArenaMatchProvinceContent(
                        player.userId,
                        int(mixId) if mixId else self._room.roomId, clientId)
                    # 冠军发送Led通知所有其他玩家
                    ledtext = dizhuled._mk_match_champion_rich_text(
                        player.userName,
                        arenaContent.get('name') if arenaContent else roomName,
                        arenaContent.get('rewardShow') if arenaContent else
                        self._room.roomConf.get('rewardShow', rewardDesc))
                    LedUtil.sendLed(ledtext, 'global')

            sequence = int(player.matchInst.instId.split('.')[1])
            matchutil.report_bi_game_event(
                'MATCH_FINISH', player.userId, player.matchInst.matchId, 0,
                sequence, 0, 0, 0,
                [int(player.mixId) if player.mixId else 255], 'match_end')