def _checkSendCondition(userId, gameId, eventId, timeStamp):
    startTime = configure.getGameJson(DIZHU_GAMEID, 'official.message',
                                      {}).get('startTime')
    stopTime = configure.getGameJson(DIZHU_GAMEID, 'official.message',
                                     {}).get('stopTime')
    start = datetime.datetime.strptime(startTime, "%H:%M").time()
    stop = datetime.datetime.strptime(stopTime, "%H:%M").time()
    now = datetime.datetime.now().time()
    if start >= stop or now < start or now > stop:
        if ftlog.is_debug():
            ftlog.debug('wx_official._checkSendCondition', 'userId=', userId,
                        'gameId=', gameId, 'start=', start, 'stop=', stop,
                        'now=', now, 'eventId=', eventId)
        return None, None
    hasSend = official_dao.getOfficialPushRecord(userId, gameId)
    if not hasSend:
        return 1, 'ok'
    hasSendAttrNames = [json.loads(i).keys()[0] for i in hasSend]
    hasSendTimes = [json.loads(i).values()[0] for i in hasSend]
    if not pktimestamp.is_same_day(timeStamp, hasSendTimes[-1]):
        return 1, None
    if timeStamp - hasSendTimes[-1] < 5 * 60:
        return None, 'ok'
    if len(hasSend) < 5:
        if eventId not in hasSendAttrNames:
            return 1, 'ok'
        if eventId in [PROMOTE, WITHDRAW, RED_ENVELOPE
                       ] and hasSendAttrNames.count(eventId) == 1:
            return 1, 'ok'
    return None, None
def getUserMatchDiscountCount(userId, bigRoomId, itemId):
    """获取用户针对特定房间特定itemId的折扣次数, 每天清零"""
    try:
        key = buildUserMatchDiscountKey(userId)
        ret = daobase.executeUserCmd(userId, 'HGET', key, bigRoomId)
        if ret:
            ret = json.loads(ret)
            if itemId in ret:
                timestamp = ret[itemId]['timestamp']
                currentTimestamp = pktimestamp.getCurrentTimestamp()
                if not pktimestamp.is_same_day(timestamp, currentTimestamp):
                    ret[itemId]['timestamp'] = currentTimestamp
                    ret[itemId]['count'] = 0
                    daobase.executeUserCmd(userId, 'HSET', key, bigRoomId, json.dumps(ret))
                if ftlog.is_debug():
                    ftlog.debug('match_signin_discount.getUserMatchDiscountCount',
                                'userId=', userId,
                                'bigRoomId=', bigRoomId,
                                'itemId=', itemId,
                                'count=', ret[itemId]['count'])
                return ret[itemId]['count']
        return 0
    except Exception, e:
        ftlog.error('match_signin_discount.getUserMatchSiginDiscountCount',
                    'userId=', userId,
                    'bigRoomId=', bigRoomId,
                    'itemId=', itemId,
                    'err=', e.message)
        return 0
示例#3
0
    def getWorshipRank(cls):
        """ 获取排行榜 """
        currentTimestamp = pktimestamp.getCurrentTimestamp()
        key = buildUserCostKey()
        first_updated_at = daobase.executeRePlayCmd('hget', key, 'first_updated_at') or currentTimestamp
        if pktimestamp.is_same_day(currentTimestamp, first_updated_at):
            ret = []
            key = buildWorshipRankKey()
            datas = daobase.executeRePlayCmd('zrevrange', key, 0, -1, 'withscores')
            if datas:
                for i in xrange(len(datas) / 2):
                    userId = int(datas[i * 2])
                    chip = int(datas[i * 2 + 1])
                    userName, purl = userdata.getAttrs(userId, ['name', 'purl'])
                    ret.append({'nickname': str(userName),
                                'img': purl,
                                'userId': userId,
                                'chip': chip,
                                'rank': i+1})

            return ret
        else:
            key = buildUserCostKey()
            clearUserCost()
            clearRankList()
            daobase.executeRePlayCmd('hset', key, 'first_updated_at', currentTimestamp)
            ftlog.info('WorshipHelper.getWorshipRank first_updated_at=', first_updated_at)
            return []
