Esempio n. 1
0
def sendTableInviteShareTodoTask(userId, gameId, tableNo, playMode, cardCount,
                                 contentStr):
    '''牌桌上邀请处理
    '''
    shareId = hallshare.getShareId('mj_invite_play_share', userId, gameId)
    if shareId:
        share = hallshare.findShare(shareId)
        if not share:
            return

        retDesc = ''
        play_mode_dict = majiang_conf.get_room_other_config(gameId).get(
            'playmode_desc_map', {})
        retDesc += play_mode_dict.get(playMode, '') if playMode else ''
        retDesc += contentStr
        ftlog.debug('sendTableInviteShareTodoTask last retDesc:', retDesc)
        share.setDesc(retDesc)

        title = share.title.getValue(userId, gameId)
        title = '房间号:' + tableNo + ',' + title
        share.setTitle(title)

        todotask = share.buildTodotask(gameId, userId, 'mj_invite_play_share')
        mo = TodoTaskHelper.makeTodoTaskMsg(gameId, userId, todotask)
        router.sendToUser(mo, userId)
Esempio n. 2
0
def getShareInfo(userId, gameId, shareKey):
    shareId = hallshare.getShareId(shareKey, userId, gameId)
    share = hallshare.findShare(shareId)
    if share:
        return share.getUrl(userId, gameId), share.getTitle(userId, gameId)
    else:
        return None, None
Esempio n. 3
0
def sendShareForWXRedEnvelope(userId, record, item):
    try:
        action = item.itemKind.findActionByName('exchange')
        from hall.entity.hallitem import TYItemActionExchange
        if isinstance(
                action,
                TYItemActionExchange) and action.isWechatRedPack():  # 微信红包
            from poker.util import strutil
            from poker.entity.dao import sessiondata
            clientId = sessiondata.getClientId(userId)
            _, cVer, _ = strutil.parseClientId(clientId)
            if cVer >= 3.90:
                from hall.entity import hallshare
                gameId = strutil.getGameIdFromHallClientId(clientId)
                shareId = hallshare.getShareId('wxRedEnvelope', userId, gameId)
                share = hallshare.findShare(shareId)
                if share:
                    todotask = share.buildTodotask(HALL_GAMEID, userId,
                                                   'wxRedEnvelope')
                    if todotask:
                        from hall.entity.todotask import TodoTaskHelper
                        TodoTaskHelper.sendTodoTask(gameId, userId, todotask)
    except:
        ftlog.error('sendShareForWXRedEnvelope', 'userId=', userId,
                    'exchangeId=', record.exchangeId, 'itemId=', item.itemId,
                    'itemKindId=', item.kindId)
Esempio n. 4
0
def _needSendBenefits(userId, gameId, clientId):
    '''
    是否需要发放救济金
    :param userId:
    :param gameId:
    :param clientId:
    '''
    global fuzhou_config
    if not _checkConditions(userId, clientId):
        return None
    
    if not hallstartchip_fuzhou.isSentStartChip(userId):
        return None
    
    if userchip.getChip(userId) >= fuzhou_config['minChip']:
        return None
    
    shareId = hallshare.getShareId(fuzhou_config['shareKey'], userId, gameId)
    if not shareId:
        return None
    share = hallshare.findShare(shareId)
    if not share:
        return None
    
    ok, rewardCount = hallshare.checkCanReward(userId, share, pktimestamp.getCurrentTimestamp())
    if not ok or rewardCount > fuzhou_config['maxCount']:
        ftlog.info("hallbenefits_fuzhou daily count:%s is used up!" % fuzhou_config['maxCount'], "userId =", userId, "gameId =", gameId, "clientId =", clientId)
        return None
    return share
Esempio n. 5
0
    def sendBenefits(self, gameId, userId, timestamp=None):
        '''
        发放救济金
        @return: isSend(True/False), TYUserBenefits
        '''
        if timestamp is None:
            timestamp = pktimestamp.getCurrentTimestamp()
        chip = pkuserchip.getUserChipAll(userId)
        if chip < self._minChip:
            # 用户金币低于指定数目时,发放救济金
            userBenefits = self.loadUserBenefits(gameId, userId, timestamp)
            if not userBenefits.hasLeftTimes():  # 没有剩余次数,弹分享引导
                oldtime = gamedata.getGameAttr(userId, HALL_GAMEID, 'relief_share_date')
                if not oldtime or datetime.fromtimestamp(oldtime).date() < datetime.fromtimestamp(timestamp).date():
                    # 每天最多弹一次
                    gamedata.setGameAttr(userId, HALL_GAMEID, 'relief_share_date', timestamp)
                    shareId = hallshare.getShareId('Relieffund', userId, gameId)
                    share = hallshare.findShare(shareId)
                    if share:
                        task = share.buildTodotask(gameId, userId, 'Relieffund')
                        TodoTaskHelper.sendTodoTask(gameId, userId, task)
                return False, userBenefits

            # 发放救济金
            userBenefits.times += 1
            self._benefitsDao.saveUserBenefitsData(userId, TYUserBenefitsData(userBenefits.times, timestamp))
            self._sendBenefits(gameId, userBenefits)
            # 通知用户金币刷新
            datachangenotify.sendDataChangeNotify(gameId, userId, ['udata'])
            return True, userBenefits
        return False, self.loadUserBenefits(gameId, userId, timestamp)
