Exemple #1
0
    def doGetPrize(self, gameId, userId, clientId):
        try:
            timestamp = pktimestamp.getCurrentTimestamp()
            status = neituiguang.loadStatus(userId, timestamp)
            if not status.isBindMobile:
                conf = neituiguang.getConf()
                TodoTaskHelper.sendTodoTask(
                    gameId, userId, TodoTaskBindPhone(conf.pleaseBindPhone,
                                                      ''))
                return
            count, assetList = neituiguang.getAllReward(status)
            if count > 0:
                conf = neituiguang.getConf()
                prizeRewardTips = strutil.replaceParams(
                    conf.prizeRewardTips, {
                        'rewardContent':
                        TYAssetUtils.buildContentsString(assetList)
                    })
                TodoTaskHelper.sendTodoTask(gameId, userId,
                                            TodoTaskGoldRain(prizeRewardTips))

                mo = self.buildQueryPrizeResponse(gameId, userId, clientId)
                router.sendToUser(mo, userId)
            else:
                TodoTaskHelper.sendTodoTask(gameId, userId,
                                            TodoTaskShowInfo('奖励已经领取', True))
            datachangenotify.sendDataChangeNotify(gameId, userId,
                                                  ['free', 'promotion_loc'])
        except TYBizException, e:
            TodoTaskHelper.sendTodoTask(gameId, userId,
                                        TodoTaskShowInfo(e.message, True))
Exemple #2
0
    def doGetTaskReward(self, gameId, userId, taskId):
        '''
        获取活动奖励
        '''
        try:
            timestamp = pktimestamp.getCurrentTimestamp()
            taskModel = neituiguangtask.newUserTaskSystem.loadTaskModel(
                userId, timestamp)
            task = taskModel.userTaskUnit.findTask(taskId)
            if not task:
                raise TYBizException(-1, '未知的任务:%s' % (taskId))
            expiresTime = self.calcTaskExpires(userId)
            if timestamp >= expiresTime:
                raise TYBizException(-1, '任务已经过期')
            if not userdata.getAttr(userId, 'bindMobile'):
                conf = neituiguang.getConf()
                TodoTaskHelper.sendTodoTask(
                    gameId, userId, TodoTaskBindPhone(conf.pleaseBindPhone,
                                                      ''))
                return
            assetList = neituiguangtask.newUserTaskSystem.getTaskReward(
                task, timestamp, 'PROMOTE_TASK', taskId)
            router.sendToUser(self.buildTaskInfoResponse(userId), userId)

            rewardStr = TYAssetUtils.buildContentsString(assetList)
            mo = MsgPack()
            mo.setCmd('promote_info')
            mo.setResult('action', 'get_task_reward')
            mo.setResult('code', 0)
            mo.setResult('info', '恭喜您获得了%s' % rewardStr)
            router.sendToUser(mo, userId)
        except TYBizException, e:
            router.sendToUser(
                self.makeErrorResponse('get_task_reward', e.errorCode,
                                       e.message), userId)
    def doGetTaskReward(self, gameId, userId, taskId):
        '''
        获取活动奖励
        '''
        try:
            timestamp = pktimestamp.getCurrentTimestamp()
            taskModel = neituiguangtask.newUserTaskSystem.loadTaskModel(userId, timestamp)
            task = taskModel.userTaskUnit.findTask(taskId)
            if not task:
                raise TYBizException(-1, '未知的任务:%s' % (taskId))
            expiresTime = self.calcTaskExpires(userId)
            if timestamp >= expiresTime:
                raise TYBizException(-1, '任务已经过期')
            if not userdata.getAttr(userId, 'bindMobile'):
                conf = neituiguang.getConf()
                TodoTaskHelper.sendTodoTask(gameId, userId, TodoTaskBindPhone(conf.pleaseBindPhone, ''))
                return
            assetList = neituiguangtask.newUserTaskSystem.getTaskReward(task, timestamp, 'PROMOTE_TASK', taskId)
            router.sendToUser(self.buildTaskInfoResponse(userId), userId)

            rewardStr = TYAssetUtils.buildContentsString(assetList)
            mo = MsgPack()
            mo.setCmd('promote_info')
            mo.setResult('action', 'get_task_reward')
            mo.setResult('code', 0)
            mo.setResult('info', '恭喜您获得了%s' % rewardStr)
            router.sendToUser(mo, userId)
        except TYBizException, e:
            router.sendToUser(self.makeErrorResponse('get_task_reward', e.errorCode, e.message), userId)