示例#4
0
 def check_reset(resettype, userid, actkey, data_field, time_field):
     oldtime = daobase.executeUserCmd(userid, 'HGET', actkey, time_field)
     curtime = timestamp.getCurrentTimestamp()
     if not oldtime or (resettype == 'day' and not timestamp.is_same_day(oldtime, curtime)):
         daobase.executeUserCmd(userid, 'HMSET', actkey, time_field, curtime, data_field, 0)
         return 0
     return daobase.executeUserCmd(userid, 'HGET', actkey, data_field)
示例#5
0
    def loadData(self):
        ''' 加载用户活跃度数据 '''
        expireDay, expireWeek = False, False
        jstr = daobase.executeUserCmd(
            self.userId, 'hget', 'actwx:%s:%s' % (DIZHU_GAMEID, self.userId),
            'active')
        if jstr:
            jdict = strutil.loads(jstr)
            userActiveData = self.decodeFromDict(jdict)
        else:
            userActiveData = self

        # 数据刷新
        if not userActiveData.activeDataWeek:
            userActiveData.activeDataWeek = ActiveDataWeek().decodeFromDict({})
        if not userActiveData.activeDataDay:
            userActiveData.activeDataDay = ActiveDataDay().decodeFromDict({})

        currentTimestamp = pktimestamp.getCurrentTimestamp()
        if not pktimestamp.is_same_week(
                userActiveData.activeDataWeek.timestamp, currentTimestamp):
            expireWeek = True
            userActiveData.activeDataWeek = ActiveDataWeek().decodeFromDict({})
            userActiveData.activeDataDay = ActiveDataDay().decodeFromDict({})
        if not pktimestamp.is_same_day(userActiveData.activeDataDay.timestamp,
                                       currentTimestamp):
            expireDay = True
            userActiveData.activeDataDay = ActiveDataDay().decodeFromDict({})

        if ftlog.is_debug():
            ftlog.debug('UserActiveData.loadData userId=',
                        userActiveData.userId, 'expireDay=', expireDay,
                        'expireWeek=', expireWeek, 'originDataStr=', jstr,
                        'data=', userActiveData.toDict())
        return userActiveData, expireDay, expireWeek
示例#6
0
def _checkSendCondition(userId, gameId, eventId, timeStamp, conf):
    startTime = configure.getGameJson(DIZHU_GAMEID, 'official.message',
                                      {}).get('startTime')
    stopTime = configure.getGameJson(DIZHU_GAMEID, 'official.message',
                                     {}).get('stopTime')
    start = datetime.datetime.strptime(startTime, "%H:%M").time()
    stop = datetime.datetime.strptime(stopTime, "%H:%M").time()
    now = datetime.datetime.now().time()
    if start >= stop or now < start or now > stop:
        if ftlog.is_debug():
            ftlog.debug('wx_official._checkSendCondition', 'userId=', userId,
                        'gameId=', gameId, 'start=', start, 'stop=', stop,
                        'now=', now, 'eventId=', eventId)
        return None, None
    hasSend = official_dao.getOfficialPushRecord(userId, gameId)
    if not hasSend:
        return 1, 'ok'
    hasSendAttrNames = [json.loads(i).keys()[0] for i in hasSend]
    hasSendTimes = [json.loads(i).values()[0] for i in hasSend]
    if not pktimestamp.is_same_day(timeStamp, hasSendTimes[-1]):
        return 1, None
    if timeStamp - hasSendTimes[-1] < conf.get('timeInterval'):
        return None, None
    if len(hasSend) < conf.get('dayTimes'):
        if hasSendAttrNames.count(
                eventId) < conf['templates'][eventId]['count']:
            return 1, 'ok'
    return None, None
示例#7
0
 def check_reset(self, resettype, userid, actkey, data_field, time_field):
     oldtime = daobase.executeUserCmd(userid, 'HGET', actkey, time_field)
     curtime = timestamp.getCurrentTimestamp()
     if not oldtime or (resettype == 'day' and not timestamp.is_same_day(oldtime, curtime)):
         daobase.executeUserCmd(userid, 'HMSET', actkey, time_field, curtime, data_field, 0)
         return 0
     return daobase.executeUserCmd(userid, 'HGET', actkey, data_field)