Esempio n. 6
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
Esempio n. 7
0
def sendTableInviteShareTodoTask(userId, gameId, tableNo, playMode, cardCount, contentStr):
    '''牌桌上邀请处理
    '''
    shareId = hallshare.getShareId('mj_invite_play_share', userId, gameId)
    if shareId:
        share =  hallshare.findShare(shareId)
        if not share:
            return
        
        retDesc = ''
        play_mode_dict = majiang_conf.get_room_other_config(gameId).get('playmode_desc_map', {})

        if gameId == 715:
            retDesc = contentStr;
        else:
            retDesc += play_mode_dict.get(playMode,'') if playMode else ''
            retDesc += contentStr
        ftlog.debug('sendTableInviteShareTodoTask last retDesc:', retDesc)
        share.setDesc(retDesc)
        
        if gameId == 715:
            title = play_mode_dict.get(playMode,'') if playMode else ''
            title += ' - 房号:' + tableNo
        else:
            title = share.title.getValue(userId, gameId)
            title = '房间号:' + tableNo + ',' + title
        share.setTitle(title)
        ftlog.debug('sendTableInviteShareTodoTask newTitle:', title)
        
        url = share.url.getValue(userId, gameId)
        url += "?ftId=" + tableNo
        url += "?from=magicWindow"
        eParams = {}
        eParams['action'] = 'hall_enter_friend_table_direct'
        fParam = {}
        fParam['ftId'] = tableNo
        eParams['params'] = fParam
        paramStr = json.dumps(eParams)
        base64Str = base64.b64encode(paramStr)
        from urllib import quote
        url += "&enterParams=" + quote(base64Str)
        share.setUrl(url)
        ftlog.debug('sendTableInviteShareTodoTask newUrl:', url
                    , ' ftId:', tableNo
                    , ' paramStr:', paramStr
                    , ' base64Str:', base64Str)
        
        todotask = share.buildTodotask(gameId, userId, 'mj_invite_play_share')
        mo = TodoTaskHelper.makeTodoTaskMsg(gameId, userId, todotask)
        router.sendToUser(mo, userId)
Esempio n. 8
0
def sendTableInviteShareTodoTask(userId, gameId, tableNo, playMode, cardCount,
                                 contentStr):
    '''牌桌上邀请处理
    '''
    shareId = hallshare.getShareId('mj_invite_play_share', userId, gameId)
    if shareId:
        share = hallshare.findShare(shareId)
        if not share:
            return

        retDesc = ''
        play_mode_dict = majiang_conf.get_room_other_config(gameId).get(
            'playmode_desc_map', {})

        if gameId == 715:
            retDesc = contentStr
        else:
            retDesc += play_mode_dict.get(playMode, '') if playMode else ''
            retDesc += contentStr
        ftlog.debug('sendTableInviteShareTodoTask last retDesc:', retDesc)
        share.setDesc(retDesc)

        if gameId == 715:
            title = play_mode_dict.get(playMode, '') if playMode else ''
            title += ' - 房号:' + tableNo
        else:
            title = share.title.getValue(userId, gameId)
            title = '房间号:' + tableNo + ',' + title
        share.setTitle(title)
        ftlog.debug('sendTableInviteShareTodoTask newTitle:', title)

        url = share.url.getValue(userId, gameId)
        url += "?ftId=" + tableNo
        url += "?from=magicWindow"
        eParams = {}
        eParams['action'] = 'hall_enter_friend_table_direct'
        fParam = {}
        fParam['ftId'] = tableNo
        eParams['params'] = fParam
        paramStr = json.dumps(eParams)
        base64Str = base64.b64encode(paramStr)
        from urllib import quote
        url += "&enterParams=" + quote(base64Str)
        share.setUrl(url)
        ftlog.debug('sendTableInviteShareTodoTask newUrl:', url, ' ftId:',
                    tableNo, ' paramStr:', paramStr, ' base64Str:', base64Str)

        todotask = share.buildTodotask(gameId, userId, 'mj_invite_play_share')
        mo = TodoTaskHelper.makeTodoTaskMsg(gameId, userId, todotask)
        router.sendToUser(mo, userId)
