def get_periods(dates): '''缓存账期''' if not dates: return if not isinstance(dates, (types.ListType, types.TupleType)): mode = 'single' dates = [dates] searchdate = list(set(dates) - set(UserDefine.ACCOUNT_PERIOD_CACHE)) if searchdate: try: periods = thrift_call(Finance, 'get_account_period', config.FINANCE_SERVERS, dates) for period in periods: UserDefine.ACCOUNT_PERIOD_CACHE[ period.search_date] = period.__dict__ except: log.warn(traceback.format_exc()) if mode == 'single': return UserDefine.ACCOUNT_PERIOD_CACHE.get(dates[0]) else: return { i: UserDefine.ACCOUNT_PERIOD_CACHE[i] for i in dates if i in UserDefine.ACCOUNT_PERIOD_CACHE }
def get_settle_statis(userid, expectdate): try: ret = thrift_call(FundService, 'findActtradeStatis', config.FUND_SERVERS, userid, expectdate) return [i.__dict__ for i in ret] except: log.warn(traceback.format_exc())
def get_appid(self): userid = int(self.user.userid) req_userids = [userid] groupid = self.get_groupid() if groupid: req_userids.append(int(groupid)) big_uid = int(self.get_big_uid()) if big_uid: req_userids.append(int(big_uid)) # 获取mp_confs try: mp_confs = thrift_call(QFMP, 'batch_mp_query', config.QFMP_SERVERS, list(set(req_userids))) except: log.warn(traceback.format_exc()) mp_confs = {} for uid in req_userids: if uid in mp_confs and mp_confs[uid]: mp_conf = mp_confs[uid][0] return mp_conf.appid, mp_conf.hj_appid else: return config.DEFAULT_APPID, config.OPENUSER_APPID
def save(self): if self._sesid: ret = thrift_call(Session, "session_set", SESSION_CONF, self._sesid, json.dumps(self.data, separators=(',', ':'))) if ret != 0: log.warn('session set error, key=%s ret=%s', self._sesid, str(ret)) else: #sesval = thrift_call(Session, "session_create", SESSION_CONF, json.dumps(self.data, separators=(',', ':'))) sesval = thrift_call(Session, "session_create_expire", SESSION_CONF, json.dumps(self.data, separators=(',', ':')), expire=self.expire) if sesval and sesval.ret == 0: self._sesid = sesval.skey
def GET(self, userid=None): d = {k: v.strip() for k, v in self.req.input().iteritems()} expectdate = d.get('expectdate') if not is_valid_date(expectdate): raise ParamError('账期格式错误') # 数据总结 settle_statis = get_settle_statis(userid, expectdate) totalmoney = totalfee = totalmonthfee = 0 for i in settle_statis: totalmoney += i['tradeamt'] totalfee += i['fee'] # 获取扣款历史 monthfees = [] try: monthfees = thrift_call(FundService, 'findWithholdHistory', config.FUND_SERVERS, userid, expectdate) except: log.warn(traceback.format_exc()) # 扣款历史 fee_detail_list = [] for monthfee in monthfees: # 费用是正的是补给用户的,加到总额里面去 if monthfee.amount > 0: totalmoney += monthfee.amount else: totalmonthfee += monthfee.amount is_rent_fee = False if isinstance(monthfee.title, types.UnicodeType): monthfee.title = monthfee.title.encode('utf-8') # 修改title如果是月租费的话 etc 12月QPOS月服务费 if monthfee.title == 'QPOS月服务费': monthfee.title = '%s月%s' % (monthfee.evidence_date[5:7], monthfee.title) is_rent_fee = True # 存在的话,就合并 is_exist = False for fee in fee_detail_list: if monthfee.title == fee['name'] and is_rent_fee: fee['value'] += monthfee.amount is_exist = True break if not is_exist: fee_detail_list.append({ 'name': monthfee.title, 'value': monthfee.amount, 'month': monthfee.evidence_date }) return self.write( success({ 'total_amt': totalmoney - totalfee + totalmonthfee, 'total_trade_amt': totalmoney, 'totalfee': totalfee, 'feedetail': fee_detail_list }))
def GET(self): default_info = { 'nickname': '微信支付顾客', 'avatar': config.HJ_AVATAR, 'gender': 3, 'num': 0, 'txamt': 0, 'last_txdtm': '' } d = self.req.inputjson() userid = int(self.user.userid) customer_id = None if d.get('customer_id'): try: customer_id = hids.decode(d['customer_id'])[0] except: if is_valid_int(d['customer_id']): customer_id = int(d['customer_id']) # 如果包含openid elif d.get('openid'): customer_id = thrift_call(OpenUser, 'get_user_id_by_openid', config.OPENUSER_SERVER, config.OPENUSER_APPID, d['openid']) if customer_id <= 0: return self.write(success(default_info)) # 获取消费者信息 r = get_member_info(customer_id) or {} member = {} with get_connection('qf_mchnt') as db: member = db.select_one('member', where={ 'userid': userid, 'customer_id': customer_id }) or {} info = {} info['nickname'] = r.get('nickname') or default_info['nickname'] info['avatar'] = r.get('avatar') or default_info['avatar'] info['gender'] = r.get('gender') or default_info['gender'] info['num'] = member.get('num') or default_info['num'] info['txamt'] = member.get('txamt') or default_info['txamt'] info['last_txdtm'] = (tstamp_to_str(member['last_txdtm']) if 'last_txdtm' in member else default_info['last_txdtm']) # 如果是储值交易 # 获取储值信息 if d.get('busicd', '').startswith('7'): balance = self.get_balance(userid, customer_id) if balance is not None: info['balance'] = balance return self.write(success(info))
def load(self, sesid=None): if not self._sesid and not sesid: return if sesid: self._sesid = sesid #log.debug('load session from %s with id:%s', self._addr, self._sesid) sesval = thrift_call(Session, 'session_get', SESSION_CONF, self._sesid) if sesval and sesval.ret == 0 and sesval.value: #log.debug('session value:%s, type:%s', sesval.value, type(sesval.value)) self.data = json.loads(sesval.value)
def get_data(aid): '''从数据组拉取数据''' datas = {} try: datas = json.loads( thrift_call(activiquer, 'activiq', config.DATAS_SERVERS, 'activity', str(aid)))[0] datas['rk_p'] = datas['rk_p'] * 100 except: log.debug('[id:{}]get_data error'.format(aid)) return datas
def GET(self, userid=None): d = {k: v.strip() for k, v in self.req.input().iteritems()} # 账期 expectdate = d.get('expectdate') if not is_valid_date(expectdate): raise ParamError('账期格式错误') # 分页信息 page, pagesize = d.get('page', 0), d.get('pagesize', 10) if not all(map(is_valid_int, (pagesize, page))): raise ParamError('分页信息错误') # 到账详细信息 details = defaultdict(list) try: trade_rs = thrift_call(FundService, 'findActtradeInfo', config.FUND_SERVERS, userid, expectdate, int(page), int(pagesize)) for r in trade_rs: details[r.tradetime[:10]].append({ 'tradetime': r.tradetime, 'tradeamt': r.tradeamt, 'fee': r.fee, 'type': r.tradetype, 'coupon_fee': r.ori_coupon_amt - r.coupon_amt, 'ori_coupon_amt': r.ori_coupon_amt }) except: log.warn(traceback.format_exc()) # 头部信息 statis = get_settle_statis(userid, expectdate) statis.sort(key=lambda d: d['tradedt'], reverse=True) ret = [] for i in statis: records = details.get(i['tradedt']) if records: ret.append({ 'txdt': i['tradedt'], 'cnt': i['cnt'], 'fee': i['fee'], 'tradeamt': i['tradeamt'], 'details': records }) return self.write(success(ret))
def get_bigmchnt_ratios(): userid = int(self._big_uid) fee = thrift_call(Finance, 'get_trade_fee', config.FINANCE_SERVERS, userid=int(userid), src='') log.debug(fee) if not fee: return '' return { field: getattr(fee, field) for field in ratio_fields if hasattr(fee, field) }
def GET(self): params = self.req.input() data = {} for i in ('appid', 'card_id', 'code'): if not params.get(i): raise ParamError('参数不完整') data[i] = params[i] try: card_ext = json.loads( thrift_call(QFMP, 'card_ext', config.QFMP_SERVERS, data['appid'], data['card_id'], data['code'])) except: raise ParamError('获取签名错误') card_ext = {} return self.write(success({'card_ext': card_ext}))
def GET(self): # userid = self.get_input_userid() params = self.req.input() if params.has_key('enuserid'): userid = params.get('enuserid') try: userid = int(userid) except: raise ParamError('enuserid参数错误') else: userid = int(self.user.userid) amt_per_wxpay = -1 # 获取每笔限额 try: is_display = int(redis_pool.get('mchnt_api_audit_display') or 0) if is_display: ret = thrift_call(DataEngine, 'get_risk_param', config.DATAENGINE_SERVERS, int(userid), '', 0x02) amt_per_wxpay = ret.user_param.param_list.param.get( 'amt_per_wxpay', 0) except: log.debug(traceback.format_exc()) # 获取审核信息 state = self.get_audit_state(userid) audit_info = {'info': '', 'title': '', 'memo': '', 'state': state} audit_info.update(UserDefine.AUDIT_STATE_DICT.get(state, {})) if state == UserDefine.AUDIT_FAIL: r = {} with get_connection('qf_mis') as db: other = 'order by create_date desc' where = {'user_id': int(userid)} r = db.select_one('mis_auditlog', where=where, other=other) or {} audit_info['memo'] = r.get('memo', '') # 更新审核状态 self.set_cache_audit(userid, state) return success({ 'amt_per_wxpay': amt_per_wxpay, 'audit_info': audit_info })
def GET(self): # userid = self.get_input_userid() params = self.req.input() if params.has_key('enuserid'): userid = params.get('enuserid') try: userid = int(userid) except: raise ParamError('enuserid参数错误') else: userid = int(self.user.userid) log.info('userid:%s' % userid) try: ret = thrift_call(Finance, 'get_trade_fee', config.FINANCE_SERVERS, userid=int(userid), src='') log.debug('ret:%s' % ret) except: log.warn('finance error:%s' % traceback.format_exc()) raise ParamError('获取签约信息失败') ratios = [] for i in config.RATIOS: ratio = getattr(ret, i['key'], '') extra_ratios = config.RATIO_CONF.get(i['key'] + '_extra', []) if ratio in extra_ratios: ratio = config.RATIO_CONF.get(i['key'] + '_extra_name', '特殊费率') else: ratio = str(ratio * 100) + '%' if ratio else '' ratios.append({'url': i['url'], 'name': i['name'], 'ratio': ratio}) return success({'ratios': ratios})
def logout(self): ret = thrift_call(Session, "session_delete", SESSION_CONF, self._sesid) if ret != 0: log.warn('session delete error, sesid:%s ret:%d', self._sesid, ret)
def GET(self, userid=None): d = {k: v.strip() for k, v in self.req.input().iteritems()} # 分页信息 page, pagesize = int(d.get('page', 0)), int(d.get('pagesize', 10)) # 获取数据 try: # 获取账期 dates = thrift_call(FundService, 'findDebitpageInfo', config.FUND_SERVERS, userid, page, pagesize) if not dates: return self.write(success({'settles': []})) # 获取划款列表 debits = thrift_call(FundService, 'findDebitInfo', config.FUND_SERVERS, userid, dates) if not debits: return self.write(success({'settles': []})) debits = [i.__dict__ for i in debits] debits.sort(key=lambda d: d['expectdate'], reverse=True) except: raise ThirdError('获取列表失败') # 划款数据整理 settles = [] for expectdate, records in groupby(debits, lambda d: d['expectdate']): records = list(records) status_dict = defaultdict(int) total_payamt, cnt = 0, len(records) week_day = datetime.datetime.strptime(expectdate, DATE_FMT).isoweekday() for record in records: status_dict[record['status']] += 1 total_payamt += record['payamt'] # 全部已划款 if status_dict['havepay'] == cnt: status = UserDefine.SETTLE_STATUS_HAVE # 全部未划款 elif status_dict['nopay'] == cnt: status = UserDefine.SETTLE_STATUS_NO # 部分划款 else: # 只有已划款和等待划款 if status_dict['havepay'] + status_dict['nopay'] == cnt: status = UserDefine.SETTLE_STATUS_PART # 包含划款失败 elif status_dict['havepay'] or status_dict['nopay']: status = UserDefine.SETTLE_STATUS_PART_FAIL # 全部划款失败 else: status = UserDefine.SETTLE_STATUS_FAIL settles.append({ 'expectdate': expectdate, 'week_day': week_day, 'status': status, 'records': records, 'total_payamt': total_payamt, 'cnt': cnt }) return self.write(success({'settles': settles}))