Exemple #1
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
Exemple #2
0
    def sendLedText(self, activityGameId, userId, prize):
        ledsMap = Tool.dictGet(self._clientConf, 'config.server.ledsMap', {})
        prizes = Tool.dictGet(self._clientConf, 'config.server.prizes', [])

        for item in prizes:
            # 根据奖励itemId找到奖励配置
            if item['itemId'] != prize['itemId']:
                continue
            # 获取led发送的配置
            ledItem = ledsMap.get(item.get('ledKey'))
            if not ledItem:
                continue
            # 查看是否满足LED发送条件
            if ledItem.get('minCount', 0) > prize['count']:
                continue
            text = ledItem.get('text')
            if not text:
                continue
            prizeContent = hallitem.buildContent(prize['itemId'],
                                                 prize['count'], True)
            ledtext = strutil.replaceParams(
                text, {
                    'nickname': UserInfo.getNickname(userId),
                    'prizeContent': prizeContent
                })
            hallled.sendLed(activityGameId, ledtext, 0, scope='hall6')
            if ftlog.is_debug():
                ftlog.debug('LuckyMoneyNew.sendLedText', 'activityGameId=',
                            activityGameId, 'activityId=',
                            self._clientConf['id'], 'userId=', userId,
                            'ledtext=', ledtext)
            break
    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 #4
0
 def sendPrizeToUser(self, userId, prizeList, mail):
     counter = 0
     for prize in prizeList:
         prizeContent = hallitem.buildContent(prize['itemId'], prize['count'], True)
         mailmessage = strutil.replaceParams(mail, {'prizeContent': prizeContent})
         UserBag.sendAssetsToUser(DIZHU_GAMEID, userId, prize, 'ACT_TABLE_REPLAY_RANKING_PRIZE', mailmessage, 0)
         ftlog.info('TableReplayRanking.sendPrizeToUser',
                    'userId=', userId,
                    'prize=', prize)
         counter += prize['count']
     return counter
    def message(cls, prize):
        lrewards = ['恭喜您获得']
        for key, value in prize.items():
            if key == "CHIP" and value:
                lrewards.append('%s金、' % value)
            elif key == "COUPON" and value:
                lrewards.append('%s、' %
                                (hallitem.buildContent('user:coupon', value)))
        message = ''.join(lrewards)

        return message.rstrip('、') + '的邀请奖励!'
Exemple #6
0
 def sendPrizeToUser(self, userId):
     if ftlog.is_debug():
         ftlog.debug('TableShareRecorder.sendPrizeToUser', 'userId=',
                     userId, 'prizeList=', self.prizeList)
     for prize in self.prizeList:
         prizeContent = hallitem.buildContent(prize['itemId'],
                                              prize['count'], True)
         mail = strutil.replaceParams(self.mail,
                                      {'prizeContent': prizeContent})
         UserBag.sendAssetsToUser(DIZHU_GAMEID, userId, prize,
                                  'ACTIVITY_REWARD', mail, self.intActId)
         ftlog.info('TableShareRecorder.sendPrizeToUser', 'userId=', userId,
                    'prize=', prize)
Exemple #7
0
 def sendPrizeToUser(self, activityGameId, userId, prize, mail):
     prizeContent = hallitem.buildContent(prize['itemId'], prize['count'],
                                          True)
     mailmessage = strutil.replaceParams(mail,
                                         {'prizeContent': prizeContent})
     _, addcount, _ = UserBag.sendAssetsToUser(activityGameId, userId,
                                               prize, self.EVENT_ID,
                                               mailmessage, 0)
     if ftlog.is_debug():
         ftlog.debug('LuckyMoneyNew.sendPrizeToUser', 'activityGameId=',
                     activityGameId, 'userId=', userId, 'prize=', prize,
                     'addcount=', addcount)
     return addcount
Exemple #8
0
    def onEventTableShare(self, event):
        if ftlog.is_debug():
            ftlog.debug('LuckyMoneyNew.onEventTableShare:'
                        'event=', event, 'event.shareid=', event.shareid)
        activityId = self._clientConf['id']
        shareId = self._clientConf['config']['server']['shareId']
        if event.shareid == shareId:
            currentDuration = self.openList.getCurrentDurationItem()
            if currentDuration:
                issueNumber = currentDuration.getIssueNumber()
                usermodel = UserModel.loadModel(self.activityGameId,
                                                activityId, event.userId)
                # 此期抽奖没有分享过并且已经抢过红包,才算分享成功且给其发奖
                if (not usermodel.hadShared(issueNumber)
                    ) and usermodel.hadGrabbed(issueNumber):
                    sharePrize = self._clientConf['config']['server'][
                        'sharePrize']
                    shareMail = self._clientConf['config']['server'][
                        'shareMail']
                    prizeContent = hallitem.buildContent(
                        sharePrize['itemId'], sharePrize['count'], True)
                    shareMail = strutil.replaceParams(
                        shareMail, {'prizeContent': prizeContent})
                    self.sendPrizeToUser(self.activityGameId, event.userId,
                                         sharePrize, shareMail)

                    usermodel.setShared(issueNumber, sharePrize)
                    usermodel.save(self.activityGameId, activityId,
                                   event.userId)

                    # 给客户端主动推送最新的活动信息
                    activityInfo = self.buildActivityInfo(
                        event.userId, usermodel)
                    mo = ActivityTcpHelper.getOldResponseMsg(
                        activityInfo, event.gameId, event.userId, activityId,
                        self.ACTION_UPDATE)
                    router.sendToUser(mo, event.userId)

            ftlog.info('LuckyMoneyNew.onEventTableShare:'
                       'activityGameId=', self.activityGameId, 'shareid=',
                       event.shareid, 'activityId=', activityId, 'userId=',
                       event.userId, 'issueNumber=', currentDuration
                       and currentDuration.getIssueNumber())
