def buildAssetKindMap(cls): assetKindMap = {} # 道具map assetKindConfList = hallconf.getItemConf().get('assets', []) # 所有道具配置表 for assetKindConf in assetKindConfList: if assetKindConf.get('kindId'): assetKindMap[assetKindConf.get('kindId')] = assetKindConf itemKindConfList = hallconf.getItemConf().get('items', []) for itemKindConf in itemKindConfList: if itemKindConf.get('kindId'): assetKindMap['item:' + str(itemKindConf.get('kindId'))] = { "kindId": 'item:' + str(itemKindConf.get('kindId')), "displayName": itemKindConf.get('displayName', ''), "pic": itemKindConf.get('pic', ''), "units": itemKindConf.get('units', '').get('displayName', '') if itemKindConf.get('units', '') else '' } return assetKindMap
def requestExchange(userId, item, params, timestamp): assert (isinstance(item, TYExchangeItem)) exchangeId = _makeExchangeId() record = TYExchangeRecord(exchangeId) record.itemId = item.itemId record.itemKindId = item.kindId record.createTime = timestamp record.params = params record.errorCode = 0 record.state = TYExchangeRecord.STATE_AUDIT jstr = json.dumps(record.toDict()) _saveRecordData(userId, exchangeId, jstr) parasDict = {} parasDict["user_id"] = userId parasDict["exchange_id"] = exchangeId parasDict["prod_id"] = item.itemId parasDict["prod_kind_name"] = item.itemKind.displayName parasDict["prod_num"] = 1 parasDict["exchange_type"] = params.get("type", 0) parasDict["exchange_amount"] = params.get("count", 0) parasDict["exchange_desc"] = params.get("desc", "") parasDict["user_phone"] = params.get("phone", "") parasDict["user_name"] = params.get("uName", "") parasDict["user_addres"] = params.get("uAddres", "") 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) ftlog.debug("requestExchange userId=", userId, "exchangeId=", exchangeId, "kindId=", item.kindId) return record
def requestExchange(userId, item, params, timestamp): assert (isinstance(item, TYExchangeItem)) exchangeId = _makeExchangeId() record = TYExchangeRecord(exchangeId) record.itemId = item.itemId record.itemKindId = item.kindId record.createTime = timestamp record.params = params record.errorCode = 0 record.state = TYExchangeRecord.STATE_AUDIT jstr = json.dumps(record.toDict()) _saveRecordData(userId, exchangeId, jstr) parasDict = {} parasDict["user_id"] = userId parasDict["exchange_id"] = exchangeId parasDict["prod_id"] = item.itemId parasDict["prod_kind_name"] = item.itemKind.displayName parasDict["prod_num"] = 1 parasDict["exchange_type"] = params.get("type", 0) parasDict["exchange_amount"] = params.get("count", 0) parasDict["exchange_desc"] = params.get("desc", "") parasDict["user_phone"] = params.get("phone", "") parasDict["user_name"] = params.get("uName", "") parasDict["user_addres"] = params.get("uAddres", "") 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) ftlog.debug("requestExchange userId=", userId, "exchangeId=", exchangeId, "kindId=", item.kindId) return record
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')
def requestExchange(userId, item, params, timestamp): assert (isinstance(item, TYExchangeItem)) exchangeId = _makeExchangeId() record = TYExchangeRecord(exchangeId) record.itemId = item.itemId record.itemKindId = item.kindId record.createTime = timestamp record.params = params record.errorCode = 0 record.state = TYExchangeRecord.STATE_NORMAL jstr = json.dumps(record.toDict()) _saveRecordData(userId, exchangeId, jstr) 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'] = item.itemId parasDict['prod_kind_name'] = item.itemKind.displayName parasDict['prod_num'] = 1 parasDict['exchange_type'] = params.get('type', 0) parasDict['exchange_amount'] = params.get('count', 0) parasDict['exchange_desc'] = params.get('desc', '') parasDict['user_phone'] = params.get('phone') parasDict['user_name'] = params.get('uName') parasDict['user_addres'] = params.get('uAddres') platformId = hallconf.getPublicConf('platformId', None) if platformId: parasDict['platform_id'] = platformId if parasDict['exchange_type'] == 5: parasDict['wxappid'] = params.get('wxappid', '') # 微信红包需要 if parasDict['exchange_type'] == 6: parasDict['user_province'] = params.get('uProvince') parasDict['user_city'] = params.get('uCity') parasDict['user_district'] = params.get('uDistrict') parasDict['user_town'] = params.get('uTown') parasDict['jd_product_id'] = params.get('jdProductId', '') 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('requestExchange', 'userId=', userId, 'exchangeId=', exchangeId, 'itemId=', item.itemId, 'itemKindId=', item.kindId, 'retcode=', retcode, 'retmsg=', retmsg) return record, retmsg