示例#8
0
    def onGameRoundFinish(cls, event):
        banConf = cls.getMatchBanConf()
        if not banConf.get("open"):
            return

        if ftlog.is_debug():
            ftlog.debug('BanHelper.onGameRoundFinish',
                        'tableId=', event.table.tableId,
                        'seats=', [(s.userId, s.seatId, s.status.isPunish, s.player.isQuit) for s in event.table.seats])
        for seat in event.table.seats:
            if hasattr(seat.player, 'mixId') and seat.player.mixId:
                roomId = int(seat.player.mixId)
            else:
                roomId = event.table.bigRoomId

            if seat.status.isTuoguan and not seat.player.isQuit and roomId in banConf.get('fromRooms', []):
                matchTuoguan = gamedata.getGameAttr(seat.userId, DIZHU_GAMEID, 'matchTuoguanCount')
                matchTuoguan = strutil.loads(matchTuoguan) if matchTuoguan else {}

                # 自然日清零
                currentTimestamp = pktimestamp.getCurrentTimestamp()
                if not pktimestamp.is_same_day(currentTimestamp, matchTuoguan.get('expired', pktimestamp.getCurrentTimestamp())):
                    matchTuoguan['expired'] = pktimestamp.getCurrentTimestamp()
                    matchTuoguan['count'] = 0

                if matchTuoguan.get('count'):
                    matchTuoguan['count'] += 1
                else:
                    matchTuoguan['count'] = 1

                banTime = cls.getTuoguanBanTime(matchTuoguan['count'], banConf)
                if banTime:
                    matchTuoguan['expired'] = banTime * 60 + pktimestamp.getCurrentTimestamp()
                gamedata.setGameAttr(seat.userId, DIZHU_GAMEID, 'matchTuoguanCount', strutil.dumps(matchTuoguan))
示例#9
0
def increaseUserPlayCount(issue, userId, bigRoomId, timestamp):
    """ 每天每个房间玩得局数 """
    try:
        key = buildUserPlayCountKey(issue)
        ret = daobase.executeRePlayCmd('hget', key, userId)
        if ret:
            ret = json.loads(ret)
            if not pktimestamp.is_same_day(timestamp, ret.get('timestamp')):
                daobase.executeRePlayCmd('hdel', key, userId)
                daobase.executeRePlayCmd(
                    'hset', key, userId,
                    json.dumps({
                        str(bigRoomId): 1,
                        'timestamp': timestamp
                    }))
            else:
                ret.setdefault(str(bigRoomId), 0)
                ret[str(bigRoomId)] = ret[str(bigRoomId)] + 1
                ret['timestamp'] = timestamp
                daobase.executeRePlayCmd('hset', key, userId, json.dumps(ret))
        else:
            daobase.executeRePlayCmd(
                'hset', key, userId,
                json.dumps({
                    str(bigRoomId): 1,
                    'timestamp': timestamp
                }))
    except Exception, e:
        ftlog.error('dizhu_red_envelope_bomb.increaseUserPlayCount', 'userId=',
                    userId, 'err=', e.message)
示例#10
0
 def fromDict(self, d):
     timestamp = d.get('timestamp', 0)
     if not pktimestamp.is_same_day(timestamp,
                                    pktimestamp.getCurrentTimestamp()):
         return self
     self.timestamp = timestamp
     self.watchCount = d.get('watchCount', 0)
     return self
