def _record_charge_event(cls, appId, userId, chip_count, diamond_count, trans_id, product_name, paytype): clientId = TyContext.UserSession.get_session_clientid(userId) total_fee = chip_count / 10000.0 + diamond_count / 10.0 # fake platform order, for gdss' sake ts = int(time.time()) seqNum = int(TyContext.RedisMix.execute('INCR', 'global.orderid.seq.a')) fake_order = paytype + TyContext.strutil.tostr62(ts, 6) + \ TyContext.strutil.tostr62(seqNum, 3) ct = datetime.now() paykey = ct.strftime('pay:%Y%m%d') name = u'%d钻石' % diamond_count if diamond_count else u'%d金币' % chip_count payinfo = { 'time': ct.strftime('%Y%m%d%H%M%S'), 'uid': userId, 'appId': appId, 'name': name, 'fee': total_fee, 'type': paytype, 'clientId': clientId, 'tyOrderId': fake_order, 'appOrderId': trans_id, 'prodId': product_name, } TyContext.RedisPayData.execute('LPUSH', paykey, json.dumps(payinfo)) # XXX 这里payCount加1不严格,但为了首充礼包,先加上。暂时无副作用 PayHelper.incr_paycount(userId) TyContext.RedisUser.execute(userId, 'HINCRBYFLOAT', 'user:'******'chargeTotal', total_fee)
def __change_user_coin__(cls, platformOrderId, total_fee, chargeInfo, consumeInfo): TyContext.ftlog.debug( '__change_user_coin__ platformOrderId, total_fee, chargeInfo, consumeInfo', platformOrderId, total_fee, chargeInfo, consumeInfo) total_fee = float(total_fee) if total_fee < 0: total_fee = float(chargeInfo['chargeTotal']) userId = chargeInfo['uid'] appId = chargeInfo['appId'] clientId = chargeInfo['clientId'] diamondId = chargeInfo['diamondId'] diamondCount = chargeInfo['chargeCoin'] chargeInfo['chargedRmbs'] = total_fee chargeInfo['chargedDiamonds'] = diamondCount is_danji_order = cls._is_danji_prods(diamondId) clientip = TyContext.UserSession.get_session_client_ip(userId) userName = TyContext.RedisUser.execute(userId, 'HGET', 'user:'******'name') if userName == None: userName = '' # 记录全局充值记录 appOrderId = '' if consumeInfo and 'prodOrderId' in consumeInfo: appOrderId = consumeInfo['prodOrderId'] ct = datetime.datetime.now() paykey = ct.strftime('pay:%Y%m%d') chargehistory = { 'time': ct.strftime('%Y%m%d%H%M%S'), 'uid': userId, 'appId': appId, 'name': chargeInfo['diamondName'], 'fee': total_fee, 'clientId': clientId, 'tyOrderId': platformOrderId, 'appOrderId': appOrderId, 'appInfo': chargeInfo.get('appInfo', ''), 'diamondId': diamondId, 'diamondCount': diamondCount, 'vouchMobile': chargeInfo.get('vouchMobile', ''), 'vouchIP': clientip, 'subPaytype': chargeInfo.get('sub_paytype', ''), 'userName': userName, 'thirdPayOrderId': chargeInfo.get('thirdOrderId', '') } if consumeInfo: chargehistory['prodId'] = consumeInfo['prodId'] if 'chargeType' in chargeInfo: chargehistory['type'] = chargeInfo['chargeType'] if 'categories' in chargeInfo: chargehistory['categories'] = chargeInfo['chargeCategories'] if chargeInfo.get('isTestOrder', False): chargehistory['isTestOrder'] = True chargehistory_dump = json.dumps(chargehistory) TyContext.ftlog.info('__change_user_coin__ chargehistory', paykey, chargehistory_dump) TyContext.RedisPayData.execute('LPUSH', paykey, chargehistory_dump) userKey = 'user:'******'charge.callback') # 增加用户的充值次数 PayHelper.incr_paycount(userId) # 增加用户总体支付的数量 TyContext.RedisUser.execute(userId, 'HINCRBYFLOAT', userKey, 'chargeTotal', total_fee) # 增加用户的钻石购买的数据 RiskControl(userId).record_diamond(diamondId) # 更新IOS充值 if 'type' in chargehistory and chargehistory['type'] == 'tuyooios': from tysdk.entity.paythird.payios import TuYouPayIos TuYouPayIos._update_ios_quota(userId, total_fee) try: ReportReyun().reportPayment(**chargeInfo) except: TyContext.ftlog.exception()