Esempio n. 9
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
Esempio n. 10
0
    def buildShareTask(self,
                       userId,
                       gameId,
                       url=None,
                       title=None,
                       desc=None,
                       tips=None,
                       shareIcon=None):
        '''
        获取分享ID
        url - 红包分享页面的URL
        title - 红包分享时的标题
        desc - 红包分享时的描述
        tips - 游戏触发分享时的提醒
        shareIcon - 分享后的图片
        '''
        from hall.entity import hallshare

        global _redEnvelopeConfig

        shareId = hallshare.getShareId('red_envelope', userId, gameId)
        share = hallshare.findShare(shareId)
        if share:
            if url:
                share.setUrl(url)

            if title:
                share.setTitle(title)

            if desc:
                share.setDesc(desc)

            if tips:
                share.setTips(tips)

            if shareIcon:
                share.setShareIcon(shareIcon)

            # 设置分享的扩展参数
            share.setNotifyInfo(userId, self.id, self.EVENTID)

            return share.buildTodotask(gameId, userId, 'red_envelope')
        else:
            return None
Esempio n. 11
0
def sendTableInviteShareTodoTask(userId, gameId, tableNo, playMode, cardCount, contentStr):
    '''牌桌上邀请处理
    '''
    shareId = hallshare.getShareId('mj_invite_play_share', userId, gameId)
    if shareId:
        share = hallshare.findShare(shareId)
        if not share:
            return

        retDesc = ''
        play_mode_dict = majiang_conf.get_room_other_config(gameId).get('playmode_desc_map', {})
        retDesc += play_mode_dict.get(playMode, '') if playMode else ''
        retDesc += contentStr
        ftlog.debug('sendTableInviteShareTodoTask last retDesc:', retDesc)
        share.setDesc(retDesc)

        title = share.title.getValue(userId, gameId)
        title = '房间号:' + tableNo + ',' + title
        share.setTitle(title)

        todotask = share.buildTodotask(gameId, userId, 'mj_invite_play_share')
        mo = TodoTaskHelper.makeTodoTaskMsg(gameId, userId, todotask)
        router.sendToUser(mo, userId)
Esempio n. 12
0
    def buildShareTask(self, userId, gameId, url=None, title=None, desc=None, tips=None, shareIcon=None):
        '''
        获取分享ID
        url - 红包分享页面的URL
        title - 红包分享时的标题
        desc - 红包分享时的描述
        tips - 游戏触发分享时的提醒
        shareIcon - 分享后的图片
        '''
        from hall.entity import hallshare

        global _redEnvelopeConfig

        shareId = hallshare.getShareId('red_envelope', userId, gameId)
        share = hallshare.findShare(shareId)
        if share:
            if url:
                share.setUrl(url)

            if title:
                share.setTitle(title)

            if desc:
                share.setDesc(desc)

            if tips:
                share.setTips(tips)

            if shareIcon:
                share.setShareIcon(shareIcon)

            # 设置分享的扩展参数    
            share.setNotifyInfo(userId, self.id, self.EVENTID)

            return share.buildTodotask(gameId, userId, 'red_envelope')
        else:
            return None