def _processUserShareLoginEventImpl(evt):
    clientId = sessiondata.getClientId(evt.shareUserId)
    actList = ActivityWxHelper.getActivityList(evt.shareUserId, clientId)
    if ftlog.is_debug():
        ftlog.debug('activity_wx_share_charm._processUserShareLoginEventImpl',
                    'userId=', evt.userId, 'shareUserId=', evt.shareUserId,
                    'actList=', actList)
    for act in actList:
        if act['typeId'] == ActivityWxShareCharm.TYPE_ID:
            actId = act['actId']
            actInstance = ActivityWxHelper.findActivity(actId)
            if actInstance:
                if ftlog.is_debug():
                    ftlog.debug(
                        'activity_wx_share_charm._processUserShareLoginEventImpl',
                        'userId=', evt.userId, 'shareUserId=', evt.shareUserId,
                        'actInstance=', actInstance)
                # 判断用户是否已经帮助过别人了
                timestamp = pktimestamp.getCurrentTimestamp()
                userData = UserShareCharmData(evt.userId).loadUserData(actId)
                saveUserData = False
                if not pktimestamp.is_same_day(userData.timestamp, timestamp):
                    userData.timestamp = timestamp
                    userData.isShareLogin = 0
                    saveUserData = True

                if userData.isShareLogin == 0:
                    # 获取当前期号
                    shareUserData = UserShareCharmData(
                        evt.shareUserId).loadUserData(actId)
                    currentIssue = calculateCurrentIssue(
                        actInstance.settleDayOrWeek)
                    # 增加魅力值
                    totalCount = shareUserData.increaseCharm(currentIssue, 1)
                    shareUserData.saveUserData(actId)
                    # 插入排行榜
                    insertRankList(actId, currentIssue, evt.shareUserId,
                                   totalCount, actInstance.maxRankNum)

                    # 更新帮助用户信息
                    userData.isShareLogin = 1
                    saveUserData = True

                if saveUserData:
                    userData.saveUserData(actId)
                    name, _ = userdata.getAttrs(evt.shareUserId,
                                                ['name', 'purl'])
                    mo = MsgPack()
                    mo.setCmd('act_wx')
                    mo.setResult('action', 'share_charm_login')
                    mo.setResult('loginMsg', '感谢您帮助【%s】增加1点魅力值哦~' % name)
                    router.sendToUser(mo, evt.userId)

                    if ftlog.is_debug():
                        ftlog.debug(
                            'activity_wx_share_charm._processUserShareLoginEventImpl',
                            'userId=', evt.userId, 'shareUserId=',
                            evt.shareUserId, 'mo=', mo)
示例#12
0
 def needRefresh(self, status, timestamp):
     need = (self._autoRefresh and
             (not pktimestamp.is_same_day(status.lastRefreshTime, timestamp)
              or (not status.tasks and self._taskKindMap)))
     if ftlog.is_debug():
         ftlog.debug('QuweiTaskActivity.needRefresh', 'gameId=',
                     self.gameId, 'actId=', self.actId, 'userId=',
                     status.userId, 'need=', need, 'lastRefreshTime=',
                     status.lastRefreshTime)
     return need
示例#13
0
 def updateRewardIdInfo(cls, nowTimestamp):
     ''' ID 从 1000001 开始 '''
     timstamp = int(
         daobase.executeRePlayCmd('HGET', 'reward.id.number', 'timestamp')
         or 0)
     if not pktimestamp.is_same_day(nowTimestamp, timstamp):
         daobase.executeRePlayCmd('HSET', 'reward.id.number', 'number',
                                  1000000)
         daobase.executeRePlayCmd('HSET', 'reward.id.number', 'timestamp',
                                  nowTimestamp)
示例#14
0
    def is_old_task(cls, create_time):
        if (cls.is_testing and cls.change_delta_ts > 0
                and gdata.mode() in (2, 3, 4)):
            delta = cls.expire_ts - int(time.time())
            is_old = create_time < cls.expire_ts - cls.change_delta_ts
            if delta <= 0:
                cls.expire_ts += cls.change_delta_ts

            return is_old
        else:
            cls.is_testing = False
            return not pktimestamp.is_same_day(create_time, int(time.time()))
示例#15
0
def getUserPlayCount(issue, userId, bigRoomId, timestamp):
    """ 每天每个房间玩得局数 """
    try:
        key = buildUserPlayCountKey(issue)
        ret = daobase.executeRePlayCmd('hget', key, userId)
        if ret:
            ret = json.loads(ret)
            if ret.get('timestamp') and pktimestamp.is_same_day(
                    timestamp, ret.get('timestamp')):
                return ret.get(str(bigRoomId), 0)
        return 0
    except Exception, e:
        ftlog.error('dizhu_red_envelope_bomb.increaseUserPlayCount', 'userId=',
                    userId, 'err=', e.message)