Exemple #4
0
    def buildQueryPrizeResponse(cls, gameId, userId, clientId):
        timestamp = pktimestamp.getCurrentTimestamp()
        conf = neituiguang.getConf()
        status = neituiguang.loadStatus(userId, timestamp)
        totalRewardCount = cls.calcTotalInvitationByState(
            status, Invitation.STATE_REWARD)
        availableRewardCount = cls.calcTotalInvitationByState(
            status, Invitation.STATE_ACCEPT)
        mo = MsgPack()
        mo.setCmd('promote_info')
        mo.setResult('action', 'query_prize')
        mo.setResult('detail', conf.prizeDetail)
        mo.setResult('imgUrl', conf.prizeImgUrl)
        mo.setResult('promoteCode', userId)

        shareId = hallshare.getShareId('neituiguang2', userId, gameId)
        share = hallshare.findShare(shareId)
        if share:
            mo.setResult('shareId', shareId)
            mo.setResult('shareLoc', conf.shareLoc)
            mo.setResult('weixinInviteDoc', share.getDesc(HALL_GAMEID, userId))
            mo.setResult('weixinInviteUrl', share.getUrl(HALL_GAMEID, userId))
            mo.setResult('smsInviteDoc', share.getSmsDesc(HALL_GAMEID, userId))

        totalRewardContent = ''
        if conf.prizeRewardItem:
            totalRewardContent = hallitem.buildContent(
                conf.prizeRewardItem.assetKindId,
                conf.prizeRewardItem.count * totalRewardCount)
        prizeGetedInfo = conf.prizeGotTotalRewardDesc if conf.prizeRewardItem and totalRewardCount else conf.prizeNotGotRewardDesc
        prizeGetedInfo = strutil.replaceParams(
            prizeGetedInfo, {'totalRewardContent': totalRewardContent})
        mo.setResult('prizeGetedInfo', prizeGetedInfo)

        availableRewardContent = ''
        if conf.prizeRewardItem:
            availableRewardContent = hallitem.buildContent(
                conf.prizeRewardItem.assetKindId,
                conf.prizeRewardItem.count * availableRewardCount)
        prizeAvailableInfo = conf.prizeAvailableRewardDesc if conf.prizeRewardItem else conf.prizeAvailableRewardDesc
        prizeAvailableInfo = strutil.replaceParams(
            prizeAvailableInfo,
            {'availableRewardContent': availableRewardContent})
        mo.setResult('prizeAvailableInfo', prizeAvailableInfo)

        prizeList = []
        invitationList = sorted(status.inviteeMap.values(),
                                key=lambda i: i.index)
        for invitation in invitationList:
            prizeList.append(cls.encodeInvitation(invitation))
        mo.setResult('prizeList', prizeList)
        mo.setResult('state', 1 if availableRewardCount > 0 else 0)
        return mo
    def doGetPrize(self, gameId, userId, clientId):
        try:
            timestamp = pktimestamp.getCurrentTimestamp()
            status = neituiguang.loadStatus(userId, timestamp)
            if not status.isBindMobile:
                conf = neituiguang.getConf()
                TodoTaskHelper.sendTodoTask(gameId, userId, TodoTaskBindPhone(conf.pleaseBindPhone, ''))
                return
            count, assetList = neituiguang.getAllReward(status)
            if count > 0:
                conf = neituiguang.getConf()
                prizeRewardTips = strutil.replaceParams(conf.prizeRewardTips,
                                                        {'rewardContent': TYAssetUtils.buildContentsString(assetList)})
                TodoTaskHelper.sendTodoTask(gameId, userId, TodoTaskGoldRain(prizeRewardTips))

                mo = self.buildQueryPrizeResponse(gameId, userId, clientId)
                router.sendToUser(mo, userId)
            else:
                TodoTaskHelper.sendTodoTask(gameId, userId, TodoTaskShowInfo('奖励已经领取', True))
            datachangenotify.sendDataChangeNotify(gameId, userId, ['free', 'promotion_loc'])
        except TYBizException, e:
            TodoTaskHelper.sendTodoTask(gameId, userId, TodoTaskShowInfo(e.message, True))
 def buildTaskInfoResponse(cls, userId):
     '''
     获取红包任务/新手任务应答
     '''
     timestamp = pktimestamp.getCurrentTimestamp()
     taskModel = neituiguangtask.newUserTaskSystem.loadTaskModel(userId, timestamp)
     tasks = [cls.encodeTask(task) for task in taskModel.userTaskUnit.taskList]
     tasks.sort(key=lambda t: t['id'])
     conf = neituiguang.getConf()
     mo = MsgPack()
     mo.setCmd('promote_info')
     mo.setResult('action', 'query_task_info')
     mo.setResult('tasks', tasks)
     mo.setResult('finalTimestamp', cls.calcTaskExpires(userId))
     mo.setResult('detail', conf.taskDetail)
     return mo
    def buildQueryPrizeResponse(cls, gameId, userId, clientId):
        timestamp = pktimestamp.getCurrentTimestamp()
        conf = neituiguang.getConf()
        status = neituiguang.loadStatus(userId, timestamp)
        totalRewardCount = cls.calcTotalInvitationByState(status, Invitation.STATE_REWARD)
        availableRewardCount = cls.calcTotalInvitationByState(status, Invitation.STATE_ACCEPT)
        mo = MsgPack()
        mo.setCmd('promote_info')
        mo.setResult('action', 'query_prize')
        mo.setResult('detail', conf.prizeDetail)
        mo.setResult('imgUrl', conf.prizeImgUrl)
        mo.setResult('promoteCode', userId)

        shareId = hallshare.getShareId('neituiguang2', userId, gameId)
        share = hallshare.findShare(shareId)
        if share:
            mo.setResult('shareId', shareId)
            mo.setResult('shareLoc', conf.shareLoc)
            mo.setResult('weixinInviteDoc', share.getDesc(HALL_GAMEID, userId))
            mo.setResult('weixinInviteUrl', share.getUrl(HALL_GAMEID, userId))
            mo.setResult('smsInviteDoc', share.getSmsDesc(HALL_GAMEID, userId))

        totalRewardContent = ''
        if conf.prizeRewardItem:
            totalRewardContent = hallitem.buildContent(conf.prizeRewardItem.assetKindId,
                                                       conf.prizeRewardItem.count * totalRewardCount)
        prizeGetedInfo = conf.prizeGotTotalRewardDesc if conf.prizeRewardItem and totalRewardCount else conf.prizeNotGotRewardDesc
        prizeGetedInfo = strutil.replaceParams(prizeGetedInfo, {'totalRewardContent': totalRewardContent})
        mo.setResult('prizeGetedInfo', prizeGetedInfo)

        availableRewardContent = ''
        if conf.prizeRewardItem:
            availableRewardContent = hallitem.buildContent(conf.prizeRewardItem.assetKindId,
                                                           conf.prizeRewardItem.count * availableRewardCount)
        prizeAvailableInfo = conf.prizeAvailableRewardDesc if conf.prizeRewardItem else conf.prizeAvailableRewardDesc
        prizeAvailableInfo = strutil.replaceParams(prizeAvailableInfo,
                                                   {'availableRewardContent': availableRewardContent})
        mo.setResult('prizeAvailableInfo', prizeAvailableInfo)

        prizeList = []
        invitationList = sorted(status.inviteeMap.values(), key=lambda i: i.index)
        for invitation in invitationList:
            prizeList.append(cls.encodeInvitation(invitation))
        mo.setResult('prizeList', prizeList)
        mo.setResult('state', 1 if availableRewardCount > 0 else 0)
        return mo
Exemple #8
0
 def buildTaskInfoResponse(cls, userId):
     '''
     获取红包任务/新手任务应答
     '''
     timestamp = pktimestamp.getCurrentTimestamp()
     taskModel = neituiguangtask.newUserTaskSystem.loadTaskModel(
         userId, timestamp)
     tasks = [
         cls.encodeTask(task) for task in taskModel.userTaskUnit.taskList
     ]
     tasks.sort(key=lambda t: t['id'])
     conf = neituiguang.getConf()
     mo = MsgPack()
     mo.setCmd('promote_info')
     mo.setResult('action', 'query_task_info')
     mo.setResult('tasks', tasks)
     mo.setResult('finalTimestamp', cls.calcTaskExpires(userId))
     mo.setResult('detail', conf.taskDetail)
     return mo