def _exchange(self, gameid, userid, actkey, exchangeid): info = self._exchanges.get(exchangeid) if not info: return {'result': 'fail', 'tip': "unknown productId"} buynum = self.get_exchange_buynum(userid, actkey, info) if buynum >= info['limitTimes']: return {'result': 'fail', 'tip': '兑换次数已满'} if not self.alter_user_credit(userid, actkey, -info['price']): return {'result': 'fail', 'tip': '您的积分不足'} daobase.executeUserCmd(userid, 'HINCRBY', actkey, self.FIELD_EXCHANGE_NUM.format(exchangeid), 1) userAssets = hallitem.itemSystem.loadUserAssets(userid) assetList = userAssets.sendContent(gameid, info['content'], 1, True, timestamp.getCurrentTimestamp(), "ACTIVITY_CREDIT_EXCHANGE", exchangeid) response = self._query(userid, actkey) ftlog.debug('TYActCreditExchange._exchange gameId=', gameid, 'userId=', userid, 'activityId=', self.getid(), 'reward=', TYAssetUtils.buildContents(assetList), 'buynum=', buynum + 1, 'credit=', response['credit']) changeNames = TYAssetUtils.getChangeDataNames(assetList) datachangenotify.sendDataChangeNotify(gameid, userid, changeNames) response['result'] = 'ok' response['tip'] = '兑换成功,您获得' + TYAssetUtils.buildContentsString( assetList) return response
def _exchange(self, gameid, userid, actkey, exchangeid): info = self._exchanges.get(exchangeid) if not info: return {'result': 'fail', 'tip': "unknown productId"} buynum = self.get_exchange_buynum(userid, actkey, info) if buynum >= info['limitTimes']: return {'result': 'fail', 'tip': '兑换次数已满'} if not self.alter_user_credit(userid, actkey, -info['price']): return {'result': 'fail', 'tip': '您的积分不足'} daobase.executeUserCmd(userid, 'HINCRBY', actkey, self.FIELD_EXCHANGE_NUM.format(exchangeid), 1) userAssets = hallitem.itemSystem.loadUserAssets(userid) assetList = userAssets.sendContent(gameid, info['content'], 1, True, timestamp.getCurrentTimestamp(), "ACTIVITY_CREDIT_EXCHANGE", exchangeid) response = self._query(userid, actkey) ftlog.debug('TYActCreditExchange._exchange gameId=', gameid, 'userId=', userid, 'activityId=', self.getid(), 'reward=', TYAssetUtils.buildContents(assetList), 'buynum=', buynum + 1, 'credit=', response['credit']) changeNames = TYAssetUtils.getChangeDataNames(assetList) datachangenotify.sendDataChangeNotify(gameid, userid, changeNames) response['result'] = 'ok' response['tip'] = '兑换成功,您获得' + TYAssetUtils.buildContentsString(assetList) return response
def _exchange(self, gameid, userid, actkey, exchangeid): info = self._exchanges.get(exchangeid) if not info: return {'result': 'fail', 'tip': "unknown productId"} buynum = self.get_exchange_buynum(userid, actkey, info) if buynum >= info['limitTimes']: return {'result': 'fail', 'tip': '兑换次数已满'} curtime = timestamp.getCurrentTimestamp() userAssets = hallitem.itemSystem.loadUserAssets(userid) try: userAssets.consumeContentItemList(gameid, info['costs'], False, curtime, "ACT_ITEM_EXCHANGE_COST", exchangeid) except: return {'result': 'fail', 'tip': '您的道具不足,快去获取道具吧'} daobase.executeUserCmd(userid, 'HINCRBY', actkey, self.FIELD_EXCHANGE_NUM.format(exchangeid), 1) assetList = userAssets.sendContent(gameid, info['content'], 1, True, timestamp.getCurrentTimestamp(), "ACT_ITEM_EXCHANGE_GAIN", exchangeid) response = self._query(userid, actkey) ftlog.info('TYActItemExchange._exchange gameId=', gameid, 'userId=', userid, 'activityId=', self.getid(), 'reward=', TYAssetUtils.buildContents(assetList), 'buynum=', buynum + 1, 'credit=', response['credit']) changeNames = TYAssetUtils.getChangeDataNames(assetList) datachangenotify.sendDataChangeNotify(gameid, userid, changeNames) response['result'] = 'ok' response['tip'] = '兑换成功,您获得' + TYAssetUtils.buildContentsString(assetList) return response