示例#16
0
 def updateUserCost(cls, userId, cost):
     """更新用户花费"""
     # 每天一更新
     currentTimestamp = pktimestamp.getCurrentTimestamp()
     key = buildUserCostKey()
     first_updated_at = daobase.executeRePlayCmd('hget', key, 'first_updated_at') or currentTimestamp
     if pktimestamp.is_same_day(currentTimestamp, first_updated_at):
         userCost = saveUserCost(userId, cost)
         insertRankList(userId, userCost)
     else:
         clearUserCost()
         clearRankList()
         key = buildUserCostKey()
         daobase.executeRePlayCmd('hset', key, 'first_updated_at', currentTimestamp)
         ftlog.info('WorshipHelper.updateUserCost first_updated_at=', first_updated_at)
示例#17
0
    def _get_click_cnt(self, userid, actkey, curtime=None):
        if not curtime:
            curtime = pktimestamp.getCurrentTimestamp()
        oldtime = daobase.executeUserCmd(userid, 'HGET', actkey, self.FIELD_TIME)
        if oldtime:
            if pktimestamp.is_same_day(oldtime, curtime):
                return daobase.executeUserCmd(userid, 'HGET', actkey, self.FIELD_WEEK_CNT), \
                       daobase.executeUserCmd(userid, 'HGET', actkey, self.FIELD_DAY_CNT)

            daobase.executeUserCmd(userid, 'HMSET', actkey, self.FIELD_TIME, curtime, self.FIELD_DAY_CNT, 0)
            if pktimestamp.is_same_week(oldtime, curtime):
                return daobase.executeUserCmd(userid, 'HGET', actkey, self.FIELD_WEEK_CNT), 0

            daobase.executeUserCmd(userid, 'HSET', actkey, self.FIELD_WEEK_CNT, 0)
            return 0, 0

        daobase.executeUserCmd(userid, 'HMSET', actkey, self.FIELD_TIME, curtime, self.FIELD_DAY_CNT, 0,
                               self.FIELD_WEEK_CNT, 0)
        return 0, 0
示例#18
0
    def loadData(self):
        shareDataStr = gamedata.getGameAttr(self.userId, DIZHU_GAMEID,
                                            'userShareData')
        if not shareDataStr:
            self.dailyCount = 0
            self.totalCount = 0
            self.timestamp = pktimestamp.getCurrentTimestamp()
        else:
            shareDataDict = json.loads(shareDataStr)
            self.dailyCount = shareDataDict.get('dailyCount', 0)
            self.totalCount = shareDataDict.get('totalCount', 0)
            self.timestamp = shareDataDict.get('timestamp', 0)

        if not pktimestamp.is_same_day(self.timestamp,
                                       pktimestamp.getCurrentTimestamp()):
            self.dailyCount = 0
            self.timestamp = pktimestamp.getCurrentTimestamp()
            self.saveData()
        return self
示例#19
0
    def fromDict(self, d):
        '''
        从数据恢复邀请状态
        '''
        timestamp = d.get('timestamp', 0)
        if not pktimestamp.is_same_day(timestamp, pktimestamp.getCurrentTimestamp()):
            return self

        self.timestamp = timestamp
        self.inviterUserIdList = d.get('inviterUserIdList', [])

        self.inviteeRewardList = []
        inviteeRewardList = d.get('inviteeRewardList', [])
        for inviteeReward in inviteeRewardList:
            invitation = Invitation(inviteeReward['userId']).fromDict(inviteeReward)
            self.inviteeRewardList.append(invitation)

        self.bigRewardState = d.get('bigRewardState', REWARD_STATE_IDEAL)
        return self