Exemple #9
0
 def _sendAuthReawrd(cls, userId):
     """发送认证奖励"""
     assets = cls.getConf('auth_reward')
     if ftlog.is_debug():
         ftlog.debug('PlayerControl._sendAuthReawrd', 'userId=', userId,
                     'assets=', assets)
     if assets:
         contentItems = [{
             'itemId': assets.get('itemId'),
             'count': assets.get('count')
         }]
         if user_remote.addAssets(DIZHU_GAMEID, userId, contentItems,
                                  'ERDAYI_AUTH_REWARD', 0):
             ftlog.info('PlayerControl._sendAuthReawrd Succ', 'userId=',
                        userId, 'assets=', assets)
             rewardDesc = hallitem.buildContent(assets.get('itemId'),
                                                assets.get('count'), False)
             mail = strutil.replaceParams(cls.getConf('auth_reward_mail'),
                                          {'reward_desc': rewardDesc})
             pkmessage.sendPrivate(9999, userId, 0, mail)
             cls.sendPopTip(userId, mail)
         else:
             ftlog.warn('PlayerControl._sendAuthReawrd Fail', 'userId=',
                        userId, 'assets=', assets)
Exemple #10
0
    def exchangeCouponItem(self, userId, couponId, **kwargs):
        couponItem = self.findCouponItem(couponId)
        if not couponItem:
            if ftlog.is_debug():
                ftlog.debug('CouponService.exchangeCouponItem userId=', userId,
                            'couponId=', couponId, 'kwargs=', kwargs,
                            'gameId=', self.gameId, 'coupons=',
                            self._couponItemMap.keys())
            raise TYBizException(-1, 'Not found couponId %s' % (couponId))

        if (couponItem.itemType == CouponItem.TYPE_PHONE_CARD
                and not kwargs.get('phone')):
            # 检查chargePhone参数
            raise TYBizException(-1, 'Please input phone number')

        # 减奖券
        trueDelta, final = pkuserchip.incrCoupon(
            userId, self.gameId, -couponItem.couponCount,
            pkdaoconst.CHIP_NOT_ENOUGH_OP_MODE_NONE, 0, 0, 0)
        if -trueDelta < couponItem.couponCount:
            raise TYBizException(-1, 'Coupon not enough')

        costContent = hallitem.buildContent('user:coupon',
                                            couponItem.couponCount)

        if couponItem.itemType == CouponItem.TYPE_PHONE_CARD:
            phone = kwargs.get('phone')
            isCtyOk = sdkclient.couponCharge(self.gameId, userId, phone, '',
                                             '', couponItem.couponCount,
                                             couponItem.itemCount)
            if isCtyOk:
                mail = couponItem.mailOk
            else:
                mail = couponItem.mailFail
            if mail:
                mail = strutil.replaceParams(
                    mail, {
                        'costContent': costContent,
                        'couponCount': str(couponItem.couponCount),
                        'itemCount': str(couponItem.itemCount),
                        'itemName': couponItem.itemName,
                        'phone': phone,
                        'qqGroup': self._qqGroup
                    })
                pkmessage.send(HALL_GAMEID, pkmessage.MESSAGE_TYPE_SYSTEM,
                               userId, mail)
                datachangenotify.sendDataChangeNotify(HALL_GAMEID, userId,
                                                      'message')
        elif couponItem.itemType == CouponItem.TYPE_ID_CHIP:
            pkuserchip.incrChip(userId, self.gameId, couponItem.itemCount,
                                pkdaoconst.CHIP_NOT_ENOUGH_OP_MODE_NONE, 0, 0,
                                0)
            mail = couponItem.mailOk
            if mail:
                mail = strutil.replaceParams(
                    mail, {
                        'costContent': costContent,
                        'couponCount': str(couponItem.couponCount),
                        'itemCount': str(couponItem.itemCount),
                        'itemName': couponItem.itemName,
                        'qqGroup': self._qqGroup
                    })
                pkmessage.send(HALL_GAMEID, pkmessage.MESSAGE_TYPE_SYSTEM,
                               userId, mail)
                datachangenotify.sendDataChangeNotify(HALL_GAMEID, userId,
                                                      'message')
        return trueDelta, final