Esempio n. 13
0
def exchangeProduct(gameId, userId, clientId, orderId, productId, count):
    product = storeSystem.findProduct(productId)
    if not product:
        raise TYBuyProductUnknownException(productId)

    if product.buyType != 'exchange':
        raise TYProductNotSupportExchangeException(productId)

    timestamp = pktimestamp.getCurrentTimestamp()

    # 限购系统锁定
    periodId = hallstocklimit.productBuyLimitSystem.lockProduct(gameId, userId, productId, count, timestamp)

    # 创建订单
    try:
        storeSystem.buyProduct(gameId, userId, clientId, orderId, productId, count)
    except:
        if periodId:
            hallstocklimit.productBuyLimitSystem.unlockProduct(gameId, userId, periodId, productId,
                                                               count, 1, timestamp)
        raise

    # 
    ftlog.info('hallstore.exchangeProduct gameId=', gameId,
               'userId=', userId,
               'clientId=', clientId,
               'orderId=', orderId,
               'productId=', productId,
               'count=', count)

    try:
        # 消耗兑换的东西
        userAssets = hallitem.itemSystem.loadUserAssets(userId)
        assetTuple = userAssets.consumeAsset(gameId, product.exchangeFeeContentItem.assetKindId,
                                             product.exchangeFeeContentItem.count * count,
                                             timestamp,
                                             'BUY_PRODUCT', pokerconf.productIdToNumber(productId))
        if assetTuple[1] < product.exchangeFeeContentItem.count * count:
            ftlog.warn('hallstore.exchangeProduct gameId=', gameId,
                       'userId=', userId,
                       'clientId=', clientId,
                       'orderId=', orderId,
                       'productId=', productId,
                       'count=', count,
                       'consumedCount=', assetTuple[1],
                       'needConsumeCount=', product.exchangeFeeContentItem.count * count,
                       'err=', 'ConsumeNotEnough')
            msg = strutil.replaceParams(product.exchangeFeeNotEnoughText, {'feeName': assetTuple[0].displayName})
            raise TYProductExchangeNotEnoughException(productId, msg)

        datachangenotify.sendDataChangeNotify(gameId, userId, TYAssetUtils.getChangeDataNames([assetTuple]))
        consumeMap = {assetTuple[0].kindId: assetTuple[1]}
        ret = storeSystem.deliveryOrder(userId, orderId, productId, TYChargeInfo('', {}, consumeMap))

        # 分享提示
        shareId = hallshare.getShareId('exchangeShare', userId, gameId)
        if ftlog.is_debug():
            ftlog.debug('handleExchangeAuditResult shareId: ', shareId)

        share = hallshare.findShare(shareId)
        if share:
            desc = share.getDesc(gameId, userId, True)
            newDesc = strutil.replaceParams(desc, {'exchangeDesc': product.displayName})
            share.setDesc(newDesc)
            task = share.buildTodotask(HALL_GAMEID, userId, 'exchange')
            TodoTaskHelper.sendTodoTask(HALL_GAMEID, userId, task)

        if periodId:
            hallstocklimit.productBuyLimitSystem.deliveryProduct(gameId, userId, periodId, productId, count, timestamp)
        return ret
    except:
        if periodId:
            hallstocklimit.productBuyLimitSystem.unlockProduct(gameId, userId, periodId, productId, count, 2, timestamp)
        raise
Esempio n. 14
0
def exchangeProduct(gameId, userId, clientId, orderId, productId, count):
    product = storeSystem.findProduct(productId)
    if not product:
        raise TYBuyProductUnknownException(productId)

    if product.buyType != 'exchange':
        raise TYProductNotSupportExchangeException(productId)

    timestamp = pktimestamp.getCurrentTimestamp()

    # 限购系统锁定
    periodId = hallstocklimit.productBuyLimitSystem.lockProduct(
        gameId, userId, productId, count, timestamp)

    # 创建订单
    try:
        storeSystem.buyProduct(gameId, userId, clientId, orderId, productId,
                               count)
    except:
        if periodId:
            hallstocklimit.productBuyLimitSystem.unlockProduct(
                gameId, userId, periodId, productId, count, 1, timestamp)
        raise

    #
    ftlog.info('hallstore.exchangeProduct gameId=', gameId, 'userId=', userId,
               'clientId=', clientId, 'orderId=', orderId, 'productId=',
               productId, 'count=', count)

    try:
        # 消耗兑换的东西
        userAssets = hallitem.itemSystem.loadUserAssets(userId)
        assetTuple = userAssets.consumeAsset(
            gameId, product.exchangeFeeContentItem.assetKindId,
            product.exchangeFeeContentItem.count * count, timestamp,
            'BUY_PRODUCT', pokerconf.productIdToNumber(productId))
        if assetTuple[1] < product.exchangeFeeContentItem.count * count:
            ftlog.warn('hallstore.exchangeProduct gameId=', gameId, 'userId=',
                       userId, 'clientId=', clientId, 'orderId=', orderId,
                       'productId=', productId, 'count=', count,
                       'consumedCount=', assetTuple[1], 'needConsumeCount=',
                       product.exchangeFeeContentItem.count * count, 'err=',
                       'ConsumeNotEnough')
            msg = strutil.replaceParams(product.exchangeFeeNotEnoughText,
                                        {'feeName': assetTuple[0].displayName})
            raise TYProductExchangeNotEnoughException(productId, msg)

        datachangenotify.sendDataChangeNotify(
            gameId, userId, TYAssetUtils.getChangeDataNames([assetTuple]))
        consumeMap = {assetTuple[0].kindId: assetTuple[1]}
        ret = storeSystem.deliveryOrder(userId, orderId, productId,
                                        TYChargeInfo('', {}, consumeMap))

        # 分享提示
        shareId = hallshare.getShareId('exchangeShare', userId, gameId)
        if ftlog.is_debug():
            ftlog.debug('handleExchangeAuditResult shareId: ', shareId)

        share = hallshare.findShare(shareId)
        if share:
            desc = share.getDesc(gameId, userId, True)
            newDesc = strutil.replaceParams(
                desc, {'exchangeDesc': product.displayName})
            share.setDesc(newDesc)
            task = share.buildTodotask(HALL_GAMEID, userId, 'exchange')
            TodoTaskHelper.sendTodoTask(HALL_GAMEID, userId, task)

        if periodId:
            hallstocklimit.productBuyLimitSystem.deliveryProduct(
                gameId, userId, periodId, productId, count, timestamp)
        return ret
    except:
        if periodId:
            hallstocklimit.productBuyLimitSystem.unlockProduct(
                gameId, userId, periodId, productId, count, 2, timestamp)
        raise