示例#20
0
    def _onGameRoundFinish(self, event):
        if ftlog.is_debug():
            ftlog.debug('DailyPlayTimesTaskSystem._onGameRoundFinish',
                        'tableId=', event.table.tableId, 'seats=',
                        [(s.userId, s.seatId) for s in event.table.seats])

        if not self._taskList:
            return
        for sst in event.gameResult.seatStatements:
            playerTask = self.getPlayerTask(sst.seat.player.userId)
            if playerTask:
                playerTask.reward = None

                # 判断是否为当天, 不是归1, 是加1
                current_timestamp = pktimestamp.getCurrentTimestamp()
                if not pktimestamp.is_same_day(playerTask.timestamp,
                                               current_timestamp):
                    playerTask.dailyPlayTimes = 1
                else:
                    playerTask.dailyPlayTimes += 1
                playerTask.timestamp = current_timestamp

                self._sendUserDailyPlayTimes(self.room.roomId, playerTask)

                # 奖励金币逻辑
                if sst.isWin:
                    for reward in self._taskList:
                        if (playerTask.dailyPlayTimes >= reward['times'][0]
                            ) and (reward['times'][1] == -1
                                   or playerTask.dailyPlayTimes <=
                                   reward['times'][1]):
                            playerTask.reward = {
                                'itemId':
                                reward['itemId'],
                                'count':
                                reward['count']['dizhu']
                                if sst.isDizhu else reward['count']['nongmin']
                            }
                            self._sendDailyPlayTimesWinRewardsIfNeed(
                                event.table, playerTask,
                                sst.seat.player.clientId)
                            break
示例#21
0
    def _get_click_cnt(self, userid, actkey, curtime=None):
        if not curtime:
            curtime = pktimestamp.getCurrentTimestamp()
        oldtime = daobase.executeUserCmd(userid, 'HGET', actkey,
                                         self.FIELD_TIME)
        if oldtime:
            if pktimestamp.is_same_day(oldtime, curtime):
                return daobase.executeUserCmd(userid, 'HGET', actkey, self.FIELD_WEEK_CNT), \
                       daobase.executeUserCmd(userid, 'HGET', actkey, self.FIELD_DAY_CNT)

            daobase.executeUserCmd(userid, 'HMSET', actkey, self.FIELD_TIME,
                                   curtime, self.FIELD_DAY_CNT, 0)
            if pktimestamp.is_same_week(oldtime, curtime):
                return daobase.executeUserCmd(userid, 'HGET', actkey,
                                              self.FIELD_WEEK_CNT), 0

            daobase.executeUserCmd(userid, 'HSET', actkey, self.FIELD_WEEK_CNT,
                                   0)
            return 0, 0

        daobase.executeUserCmd(userid, 'HMSET', actkey, self.FIELD_TIME,
                               curtime, self.FIELD_DAY_CNT, 0,
                               self.FIELD_WEEK_CNT, 0)
        return 0, 0
示例#22
0
def is_today_daily_task(create_time):
    return pktimestamp.is_same_day(create_time, int(time.time()))
示例#23
0
 def isSameCycle(self, ts1, ts2):
     '''
     判断ts1和ts2是否属于同一个周期
     '''
     return pktimestamp.is_same_day(ts1, ts2)
