def handleShippingResultCoupon(userId, record, result): timestamp = pktimestamp.getCurrentTimestamp() userAssets = hallitem.itemSystem.loadUserAssets(userId) if result == RESULT_OK: record.state = TYExchangeRecord.STATE_SHIPPING_SUCC elif result == RESULT_SHIPPINGFAIL_RETURN: record.state = TYExchangeRecord.STATE_SHIPPING_FAIL_RETURN count = record.params.get('count', 0) userAssets.addAsset(HALL_GAMEID, hallitem.ASSET_COUPON_KIND_ID, count, timestamp, 'WX_GET_CASH_BACK', count) # 历史提现记录对应减掉这个数额 userdata.incrAttr(userId, 'exchangedCoupon', -abs(count)) elif result == RESULT_SHIPPINGFAIL: record.state = TYExchangeRecord.STATE_SHIPPING_FAIL else: assert (0) amount = record.params.get('amount', 0) if result != RESULT_OK: mail = '您申请提现%.2f元,审核未通过,抱歉。' % (amount) else: mail = '您已成功提现%.2f元,请查收。' % (amount) pkmessage.send(HALL_GAMEID, pkmessage.MESSAGE_TYPE_SYSTEM, userId, mail) datachangenotify.sendDataChangeNotify(HALL_GAMEID, userId, 'message') return record
def handleAuditResultCoupon(userId, record, result): timestamp = pktimestamp.getCurrentTimestamp() userAssets = hallitem.itemSystem.loadUserAssets(userId) if result == RESULT_AUDITSUCC: record.state = TYExchangeRecord.STATE_ACCEPT elif result == RESULT_REJECT: record.state = TYExchangeRecord.STATE_REJECT elif result == RESULT_REJECT_RETURN: record.state = TYExchangeRecord.STATE_REJECT_RETURN count = record.params.get('count', 0) userAssets.addAsset(HALL_GAMEID, hallitem.ASSET_COUPON_KIND_ID, count, timestamp, 'WX_GET_CASH_BACK', count) # 历史提现记录对应减掉这个数额 userdata.incrAttr(userId, 'exchangedCoupon', -abs(count)) else: assert (0) if result in (RESULT_REJECT, RESULT_REJECT_RETURN): mail = '您申请提现%.2f元,审核未通过,抱歉。' % (record.params.get('amount', 0)) pkmessage.send(HALL_GAMEID, pkmessage.MESSAGE_TYPE_SYSTEM, userId, mail) datachangenotify.sendDataChangeNotify(HALL_GAMEID, userId, 'message') return record
def tryRename(gameId, userId, newName): consumeCount = 0 oldName, setNameSum = userdata.getAttrs(userId, ['name', 'set_name_sum']) if ftlog.is_debug(): ftlog.info( 'hallrename.tryRename gameId=', gameId, 'setNameSum=', setNameSum, 'userId=', userId, 'oldName=', oldName, 'newName=', newName, ) if oldName == newName: if ftlog.is_debug(): ftlog.info('hallrename.tryRename gameId=', gameId, 'userId=', userId, 'name not changed !') return -3, 'not changed' setNameSum = userdata.incrAttr(userId, 'set_name_sum', 1) if setNameSum > 1: # 消耗一个改名卡 timestamp = pktimestamp.getCurrentTimestamp() userAssets = hallitem.itemSystem.loadUserAssets(userId) _, consumeCount, final = userAssets.consumeAsset( gameId, hallitem.ASSET_RENAME_CARD_KIND_ID, 1, timestamp, 'USER_RENAME', 0) if consumeCount < 1: if ftlog.is_debug(): ftlog.info('hallrename.tryRename gameId=', gameId, 'userId=', userId, 'no rename card !') return -2, 'no rename card' ftlog.info('hallrename.tryRename gameId=', gameId, 'userId=', userId, 'newName=', newName, 'consumeCount=', consumeCount, 'setNameSum=', setNameSum, 'final=', final) code, info = _rename(gameId, userId, newName) if code != 0 and consumeCount > 0: # 改名失败,退回改名卡 userAssets = hallitem.itemSystem.loadUserAssets(userId) _, addCount, final = userAssets.addAsset( gameId, hallitem.ASSET_RENAME_CARD_KIND_ID, 1, timestamp, 'USER_RENAME', 0) ftlog.info('hallrename.tryRename rollback gameId=', gameId, 'userId=', userId, 'newName=', newName, 'addCount=', addCount, 'setNameSum=', setNameSum, 'final=', final) if code != 0 and setNameSum == 1: # 第一次修改失败,退回 userdata.incrAttr(userId, 'set_name_sum', -1) datachangenotify.sendDataChangeNotify(gameId, userId, ['item', 'udata']) return code, info
def testAlipayGift(self): itemKind = hallitem.itemSystem.findItemKind(item_alipay_gift_id) userAssets = hallitem.itemSystem.loadUserAssets(self.userId) userBag = userAssets.getUserBag() self.assertEqual(userBag.getAllKindItem(itemKind), []) userBag.addItemUnitsByKind(self.gameId, itemKind, 1, self.timestamp, 0, 'TEST_ADJUST', 0) item = userBag.getItemByKind(itemKind) self.assertEqual(item.remaining, 1) self.assertEqual(item.expiresTime, -1) self.assertRaises(TYItemActionConditionNotEnoughException, userBag.doAction, self.gameId, item, 'open') pkuserdata.incrAttr(userAssets.userId, 'used_alipay', 1) result = userBag.doAction(self.gameId, item, 'open').gotAssetList self.assertEqual(result[0][0].kindId, 'user:chip') self.assertEqual(result[0][1], 30000) self.assertEqual(result[0][2], 30000)
def testAlipayGift(self): itemKind = hallitem.itemSystem.findItemKind(item_alipay_gift_id) userAssets = hallitem.itemSystem.loadUserAssets(self.userId) userBag = userAssets.getUserBag() self.assertEqual(userBag.getAllKindItem(itemKind), []) userBag.addItemUnitsByKind(self.gameId, itemKind, 1, self.timestamp, 0, 'TEST_ADJUST', 0) item = userBag.getItemByKind(itemKind) self.assertEqual(item.remaining, 1) self.assertEqual(item.expiresTime, -1) self.assertRaises(TYItemActionConditionNotEnoughException, userBag.doAction, self.gameId, item, 'open') pkuserdata.incrAttr(userAssets.userId, 'used_alipay', 1) result = userBag.doAction(self.gameId, item, 'open').gotAssetList self.assertEqual(result[0][0].kindId, 'user:chip') self.assertEqual(result[0][1], 30000) self.assertEqual(result[0][2], 30000)
def incrCoupon(uid, gameid, deltaCount, chipNotEnoughOpMode, eventId, intEventParam, clientId, extentId=0, roomId=0, tableId=0, roundId=0, param01=0, param02=0): ''' 对用户的兑换券进行INCR操作 参考: incr_chip ''' trueDelta, finalCount = _incrUserChipFiled(uid, gameid, deltaCount, -1, -1, chipNotEnoughOpMode, eventId, daoconst.CHIP_TYPE_COUPON, intEventParam, clientId, tableId=tableId, extentId=extentId, roomId=roomId, roundId=roundId, param01=param01, param02=param02) if trueDelta < 0: userdata.incrAttr(uid, 'exchangedCoupon', abs(trueDelta)) return trueDelta, finalCount
def requestExchangeCash(userId, count, wxappId, timestamp): # 扣除奖券 userAssets = hallitem.itemSystem.loadUserAssets(userId) _, consumeCount, _ = userAssets.consumeAsset(HALL_GAMEID, hallitem.ASSET_COUPON_KIND_ID, count, timestamp, 'WX_GET_CASH', count) if consumeCount < count: raise TYExchangeRequestError('余额不足') exchangeId = None try: exchangeId = _makeExchangeId() record = TYExchangeRecord(exchangeId) record.createTime = timestamp amount = count / 100.0 record.params = { 'type': 7, 'count': count, 'amount': amount, 'wxappId': wxappId } record.errorCode = 0 record.state = TYExchangeRecord.STATE_NORMAL jstr = json.dumps(record.toDict()) _saveRecordData(userId, exchangeId, jstr) displayName = '%.2f现金' % (amount) parasDict = {} httpAddr = gdata.httpGame() parasDict[ 'callbackAudit'] = httpAddr + '/v3/game/exchange/auditCallback' parasDict[ 'callbackShipping'] = httpAddr + '/v3/game/exchange/shippingResultCallback' parasDict['user_id'] = userId parasDict['exchange_id'] = exchangeId parasDict['prod_id'] = 'cash' parasDict['prod_kind_name'] = displayName parasDict['prod_num'] = 1 parasDict['exchange_type'] = record.params.get('type', 7) parasDict['exchange_amount'] = amount parasDict['exchange_desc'] = displayName platformId = hallconf.getPublicConf('platformId', None) if platformId: parasDict['platform_id'] = platformId # gdss那边需要 parasDict['user_phone'] = '' parasDict['user_name'] = '' parasDict['user_addres'] = '' parasDict['wxappid'] = wxappId gdssUrl = hallconf.getItemConf().get( 'exchangeGdssUrl', 'http://gdss.touch4.me/?act=api.propExchange') from poker.util import webpage try: hbody, _ = webpage.webgetGdss(gdssUrl, parasDict) resJson = json.loads(hbody) except: ftlog.exception() raise TYExchangeRequestError() retcode = resJson.get('retcode', -1) retmsg = resJson.get('retmsg', '兑换请求出错') if retcode != 1: raise TYExchangeRequestError(retmsg) record.state = TYExchangeRecord.STATE_AUDIT rStr = json.dumps(record.toDict()) _saveRecordData(userId, exchangeId, rStr) ftlog.info('requestExchangeCash', 'userId=', userId, 'count=', count, 'amount=', amount, 'wxappId=', wxappId, 'exchangeId=', exchangeId, 'retcode=', retcode, 'retmsg=', retmsg) return record, retmsg except: userAssets.addAsset(HALL_GAMEID, hallitem.ASSET_COUPON_KIND_ID, count, timestamp, 'WX_GET_CASH_BACK', count) # 历史提现记录对应减掉这个数额 userdata.incrAttr(userId, 'exchangedCoupon', -abs(count)) ftlog.warn('requestExchangeCash BackCoupon', 'userId=', userId, 'count=', count, 'wxappId=', wxappId, 'exchangeId=', exchangeId) raise finally: datachangenotify.sendDataChangeNotify(HALL_GAMEID, userId, 'coupon')