Esempio n. 15
0
def handleShippingResult1(userId, exchangeId, result):
    '''
    发货结果处理
    '''
    if ftlog.is_debug():
        ftlog.debug('enter handleShippingResult(), userId:', userId,
                    'exchangeId:', exchangeId, 'result:', result)

    record = loadRecord(userId, exchangeId)
    if not record:
        raise TYUnknownExchangeOrder()
    if record.state != TYExchangeRecord.STATE_ACCEPT:
        raise TYBadStateExchangeOrder()

    userBag = hallitem.itemSystem.loadUserAssets(userId).getUserBag()
    item = userBag.findItem(record.itemId)

    if not isinstance(item, TYExchangeItem):
        raise TYBizException(-1, '系统错误')

    if item.state != TYExchangeItem.STATE_SHIPPING:
        raise TYBizException(-1, '道具状态错误')

    timestamp = pktimestamp.getCurrentTimestamp()

    if result == RESULT_OK:
        record.state = TYExchangeRecord.STATE_SHIPPING_SUCC
        userBag.removeItem(HALL_GAMEID, item, timestamp, 'EXCHANGE',
                           item.kindId)
    elif result == RESULT_SHIPPINGFAIL_RETURN:
        record.state = TYExchangeRecord.STATE_SHIPPING_FAIL_RETURN
        item.state = TYExchangeItem.STATE_NORMAL
        userBag.updateItem(HALL_GAMEID, item, timestamp)
    elif result == RESULT_SHIPPINGFAIL:
        record.state = TYExchangeRecord.STATE_SHIPPING_FAIL
        userBag.removeItem(HALL_GAMEID, item, timestamp, 'EXCHANGE',
                           item.kindId)
    else:
        raise TYBizException(-1, '错误的请求状态')

    itemDisPlayName = item.itemKind.displayName
    exchangeDesc = record.params.get('desc', '')
    if result == RESULT_OK:
        mail = '您申请用%s兑换(领取)%s,已成功为您办理,请查收。' % (itemDisPlayName, exchangeDesc)
    else:
        mail = '您申请用%s兑换(领取)%s,审核未通过,抱歉。' % (itemDisPlayName, exchangeDesc)

    pkmessage.send(HALL_GAMEID, pkmessage.MESSAGE_TYPE_SYSTEM, userId, mail)
    datachangenotify.sendDataChangeNotify(HALL_GAMEID, userId, 'message')

    if result == RESULT_OK:
        action = item.itemKind.findActionByName('exchange')
        from hall.entity.hallitem import TYItemActionExchange
        if isinstance(
                action,
                TYItemActionExchange) and action.isWechatRedPack():  # 微信红包
            from poker.util import strutil
            from poker.entity.dao import sessiondata
            clientId = sessiondata.getClientId(userId)
            _, cVer, _ = strutil.parseClientId(clientId)
            if cVer >= 3.90:
                from hall.entity import hallshare
                gameId = strutil.getGameIdFromHallClientId(clientId)
                shareId = hallshare.getShareId('wxRedEnvelope', userId, gameId)
                share = hallshare.findShare(shareId)
                if share:
                    todotask = share.buildTodotask(HALL_GAMEID, userId,
                                                   'wxRedEnvelope')
                    if todotask:
                        from hall.entity.todotask import TodoTaskHelper
                        TodoTaskHelper.sendTodoTask(gameId, userId, todotask)

    jstr = json.dumps(record.toDict())
    _saveRecordData(userId, exchangeId, jstr)

    ftlog.info('hallexchange.handleShippingResult1', 'userId=', userId,
               'exchangeId=', exchangeId, 'result=', result, 'itemId=',
               item.itemId, 'itemKindId=', item.kindId, 'orderState=',
               record.state)

    return record