示例#24
0
def doGoldLottery(userId, gameId, clientId, number):
    '''
        金盘抽奖
    '''
    if number <= 0 or number > 50:
        ftlog.error(
            'doGoldLottery number best be > 0 or <= 50, the msg is fake')
        return

    if ftlog.is_debug():
        ftlog.debug('hallroulette.doGoldLottery userId:', userId, ' gameId:',
                    gameId, ' clientId:', clientId, ' number:', number)

    # 添加关于部分情况下每日抽奖次数限制的功能
    addLottoryNum = 0  # 0:初始值 1:增加数量1或者隔天后重新开始,初值设置为1
    #add50LottoryOrReset = 0  # 0:初始值 1:增加数量1或者隔天后重新开始,初值设置为1
    now_time = pktimestamp.getCurrentTimestamp()

    isSuitableClient = isSuitableClientID(userId, gameId, clientId)
    if isSuitableClient:
        tempResult = getWeightConfTemplate(userId, gameId, clientId)
        lastDoLottoryTime = pkgamedata.getGameAttrInt(userId, HALL_GAMEID,
                                                      'LastDoLottoryTime')

        if not pktimestamp.is_same_day(now_time, lastDoLottoryTime):
            resetDailyRouletteData(userId, now_time)

        if 10 == number:
            dailyDo10LottoryNum = pkgamedata.getGameAttrInt(
                userId, HALL_GAMEID, 'Do10LottoryNum')
            do10LottoryMaxTimes = tempResult.get('roulette_10_max_daily_num',
                                                 1000)
            if dailyDo10LottoryNum >= do10LottoryMaxTimes:
                ftlog.debug(
                    'hallroulette.doGoldLottery dailyDo10LottoryNum >= do10LottoryMaxTimes, beyond max limit',
                    'dailyDo10LottoryNum', dailyDo10LottoryNum,
                    'do10LottoryMaxTimes', do10LottoryMaxTimes)
                return reach10MaxTimes()
            else:
                addLottoryNum = 1

        if 50 == number:
            dailyDo50LottoryNum = pkgamedata.getGameAttrInt(
                userId, HALL_GAMEID, 'Do50LottoryNum')
            do50LottoryMaxTimes = tempResult.get('roulette_50_max_daily_num',
                                                 1000)
            if dailyDo50LottoryNum >= do50LottoryMaxTimes:
                ftlog.debug(
                    'hallroulette.doGoldLottery dailyDo50LottoryNum >= do50LottoryMaxTimes, beyond max limit',
                    'dailyDo50LottoryNum', dailyDo50LottoryNum,
                    'do50LottoryMaxTimes', do50LottoryMaxTimes)
                return reach50MaxTimes()
            else:
                addLottoryNum = 1

    # 减少钻石
    result = {}
    count = -(number * 20)
    trueDelta, _finalCount = userchip.incrDiamond(
        userId, gameId, count, daoconst.CHIP_NOT_ENOUGH_OP_MODE_NONE,
        'HALL_ROULETTE', 0, 0)
    if not trueDelta:
        # 消费失败
        return toShop()

    #在扣除砖石后做每日抽奖次数限制的功能的数值设定0
    if isSuitableClient:
        tempResult = getWeightConfTemplate(userId, gameId, clientId)
        if 1 == addLottoryNum:
            if 10 == number:
                pkgamedata.incrGameAttr(userId, HALL_GAMEID, 'Do10LottoryNum',
                                        1)
                pkgamedata.setGameAttr(userId, HALL_GAMEID,
                                       'LastDoLottoryTime', now_time)
            if 50 == number:
                pkgamedata.incrGameAttr(userId, HALL_GAMEID, 'Do50LottoryNum',
                                        1)
                pkgamedata.setGameAttr(userId, HALL_GAMEID,
                                       'LastDoLottoryTime', now_time)

        result['10lottoryNum'] = pkgamedata.getGameAttrInt(
            userId, HALL_GAMEID, 'Do10LottoryNum')
        result['50lottoryNum'] = pkgamedata.getGameAttrInt(
            userId, HALL_GAMEID, 'Do50LottoryNum')
        result['10MaxNum'] = tempResult.get('roulette_10_max_daily_num', 1000)
        result['50MaxNum'] = tempResult.get('roulette_50_max_daily_num', 1000)
        ftlog.debug('after change diamond, roulette limit data, 10lottoryNum',
                    result['10lottoryNum'], '50lottoryNum',
                    result['50lottoryNum'], '10MaxNum', result['10MaxNum'],
                    '50MaxNum', result['50MaxNum'])

    #将抽奖数进行存储,满足bigRewardNumber,使用大奖概率,否则使用小奖概率
    addBigRewardToPool(userId, gameId, clientId, number)
    # 抽奖
    items = []
    for _num in range(0, number):
        items.append(doRouletteLottery(userId, gameId, clientId))

    result['items'] = items
    #对抽奖进行修改,连抽的话进行统一的数据库操作
    sendGiftsToUser(userId, gameId, clientId, items)
    #更新钻石
    datachangenotify.sendDataChangeNotify(gameId, userId, ['udata'])
    #抽奖成功,进行小兵的下发
    for _ in range(0, number):
        daobase.executeMixCmd('RPUSH', CURKEY, userId)

    #统计需求
    ftlog.hinfo('doGoldLottery.userId=', userId, 'gameId=', gameId,
                'clientId=', clientId, 'number=', number, 'rouletteType=', 2,
                'rewardItem=', items)
    TGHall.getEventBus().publishEvent(
        TYEventRouletteDiamond(userId, gameId, number))
    return result
