def get_app_manage(account_id, appid, app_type, valid, name, page, size): limit = _DEFAULT_PAGE_SIZE if not size or size > _DEFAULT_PAGE_SIZE else size if not page or page < 1: page = 1 offset = 0 if not page else (page - 1) * limit apps, counts = query_app_manage(account_id, appid=appid, app_type=app_type, valid=valid, appname=name, limit=limit, offset=offset) pages = int(counts / float(limit)) + 1 resp = [] for app in apps: data = { 'name': app.appname, 'appid': app.appid, 'appkey': get_appkey(app.appid), 'app_type': app.app_type, 'pay_type': json.loads(app.pay_type), 'status': app.valid, 'created_at': utc_to_local_str(app.created_at), } resp.append(data) resp_wrap = {'pages': pages, 'resp': resp} # 需有加个分页 return resp_wrap
def get_app_manage(mchid, page, size, appid, app_type, valid, status, bank_name, begin_at, end_at, mch_name, mch_short_name, appname, paymenttype): limit = _DEFAULT_PAGE_SIZE if not size or size > _DEFAULT_PAGE_SIZE else size if not page or page < 1: page = 1 offset = 0 if not page else (page - 1) * limit apps, count = db.query_app_manage(mchid, appid=appid, app_type=app_type, valid=valid, appname=appname, limit=limit, offset=offset, begin_at=begin_at, end_at=end_at, mch_name=mch_name, mch_short_name=mch_short_name, paymenttype=paymenttype) return {"total": count, "jinjians": [ { "id": app.id, "status": app.valid, "appname": app.appname, "app_type": app.app_type, "appid": app.appid, "appkey": db.get_appkey(app.appid), "mch_name": app.mch_name, "mch_short_name": app.mch_short_name, "updated_at": tz.utc_to_local_str(app.updated_at), "bank_name": _convert_paymenttype_to_banklinkname(app.paymenttype) } for app in apps ] if apps else [] }
def get_merchants(accountid, mch_name, appid, page, size): limit = _DEFAULT_PAGE_SIZE if not size or size > _DEFAULT_PAGE_SIZE else size if not page or page < 1: page = 1 offset = 0 if not page else (page - 1) * limit apps, counts = db.query_app_manage(accountid, mch_name=mch_name, appid=appid, limit=limit, offset=offset) resp = [] if apps: for app in apps: user = db.get_user(app.accountid) appid_detail = db.get_appid_detail(app.appid) real_pay = REAL_PAY.get_label(appid_detail.real_pay) if appid_detail else None extend = None if app.extend: extend = json.loads(app.extend).get('extend', '') resp.append({"real_pay": real_pay, "mch_name": app.mch_name, "phone": user.phone if user else None, "appid": app.appid, "extend": extend, "appkey": db.get_appkey(app.appid), "updated_at": tz.utc_to_local_str(app.updated_at), "mch_number": app.id}) pages = int(counts / float(limit)) + 1 return {"pages": pages, "resp": resp}
def export_pay_records(mchid, pay_type, pay_status, start_date, end_date, order_id, appid): query, _, _ = get_query(mchid) filters = [] junction = orm.and_ if pay_type: filters.append(PayRecord.pay_type == pay_type) if pay_status: filters.append(PayRecord.pay_status == pay_status) if order_id: filters.append(PayRecord.orderid == order_id) if start_date: filters.append(PayRecord.created_at >= start_date) if end_date: filters.append(PayRecord.created_at < end_date) if appid: filters.append(PayRecord.appid == appid) if filters: query = query.filter(junction(*filters)) items = query.all() resp_items = [] for item in items: data = [ item.mchid, item.appid, item.orderid, utc_to_local_str(item.created_at), item.pay_type, item.pay_status, str(item.amount) ] resp_items.append(data) return resp_items
def as_dict(self, convert_time=False): data = {c.name: getattr(self, c.name) for c in self.__table__.columns} if convert_time: for k in data: if k.endswith('_at'): data[k] = tz.utc_to_local_str(data[k]) return data
def get_withdraw_record(accountid, order_code, pay_type, pay_status, start_amount, end_amount, appid, start_date, end_date, withdraw_status, page, size): pages, records, count, amount, fee, service_fee, balance = controller.get_withdraw_record( accountid, order_code, pay_type, pay_status, start_amount, end_amount, appid, start_date, end_date, page, size, withdraw_status=withdraw_status, source=True) resp = { "pages": pages, "record": [], "count": '%.2f' % count, "amount": '%.2f' % amount, "fee": '%.2f' % fee, "service_fee": '%.2f' % service_fee, "balance": '%.2f' % balance } if records: for record in records: resp['record'].append({ "id": str(record.id), "updated_at": utc_to_local_str(record.updated_at), "channel": record.channel, "appid": record.appid, "paystatus": record.status, "amount": '%.2f' % record.amount, "fee": '%.2f' % record.fee, "to_account": record.to_account, "order_code": record.order_code, "extend": record.extend }) return resp
def convert_bills(bills): results = [] for bill in bills: result = {} result['access_seq'] = bill.orderid result['mchid'] = bill.mchid result['appid'] = bill.appid result['pay_type'] = bill.pay_type result['pay_status'] = bill.pay_status result['created_at'] = utc_to_local_str(bill.created_at) result['amount'] = str(bill.amount) result['description'] = bill.description results.append(result) return results
def query_withdraw_detail(): id = request.args.get('id') withdraw_detail = get_withdraw_by_id(id) appid = withdraw_detail.appid appid_detail = get_appid_detail(appid) resp = { "channel": withdraw_detail.channel, "to_account": withdraw_detail.to_account, "to_acc_name": withdraw_detail.acc_name, "created_at": utc_to_local_str(withdraw_detail.created_at), "extend": withdraw_detail.extend, "appid": withdraw_detail.appid, "amount": '%.2f' % withdraw_detail.amount, "fee": '%.2f' % withdraw_detail.fee, "total": '%.2f' % (withdraw_detail.amount + withdraw_detail.fee) } return resp
def daifu_record(accountid, status, bank_account_no, bank_account_name, page, size): limit = _DEFAULT_PAGE_SIZE if not size or size > _DEFAULT_PAGE_SIZE else size if not page or page < 1: page = 1 offset = 0 if not page else (page - 1) * limit total_pages, items = get_daifu_record(accountid, status, bank_account_no, bank_account_name, page, size) apply_amount, apply_count, suc_amount, fee_sum, submit_sum = get_daifu_sum( accountid) data = [] for item in items: appid, balance = get_balance_by_accountid(accountid) resp = {} resp['daifu_id'] = str(item.id) resp['accountid'] = item.mchid resp['daifu_type'] = item.daifu_type resp['amount'] = float(item.amount) resp['fee'] = float(item.fee) resp['status'] = item.status resp['appid'] = appid resp['balance'] = float(balance) resp['bank'] = item.bank resp['bank_name'] = item.bank_name resp['bank_province'] = item.bank_province resp['bank_city'] = item.bank_city resp['bank_account_no'] = item.bank_account_no resp['bank_account_name'] = item.bank_account_name resp['card_type'] = item.card_type resp['created_at'] = tz.utc_to_local_str(item.created_at) data.append(resp) return { 'records': data, 'pages': total_pages, 'apply_amount': '%.2f' % apply_amount, 'apply_count': apply_count, 'suc_apply_amount': '%.2f' % suc_amount, 'fee_sum': '%.2f' % fee_sum, 'submit_sum': '%.2f' % submit_sum, }
def withdraw_record(account_id, to_acc, to_acc_name, begin_at, end_at, appid, status, order_code, withdraw_type, page, size): limit = _DEFAULT_PAGE_SIZE if not size or size > _DEFAULT_PAGE_SIZE else size if not page or page < 1: page = 1 offset = 0 if not page else (page - 1) * limit total_pages, items = get_withdraw_record(account_id, order_code, 'bank', '', '', '', appid, begin_at, end_at, page, size, withdraw_type, status, to_account=to_acc, acc_name=to_acc_name) apply_amount, apply_count, suc_apply_amount, _ = get_withdraw_sum( account_id, order_code, 'bank', appid, begin_at, end_at, withdraw_type, status, to_acc, to_acc_name) data = [] for item in items: resp = {} resp['withdraw_id'] = str(item.id) resp['appid'] = item.appid resp['withdraw_type'] = item.withdraw_type resp['amount'] = float(item.amount) resp['fee'] = float(item.fee) resp['status'] = item.status resp['mch_name'] = get_mch_name(item.appid) resp['mchid'] = item.mchid resp['bank_name'] = item.bank_name resp['bank_no'] = item.to_account resp['acc_name'] = item.acc_name resp['updated_at'] = tz.utc_to_local_str(item.updated_at) data.append(resp) return total_pages, data, apply_amount, apply_count, suc_apply_amount
def get_merchant(accountid, merchant_id): mch = db.get_appmanage(merchant_id) user = db.get_user(mch.accountid) resp = None if not mch: raise err.ResourceNotFound("无此商户") appid_detail = db.get_appid_detail(mch.appid) real_pay = REAL_PAY.get_label(appid_detail.real_pay) if appid_detail else None resp = mch.as_dict() resp.pop("accountid") resp.pop("created_at") resp.pop("paymenttype") resp.pop("mch_number") resp.pop("industry_no") resp.pop("mch_short_name") resp['phone'] = user.phone extend = json.loads(resp['extend']) resp.update(extend.get('fee', '')) resp['extend'] = extend.get('extend', '') resp['updated_at'] = tz.utc_to_local_str(resp['updated_at']) resp['real_pay'] = real_pay return resp
def list_merchant_jinjians(): """ 列出商户进件信息 """ accountid = g.user['id'] merchant_id = request.args.get('id') if merchant_id: jinjian = db.get_jinjian_by_appmanageid(merchant_id) if not jinjian: raise err.Issue(merchant_id) # 这个错误有问题 return { "info": controller.parse_jinjian_info(jinjian), "status": jinjian.status, "updated_at": tz.utc_to_local_str(jinjian.updated_at) } begin_at = request.args.get('begin_at') end_at = request.args.get('end_at') bank_name = request.args.get("bank_name") mch_name = request.args.get("mch_name") mch_short_name = request.args.get("mch_shortName") appname = request.args.get('appname') app_type = request.args.get('app_type') appid = request.args.get('appid') page = request.args.get('page', 1) page = int(page) size = request.args.get('size', 10) size = int(size) if bank_name not in ['', 'd0', 'd1', 'd0,d1']: raise err.ParamError(bank_name) if bank_name == 'd0,d1': bank_name = '' valid, status = '', '' return controller.get_app_manage(accountid, page, size, appid, app_type, valid, status, bank_name, begin_at, end_at, mch_name, mch_short_name, appname, bank_name.upper())