示例#25
0
 def adjust(self, model, timestamp):
     if not pktimestamp.is_same_day(timestamp, model.lastFinishTime):
         model.lastFinishTime = timestamp
         model.finishCount = 0
     return model
示例#26
0
    def _doReport(cls, gameId, userId, otherPlayerId, reasons):
        mo = MsgPack()
        mo.setCmd('dizhu')
        mo.setResult('action', 'user_report')
        # 检测举报条件
        reportDetail = gamedata.getGameAttr(userId, gameId, 'report')
        reportDetail = strutil.loads(reportDetail) if reportDetail else {}
        reportCount = reportDetail.setdefault('count', 0)
        reportTimestamp = reportDetail.setdefault('timestamp', 1356969600)
        currentTimestamp = pktimestamp.getCurrentTimestamp()

        if not pktimestamp.is_same_day(currentTimestamp, reportTimestamp):
            reportDetail['count'] = 0
        else:
            if reportCount >= 10:
                mo.setError(1, '举报过于频繁,系统正在核实举报信息')
                router.sendToUser(mo, userId)
                return

            if currentTimestamp - reportTimestamp < 180:
                mo.setError(2, '举报过于频繁,系统正在核实举报信息')
                mo.setResult('remaining',
                             180 - (currentTimestamp - reportTimestamp))
                router.sendToUser(mo, userId)
                return

        # 发送消息给举报者, 增加举报者举报次数
        reportDetail['count'] += 1
        reportDetail['timestamp'] = currentTimestamp
        gamedata.setGameAttr(userId, gameId, 'report',
                             strutil.dumps(reportDetail))
        reportStr = ''
        for reason in reasons:
            reportStr += cls._getTipByReason(reason)
        tip = '举报反馈:\n  您举报了玩家【%s】。\n  我们会核实原因,进行相应处理。' % (
            UserInfo.getNickname(otherPlayerId))
        mo.setResult('success', 1)
        mo.setResult('tip', tip)
        router.sendToUser(mo, userId)
        pkmessage.send(gameId, pkmessage.MESSAGE_TYPE_SYSTEM, userId, tip)

        # 发送消息给被举报者,只有在原因①/③的情况下,被举报玩家才会收到信息,若被举报玩家同时因①③被举报,则优先使用①的被举报文本。
        # 增加被举报者举报次数
        reportedDetail = gamedata.getGameAttr(otherPlayerId, gameId,
                                              'reported')
        reportedDetail = strutil.loads(
            reportedDetail) if reportedDetail else {}
        reportedDetail.setdefault('count', 0)

        for r in reasons:
            if r in [UserReportReason.NEGATIVE, UserReportReason.OFFLINE]:
                reportedDetail['count'] += 1
                if not pktimestamp.is_same_day(currentTimestamp,
                                               reportTimestamp):
                    reportedDetail.setdefault(str(r), 0)
                    reportedDetail[str(r)] = 0
                else:
                    reportedDetail.setdefault(str(r), 0)
                    reportedDetail[str(r)] += 1
        gamedata.setGameAttr(otherPlayerId, gameId, 'reported',
                             strutil.dumps(reportedDetail))

        tip = ''
        if UserReportReason.NEGATIVE in reasons:
            tip = '举报信息:\n  您因<%s>被玩家举报。\n  系统已记录,下次要认真一些喔~' % cls._getTipByReason(
                UserReportReason.NEGATIVE)
            if reportedDetail.setdefault(str(UserReportReason.NEGATIVE),
                                         0) > 5:
                tip = ''

        if UserReportReason.OFFLINE in reasons:
            if reportedDetail.setdefault(str(UserReportReason.OFFLINE), 0) > 5:
                tip = tip
            else:
                tip = '举报信息:\n  您因<%s>被玩家举报。\n  快去找一个好的网络环境吧~' % cls._getTipByReason(
                    UserReportReason.OFFLINE)

        if tip:
            pkmessage.send(gameId, pkmessage.MESSAGE_TYPE_SYSTEM,
                           otherPlayerId, tip)