Commit f079d244 authored by xiaozhe.chen's avatar xiaozhe.chen

添加出表代码

parents
Pipeline #351 failed with stages
# Default ignored files
/workspace.xml
# Default ignored files
/workspace.xml
\ No newline at end of file
# encoding:utf8
import os
from sqlalchemy import create_engine
class sql_engine():
def __init__(self, db, db_name=None, echo=False):
"""
给出数据库名字,创建数据库连接
:param db:
:param db_name:
:param echo:
"""
try:
import Configparser
self.cf = Configparser.ConfigParser()
except:
import configparser
self.cf = configparser.ConfigParser()
self.cf.read(os.path.join(os.path.split(os.path.realpath(__file__))[0], 'config.ini'))
host = self.cf.get(db, 'host')
user = self.cf.get(db, 'user')
passwd = self.cf.get(db, 'passwd')
port = int(self.cf.get(db, 'port'))
if not db_name:
db_name = self.cf.get(db, 'db')
try:
self.__engine = create_engine(
'mysql+mysqldb://%s:%s@%s:%s/%s?charset=utf8' % (user, passwd, host, port, db_name), echo=echo,
connect_args={'connect_timeout': 3600})
except:
self.__engine = create_engine(
'mysql+pymysql://%s:%s@%s:%s/%s?charset=utf8' % (user, passwd, host, port, db_name), echo=echo,
connect_args={'connect_timeout': 3600})
def get_engine(self):
return self.__engine
if 'echo' not in vars():
echo = False
engine_xyqb = sql_engine('xyqb', 'xyqb', echo).get_engine()
engine_pay_center = sql_engine('paycenter', 'payment_center', echo).get_engine()
engine_audit = sql_engine('audit_w', 'audit', echo).get_engine()
engine_bt_audit = sql_engine('audit_w', 'baitiao_audit', echo).get_engine()
engine_trans = sql_engine('audit_w', 'new_transaction', echo).get_engine()
engine_test = sql_engine('audit_w', 'test_mzh', echo).get_engine()
engine_analysis = sql_engine('analysis', 'analysis', echo).get_engine()
engine_mall = sql_engine('paycenter', 'mall').get_engine()
engine_financial = sql_engine('paycenter', 'financial_system').get_engine()
engine_offline = sql_engine('paycenter', 'offline').get_engine()
engine_merchant = sql_engine('paycenter', 'merchant').get_engine()
engine_trans_tmp = sql_engine('audit_w_tmp', 'new_transaction', echo).get_engine()
if __name__ == '__main__':
import pandas as pd
engine = sql_engine('local', 'test').get_engine()
result = engine.execute(
'select biz_type, plan_id, repay_type, record_id, ref_amount from repay_plan_repay_record_ref limit 10;')
df = pd.DataFrame(data=list(result), columns=['biz_type', 'plan_id', 'repay_type', 'record_id', 'ref_amount'])
print(df.head())
# -*- coding: utf-8 -*-
import datetime
import sys
import pandas as pd
import os
sys.path.append('../../../finance_out_table')
from db_con.db_connect import sql_engine
path = '/home/quant_group/vpants/finance/table/'
conn = sql_engine('audit', 'test_mzh').get_engine()
sql_debt_age = """
select
timestampdiff(
month,
concat(
date_format(loan_paid_at, '%%Y-%%m'),
'-01'
),
concat(
date_format(
if(
deadline > '{0}',
deadline,
'{0}'
),
'%%Y-%%m'
),
'-01'
)
) loan_age,
date_format(deadline, '%%Y-%%m') 应还年月,
class 风险等级,
sum(assets) assets
from
test_mzh.cash_assets_model
where loan_paid_at < '{0}' and is_active = 1
group by 1, 2 ;
"""
sql_remain = """
select
loan_id,
class 风险等级,
date(loan_paid_at) 放款日期,
service_fee 应还服务费,
assets_remain
from
test_mzh.cash_assets_model
where loan_paid_at < '{0}' and
assets_remain <> 0 and is_active = 1;
"""
sql_term_no = """
select
term_no 当前期数,
date_format(deadline, '%%Y-%%m') 应还年月,
class 风险等级,
sum(assets) assets
from
test_mzh.cash_assets_model
where loan_paid_at < '{0}' and is_active = 1
group by 1, 2, 3 ;
"""
sql_total = """
select
sum(
if(
term_no = 1,
contract_loan_amount,
0
)
) 放款金额,
sum(
if(
term_no = 1,
bad_debt_fee,
0
)
) 计提风险金,
sum(
if(
term_no = 1,
bad_debt_fee_no_pre_fee,
0
)
) 去掉一次性服务费的计提风险金,
sum(assets) assets,
sum(assets_remain) assets_remain
from
test_mzh.cash_assets_model
where loan_paid_at < '{}'
and is_active = 1
"""
class asserts():
def __init__(self):
today = datetime.date.today()
self.end = datetime.date(today.year, today.month, 1)
last_day = self.end + datetime.timedelta(days=-1)
self.start = datetime.date(last_day.year, last_day.month, 1)
self.dir_path = path + self.start.strftime('%Y%m')
if not os.path.exists(self.dir_path):
os.makedirs(self.dir_path)
def asserts_details(self):
df = pd.read_sql(sql=sql_total.format(self.end), con=conn)
df1 = pd.read_sql(sql=sql_debt_age.format(self.end), con=conn)
df2 = pd.read_sql(sql=sql_term_no.format(self.end), con=conn)
df3 = pd.read_sql(sql=sql_remain.format(self.end), con=conn)
excel_file = pd.ExcelWriter(
os.path.join(self.dir_path, u'assets减值明细-{}.xlsx'.format(self.start.strftime('%Y%m'))))
df.to_excel(excel_file, sheet_name=u'汇总', index=None)
df1.to_excel(excel_file, sheet_name=u'账龄汇总', index=None)
df2.to_excel(excel_file, sheet_name=u'期数汇总', index=None)
df3.to_excel(excel_file, sheet_name=u'assets_remain', index=None)
excel_file.close()
if __name__ == '__main__':
asserts().asserts_details()
print('======================asserts done===================================')
This diff is collapsed.
# -*- coding: utf-8 -*-
import datetime
import sys
import pandas as pd
import os
sys.path.append('../../../finance_out_table')
from db_con.db_connect import sql_engine
path = '/home/quant_group/vpants/finance/table/'
conn = sql_engine('audit', 'test_mzh').get_engine()
engine_new_transaction = sql_engine('audit', 'new_transaction').get_engine()
collect_data_sql = """
INSERT INTO tmp_xjd_plan_ref SELECT
plan_id,
sum(ref_amount) ref_amount,
sum(principle) principle,
sum(interest) interest,
sum(service_fee) service_fee,
sum(punish) punish,
sum(collection_relief) collection_relief,
sum(remain_income) remain_income,
sum(xyqb_poundage) xyqb_poundage,
sum(mitigate_collection_relief) mitigate_collection_relief,
sum(mitigate_service_fee) mitigate_service_fee,
sum(mitigate_interest) mitigate_interest,
sum(mitigate_principle) mitigate_principle,
sum(red_package_fee) red_package_fee,
sum(mitigate_all) mitigate_all,
sum(residual_service_fee) residual_service_fee,
min(bill_time) first_repaid_at,
max(bill_time) last_repaid_at
FROM
new_transaction.xjd_repay_plan_repay_record_ref where bill_time < {}
GROUP BY
1;
"""
append_collect_data_sql = """
INSERT INTO tmp_xjd_plan_ref SELECT
plan_id,
sum(ref_amount) ref_amount,
sum(principle) principle,
sum(interest) interest,
sum(service_fee) service_fee,
sum(punish) punish,
sum(collection_relief) collection_relief,
sum(remain_income) remain_income,
sum(xyqb_poundage) xyqb_poundage,
sum(mitigate_collection_relief) mitigate_collection_relief,
sum(mitigate_service_fee) mitigate_service_fee,
sum(mitigate_interest) mitigate_interest,
sum(mitigate_principle) mitigate_principle,
sum(red_package_fee) red_package_fee,
sum(mitigate_all) mitigate_all,
sum(residual_service_fee) residual_service_fee,
min(bill_time) first_repaid_at,
max(bill_time) last_repaid_at
FROM
new_transaction.xjd_repay_plan_repay_record_ref where bill_time >= {} and bill_time < {}
GROUP BY
1;
"""
loan_sql = """
select
lm.is_active,
lm.funding_code,
date_format(lm.loan_paid_at, '%%Y-%%m') loan_paid_at,
sum(lm.contract_loan_amount) contract_loan_amount
from
audit.loan_manifest lm
where lm.funding_code in (270, 310, 320, 390, 410, 490)
group by 1,2,3;
"""
behalf_sql = """
select
lm.is_active,
lm.funding_code,
date_format(lm.loan_paid_at, '%%Y-%%m') loan_paid_at,
urp.term_no,
date_format(urp.deadline, '%%Y-%%m') deadline,
sum(urp.principle + urp.interest) req_prin_inst
from
new_transaction.user_repayment_plan urp
join audit.loan_manifest lm
on lm.ref_id = urp.ref_id
and lm.funding_code in (270, 310, 320, 390)
left join test_mzh.tmp_xjd_plan_ref ref
on urp.id = ref.plan_id
where ref.plan_id is null
group by 1,2,3,4,5
union
all
select
lm.is_active,
lm.funding_code,
date_format(lm.loan_paid_at, '%%Y-%%m') loan_paid_at,
urp.term_no,
date_format(urp.deadline, '%%Y-%%m') deadline,
sum(urp.principle + urp.interest) req_prin_inst
from
test_mzh.tmp_xjd_plan_ref ref
join new_transaction.user_repayment_plan urp
on urp.id = ref.plan_id
and urp.fund_code in (270, 310, 320, 390)
and date_format(urp.deadline, '%%Y-%%m') < date_format(ref.first_repaid_at, '%%Y-%%m')
join audit.loan_manifest lm
on lm.ref_id = urp.ref_id
group by 1,2,3,4,5;
"""
collect_sql = """
select
lm.is_active,
lm.funding_code,
date_format(lm.loan_paid_at, '%%Y-%%m') loan_paid_at,
urp.term_no,
date_format(ref.first_repaid_at, '%%Y-%%m') repaid_at,
sum(if (
date_format(urp.deadline, '%%Y-%%m') < date_format(ref.first_repaid_at, '%%Y-%%m'),
ref.principle - ref.mitigate_principle + ref.interest - ref.mitigate_interest,
0
)) paid_prin_inst ,
sum(ref.punish - ref.mitigate_collection_relief) paid_punish
from
test_mzh.tmp_xjd_plan_ref ref
join new_transaction.user_repayment_plan urp
on urp.id = ref.plan_id
and urp.fund_code in (270, 310, 320, 390)
join audit.loan_manifest lm
on lm.ref_id = urp.ref_id
group by 1,2,3,4,5;
"""
head_repay_sql = """
SELECT
lm.is_active,
lm.funding_code,
date_format(lm.loan_paid_at, '%%Y-%%m') loan_paid_at,
urp.term_no,
date_format(
ref.first_repaid_at,
'%%Y-%%m'
) repaid_at,
sum(
ref.principle - ref.mitigate_principle + ref.interest - ref.mitigate_interest
) repay_prin_inst
FROM
test_mzh.tmp_xjd_plan_ref ref
JOIN new_transaction.user_repayment_plan urp ON urp.id = ref.plan_id
AND urp.fund_code in (410, 490)
AND date_format(urp.deadline, '%%Y-%%m') >= date_format(
ref.first_repaid_at,
'%%Y-%%m'
)
JOIN audit.loan_manifest lm ON lm.ref_id = urp.ref_id
GROUP BY 1, 2, 3, 4, 5;
"""
t_plus_behalf_sql = """
SELECT
lm.is_active,
lm.funding_code,
date_format(lm.loan_paid_at, '%%Y-%%m') loan_paid_at,
urp.term_no,
date_format(urp.deadline, '%%Y-%%m') deadline,
sum(urp.principle + urp.interest) req_prin_inst
FROM
new_transaction.user_repayment_plan urp
JOIN audit.loan_manifest lm ON lm.ref_id = urp.ref_id
AND lm.funding_code in (410, 490)
LEFT JOIN test_mzh.tmp_xjd_plan_ref ref ON urp.id = ref.plan_id
WHERE
ref.plan_id IS NULL
GROUP BY 1,2,3,4,5
UNION ALL
SELECT
lm.is_active,
lm.funding_code,
date_format(lm.loan_paid_at, '%%Y-%%m') loan_paid_at,
urp.term_no,
date_format(urp.deadline, '%%Y-%%m') deadline,
sum(urp.principle + urp.interest) req_prin_inst
FROM
test_mzh.tmp_xjd_plan_ref ref
JOIN new_transaction.user_repayment_plan urp ON urp.id = ref.plan_id
AND urp.fund_code in (410, 490)
AND date_format(
DATE_ADD(
urp.deadline,
INTERVAL 1 MONTH
),
'%%Y-%%m'
) < date_format(
ref.first_repaid_at,
'%%Y-%%m'
)
JOIN audit.loan_manifest lm ON lm.ref_id = urp.ref_id
GROUP BY 1,2,3,4,5;
"""
t_plus_collect_sql = """
SELECT
lm.is_active,
lm.funding_code,
date_format(lm.loan_paid_at, '%%Y-%%m') loan_paid_at,
urp.term_no,
date_format(
ref.first_repaid_at,
'%%Y-%%m'
) repaid_at,
sum(
IF (
date_format(
DATE_ADD(
urp.deadline,
INTERVAL 1 MONTH
),
'%%Y-%%m'
) < date_format(
ref.first_repaid_at,
'%%Y-%%m'
),
ref.principle - ref.mitigate_principle + ref.interest - ref.mitigate_interest,
0
)
) paid_prin_inst,
sum(
ref.punish - ref.mitigate_collection_relief
) paid_punish
FROM
test_mzh.tmp_xjd_plan_ref ref
JOIN new_transaction.user_repayment_plan urp ON urp.id = ref.plan_id
AND urp.fund_code in (410, 490)
JOIN audit.loan_manifest lm ON lm.ref_id = urp.ref_id
GROUP BY 1,2,3,4,5;
"""
class collection_behalf():
def __init__(self, is_mock):
self.is_mock = is_mock
today = datetime.date.today()
self.end = datetime.date(today.year, today.month, 1)
last_day = self.end + datetime.timedelta(days=-1)
self.start = datetime.date(last_day.year, last_day.month, 1)
self.dir_path = path + self.start.strftime('%Y%m')
if not os.path.exists(self.dir_path):
os.makedirs(self.dir_path)
def collection_behalf_details(self):
if not self.is_mock:
# 准备数据
conn.execute(collect_data_sql.format(self.end.strftime("'%Y-%m-%d'")))
# 出表
# 放款统计
df_loan = pd.read_sql(sql=loan_sql, con=engine_new_transaction)
# 代偿统计
df_behalf = pd.read_sql_query(sql=behalf_sql, con=engine_new_transaction)
# 催回
df_collect = pd.read_sql_query(sql=collect_sql, con=engine_new_transaction)
# T+1日提前还款
df_head_repay = pd.read_sql_query(sql=head_repay_sql, con=engine_new_transaction)
# T+1日代偿
df_t_plus_behalf = pd.read_sql_query(sql=t_plus_behalf_sql, con=engine_new_transaction)
# T+1日催回
df_t_plus_collect = pd.read_sql_query(sql=t_plus_collect_sql, con=engine_new_transaction)
excel_file = pd.ExcelWriter(os.path.join(self.dir_path, u'渤海催回和代偿-{}.xlsx'.format(self.start.strftime('%Y%m'))))
df_loan.to_excel(excel_file, '放款', index=None)
df_behalf.to_excel(excel_file, 'T-代偿', index=None)
df_collect.to_excel(excel_file, 'T-催回', index=None)
df_head_repay.to_excel(excel_file, 'T+1-提前还款', index=None)
df_t_plus_behalf.to_excel(excel_file, 'T+1-代偿', index=None)
df_t_plus_collect.to_excel(excel_file, 'T+1-催回', index=None)
excel_file.save()
if __name__ == '__main__':
collection_behalf(False).collection_behalf_details()
print('======================bohai collection_behalf done===================================')
# -*- coding: utf-8 -*-
import datetime
import sys
import pandas as pd
import os
sys.path.append('../../../finance_out_table')
from db_con.db_connect import sql_engine
path = '/home/quant_group/vpants/finance/table/'
engine_audit = sql_engine('audit', 'audit').get_engine()
summary_sql = """
SELECT
year(loan.loan_paid_at) 放款年,
month(loan.loan_paid_at) 放款月,
f.name 资金方,
loan.class 风险等级,
sum(loan.contract_loan_amount) 放款金额
FROM
audit.loan_manifest loan
JOIN basic.funding_corp f
ON f.funding_code = loan.funding_code
where loan.loan_paid_at >= '{0}'
AND loan.loan_paid_at < '{1}'
and loan.funding_code not in (590,600,630)
GROUP BY 1, 2, 3, 4 ;
"""
details_sql = """
SELECT
f.name 资金方,
loan.loan_id,
loan.contract_no 贷款合同号,
date(loan.loan_paid_at) 放款日期,
loan.contract_loan_amount 放款金额,
loan.contract_term 总期数,
loan.monthly_interest_rate 月利率,
loan.class 风险等级
FROM
audit.loan_manifest loan
JOIN basic.funding_corp f
ON f.funding_code = loan.funding_code
AND loan.loan_paid_at >= '{0}'
AND loan.loan_paid_at < '{1}'
and loan.funding_code not in (590,600,630)
"""
class loan_order():
def __init__(self):
today = datetime.date.today()
self.end = datetime.date(today.year, today.month, 1)
last_day = self.end + datetime.timedelta(days=-1)
self.start = datetime.date(last_day.year, last_day.month, 1)
self.dir_path = path + self.start.strftime('%Y%m')
if not os.path.exists(self.dir_path):
os.makedirs(self.dir_path)
def loan_order_details(self):
df = pd.read_sql(sql=summary_sql.format(self.start, self.end), con=engine_audit)
df.to_excel(os.path.join(self.dir_path, u'现金贷放款表-新模式-汇总表-{}.xlsx'.format(self.start.strftime('%Y%m'))),
index=None)
df = pd.read_sql(sql=details_sql.format(self.start, self.end), con=engine_audit)
df.to_excel(os.path.join(self.dir_path, u'现金贷放款表-新模式-明细表-{}.xlsx'.format(self.start.strftime('%Y%m'))),
index=None)
if __name__ == '__main__':
loan_order().loan_order_details()
print('======================loan_order done===================================')
# -*- coding: utf-8 -*-
import datetime
import sys
import pandas as pd
import os
sys.path.append('../../../finance_out_table')
from db_con.db_connect import sql_engine
path = '/home/quant_group/vpants/finance/table/'
engine_new_transaction = sql_engine('audit', 'new_transaction').get_engine()
sql_repay = """
select
year(t8.loan_paid_at) l_year,
month(t8.loan_paid_at) l_month,
year(t1.bill_time) r_year,
month(t1.bill_time) r_month,
t6.name funding_name,
t7.approach_name,
sum(t1.ref_amount) 总额,
sum(t1.principle) 本金,
sum(t1.interest) 利息,
sum(t1.service_fee) 服务费,
sum(t1.collection_relief) 催收减免,
-- sum(t1.red_package_fee) 实还红包减免,
sum(t1.punish) 逾期罚款收益,
sum(t1.remain_income) 其他收益,
sum(mitigate_principle) 减免本金,
sum(mitigate_interest) 减免利息,
sum(mitigate_service_fee) 减免服务费,
sum(mitigate_collection_relief) 减免罚息,
sum(t1.residual_service_fee) 剩余未还服务费,
sum(t1.subsidy_fee) 还款补贴,
sum(t1.mitigate_subsidy_fee) 还款补贴减免,
sum(t1.premium) 保费,
sum(t1.mitigate_premium) 保费减免
from
new_transaction.xjd_repay_plan_repay_record_ref t1
join new_transaction.user_repayment_plan t2
on t2.id = t1.plan_id
join basic.funding_corp t6
on t2.fund_code = t6.funding_code
join new_transaction.repay_channel t7
on t1.repay_channel = t7.id
join audit.loan_manifest t8
on t8.ref_id = t2.ref_id
and t8.loan_paid_at {} '2018-01-03'
group by 1, 2, 3, 4, 5, 6;
"""
new_sql_repay = """
select
year(t8.loan_paid_at) l_year,
month(t8.loan_paid_at) l_month,
year(t1.bill_time) r_year,
month(t1.bill_time) r_month,
t6.name funding_name,
t7.approach_name,
sum(t1.ref_amount) 总额,
sum(t1.principle) 本金,
sum(t1.interest) 利息,
sum(t1.service_fee) 服务费,
sum(t1.collection_relief) 催收减免,
-- sum(t1.red_package_fee) 实还红包减免,
sum(t1.punish) 逾期罚款收益,
sum(t1.remain_income) 其他收益,
sum(mitigate_principle) 减免本金,
sum(mitigate_interest) 减免利息,
sum(mitigate_service_fee) 减免服务费,
sum(mitigate_collection_relief) 减免罚息,
sum(t1.residual_service_fee) 剩余未还服务费,
sum(t1.subsidy_fee) 还款补贴,
sum(t1.mitigate_subsidy_fee) 还款补贴减免,
sum(t1.premium) 保费,
sum(t1.mitigate_premium) 保费减免
from
new_transaction.xjd_repay_plan_repay_record_ref t1
join new_transaction.user_repayment_plan t2
on t2.id = t1.plan_id
join basic.funding_corp t6
on t2.fund_code = t6.funding_code
join new_transaction.repay_channel t7
on t1.repay_channel = t7.id
join audit.loan_manifest t8
on t8.ref_id = t2.ref_id
and t8.loan_paid_at > '2018-01-03'
where t1.bill_time < {}
group by 1, 2, 3, 4, 5, 6;
"""
sql_dunjiao_serivce_fee = """
select
year (t3.loan_paid_at) l_year,
month (t3.loan_paid_at) l_month,
year (t4.bill_time) r_year,
month (t4.bill_time) r_month,
t5.NAME funding_name,
t6.approach_name,
sum(t1.ref_amount) "实还趸收服务费"
from
new_transaction.xjd_dunjiao_plan_ref t1
join new_transaction.xjd_dunjiao_plan t2
on t1.plan_id = t2.id
join audit.loan_manifest t3
on t2.ref_id = t3.ref_id
join repay_record_online t4
on t1.record_id = t4.id
join basic.funding_corp t5
on t5.funding_code = 150
join new_transaction.repay_channel t6
on t6.id = t1.repay_channel
and t4.pay_approach = t1.repay_channel
group by 1, 2, 3, 4, 5, 6
"""
sort_cols = ['l_year', 'l_month', 'r_year', 'r_month', 'funding_name', 'approach_name']
new_cols = {'l_year': u'放款年', 'l_month': u'放款月', 'r_year': u'还款年', 'r_month': u'还款月', 'funding_name': u'资金方',
'approach_name': u'收款账户'}
out_cols = [u'放款年', u'放款月', u'还款年', u'还款月', u'资金方', u'收款账户', u'总额', u'本金', u'利息', u'服务费', u'催收减免', u'逾期罚款收益', u'其他收益',
u'减免本金', u'减免利息', u'减免服务费', u'减免罚息', u'剩余未还服务费', u'实还趸收服务费', u'还款补贴', u'还款补贴减免', u'保费', u'保费减免']
class loan_repay():
def __init__(self):
today = datetime.date.today()
self.end = datetime.date(today.year, today.month, 1)
last_day = self.end + datetime.timedelta(days=-1)
self.start = datetime.date(last_day.year, last_day.month, 1)
self.dir_path = path + self.start.strftime('%Y%m')
if not os.path.exists(self.dir_path):
os.makedirs(self.dir_path)
def loan_repay_details(self):
df_old = pd.read_sql(sql=sql_repay.format('<'), con=engine_new_transaction)
df_new = pd.read_sql(sql=new_sql_repay.format(self.end.strftime("'%Y-%m-%d'")), con=engine_new_transaction)
df_dunjiao = pd.read_sql(sql=sql_dunjiao_serivce_fee, con=engine_new_transaction)
df_old = pd.merge(df_old, df_dunjiao, how='left',
on=['l_year', 'l_month', 'r_year', 'r_month', 'funding_name', 'approach_name'])
df_old[u'实还趸收服务费'].fillna(value=0, inplace=True)
df_old[u'总额'] = df_old[u'总额'] + df_old[u'实还趸收服务费']
df_old.sort_values(sort_cols, inplace=True)
df_old.rename(columns=new_cols, inplace=True)
df_new.sort_values(sort_cols, inplace=True)
df_new.rename(columns=new_cols, inplace=True)
excel_file = pd.ExcelWriter(os.path.join(self.dir_path , u'现金贷还款表汇总-{}.xlsx'.format(self.start.strftime('%Y%m'))))
df_old.to_excel(excel_file, u'旧模式', columns=out_cols, index=None)
df_new.to_excel(excel_file, u'新模式', columns=out_cols, index=None)
excel_file.save()
if __name__ == '__main__':
loan_repay().loan_repay_details()
print('======================loan_repay done===================================')
# -*- coding: utf-8 -*-
import datetime
import sys
import pandas as pd
import os
sys.path.append('../../../finance_out_table')
from db_con.db_connect import sql_engine
#path = '/home/quant_group/vpants/finance/table/'
path = '/Users/chenxiaozhe/Downloads/test/'
engine_new_transaction = sql_engine('audit', 'new_transaction').get_engine()
sql_repay = """
select
t8.ref_id,
year(t8.loan_paid_at) l_year,
month(t8.loan_paid_at) l_month,
year(t1.bill_time) r_year,
month(t1.bill_time) r_month,
t2.deadline '应还日期',
t6.name funding_name,
t7.approach_name,
sum(t1.ref_amount) 总额,
sum(t1.principle) 本金,
sum(t1.interest) 利息,
sum(t1.service_fee) 服务费,
sum(t1.collection_relief) 催收减免,
-- sum(t1.red_package_fee) 实还红包减免,
sum(t1.punish) 逾期罚款收益,
sum(t1.remain_income) 其他收益,
sum(mitigate_principle) 减免本金,
sum(mitigate_interest) 减免利息,
sum(mitigate_service_fee) 减免服务费,
sum(mitigate_collection_relief) 减免罚息,
sum(t1.residual_service_fee) 剩余未还服务费,
sum(t1.subsidy_fee) 还款补贴,
sum(t1.mitigate_subsidy_fee) 还款补贴减免,
sum(t1.premium) 保费,
sum(t1.mitigate_premium) 保费减免
from
new_transaction.xjd_repay_plan_repay_record_ref t1
join new_transaction.user_repayment_plan t2
on t2.id = t1.plan_id
join basic.funding_corp t6
on t2.fund_code = t6.funding_code
join new_transaction.repay_channel t7
on t1.repay_channel = t7.id
join audit.loan_manifest t8
on t8.ref_id = t2.ref_id
and t8.loan_paid_at < '2018-01-03'
where t1.bill_time >= {} and t1.bill_time < {}
group by 1, 2, 3, 4, 5, 6;
"""
new_sql_repay = """
select
t8.ref_id,
year(t8.loan_paid_at) l_year,
month(t8.loan_paid_at) l_month,
year(t1.bill_time) r_year,
month(t1.bill_time) r_month,
t2.deadline '应还日期',
t6.name funding_name,
t7.approach_name,
sum(t1.ref_amount) 总额,
sum(t1.principle) 本金,
sum(t1.interest) 利息,
sum(t1.service_fee) 服务费,
sum(t1.collection_relief) 催收减免,
-- sum(t1.red_package_fee) 实还红包减免,
sum(t1.punish) 逾期罚款收益,
sum(t1.remain_income) 其他收益,
sum(mitigate_principle) 减免本金,
sum(mitigate_interest) 减免利息,
sum(mitigate_service_fee) 减免服务费,
sum(mitigate_collection_relief) 减免罚息,
sum(t1.residual_service_fee) 剩余未还服务费,
sum(t1.subsidy_fee) 还款补贴,
sum(t1.mitigate_subsidy_fee) 还款补贴减免,
sum(t1.premium) 保费,
sum(t1.mitigate_premium) 保费减免
from
new_transaction.xjd_repay_plan_repay_record_ref t1
join new_transaction.user_repayment_plan t2
on t2.id = t1.plan_id
join basic.funding_corp t6
on t2.fund_code = t6.funding_code
join new_transaction.repay_channel t7
on t1.repay_channel = t7.id
join audit.loan_manifest t8
on t8.ref_id = t2.ref_id
and t8.loan_paid_at > '2018-01-03'
where t1.bill_time >= {} and t1.bill_time < {}
group by 1, 2, 3, 4, 5, 6;
"""
sql_dunjiao_serivce_fee = """
select
year (t3.loan_paid_at) l_year,
month (t3.loan_paid_at) l_month,
year (t4.bill_time) r_year,
month (t4.bill_time) r_month,
t5.NAME funding_name,
t6.approach_name,
sum(t1.ref_amount) "实还趸收服务费"
from
new_transaction.xjd_dunjiao_plan_ref t1
join new_transaction.xjd_dunjiao_plan t2
on t1.plan_id = t2.id
join audit.loan_manifest t3
on t2.ref_id = t3.ref_id
join repay_record_online t4
on t1.record_id = t4.id
join basic.funding_corp t5
on t5.funding_code = 150
join new_transaction.repay_channel t6
on t6.id = t1.repay_channel
and t4.pay_approach = t1.repay_channel
group by 1, 2, 3, 4, 5, 6
"""
sort_cols = ['l_year', 'l_month', 'r_year', 'r_month', 'funding_name', 'approach_name']
new_cols = {'l_year': u'放款年', 'l_month': u'放款月', 'r_year': u'还款年', 'r_month': u'还款月', 'funding_name': u'资金方',
'approach_name': u'收款账户'}
out_cols = ['ref_id', u'放款年', u'放款月', u'还款年', u'还款月',u'应还日期', u'资金方', u'收款账户', u'总额', u'本金', u'利息', u'服务费', u'催收减免', u'逾期罚款收益', u'其他收益',
u'减免本金', u'减免利息', u'减免服务费', u'减免罚息', u'剩余未还服务费', u'实还趸收服务费', u'还款补贴', u'还款补贴减免', u'保费', u'保费减免']
class loan_repay():
def __init__(self):
today = datetime.date.today()
self.end = datetime.date(today.year, today.month, 1)
last_day = self.end + datetime.timedelta(days=-1)
self.start = datetime.date(last_day.year, last_day.month, 1)
self.dir_path = path + self.start.strftime('%Y%m')
if not os.path.exists(self.dir_path):
os.makedirs(self.dir_path)
def loan_repay_details(self):
#self.start = datetime.date(2019, 1, 1)
#self.end = datetime.date(2019, 2, 1)
#self.end = datetime.date(2019, 2, 1)
begin_time = self.start.strftime("'%Y-%m-%d'")
end_time = self.end.strftime("'%Y-%m-%d'")
df_old = pd.read_sql(sql=sql_repay.format(begin_time, end_time), con=engine_new_transaction)
df_new = pd.read_sql(sql=new_sql_repay.format(begin_time, end_time), con=engine_new_transaction)
df_dunjiao = pd.read_sql(sql=sql_dunjiao_serivce_fee, con=engine_new_transaction)
df_old = pd.merge(df_old, df_dunjiao, how='left',
on=['l_year', 'l_month', 'r_year', 'r_month', 'funding_name', 'approach_name'])
df_old[u'实还趸收服务费'].fillna(value=0, inplace=True)
df_old[u'总额'] = df_old[u'总额'] + df_old[u'实还趸收服务费']
df_old.sort_values(sort_cols, inplace=True)
df_old.rename(columns=new_cols, inplace=True)
df_new.sort_values(sort_cols, inplace=True)
df_new.rename(columns=new_cols, inplace=True)
excel_file = pd.ExcelWriter(os.path.join(self.dir_path , u'现金贷还款表汇总refId-test{}.xlsx'.format(self.start.strftime('%Y%m'))))
df_old.to_excel(excel_file, u'旧模式', columns=out_cols, index=None)
df_new.to_excel(excel_file, u'新模式', columns=out_cols, index=None)
excel_file.save()
if __name__ == '__main__':
loan_repay().loan_repay_details()
print('======================loan_repay done===================================')
# -*- coding: utf-8 -*-
import datetime
import sys
import pandas as pd
import os
sys.path.append('../../../finance_out_table')
from db_con.db_connect import sql_engine
path = '/home/quant_group/vpants/finance/table/week/'
engine_new_transaction = sql_engine('audit', 'new_transaction').get_engine()
repay_sql = '''
select
t1.bill_time ,
t6.name funding_name ,
t7.approach_name ,
sum(t1.ref_amount) sum_amount
from
new_transaction.xjd_repay_plan_repay_record_ref t1
join new_transaction.user_repayment_plan t2
on t2.id = t1.plan_id
join basic.funding_corp t6
on t2.fund_code = t6.funding_code
join new_transaction.repay_channel t7
on t1.repay_channel = t7.id
join audit.loan_manifest t8
on t8.ref_id = t2.ref_id
and t8.loan_paid_at > '2018-01-03'
where t1.bill_time >= {} and t1.bill_time < {}
group by 1, 2, 3;
'''
new_cols = {'bill_time': u'还款时间', 'funding_name': u'资金方', 'approach_name': u'还款渠道', 'sum_amount': u'金额'}
class week_repay():
def __init__(self,today):
if not today:
self.today = datetime.date.today()
else:
self.today = today
self.end = self.today
self.start = self.today + datetime.timedelta(days=-7)
self.dir_path = path
if not os.path.exists(self.dir_path):
os.makedirs(self.dir_path)
def week_repay_details(self):
df_repay = pd.read_sql(sql=repay_sql.format(self.start.strftime("'%Y-%m-%d'"), self.end.strftime("'%Y-%m-%d'")), con=engine_new_transaction)
df_repay.rename(columns=new_cols, inplace=True)
df_repay.to_excel(os.path.join(self.dir_path, u'新模式-客户还款表-周({}-{}).xlsx'.format(self.start.strftime("%Y%m%d"), (self.end + datetime.timedelta(days=-1)).strftime("%Y%m%d"))),index=None)
if __name__ == '__main__':
today = None
#today = datetime.date(2018, 10, 29)
week_repay(today).week_repay_details()
print('======================week_repay done===================================')
# -*- coding: utf-8 -*-
import datetime
import sys
import pandas as pd
import os
sys.path.append('../../../finance_out_table')
from db_con.db_connect import sql_engine
path = '/home/quant_group/vpants/finance/table/'
engine_audit = sql_engine('audit', 'audit').get_engine()
sql = """
SELECT
year(lm.loan_paid_at) 放款年,
month(lm.loan_paid_at) 放款月,
YEAR (t1.repaid_at) 打款年份,
MONTH (t1.repaid_at) 打款月份,
fc.`name` 资金方,
sum(IFNULL(t1.current_repayment, 0)) 当期总额,
sum(IFNULL(t1.principle, 0)) 当期本金,
sum(IFNULL(t1.interest, 0)) 当期利息,
sum(IFNULL(t1.prepay_fee, 0)) 提前还款服务费,
sum(IFNULL(t1.funding_service_fee, 0)) 资金方服务费,
sum(IFNULL(t1.punish_fee, 0)) 逾期罚息
FROM
funding_repayment_record t1
JOIN basic.funding_corp fc ON t1.funding_code = fc.funding_code
join audit.loan_manifest lm on lm.ref_id=t1.ref_id
WHERE
t1.repaid_at>='2015-01-01'
AND t1.divide_status in(0,2)
GROUP BY 1, 2, 3,4,5
"""
sql_yeepay_fenzhang = """
SELECT
year(lm.loan_paid_at) 放款年,
month(lm.loan_paid_at) 放款月,
YEAR (t1.repaid_at) 打款年份,
MONTH (t1.repaid_at) 打款月份,
concat(fc.`name`,'-易宝分账') 资金方,
sum(IFNULL(t1.current_repayment, 0)) 当期总额,
sum(IFNULL(t1.principle, 0)) 当期本金,
sum(IFNULL(t1.interest, 0)) 当期利息,
sum(IFNULL(t1.prepay_fee, 0)) 提前还款服务费,
sum(IFNULL(t1.funding_service_fee, 0)) 资金方服务费,
sum(IFNULL(punish_fee, 0)) 逾期罚息
FROM
funding_repayment_record t1
JOIN basic.funding_corp fc ON t1.funding_code = fc.funding_code
join audit.loan_manifest lm on lm.ref_id=t1.ref_id
WHERE
t1.repaid_at>='2015-01-01'
AND t1.divide_status in(1,2)
AND t1.funding_code IN (290,330,390)
GROUP BY 1, 2, 3,4,5
"""
sql_huijinsuo = """
SELECT
year(lm.loan_paid_at) 放款年,
month(lm.loan_paid_at) 放款月,
YEAR (t1.repaid_at) 打款年份,
MONTH (t1.repaid_at) 打款月份,
concat(fc.`name`,'-线下打款') 资金方,
sum(IFNULL(t1.current_repayment, 0)) 当期总额,
sum(IFNULL(t1.principle, 0)) 当期本金,
sum(IFNULL(t1.interest, 0)) 当期利息,
sum(IFNULL(t1.prepay_fee, 0)) 提前还款服务费,
sum(IFNULL(t1.funding_service_fee, 0)) 资金方服务费,
sum(IFNULL(punish_fee, 0)) 逾期罚息
FROM
funding_repayment_record t1
JOIN basic.funding_corp fc ON t1.funding_code = fc.funding_code
join audit.loan_manifest lm on lm.ref_id=t1.ref_id
WHERE
t1.repaid_at>='2015-01-01'
AND t1.divide_status=-1
AND t1.funding_code =420
GROUP BY 1, 2, 3,4,5
"""
class fund_repay():
def __init__(self):
today = datetime.date.today()
self.end = datetime.date(today.year, today.month, 1)
last_day = self.end + datetime.timedelta(days=-1)
self.start = datetime.date(last_day.year, last_day.month, 1)
self.dir_path = path + self.start.strftime('%Y%m')
if not os.path.exists(self.dir_path):
os.makedirs(self.dir_path)
def fund_repay_details(self):
df_yeepay = pd.read_sql(sql=sql_yeepay_fenzhang, con=engine_audit)
df_com = pd.read_sql(sql=sql, con=engine_audit)
df_hjs = pd.read_sql(sql=sql_huijinsuo, con=engine_audit)
df = pd.concat([df_com, df_yeepay, df_hjs], ignore_index=True, axis=0)
df.sort_values([u'打款年份', u'打款月份'])
df.to_excel(os.path.join(self.dir_path, u'还资金方汇总表-{}.xlsx'.format(self.start.strftime('%Y%m'))), index=None)
if __name__ == '__main__':
fund_repay().fund_repay_details()
print('======================fund_repay done===================================')
# -*- coding: utf-8 -*-
import sys
import pandas as pd
import datetime
import os
import numpy as np
# 广达-账户不可用资金统计#
sys.path.append('../../../finance_out_table')
from db_con.db_connect import sql_engine
# path = '/home/quant_group/vpants/finance/table/'
path = '/Users/chenxiaozhe/Downloads/test/'
xyqb_conn = sql_engine('xyqb', 'xyqb').get_engine()
payment_center_conn = sql_engine('paycenter', 'payment_center').get_engine()
query_xyqb_sql = """
select rr.actual_repayment,rr.pay_center_order_no from repayment_record rr
inner join loan_application_manifest_history lamh on lamh.loan_application_history_id=rr.loan_application_history_id and lamh.funding_corp_id=480 and lamh.transaction_status=2
and lamh.loan_paid_at > '2018-01-03'
where rr.repayment_status=3 and rr.repayment_received_at >= {} and repayment_received_at < {}
"""
query_paycenter_sql = """
select merchant_repay_order_no as pay_center_order_no ,amount from repay_order where repay_status=3 and merchant_id=3 and merchant_repay_order_no in {}
"""
class fund_account():
def __init__(self):
self.last_day = datetime.date.today() + datetime.timedelta(-1)
self.today = datetime.date.today()
self.tomorrow = datetime.date.today() + datetime.timedelta(1)
def account(self):
#begin_time = self.last_day.strftime("'%Y-%m-%d'")
#end_time = self.today.strftime("'%Y-%m-%d'")
#begin_time = "'2019-08-20'"
#end_time = "'2019-08-21'"
begin_time = self.today.strftime("'%Y-%m-%d'")
end_time = self.tomorrow.strftime("'%Y-%m-%d'")
df_xyqb = pd.read_sql(sql=query_xyqb_sql.format(begin_time,end_time), con=xyqb_conn)
df_xyqb.pay_center_order_no = df_xyqb.pay_center_order_no.astype(str)
df_repay_order = pd.read_sql(
sql=query_paycenter_sql.format(str(tuple(df_xyqb.pay_center_order_no)).replace(',)', ')')),
con=payment_center_conn)
df_repay_all = pd.merge(df_xyqb, df_repay_order, how='inner', on='pay_center_order_no')
sumAmount = np.round(df_repay_all['amount'].sum(),2)
#table = {'统计日期': [self.today.strftime("%Y-%m-%d")], '金额': [sumAmount]}
table = {'统计日期': [begin_time], '金额': [sumAmount]}
df_table = pd.DataFrame(data=table)
#df_table.to_excel(os.path.join(path, '广达-众信利民代收的客户还款-不可用金额-{}.xlsx'.format(self.last_day.strftime("%Y-%m-%d"))), index=None)
df_table.to_excel(os.path.join(path, '广达-众信利民代收的客户还款-不可用金额-{}.xlsx'.format(begin_time)), index=None)
print df_table
if __name__ == '__main__':
fund_account().account()
print('======================fund_account done===================================')
# -*- coding: utf-8 -*-
import sys
import datetime
import os
import pandas as pd
sys.path.append('../../../finance_out_table')
from db_con.db_connect import sql_engine
engine_new_transaction = sql_engine('audit', 'new_transaction').get_engine()
path = '/home/quant_group/vpants/finance/table/'
sql_gd_repay = """
select
lm.loan_id,
lm.contract_loan_amount 放款金额,
date(lm.loan_paid_at) 放款日期,
f.name 资金方,
date(plan.deadline) 应还日期,
plan.term_no 当前期数,
date(ref.bill_time) 还款日期,
rc.approach_name 还款账户,
ref.ref_amount 还款总额,
ref.principle 还款本金,
ref.interest 还款利息,
ref.service_fee 还款服务费,
ref.collection_relief 催收减免,
ref.punish 逾期罚息,
ref.remain_income 其他收益,
mitigate_principle 减免本金,
mitigate_interest 减免利息,
mitigate_service_fee 减免服务费,
mitigate_collection_relief 减免罚息,
ref.residual_service_fee 剩余未还服务费,
ref.subsidy_fee 还款补贴,
ref.mitigate_subsidy_fee 还款补贴减免,
ref.premium 保费,
ref.mitigate_premium 保费减免
from
new_transaction.xjd_repay_plan_repay_record_ref ref
join new_transaction.repay_channel rc
on ref.repay_channel = rc.id
and ref.repay_channel = 25
and ref.bill_time >= '{}'
and ref.bill_time < '{}'
join new_transaction.user_repayment_plan plan
on plan.id = ref.plan_id
join audit.loan_manifest lm
on lm.ref_id = plan.ref_id
and lm.funding_code = 480
and lm.loan_paid_at < '2018-01-01'
join basic.funding_corp f
on f.funding_code = lm.funding_code ;
"""
class guangda_repay():
def __init__(self):
today = datetime.date.today()
self.end = datetime.date(today.year, today.month, 1)
last_day = self.end + datetime.timedelta(days=-1)
self.start = datetime.date(last_day.year, last_day.month, 1)
self.dir_path = path + self.start.strftime('%Y%m')
if not os.path.exists(self.dir_path):
os.makedirs(self.dir_path)
def yeepay_guangda_repay_details(self):
df = pd.read_sql(sql=sql_gd_repay.format(self.start, self.end), con=engine_new_transaction)
df.to_excel(os.path.join(self.dir_path, '易宝广达-客户还款表-{}.xlsx'.format(self.start.strftime('%Y%m'))), index=None)
if __name__ == '__main__':
guangda_repay().yeepay_guangda_repay_details()
print('======================yeepay_guangda_repay_details done===================================')
# -*- coding: utf-8 -*-
import sys
import pandas as pd
import datetime
import os
import numpy as np
# 广达-账户不可用资金统计#
sys.path.append('../../../finance_out_table')
from db_con.db_connect import sql_engine
# path = '/home/quant_group/vpants/finance/table/'
path = '/Users/chenxiaozhe/Downloads/test/'
xyqb_conn = sql_engine('xyqb', 'xyqb').get_engine()
payment_center_conn = sql_engine('paycenter', 'payment_center').get_engine()
query_xyqb_sql = """
select rr.actual_repayment,rr.pay_center_order_no from repayment_record rr
inner join loan_application_manifest_history lamh on lamh.loan_application_history_id=rr.loan_application_history_id and lamh.funding_corp_id=420 and lamh.transaction_status=2
where rr.repayment_status=3 and rr.repayment_received_at >= {} and repayment_received_at < {}
"""
query_paycenter_sql = """
select merchant_repay_order_no as pay_center_order_no ,amount from repay_order where repay_status=3 and merchant_id=3 and merchant_repay_order_no in {}
"""
class fund_account():
def __init__(self):
self.last_day = datetime.date.today() + datetime.timedelta(-1)
self.today = datetime.date.today()
def account(self):
#begin_time = self.last_day.strftime("'%Y-%m-%d'")
#end_time = self.today.strftime("'%Y-%m-%d'")
begin_time = "'2019-02-24'"
end_time = "'2019-02-25'"
df_xyqb = pd.read_sql(sql=query_xyqb_sql.format(begin_time,end_time), con=xyqb_conn)
df_xyqb.pay_center_order_no = df_xyqb.pay_center_order_no.astype(str)
if len(df_xyqb)==0:
sumAmount = 0
else:
df_repay_order = pd.read_sql(
sql=query_paycenter_sql.format(str(tuple(df_xyqb.pay_center_order_no)).replace(',)', ')')),
con=payment_center_conn)
df_repay_all = pd.merge(df_xyqb, df_repay_order, how='inner', on='pay_center_order_no')
sumAmount = np.round(df_repay_all['amount'].sum(),2)
#table = {'统计日期': [self.today.strftime("%Y-%m-%d")], '金额': [sumAmount]}
table = {'统计日期': ['2019-02-24'], '金额': [sumAmount]}
df_table = pd.DataFrame(data=table)
#df_table.to_excel(os.path.join(path, '广达-众信利民代收的客户还款-不可用金额-{}.xlsx'.format(self.last_day.strftime("%Y-%m-%d"))), index=None)
df_table.to_excel(os.path.join(path, '惠金所420-众信利民代收的客户还款-不可用金额-{}.xlsx'.format(begin_time)), index=None)
print df_table
if __name__ == '__main__':
fund_account().account()
print('======================fund_account done===================================')
# -*- coding: utf-8 -*-
import sys
import pandas as pd
import datetime
import os
import numpy as np
# 广达-账户不可用资金统计#
sys.path.append('../../../finance_out_table')
from db_con.db_connect import sql_engine
# path = '/home/quant_group/vpants/finance/table/'
path = '/Users/chenxiaozhe/Downloads/test/'
xyqb_conn = sql_engine('xyqb', 'xyqb').get_engine()
payment_center_conn = sql_engine('paycenter', 'payment_center').get_engine()
query_xyqb_sql = """
select rr.actual_repayment,rr.pay_center_order_no from repayment_record rr
inner join loan_application_manifest_history lamh on lamh.loan_application_history_id=rr.loan_application_history_id and lamh.funding_corp_id=520 and lamh.transaction_status=2
where rr.repayment_status=3 and rr.repayment_received_at >= {} and repayment_received_at < {}
"""
query_paycenter_sql = """
select merchant_repay_order_no as pay_center_order_no ,amount from repay_order where repay_status=3 and merchant_id=27 and pay_approach=5 and merchant_repay_order_no in {}
"""
class fund_account():
def __init__(self):
self.last_day = datetime.date.today() + datetime.timedelta(-1)
self.today = datetime.date.today()
self.tomorrow = datetime.date.today() + datetime.timedelta(1)
def account(self):
#begin_time = self.last_day.strftime("'%Y-%m-%d'")
#end_time = self.today.strftime("'%Y-%m-%d'")
#begin_time = "'2019-08-20'"
#end_time = "'2019-08-21'"
begin_time = self.today.strftime("'%Y-%m-%d'")
end_time = self.tomorrow.strftime("'%Y-%m-%d'")
#print begin_time,end_time
df_xyqb = pd.read_sql(sql=query_xyqb_sql.format(begin_time,end_time), con=xyqb_conn)
df_xyqb.pay_center_order_no = df_xyqb.pay_center_order_no.astype(str)
df_repay_order = pd.read_sql(
sql=query_paycenter_sql.format(str(tuple(df_xyqb.pay_center_order_no)).replace(',)', ')')),
con=payment_center_conn)
df_repay_all = pd.merge(df_xyqb, df_repay_order, how='inner', on='pay_center_order_no')
sumAmount = np.round(df_repay_all['amount'].sum(),2)
#table = {'统计日期': [self.today.strftime("%Y-%m-%d")], '金额': [sumAmount]}
table = {'统计日期': [begin_time], '金额': [sumAmount]}
df_table = pd.DataFrame(data=table)
#df_table.to_excel(os.path.join(path, '广达-众信利民代收的客户还款-不可用金额-{}.xlsx'.format(self.last_day.strftime("%Y-%m-%d"))), index=None)
df_table.to_excel(os.path.join(path, '惠金所520-众信利民代收的客户还款-不可用金额-{}.xlsx'.format(begin_time)), index=None)
print df_table
if __name__ == '__main__':
fund_account().account()
print('======================fund_account done===================================')
# -*- coding: utf-8 -*-
import datetime
import sys
import pandas as pd
import os
sys.path.append('../../../finance_out_table')
from db_con.db_connect import sql_engine
path = '/home/quant_group/vpants/finance/table/'
engine_new_transaction = sql_engine('audit', 'new_transaction').get_engine()
sql_repay = """
select
t8.ref_id,
year(t8.loan_paid_at) l_year,
month(t8.loan_paid_at) l_month,
year(t1.bill_time) r_year,
month(t1.bill_time) r_month,
t2.deadline '应还日期',
t6.name funding_name,
t7.approach_name,
sum(t1.ref_amount) 总额,
sum(t1.principle) 本金,
sum(t1.interest) 利息,
sum(t1.service_fee) 服务费,
sum(t1.collection_relief) 催收减免,
sum(t1.punish) 逾期罚款收益,
sum(t1.remain_income) 其他收益,
sum(mitigate_principle) 减免本金,
sum(mitigate_interest) 减免利息,
sum(mitigate_service_fee) 减免服务费,
sum(mitigate_collection_relief) 减免罚息,
sum(t1.residual_service_fee) 剩余未还服务费,
sum(t1.subsidy_fee) 还款补贴,
sum(t1.mitigate_subsidy_fee) 还款补贴减免,
sum(t1.premium) 保费,
sum(t1.mitigate_premium) 保费减免
from
new_transaction.xjd_repay_plan_repay_record_ref t1
join new_transaction.user_repayment_plan t2
on t2.id = t1.plan_id
join basic.funding_corp t6
on t2.fund_code = t6.funding_code and t6.`funding_code`=420
join new_transaction.repay_channel t7
on t1.repay_channel = t7.id
join audit.loan_manifest t8
on t8.ref_id = t2.ref_id
and t8.loan_paid_at < '2018-01-03'
where t1.bill_time >= {} and t1.bill_time < {}
group by 1, 2, 3, 4, 5, 6;
"""
sql_dunjiao_serivce_fee = """
select
year (t3.loan_paid_at) l_year,
month (t3.loan_paid_at) l_month,
year (t4.bill_time) r_year,
month (t4.bill_time) r_month,
t5.NAME funding_name,
t6.approach_name,
sum(t1.ref_amount) "实还趸收服务费"
from
new_transaction.xjd_dunjiao_plan_ref t1
join new_transaction.xjd_dunjiao_plan t2
on t1.plan_id = t2.id
join audit.loan_manifest t3
on t2.ref_id = t3.ref_id
join repay_record_online t4
on t1.record_id = t4.id
join basic.funding_corp t5
on t5.funding_code = 150
join new_transaction.repay_channel t6
on t6.id = t1.repay_channel
and t4.pay_approach = t1.repay_channel
group by 1, 2, 3, 4, 5, 6
"""
sort_cols = ['l_year', 'l_month', 'r_year', 'r_month', 'funding_name', 'approach_name']
new_cols = {'l_year': u'放款年', 'l_month': u'放款月', 'r_year': u'还款年', 'r_month': u'还款月', 'funding_name': u'资金方',
'approach_name': u'收款账户'}
out_cols = ['ref_id', u'放款年', u'放款月', u'还款年', u'还款月',u'应还日期', u'资金方', u'收款账户', u'总额', u'本金', u'利息', u'服务费', u'催收减免', u'逾期罚款收益', u'其他收益',
u'减免本金', u'减免利息', u'减免服务费', u'减免罚息', u'剩余未还服务费', u'实还趸收服务费', u'还款补贴', u'还款补贴减免', u'保费', u'保费减免']
class huijinsuo_loan_repay():
def __init__(self):
today = datetime.date.today()
self.end = datetime.date(today.year, today.month, 1)
last_day = self.end + datetime.timedelta(days=-1)
self.start = datetime.date(last_day.year, last_day.month, 1)
self.dir_path = path + self.start.strftime('%Y%m')
if not os.path.exists(self.dir_path):
os.makedirs(self.dir_path)
def huijinsuo_loan_repay_details(self):
begin_time = self.start.strftime("'%Y-%m-%d'")
end_time = self.end.strftime("'%Y-%m-%d'")
df_old = pd.read_sql(sql=sql_repay.format(begin_time, end_time), con=engine_new_transaction)
df_dunjiao = pd.read_sql(sql=sql_dunjiao_serivce_fee, con=engine_new_transaction)
df_old = pd.merge(df_old, df_dunjiao, how='left',
on=['l_year', 'l_month', 'r_year', 'r_month', 'funding_name', 'approach_name'])
df_old[u'实还趸收服务费'].fillna(value=0, inplace=True)
df_old[u'总额'] = df_old[u'总额'] + df_old[u'实还趸收服务费']
df_old.sort_values(sort_cols, inplace=True)
df_old.rename(columns=new_cols, inplace=True)
excel_file = pd.ExcelWriter(os.path.join(self.dir_path , u'惠金所还款表汇总-{}.xlsx'.format(self.start.strftime('%Y%m'))))
df_old.to_excel(excel_file, u'旧模式', columns=out_cols, index=None)
excel_file.save()
if __name__ == '__main__':
huijinsuo_loan_repay().huijinsuo_loan_repay_details()
print('======================huijinsuo_loan_repay done===================================')
# -*- coding: utf-8 -*-
import sys
import pandas as pd
import datetime
import os
sys.path.append('../../../finance_out_table')
from db_con.db_connect import sql_engine
#path = '/home/quant_group/vpants/finance/table/'
path = '/Users/chenxiaozhe/Downloads/test/201901'
audit_conn = sql_engine('audit', 'audit').get_engine()
new_transaction_conn = sql_engine('audit', 'new_transaction').get_engine()
summary_sql = """
SELECT
year(loan.loan_paid_at) 放款年,
month(loan.loan_paid_at) 放款月,
f.name 资金方,
sum(loan.contract_loan_amount) 放款金额
FROM
audit.loan_manifest loan
JOIN basic.funding_corp f
ON f.funding_code = loan.funding_code
where loan.loan_paid_at >= '{0}'
AND loan.loan_paid_at < '{1}'
and loan.funding_code = 620
GROUP BY 1, 2;
"""
details_sql = """
SELECT
f.name 资金方,
loan.loan_id,
loan.contract_no 贷款合同号,
date(loan.loan_paid_at) 放款日期,
loan.contract_loan_amount 放款金额,
loan.contract_term 总期数
FROM
audit.loan_manifest loan
JOIN basic.funding_corp f
ON f.funding_code = loan.funding_code
AND loan.loan_paid_at >= '{0}'
AND loan.loan_paid_at < '{1}'
and loan.funding_code = 620
"""
repay_sql = """
select year(loan_paid_at) as '放款年',month(loan_paid_at) as '放款月',loan_id,term_no as '期数', year(bill_time) as '还款年',month(bill_time) as '还款月', principle as '本金',interest as '利息',punish as '罚息',over_due_days as '逾期天数' from minjin_repay_record_online
where bill_time >= '{0}' and bill_time < '{1}';
"""
repay_sum_sql = """
select year(bill_time) as '实还年',month(bill_time) as '实还月', sum(principle) as '当期实还本金',sum(interest) as '当期实还利息', sum(punish) as '当期实还罚息', sum(IF(over_due_days > 90 ,0,round((interest+punish) * 0.25,2))) as 'QG服务费金额2-期收' from minjin_repay_record_online
group by 1,2
"""
loan_repay_sql = """
select year(bill_time) as '实还年',month(bill_time) as '实还月',loan_id, principle as '当期实还本金',interest as '当期实还利息', punish as '当期实还罚息', IF(over_due_days > 90 ,0,round((interest+punish) * 0.25,2)) as 'QG服务费金额2-期收' from minjin_repay_record_online
"""
class minjin_loan_repay():
def __init__(self):
today = datetime.date.today()
self.end = datetime.date(today.year, today.month, 1)
last_day = self.end + datetime.timedelta(days=-1)
self.start = datetime.date(last_day.year, last_day.month, 1)
self.dir_path = path + self.start.strftime('%Y%m')
if not os.path.exists(self.dir_path):
os.makedirs(self.dir_path)
def minjin_loan_repay_detail(self):
# 放款汇总表
#df_loan = pd.read_sql(sql=summary_sql.format(self.start, self.end), con=audit_conn)
#df_loan.to_excel(os.path.join(self.dir_path, u'民金放款-汇总表-{}.xlsx'.format(self.start.strftime('%Y%m'))),index=None)
# 放款明细表
#df_detail = pd.read_sql(sql=details_sql.format(self.start, self.end), con=audit_conn)
#df_detail.to_excel(os.path.join(self.dir_path, u'民金放款-明细表-{}.xlsx'.format(self.start.strftime('%Y%m'))),index=None)
# 客户还款表
df_repay = pd.read_sql(sql=repay_sql.format(self.start, self.end), con=new_transaction_conn)
df_repay['总额'] = round(df_repay['本金'] + df_repay['利息'] + df_repay['罚息'], 2)
df_repay.to_excel(os.path.join(self.dir_path, '民金-还款-{}.xlsx'.format(self.start.strftime('%Y%m'))),
index=None)
# 收入确认表
df_qishou = pd.read_sql(sql=repay_sum_sql, con=new_transaction_conn)
df_qishou['总额'] = round(
df_qishou['当期实还本金'] + df_qishou['当期实还利息'] + df_qishou['当期实还罚息'], 2)
df_qishou.to_excel(os.path.join(self.dir_path, '民金-收入确认-{}.xlsx'.format(self.start.strftime('%Y%m'))),
index=None)
df_loan_qishou = pd.read_sql(sql=loan_repay_sql, con=new_transaction_conn)
df_loan_qishou['总额'] = round(
df_loan_qishou['当期实还本金'] + df_loan_qishou['当期实还利息'] + df_loan_qishou['当期实还罚息'], 2)
df_loan_qishou.to_excel(os.path.join(self.dir_path, '民金-结算-{}.xlsx'.format(self.start.strftime('%Y%m'))), index=None)
if __name__ == '__main__':
minjin_loan_repay().minjin_loan_repay_detail()
print('======================minjin_loan done===================================')
# -*- coding: utf-8 -*-
import os
import sys
import datetime
import pandas as pd
sys.path.append('../../../finance_out_table')
from db_con.db_connect import sql_engine
path = '/home/quant_group/vpants/finance/table/'
new_transaction_conn = sql_engine('audit', 'new_transaction').get_engine()
query_poundage_sql = """
select r1.pay_approach as '渠道号' ,r2.approach_name as '还款渠道' ,sum(poundage) as '手续费' from repay_record_online r1 inner join repay_channel r2 on r1.pay_approach=r2.id where r1.bill_time>={} and r1.bill_time<{} group by r1.pay_approach
"""
class month_poundage():
def __init__(self):
today = datetime.date.today()
self.end = datetime.date(today.year, today.month, 1)
last_day = self.end + datetime.timedelta(days=-1)
self.start = datetime.date(last_day.year, last_day.month, 1)
self.dir_path = path + self.start.strftime('%Y%m')
if not os.path.exists(self.dir_path):
os.makedirs(self.dir_path)
def poundage_details(self):
df = pd.read_sql(sql=query_poundage_sql.format(self.start.strftime("'%Y-%m-%d'"), self.end.strftime("'%Y-%m-%d'")), con=new_transaction_conn)
df.to_excel(os.path.join(self.dir_path, u'手续费-{}.xlsx'.format(self.start.strftime('%Y%m'))), index=None)
if __name__ == '__main__':
month_poundage().poundage_details()
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
# -*- coding: utf-8 -*-
import sys
import datetime
from out_table.cash_loan.plan_punish import plan_punish
from out_table.cash_loan.repay_split import repay_split
sys.path.append('../../../finance_out_table')
class punish_split():
def __init__(self, is_mock):
self.is_mock = is_mock
def punish_split_detail(self):
# 罚息计算
plan_punish(self.is_mock).plan_punish_details(plan_ids=None)
# 拆分
today = datetime.date.today()
end = datetime.date(today.year, today.month, 1)
last_day = end + datetime.timedelta(days=-1)
start = datetime.date(last_day.year, last_day.month, 1)
##test##
# start = datetime.date(2018, 8, 1)
# end = datetime.date(2018, 9, 1)
##test##
split_instance = repay_split(self.is_mock, start, end)
split_instance.update_repay_ref(plan_ids=None)
split_instance.update_refund_ref(plan_ids=None)
if __name__ == '__main__':
punish_split(is_mock=False).punish_split_detail()
This diff is collapsed.
# -*- coding: utf-8 -*-
import pandas as pd
from sqlalchemy import create_engine
import numpy as np
import datetime
import sys
import os
path = '/Users/chenxiaozhe/Downloads/account/19_01/'
sys.path.append('../../../finance_out_table')
from db_con.db_connect import sql_engine
engine_audit_w = sql_engine('audit_w', 'new_transaction').get_engine()
engine_audit = sql_engine('audit', 'audit').get_engine()
"""
(1)
select merchant_repay_order_no from repay_order where order_id in ()
(2)
select rr.loan_application_history_id as loan_id,rr.repayment_plan_id as plan_id,610,rr.term_no,lamh.loan_paid_at,
rr.principal,rr.interest,rr.premium,rr.actual_repayment as total_amount,'2019-01-23', rr.repayment_plan_id as pay_center_order_no from repayment_record rr
inner join loan_application_manifest_history lamh on lamh.loan_application_history_id=rr.loan_application_history_id
where rr.pay_center_order_no in ()
order by loan_id
(3)
select count(*) from xiaoyingp2p_repay_record_online where created_at>='2019-01-31 14:00:00'
"""
if __name__ == '__main__':
df_excel = pd.read_excel(path + u"xiaoying-03-29.xlsx", skiprows=1, names=[
'loan_id',
'plan_id',
'fund_id',
'term_no',
'loan_paid_at',
'principle',
'interest',
'premium',
'total_amount',
'bill_time',
'pay_center_order_no'
], header=None)
df_excel['loan_id'] = df_excel['loan_id'].astype(str)
query_sql = """
select loan_id ,ref_id from audit.loan_manifest where loan_id in {}
"""
df_repay_order = pd.read_sql(
sql=query_sql.format(str(tuple(df_excel.loan_id)).replace(',)', ')')),
con=engine_audit)
df_repay_all = pd.merge(df_excel, df_repay_order, how='inner', on='loan_id')
df_repay_all_610 = df_repay_all.loc[df_repay_all['fund_id'] == 610]
df_repay_all_610['product_type'] = 1
df_repay_all_710 = df_repay_all.loc[df_repay_all['fund_id'] == 700]
df_repay_all_710['product_type'] = 2
#df_repay_all.to_sql('xiaoyingp2p_repay_record_online', con=engine_audit_w, if_exists='append', index=None)
print df_repay_all_610
print df_repay_all_710
# -*- coding: utf-8 -*-
import sys
import pandas as pd
import datetime
import os
sys.path.append('../../../finance_out_table')
from db_con.db_connect import sql_engine
#path = '/home/quant_group/vpants/finance/table/'
path = '/Users/chenxiaozhe/Downloads/test/'
audit_conn = sql_engine('audit', 'audit').get_engine()
query_loan_sql = """
SELECT
year(loan.loan_paid_at) 放款年,
month(loan.loan_paid_at) 放款月,
f.name 资金方,
sum(loan.contract_loan_amount) 放款金额
FROM
audit.loan_manifest loan
JOIN basic.funding_corp f
ON f.funding_code = loan.funding_code
AND loan.loan_paid_at >= '{0}'
AND loan.loan_paid_at < '{1}'
AND loan.funding_code = 630
GROUP BY 1, 2, 3 ;
"""
query_loan_details = """
SELECT
f.name 资金方,
loan.loan_id,
loan.contract_no 贷款合同号,
date(loan.loan_paid_at) 放款日期,
loan.contract_loan_amount 放款金额,
loan.contract_term 总期数,
loan.monthly_interest_rate 月利率,
loan.class 风险等级
FROM
audit.loan_manifest loan
JOIN basic.funding_corp f
ON f.funding_code = loan.funding_code
where loan.loan_paid_at >= '{0}'
AND loan.loan_paid_at < '{1}'
AND loan.funding_code = 630
"""
query_duishou_sql = """
SELECT loan_year 放款年,loan_month 放款月,fund_name 资金方, sum(loan_amount) 放款金额 , sum(duishou_amount) QG服务费金额趸收 FROM (
SELECT
year(loan.loan_paid_at) loan_year,
month(loan.loan_paid_at) loan_month,
f.name fund_name,
loan.contract_loan_amount loan_amount,
round(loan.contract_loan_amount * 0.00875,2 ) duishou_amount
FROM
audit.loan_manifest loan
JOIN basic.funding_corp f
ON f.funding_code = loan.funding_code
AND loan.loan_paid_at >= '{0}'
AND loan.loan_paid_at < '{1}'
AND loan.funding_code = 630
) t group by 1,2,3
"""
class xiaoniu_loan_repay():
def __init__(self):
today = datetime.date.today()
self.end = datetime.date(today.year, today.month, 1)
last_day = self.end + datetime.timedelta(days=-1)
self.start = datetime.date(last_day.year, last_day.month, 1)
self.dir_path = path + self.start.strftime('%Y%m')
if not os.path.exists(self.dir_path):
os.makedirs(self.dir_path)
def xiaoniu_loan_repay_details(self):
# 放款汇总
df_loan = pd.read_sql(sql=query_loan_sql.format(self.start, self.end), con=audit_conn)
df_loan.to_excel(os.path.join(self.dir_path, u'小牛-放款汇总表-{}.xlsx'.format(self.start.strftime('%Y%m'))), index=None)
# 放款明细
df_loan_details = pd.read_sql(sql=query_loan_details.format(self.start, self.end), con=audit_conn)
df_loan_details.to_excel(os.path.join(self.dir_path, u'小牛-放款明细表-{}.xlsx'.format(self.start.strftime('%Y%m'))), index=None)
# 趸收收入确认表
df_loan_details = pd.read_sql(sql=query_duishou_sql.format(self.start, self.end), con=audit_conn)
df_loan_details.to_excel(os.path.join(self.dir_path, u'小牛-趸收收入确认表-{}.xlsx'.format(self.start.strftime('%Y%m'))), index=None)
if __name__ == '__main__':
xiaoniu_loan_repay().xiaoniu_loan_repay_details()
print('======================xiaoniu_loan_repay done===================================')
# -*- coding: utf-8 -*-
import sys
import pandas as pd
import datetime
import os
import numpy as np
# 小赢p2p-众信利民代收的客户还款-不可用金额#
sys.path.append('../../../finance_out_table')
from db_con.db_connect import sql_engine
# path = '/home/quant_group/vpants/finance/table/'
path = '/Users/chenxiaozhe/Downloads/test/'
xyqb_conn = sql_engine('xyqb', 'xyqb').get_engine()
payment_center_conn = sql_engine('paycenter', 'payment_center').get_engine()
query_xyqb_sql = """
select rr.actual_repayment,rr.pay_center_order_no from repayment_record rr
inner join loan_application_manifest_history lamh on lamh.loan_application_history_id=rr.loan_application_history_id and lamh.funding_corp_id=610 and lamh.transaction_status=2
where rr.repayment_status=3 and rr.repayment_received_at < rr.deadline and rr.deadline > {}
"""
query_paycenter_sql = """
select merchant_repay_order_no as pay_center_order_no ,amount from repay_order where repay_status=3 and merchant_id=3 and merchant_repay_order_no in {}
"""
class fund_account():
def __init__(self):
self.today = datetime.date.today() + datetime.timedelta(-1)
self.tomorrow = datetime.date.today() + datetime.timedelta(1)
def account(self):
#begin_time = self.today.strftime("'%Y-%m-%d'")
#begin_time = datetime.date(2019, 8, 20).strftime("'%Y-%m-%d'")
begin_time = datetime.date.today().strftime("'%Y-%m-%d'")
df_xyqb = pd.read_sql(sql=query_xyqb_sql.format(begin_time), con=xyqb_conn)
df_xyqb.pay_center_order_no = df_xyqb.pay_center_order_no.astype(str)
df_repay_order = pd.read_sql(
sql=query_paycenter_sql.format(str(tuple(df_xyqb.pay_center_order_no)).replace(',)', ')')),
con=payment_center_conn)
df_repay_all = pd.merge(df_xyqb, df_repay_order, how='inner', on='pay_center_order_no')
sumAmount = np.round(df_repay_all['amount'].sum(),2)
#table = {'统计日期': [self.today.strftime("%Y-%m-%d")], '金额': [sumAmount]}
table = {'统计日期': [begin_time], '金额': [sumAmount]}
df_table = pd.DataFrame(data=table)
#df_table.to_excel(os.path.join(path, '小赢p2p-众信利民代收的客户还款-不可用金额-{}.xlsx'.format(self.today.strftime("%Y-%m-%d"))),index=None)
df_table.to_excel(os.path.join(path, '小赢p2p-众信利民代收的客户还款-不可用金额-{}.xlsx'.format(begin_time)),index=None)
print df_table
if __name__ == '__main__':
fund_account().account()
print('======================fund_account done===================================')
This diff is collapsed.
This diff is collapsed.
# -*- coding: utf-8 -*-
import sys
import pandas as pd
import datetime
import os
import numpy as np
sys.path.append('../../../finance_out_table')
from db_con.db_connect import sql_engine
path = '/home/quant_group/vpants/finance/table/'
#path = '/Users/chenxiaozhe/Downloads/test/'
new_transaction_conn = sql_engine('audit', 'new_transaction').get_engine()
xyqb_conn = sql_engine('xyqb', 'xyqb').get_engine()
query_qishou2_repay_sql = """
select xrro.bill_time as '还款时间',xrro.loan_paid_at as '放款时间',xrro.principle as '实还本金',xrro.interest as '实还利息',xrro.premium as '实还保费',
loan.contract_loan_amount as '放款本金',loan.contract_term as '总期数' from xiaoyingp2p_repay_record_online xrro
inner join audit.loan_manifest loan on loan.loan_id=xrro.loan_id where xrro.product_type=2
"""
# where xrro.bill_time >= {} and xrro.bill_time < {}
query_behalf_sql = """
select fbp.behalf_at as '代偿时间',fii.xyqb_loan_request_id as '合作方订单号', lm.loan_paid_at as '放款时间',lm.contract_loan_amount as '放款本金',lm.contract_term as '总期数',
behalf_principal+behalf_interest+rr.premium as '实还总额', behalf_principal as '实还本金',behalf_interest as '实还利息',rr.premium as '实还保费',rr.term_no as '第几期' from fund_behalf_plan fbp
INNER JOIN repayment_record rr on rr.repayment_plan_id=fbp.plan_id and fbp.fund_id=640
INNER JOIN loan_application_manifest_history lm on lm.loan_application_history_id=rr.loan_application_history_id
INNER JOIN funding_interaction_info fii on fii.loan_id = lm.loan_application_history_id
"""
class xiaoying_short_repay():
def __init__(self):
today = datetime.date.today()
self.end = datetime.date(today.year, today.month, 1)
last_day = self.end + datetime.timedelta(days=-1)
self.start = datetime.date(last_day.year, last_day.month, 1)
self.dir_path = path + self.start.strftime('%Y%m')
if not os.path.exists(self.dir_path):
os.makedirs(self.dir_path)
def qishou(self):
# 2018-10-19号之前
begin_time = self.start.strftime("'%Y-%m-%d'")
end_time = self.end.strftime("'%Y-%m-%d'")
# 2018-10-19号之后
df_qishou2 = pd.read_sql(sql=query_qishou2_repay_sql, con=new_transaction_conn)
if len(df_qishou2) == 0:
return
df_qishou2[u'资金方'] = '小赢p2p'
df_qishou2[u'实还总额'] = df_qishou2[u'实还本金'] + df_qishou2[u'实还利息'] + df_qishou2[u'实还保费']
df_qishou2[u'小赢14%部分本息'] = np.round(np.pmt(0.011667, df_qishou2[u'总期数'], -df_qishou2[u'放款本金']), 2)
df_qishou2[u'借款人每期36%部分还款本息'] = np.round(df_qishou2[u'放款本金'] * 0.36 / 12 + df_qishou2[u'放款本金'] / df_qishou2[u'总期数'], 2)
df_qishou2[u'QG服务费金额-期收'] = df_qishou2[u'借款人每期36%部分还款本息'] - df_qishou2[u'小赢14%部分本息']
df_qishou2.to_csv(os.path.join(self.dir_path, '小赢p2p-短期-期收收入确认表-{}.csv'.format(self.start.strftime('%Y%m'))), index=None, encoding='gbk')
#代偿
df_behalf = pd.read_sql(sql=query_behalf_sql, con=xyqb_conn)
if len(df_behalf) == 0:
return
df_behalf[u'资金方'] = '小赢p2p'
df_behalf[u'小赢14%部分本息'] = np.round(np.pmt(0.011667, df_behalf[u'总期数'], -df_behalf[u'放款本金']), 2)
df_behalf[u'借款人每期36%部分还款本息'] = np.round(df_behalf[u'放款本金'] * 0.36 / 12 + df_behalf[u'放款本金'] / df_behalf[u'总期数'], 2)
df_behalf[u'QG服务费金额-期收'] = df_behalf[u'借款人每期36%部分还款本息'] - df_behalf[u'小赢14%部分本息']
df_behalf.to_csv(os.path.join(self.dir_path, '小赢p2p-短期-代偿表-{}.csv'.format(self.start.strftime('%Y%m'))),index=None, encoding='gbk')
def xiaoying_short_repay_detail(self):
self.qishou()
if __name__ == '__main__':
xiaoying_short_repay().xiaoying_short_repay_detail()
print('======================xiaoying_short_repay done===================================')
\ No newline at end of file
# -*- coding: utf-8 -*-
import sys
import pandas as pd
import datetime
import os
import numpy as np
# 小赢期收10月19号之后的放款且还款至众信利民统计#
sys.path.append('../../../finance_out_table')
from db_con.db_connect import sql_engine
# path = '/home/quant_group/vpants/finance/table/'
path = '/Users/chenxiaozhe/Downloads/test/201901'
xyqb_conn = sql_engine('xyqb', 'xyqb').get_engine()
payment_center_conn = sql_engine('paycenter', 'payment_center').get_engine()
query_xyqb_sql = """
select rr.deadline as '应还时间',rr.repayment_received_at as '实还时间',lamh.loan_paid_at as '放款时间', rr.actual_repayment as '实还总额',rr.pay_center_order_no,lamh.loan_application_history_id,fii.xyqb_loan_request_id,
rr.principal as '实还本金',rr.interest as '实还利息',rr.premium as '实还保费',lamh.contract_loan_amount as '放款本金',lamh.contract_term as '总期数',rr.term_no as '期数' from repayment_record rr
inner join loan_application_manifest_history lamh on lamh.loan_application_history_id=rr.loan_application_history_id and lamh.funding_corp_id=610 and lamh.transaction_status=2 and lamh.loan_paid_at >='2018-10-19'
inner join funding_interaction_info fii on fii.loan_id=lamh.loan_application_history_id
where rr.updated_at>='2019-01-01' and rr.updated_at <= '2019-01-22 11:22:51' and rr.repayment_status=3 and rr.overdue_days = 0
"""
query_paycenter_sql = """
select merchant_repay_order_no as pay_center_order_no ,amount from repay_order where repay_status=3 and merchant_id=3 and merchant_repay_order_no in {}
"""
class xiaoying_zxlm():
def __init__(self):
today = datetime.date.today()
self.end = datetime.date(today.year, today.month, 1)
last_day = self.end + datetime.timedelta(days=-1)
self.start = datetime.date(last_day.year, last_day.month, 1)
self.dir_path = path + self.start.strftime('%Y%m')
if not os.path.exists(self.dir_path):
os.makedirs(self.dir_path)
def xiaoying_zxlm_detail(self):
df_xyqb = pd.read_sql(sql=query_xyqb_sql, con=xyqb_conn)
df_xyqb.pay_center_order_no = df_xyqb.pay_center_order_no.astype(str)
df_repay_order = pd.read_sql(
sql=query_paycenter_sql.format(str(tuple(df_xyqb.pay_center_order_no)).replace(',)', ')')),
con=payment_center_conn)
df_repay_all = pd.merge(df_xyqb, df_repay_order, how='inner', on='pay_center_order_no')
df_repay_all[u'小赢14%部分本息'] = np.round(np.pmt(0.011667, df_repay_all[u'总期数'], -df_repay_all[u'放款本金']), 2)
df_repay_all[u'借款人每期36%部分还款本息'] = np.round(
df_repay_all[u'放款本金'] * 0.36 / 12 + df_repay_all[u'放款本金'] / df_repay_all[u'总期数'], 2)
df_repay_all[u'QG服务费金额-期收'] = df_repay_all[u'借款人每期36%部分还款本息'] - df_repay_all[u'小赢14%部分本息']
df_repay_all.to_csv(os.path.join(path, '小赢期收10月19号之后的放款且还款至众信利民统计new-{}.csv'.format(self.start.strftime('%Y%m'))),index=None,encoding='gbk')
if __name__ == '__main__':
xiaoying_zxlm().xiaoying_zxlm_detail()
print('==================================xiaoying_zxlm done===================================')
# -*- coding: utf-8 -*-
import sys
import pandas as pd
import datetime
import os
sys.path.append('../../../finance_out_table')
from db_con.db_connect import sql_engine
path = '/home/quant_group/vpants/finance/table/'
audit_conn = sql_engine('audit', 'audit').get_engine()
query_loan_sql = """
SELECT
year(loan.loan_paid_at) 放款年,
month(loan.loan_paid_at) 放款月,
f.name 资金方,
loan.class 风险等级,
sum(loan.contract_loan_amount) 放款金额
FROM
audit.loan_manifest loan
JOIN basic.funding_corp f
ON f.funding_code = loan.funding_code
AND loan.loan_paid_at >= '{0}'
AND loan.loan_paid_at < '{1}'
AND loan.funding_code = 600
GROUP BY 1, 2, 3, 4 ;
"""
count_loan_sql = """
SELECT
count(*) loan_count
FROM
audit.loan_manifest loan
JOIN basic.funding_corp f
ON f.funding_code = loan.funding_code
AND loan.loan_paid_at >= '{0}'
AND loan.loan_paid_at < '{1}'
AND loan.funding_code = 600
"""
query_loan_details = """
SELECT
f.name 资金方,
loan.loan_id,
loan.contract_no 贷款合同号,
date(loan.loan_paid_at) 放款日期,
loan.contract_loan_amount 放款金额,
loan.contract_term 总期数,
loan.monthly_interest_rate 月利率,
loan.class 风险等级
FROM
audit.loan_manifest loan
JOIN basic.funding_corp f
ON f.funding_code = loan.funding_code
where loan.loan_paid_at >= '{0}'
AND loan.loan_paid_at < '{1}'
AND loan.funding_code = 600
"""
class xingye_loan():
def __init__(self):
today = datetime.date.today()
self.end = datetime.date(today.year, today.month, 1)
last_day = self.end + datetime.timedelta(days=-1)
self.start = datetime.date(last_day.year, last_day.month, 1)
##test##
#self.start = datetime.date(2018, 9, 1)
#self.end = datetime.date(2018, 10, 1)
##test##
self.dir_path = path + self.start.strftime('%Y%m')
if not os.path.exists(self.dir_path):
os.makedirs(self.dir_path)
def xingye_loan_details(self):
#放款汇总
df_loan = pd.read_sql(sql=query_loan_sql.format(self.start, self.end), con=audit_conn)
df_loan_count = pd.read_sql(sql=count_loan_sql.format(self.start, self.end), con=audit_conn)
df_loan['代付成本'] = df_loan_count['loan_count'].tolist()[0] * 1
df_loan.to_excel(os.path.join(self.dir_path, u'兴业-放款汇总表-{}.xlsx'.format(self.start.strftime('%Y%m'))), index=None)
#放款明细
df_loan_details = pd.read_sql(sql=query_loan_details.format(self.start, self.end), con=audit_conn)
df_loan_details.to_excel(os.path.join(self.dir_path, u'兴业-放款明细表-{}.xlsx'.format(self.start.strftime('%Y%m'))), index=None)
if __name__ == '__main__':
xingye_loan().xingye_loan_details()
print('======================xingye_loan done===================================')
\ No newline at end of file
# -*- coding: utf-8 -*-
import sys
import pandas as pd
import datetime
import os
import numpy as np
sys.path.append('../../../finance_out_table')
from db_con.db_connect import sql_engine
path = '/home/quant_group/vpants/finance/table/'
new_transaction_conn = sql_engine('audit', 'new_transaction').get_engine()
audit_conn = sql_engine('audit', 'audit').get_engine()
#test
#query_repay_sql = """
# select t8.loan_id,t1.bill_time,year(t8.loan_paid_at) loan_year,month(t8.loan_paid_at) loan_month,year(t1.bill_time) repay_year,month(t1.bill_time) repay_month,
# t1.ref_amount total_amount,t1.principle act_principle,t1.interest act_interest,t1.service_fee act_punish,t1.collection_relief act_penalty
#from
# new_transaction.xjd_repay_plan_repay_record_ref t1 join new_transaction.user_repayment_plan t2 on t2.id = t1.plan_id
# join basic.funding_corp t6 on t2.fund_code = t6.funding_code and t6.`funding_code`=600 join audit.loan_manifest t8 on t8.ref_id = t2.ref_id
# where t1.bill_time >= {} and t1.bill_time < {}
#"""
query_repay_sql = """
select loan_id,bill_time,year(loan_paid_at) loan_year, month(loan_paid_at) loan_month ,year(bill_time) repay_year, month(bill_time) repay_month, total_amount, act_principle,act_interest,act_punish,act_penalty from xingye_repay_record_online
where bill_time >= {} and bill_time < {}
"""
# 测试 funding_code=420
# funding_code=600
query_loan_count_sql = """
select count(*) loan_count from audit.loan_manifest where funding_code = 600 and loan_paid_at >= {} and loan_paid_at < {}
"""
query_plan_sql = """
select t1.loan_id,t1.ref_id,year(loan_paid_at) as fkyear,month(loan_paid_at) as fkmonth,year(max(deadline)) as hkyear,month(max(deadline)) as hkmonth, sum(principle) as principle ,sum(interest) as interest ,sum(service_fee) as service_fee from audit.loan_manifest t1 inner join new_transaction.user_repayment_plan t2 on t1.ref_id=t2.ref_id and t1.funding_code=600
group by t1.ref_id
"""
query_max_deadline_sql = """
select t1.loan_id , DATE_FORMAT(date_add(max(deadline), interval 1 month),'%%Y-%%m-01') deadline from audit.loan_manifest t1 inner join new_transaction.user_repayment_plan t2 on t1.ref_id=t2.ref_id and t1.funding_code=600
where t1.loan_id
group by t1.loan_id
"""
class xingye_repay():
def __init__(self):
today = datetime.date.today()
self.end = datetime.date(today.year, today.month, 1)
last_day = self.end + datetime.timedelta(days=-1)
self.start = datetime.date(last_day.year, last_day.month, 1)
##test##
#self.start = datetime.date(2018, 9, 1)
#self.end = datetime.date(2018, 10, 1)
##test##
self.dir_path = path + self.start.strftime('%Y%m')
if not os.path.exists(self.dir_path):
os.makedirs(self.dir_path)
def xingye_repay(self):
# 期收
begin_time = self.start.strftime("'%Y-%m-%d'")
end_time = self.end.strftime("'%Y-%m-%d'")
df_repay = pd.read_sql(sql=query_repay_sql.format(begin_time, end_time), con=new_transaction_conn)
if len(df_repay) == 0:
return
#统计当月放款数量
df_loan = pd.read_sql(sql=query_loan_count_sql.format(begin_time, end_time), con=new_transaction_conn)
df_repay['loan_count'] = df_loan['loan_count'].tolist()[0]
df_repay['fund_name'] = '兴业'
#代收
df_repay['collection'] = np.round(df_repay['total_amount'] * 0.002, 2)
#代付
df_repay['substitute'] = df_repay['loan_count'] * 1
#期收
df_repay['qishou'] = np.round((df_repay['act_interest'] + df_repay['act_punish'] + df_repay['act_penalty'] - df_repay['collection'] - df_repay['substitute']) * 0.01, 2)
#要把还款时间在该笔loan,最后一期deadline + 1个月后的还款排除去,出在另外一张表 '收入确认表-贷后服务费3'
df_repay.loan_id = df_repay.loan_id.astype(str)
df_loan_deadline = pd.read_sql(sql=query_max_deadline_sql.format(str(tuple(df_repay.loan_id)).replace(',)', ')')) , con=audit_conn)
df_loan_deadline['deadline'] = pd.to_datetime(df_loan_deadline['deadline']).dt.date
df_repay['bill_time'] = pd.to_datetime(df_repay['bill_time']).dt.date
df_all = pd.merge(df_repay, df_loan_deadline, how='left', on='loan_id')
df_before_deadline_repay = df_all.ix[df_all['bill_time'] < df_all['deadline']]
df_after_deadline_repay = df_all.ix[df_all['bill_time'] > df_all['deadline']]
# 期收1
df_before_deadline_repay = df_before_deadline_repay[['loan_year','loan_month','repay_year','repay_month','fund_name','total_amount','act_principle','act_interest','act_punish','act_penalty','substitute','collection','qishou']]
df_before_deadline_repay.rename(columns={
'loan_year': '放款年', 'loan_month': '放款月', 'repay_year': '还款年', 'repay_month': '还款月',
'fund_name': '资金方', 'total_amount': '还款总额', 'act_principle':'实还本金', 'act_interest':'实还利息' ,
'act_punish':'实还罚息', 'act_penalty' :'实还违约金', 'substitute':'代付成本', 'collection':'代收成本', 'qishou':'QG服务费金额1-期收'
}, inplace=True)
df_before_deadline_repay.to_excel(os.path.join(self.dir_path, '兴业-收入确认表(期收1-固定可收回)-{}.xlsx'.format(self.start.strftime('%Y%m'))), index=None)
#期收1
#逾期期收
if len(df_after_deadline_repay) == 0:
return
#
df_after_deadline_repay['qishou'] = np.round((df_after_deadline_repay['act_principle'] + df_after_deadline_repay['act_interest'] + df_after_deadline_repay['act_punish']) * 0.5, 2)
df_after_deadline_repay = df_after_deadline_repay[
['loan_year', 'loan_month', 'repay_year', 'repay_month', 'fund_name', 'total_amount', 'act_principle', 'act_interest', 'act_punish', 'act_penalty', 'qishou']]
df_after_deadline_repay.rename(columns={
'loan_year': '放款年', 'loan_month': '放款月', 'repay_year': '逾期还款年', 'repay_month': '逾期还款月',
'fund_name': '资金方', 'total_amount': '还款总额', 'act_principle': '实还本金', 'act_interest': '实还利息',
'act_punish': '实还罚息', 'act_penalty': '实还违约金', 'qishou': 'QG服务费金额3-贷后服务费'
}, inplace=True)
df_after_deadline_repay.to_excel(os.path.join(self.dir_path, '兴业-收入确认表(贷后服务费3)-{}.xlsx'.format(self.start.strftime('%Y%m'))), index=None)
# 逾期期收
def xingye_plan(self):
df_plan = pd.read_sql(query_plan_sql, new_transaction_conn)
df_plan['sumAmount'] = df_plan['principle'] + df_plan['interest'] + df_plan['service_fee']
df_plan['sumAmount'] = np.round(df_plan['sumAmount'], 2)
df_plan.rename(columns={
'fkyear': '放款年', 'fkmonth': '放款月', 'hkyear': '到期年', 'hkmonth': '到期月',
'principle': '应还本金', 'interest': '应还利息', 'service_fee': '应还服务费', 'sumAmount': '应还总额'
}, inplace=True)
df_plan.to_csv(os.path.join(self.dir_path, '兴业-还款计划表-{}.csv'.format(self.start.strftime('%Y%m'))), index=None, encoding='gbk')
def xingye_repay_details(self):
self.xingye_repay()
self.xingye_plan()
if __name__ == '__main__':
xingye_repay().xingye_repay_details()
print('======================xingye_repay done===================================')
# -*- coding: utf-8 -*-
import sys
import pandas as pd
import datetime
import os
path = '/home/quant_group/vpants/finance/table/'
sys.path.append('../../../finance_out_table')
from db_con.db_connect import sql_engine
engine_audit = sql_engine('audit_w', 'audit').get_engine()
engine_xyqb = sql_engine('xyqb', 'xyqb').get_engine()
sql_xyqb_loan_manifest = """
SELECT
loan_id,
ref_id
FROM
loan_manifest lm
WHERE
lm.loan_paid_at >= '{0}'
and lm.loan_paid_at < '{1}'
and lm.funding_code = 590
"""
sql_xjd_dunjiao_info = """
SELECT
loan_id,
amount qg_one_time_service_fee,
pay_status repay_status,
pay_finished_at xyqb_repaid_at
FROM
loan_extra_fee
WHERE
loan_id in {}
"""
sql_xjd_dunjiao_info_real = """
select loan_id, amount, pay_finished_at from loan_extra_fee where product_type = 3 and pay_finished_at >= '{0}' and pay_finished_at < '{1}';
"""
sql_audit_query_loan_id = """
select loan_id from xjd_zhongan_dunjiao_plan where loan_id in {};
"""
sql_dunjiao_exists = """SELECT id,loan_id FROM xjd_zhongan_dunjiao_plan WHERE loan_id in {} and repay_status = 3"""
sql_dunjiao_update = """
update xjd_zhongan_dunjiao_plan set real_qg_one_time_service_fee = %s, xyqb_repaid_at = %s where loan_id = %s'
"""
sql_new_summary = """
SELECT
year(loan.loan_paid_at) 放款年,
month(loan.loan_paid_at) 放款月,
f.name 资金方,
loan.class 风险等级,
sum(loan.contract_loan_amount) 放款金额,
sum(d.qg_one_time_service_fee) 保证险应收金额,
sum(d.real_qg_one_time_service_fee) 保证险实收金额,
sum(d.qg_one_time_service_fee) - sum(d.real_qg_one_time_service_fee) 待还保证金
FROM
audit.loan_manifest loan
JOIN basic.funding_corp f
ON f.funding_code = loan.funding_code
JOIN audit.xjd_zhongan_dunjiao_plan d on loan.ref_id = d.ref_id
AND loan.loan_paid_at >= '{0}'
AND loan.loan_paid_at < '{1}'
AND loan.funding_code = 590
GROUP BY 1, 2, 3, 4 ;
"""
sql_new_details = """
SELECT
f.name 资金方,
loan.loan_id,
loan.contract_no 贷款合同号,
date(loan.loan_paid_at) 放款日期,
loan.contract_loan_amount 放款金额,
loan.contract_term 总期数,
d.qg_one_time_service_fee 保证险应收金额,
loan.monthly_interest_rate 月利率,
loan.class 风险等级
FROM
audit.loan_manifest loan
JOIN basic.funding_corp f
ON f.funding_code = loan.funding_code
JOIN audit.xjd_zhongan_dunjiao_plan d on loan.ref_id = d.ref_id
where loan.loan_paid_at >= '{0}'
AND loan.loan_paid_at < '{1}'
AND loan.funding_code = 590
"""
sql_dun_details = """
SELECT
year(loan.loan_paid_at) 放款年,
month(loan.loan_paid_at) 放款月,
f.name 资金方,
sum(loan.contract_loan_amount) 放款金额,
sum(loan.contract_loan_amount)*0.01 QG服务费金额1趸收
FROM
audit.loan_manifest loan
JOIN basic.funding_corp f
ON f.funding_code = loan.funding_code
AND loan.loan_paid_at >= '{0}'
AND loan.loan_paid_at < '{1}'
AND loan.funding_code = 590
GROUP BY 1, 2, 3
"""
class zhongan_loan():
def __init__(self, is_mock):
self.is_mock = is_mock
today = datetime.date.today()
self.end = datetime.date(today.year, today.month, 1)
last_day = self.end + datetime.timedelta(days=-1)
self.start = datetime.date(last_day.year, last_day.month, 1)
self.dir_path = path + self.start.strftime('%Y%m')
if not os.path.exists(self.dir_path):
os.makedirs(self.dir_path)
def fetch_zhongan_loan_manifest(self, start, end):
print('--------------开始{}的众安保证金数据录入----------------'.format(start))
"""根据时间查询放款"""
df_loan = pd.read_sql(sql=sql_xyqb_loan_manifest.format(start, end), con=engine_audit)
if len(df_loan) <= 0:
return
df_loan.loan_id = df_loan.loan_id.astype(str)
loan_ids = df_loan.loan_id.tolist()
"""查保证金已经存在的loan"""
df_audit_exist_loan = pd.read_sql(sql=sql_audit_query_loan_id.format(str(tuple(loan_ids)).replace(',)', ')')),
con=engine_audit)
"""去掉已经存在的"""
if len(df_audit_exist_loan) > 0:
exist_loan_id_list = df_audit_exist_loan.loan_id.tolist()
print("存在 exist loan_id: {}".format(str(exist_loan_id_list)))
df_loan = df_loan.loc[~df_loan.loan_id.isin(df_audit_exist_loan.loan_id)]
if len(df_loan) <= 0:
return
loan_ids = df_loan.loan_id.tolist()
df_loan_dunjiao = pd.read_sql(sql=sql_xjd_dunjiao_info.format(str(tuple(loan_ids)).replace(',)', ')')),
con=engine_xyqb)
df_loan_dunjiao.loan_id = df_loan_dunjiao.loan_id.astype(str)
df_dunjiao = pd.merge(df_loan, df_loan_dunjiao, how='inner', on='loan_id')
df_dunjiao['real_qg_one_time_service_fee'] = 0
df_dunjiao.loc[df_dunjiao['repay_status'] == 3, 'real_qg_one_time_service_fee'] = df_dunjiao[
'qg_one_time_service_fee']
if not self.is_mock:
df_dunjiao.to_sql(name='xjd_zhongan_dunjiao_plan', con=engine_audit, if_exists='append', index=None,
chunksize=10000)
print('----------------{}保证金录入完毕------------------'.format(start))
def update_exists_dunjiao(self, start, end):
print('--------------开始{}的更新保证金----------------'.format(start))
df_dunjiao = pd.read_sql(sql=sql_xjd_dunjiao_info_real.format(start, end), con=engine_xyqb)
if len(df_dunjiao) <= 0:
return
df_dunjiao.loan_id = df_dunjiao.loan_id.astype(str)
loan_ids = tuple(df_dunjiao.loan_id)
df_exists = pd.read_sql(sql=sql_dunjiao_exists.format(str(loan_ids).replace(',)', ')')), con=engine_audit)
df_dunjiao = df_dunjiao.loc[~df_dunjiao.loan_id.isin(df_exists.loan_id)]
if len(df_dunjiao) <= 0:
print('---没有需要更新的数据---')
return
df_dunjiao.pay_finished_at = df_dunjiao.pay_finished_at.astype(str)
if not self.is_mock:
engine_audit.execute(sql_dunjiao_update,
df_dunjiao[['amount', 'pay_finished_at', 'loan_id']].values.tolist())
print('--------------结束{}更新保证金----------------'.format(start))
def zhongan_loan_detail(self):
# 准备数据
if not self.is_mock:
print('zhongan loan fetch data')
self.fetch_zhongan_loan_manifest(self.start, self.end)
self.update_exists_dunjiao(self.start, self.end)
# 出表
df = pd.read_sql(sql=sql_new_summary.format(self.start, self.end), con=engine_audit)
df.to_excel(os.path.join(self.dir_path, u'众安-放款汇总表-{}.xlsx'.format(self.start.strftime('%Y%m'))),
index=None)
df = pd.read_sql(sql=sql_new_details.format(self.start, self.end), con=engine_audit)
df.to_excel(os.path.join(self.dir_path, u'众安-放款明细表-{}.xlsx'.format(self.start.strftime('%Y%m'))),
index=None)
df = pd.read_sql(sql=sql_dun_details.format(self.start, self.end), con=engine_audit)
df.to_excel(os.path.join(self.dir_path, u'众安-趸收表-{}.xlsx'.format(self.start.strftime('%Y%m'))),
index=None)
if __name__ == '__main__':
zhongan_loan(False).zhongan_loan_detail()
print('======================zhongan_loan done===================================')
# -*- coding: utf-8 -*-
import sys
import pandas as pd
import numpy as np
import datetime
import os
sys.path.append('../../../finance_out_table')
from db_con.db_connect import sql_engine
path = '/home/quant_group/vpants/finance/table/'
new_transaction_conn = sql_engine('audit', 'new_transaction').get_engine()
query_sql = """
select order_id,term_no,repay_app_no,bill_time,principle,interest,punish,breach_overdue,breach_early_settle,
charge,other_fee,deduct_breach_overdue,deduct_breach_early_settle,deduct_charge,loan_id,ref_id,safe_fee
from zhongan_repay_record_online where enable=1;
"""
query_repayment_sql = """
select t1.loan_id,t1.ref_id,year(loan_paid_at) as fkyear,month(loan_paid_at) as fkmonth,year(max(deadline)) as hkyear,month(max(deadline)) as hkmonth, sum(principle) as principle ,sum(interest) as interest ,sum(service_fee) as service_fee from audit.loan_manifest t1 inner join new_transaction.user_repayment_plan t2 on t1.ref_id=t2.ref_id and t1.funding_code=590
group by t1.ref_id
"""
class zhongan_repay():
def __init__(self):
today = datetime.date.today()
self.end = datetime.date(today.year, today.month, 1)
last_day = self.end + datetime.timedelta(days=-1)
self.start = datetime.date(last_day.year, last_day.month, 1)
self.dir_path = path + self.start.strftime('%Y%m')
if not os.path.exists(self.dir_path):
os.makedirs(self.dir_path)
def zhongan_repay_detail(self):
df_all = pd.read_sql(sql=query_sql, con=new_transaction_conn)
df_all['deduct_penalty'] = 0 # todo 给的excel中没有,但是众安的对账文件中存在这个字段,和产品沟通吧
df_all['fund_name'] = '众安'
df_all['year'] = df_all['bill_time'].apply(lambda x: pd.datetime.strftime(x, '%Y'))
df_all['month'] = df_all['bill_time'].apply(lambda x: pd.datetime.strftime(x, '%m'))
# 客户还款表: 还款总额=还款本金+还款利息+逾期违约+账户安全险+提前结清违约金+服务费+罚息+其他费用-减免罚息-减免逾期违约金-减免提前结清违约金-减免服务费
df_all['sum_amount'] = (df_all['principle'] + df_all['interest'] + df_all['punish'] + df_all['breach_overdue'] + \
df_all['breach_early_settle'] + df_all['other_fee'] + df_all[
'safe_fee']) - (df_all['deduct_breach_overdue'] + df_all['deduct_penalty']
+ df_all['deduct_breach_early_settle'] + df_all['deduct_charge'])
df_all.drop('order_id', axis=1, inplace=True)
df_all['repay_time'] = df_all['bill_time'].apply(lambda x: pd.datetime.strftime(x, '%Y-%m-%d'))
df_all_table = df_all.groupby(['year', 'month', 'repay_time'])[[
'fund_name', 'sum_amount', 'principle', 'interest', 'breach_overdue', 'safe_fee', 'breach_early_settle',
'punish', 'other_fee', 'deduct_penalty', 'deduct_breach_overdue', 'deduct_breach_early_settle',
'deduct_charge'
]].agg(
'sum').reset_index().rename(columns={
'year': '还款年', 'month': '还款月', 'repay_time': '还款成功日期', 'fund_name': '资金方', 'sum_amount': '还款总额',
'principle': '还款本金', 'interest': '还款利息', 'breach_overdue': '逾期违约金',
'safe_fee': '账户安全险(意外伤害险)', 'breach_early_settle': '提前结清违约金', 'punish': '罚息',
'other_fee': '其他费用', 'deduct_penalty': '减免罚息', 'deduct_breach_overdue': '减免逾期违约金',
'deduct_breach_early_settle': '减免提前结清违约金', 'deduct_charge': '减免服务费'
})
df_all_table.to_excel(os.path.join(self.dir_path, u'众安-还款表-{}.xlsx'.format(self.start.strftime('%Y%m'))), index=None)
# 收入确认表-期收
# 期收收入确认表: 实还总额= 当期实还本金+当期实还利息+实还服务费+实还账户安全险
df_all['qishou_service_amount'] = np.round(df_all['safe_fee'] * 0.8, 2)
df_all['qishou_sum_amount'] = df_all['principle'] + df_all['interest'] + df_all['punish'] + df_all['safe_fee']
df_all_qishou_table = df_all.groupby(['year', 'month'])[[
'fund_name', 'qishou_sum_amount', 'principle', 'interest', 'safe_fee',
'qishou_service_amount']].agg(
'sum').reset_index().rename(columns={
'year': '实还年', 'month': '实还月', 'fund_name': '资金方', 'term_no': '期数', 'qishou_sum_amount': '实还总额',
'principle': '当期实还本金', 'interest': '当期实还利息', 'safe_fee': '账户安全险(意外伤害险)',
'qishou_service_amount': 'QG服务费金额2-期收'
})
df_all_qishou_table.to_excel(os.path.join(self.dir_path, u'众安-期收表-{}.xlsx'.format(self.start.strftime('%Y%m'))), index=None)
# 还款计划
df_plan = pd.read_sql(query_repayment_sql, new_transaction_conn)
df_plan['sumAmount'] = df_plan['principle'] + df_plan['interest'] + df_plan['service_fee']
df_plan['sumAmount'] = np.round(df_plan['sumAmount'], 2)
df_plan.rename(columns={
'fkyear': '放款年', 'fkmonth': '放款月', 'hkyear': '应还款年', 'hkmonth': '应还款月', 'sumAmount': '应还总额',
'principle': '应还本金', 'interest': '应还利息', 'service_fee': '应还服务费'
}, inplace=True)
df_plan.to_excel(os.path.join(self.dir_path, u'众安-还款计划表-{}.xlsx'.format(self.start.strftime('%Y%m'))), index=None)
if __name__ == '__main__':
zhongan_repay().zhongan_repay_detail()
print('======================zhongan_repay done===================================')
# -*- coding: utf-8 -*-
import pandas as pd
import numpy as np
import sys
import os
import datetime
sys.path.append('../../../finance_out_table')
from db_con.db_connect import sql_engine
path = '/home/quant_group/vpants/finance/table/'
new_transaction_conn = sql_engine('audit', 'new_transaction').get_engine()
query_sql = """
select order_id,term_no,principle,interest,punish,bill_time,ref_id,loan_id from zhongwang_repay_record_online;
"""
class zhongwang2_repay():
def __init__(self):
today = datetime.date.today()
self.end = datetime.date(today.year, today.month, 1)
last_day = self.end + datetime.timedelta(days=-1)
self.start = datetime.date(last_day.year, last_day.month, 1)
self.dir_path = path + self.start.strftime('%Y%m')
if not os.path.exists(self.dir_path):
os.makedirs(self.dir_path)
def zhongwang2_repay_detail(self):
df_all = pd.read_sql(sql=query_sql, con=new_transaction_conn)
df_all['fund_name'] = '众网小贷2'
df_all['bill_time'] = pd.to_datetime(df_all['bill_time'])
df_all['year'] = df_all['bill_time'].apply(lambda x: pd.datetime.strftime(x, '%Y'))
df_all['month'] = df_all['bill_time'].apply(lambda x: pd.datetime.strftime(x, '%m'))
df_all.drop('order_id', axis=1, inplace=True)
# 客户还款表
df_all['sum_amount'] = df_all['principle'] + df_all['interest'] + df_all['punish']
df_all_table = df_all.groupby(['year', 'month'])[[
'fund_name', 'sum_amount', 'principle', 'interest', 'punish'
]].agg(
'sum').reset_index().rename(columns={
'year': '实还年', 'month': '实还月', 'fund_name': '资金方', 'sum_amount': '实还总额',
'principle': '当期实还本金', 'interest': '当期实还利息', 'punish': '实还罚息'
})
df_all_table.to_excel(os.path.join(self.dir_path, u'众网小贷2-还款表-{}.xlsx'.format(self.start.strftime('%Y%m'))), index=None)
# 收入确认表-期收
df_all['qishou_service_amount'] = np.round(df_all['interest'] * 0.18, 2)
df_all['qishou_sum_amount'] = df_all['principle'] + df_all['interest'] + df_all['punish']
df_all_qishou_table = df_all.groupby(['year', 'month'])[[
'fund_name', 'qishou_sum_amount', 'principle', 'interest', 'punish', 'qishou_service_amount']].agg(
'sum').reset_index() \
.rename(columns={
'year': '实还年', 'month': '实还月', 'fund_name': '资金方', 'qishou_sum_amount': '实还总额',
'principle': '当期实还本金', 'interest': '当期实还利息', 'punish': '当期实还罚息', 'qishou_service_amount': 'QG服务费金额2-期收'
})
df_all_qishou_table.to_excel(os.path.join(self.dir_path, u'众网小贷2-期收表-{}.xlsx'.format(self.start.strftime('%Y%m'))), index=None)
if __name__ == '__main__':
zhongwang2_repay().zhongwang2_repay_detail()
print('======================zhongwang2_repay done===================================')
# -*- coding: utf-8 -*-
import pandas as pd
import numpy as np
import sys
import os
import datetime
sys.path.append('../../../finance_out_table')
from db_con.db_connect import sql_engine
#path = '/home/quant_group/vpants/finance/table/'
path = '/Users/chenxiaozhe/Downloads/test/201901'
new_transaction_conn = sql_engine('audit', 'new_transaction').get_engine()
query_sql = """
select lm.contract_term,order_id,term_no,principle,interest,punish,bill_time,zrro.ref_id,zrro.loan_id from zhongwang_repay_record_online zrro
inner join audit.loan_manifest lm on lm.loan_id=zrro.loan_id
"""
query_loan_sql = """
select year(loan_paid_at) as '放款年',month(loan_paid_at) as '放款月', contract_term as '期数' ,sum(contract_loan_amount) as '放款金额' from audit.loan_manifest
where funding_code=560 group by 1,2,3
"""
class zhongwang2_repay():
def __init__(self):
today = datetime.date.today()
self.end = datetime.date(today.year, today.month, 1)
last_day = self.end + datetime.timedelta(days=-1)
self.start = datetime.date(last_day.year, last_day.month, 1)
self.dir_path = path + self.start.strftime('%Y%m')
if not os.path.exists(self.dir_path):
os.makedirs(self.dir_path)
def zhongwang2_repay_detail(self):
df_all = pd.read_sql(sql=query_sql, con=new_transaction_conn)
df_all['fund_name'] = '众网小贷2'
df_all['bill_time'] = pd.to_datetime(df_all['bill_time'])
df_all['year'] = df_all['bill_time'].apply(lambda x: pd.datetime.strftime(x, '%Y'))
df_all['month'] = df_all['bill_time'].apply(lambda x: pd.datetime.strftime(x, '%m'))
df_all.drop('order_id', axis=1, inplace=True)
# 客户还款表
df_all['sum_amount'] = df_all['principle'] + df_all['interest'] + df_all['punish']
df_all_table = df_all.groupby(['year', 'month'])[[
'fund_name', 'sum_amount', 'principle', 'interest', 'punish'
]].agg(
'sum').reset_index().rename(columns={
'year': '实还年', 'month': '实还月', 'fund_name': '资金方', 'sum_amount': '实还总额',
'principle': '当期实还本金', 'interest': '当期实还利息', 'punish': '实还罚息'
})
df_all_table.to_excel(os.path.join(self.dir_path, u'众网小贷2-还款表-{}.xlsx'.format(self.start.strftime('%Y%m'))), index=None)
# 收入确认表-期收
df_all_3 = df_all.loc[df_all['contract_term'] == 3]
df_all_not_3 = df_all.loc[df_all['contract_term'] != 3]
if len(df_all_3) > 0:
df_all_3['qishou_service_amount'] = np.round(df_all_3['interest'] * 0.078, 2)
df_all_3['qishou_sum_amount'] = df_all_3['principle'] + df_all_3['interest'] + df_all_3['punish']
df_all_qishou_table = df_all_3.groupby(['year', 'month'])[[
'fund_name', 'qishou_sum_amount', 'principle', 'interest', 'punish', 'qishou_service_amount']].agg(
'sum').reset_index() \
.rename(columns={
'year': '实还年', 'month': '实还月', 'fund_name': '资金方', 'qishou_sum_amount': '实还总额',
'principle': '当期实还本金', 'interest': '当期实还利息', 'punish': '当期实还罚息', 'qishou_service_amount': 'QG服务费金额2-期收'
})
df_all_qishou_table.to_excel(
os.path.join(self.dir_path, u'众网小贷2-期收表(3期)-{}.xlsx'.format(self.start.strftime('%Y%m'))), index=None)
if len(df_all_not_3) > 0:
df_all_not_3['qishou_service_amount'] = np.round(df_all_not_3['interest'] * 0.18, 2)
df_all_not_3['qishou_sum_amount'] = df_all_not_3['principle'] + df_all_not_3['interest'] + df_all_not_3['punish']
df_all_qishou_table = df_all_not_3.groupby(['year', 'month'])[[
'fund_name', 'qishou_sum_amount', 'principle', 'interest', 'punish', 'qishou_service_amount']].agg(
'sum').reset_index() \
.rename(columns={
'year': '实还年', 'month': '实还月', 'fund_name': '资金方', 'qishou_sum_amount': '实还总额',
'principle': '当期实还本金', 'interest': '当期实还利息', 'punish': '当期实还罚息', 'qishou_service_amount': 'QG服务费金额2-期收'
})
df_all_qishou_table.to_excel(os.path.join(self.dir_path, u'众网小贷2-期收表(非3期)-{}.xlsx'.format(self.start.strftime('%Y%m'))), index=None)
#趸收
df_ds_all = pd.read_sql(sql=query_loan_sql, con=new_transaction_conn)
df_ds_3_all = df_ds_all.loc[df_ds_all[u'期数'] == 3]
df_ds_3_all[u'趸收'] = np.round(df_ds_3_all[u'放款金额'] * 0.016, 2)
df_ds_not_3_all = df_ds_all.loc[df_ds_all[u'期数'] != 3]
df_ds_not_3_all[u'趸收'] = np.round(df_ds_not_3_all[u'放款金额'] * 0.03, 2)
df_dunshou_all = pd.concat([df_ds_3_all, df_ds_not_3_all], axis=0)
df_dunshou_all.to_excel(os.path.join(self.dir_path, u'众网小贷2-趸收-{}.xlsx'.format(self.start.strftime('%Y%m'))), index=None)
if __name__ == '__main__':
zhongwang2_repay().zhongwang2_repay_detail()
print('======================zhongwang2_repay done===================================')
# -*- coding: utf-8 -*-
from apscheduler.schedulers.blocking import BlockingScheduler
from apscheduler.executors.pool import ThreadPoolExecutor, ProcessPoolExecutor
from out_table.cash_loan.punish_split import punish_split
executors = {
'default': ThreadPoolExecutor(2),
'processpool': ProcessPoolExecutor(1)
}
def punish_split_job():
job_instance = punish_split(is_mock=False)
job_instance.punish_split_detail()
# 用python2 执行
if __name__ == "__main__":
scheduler = BlockingScheduler(executors=executors)
scheduler.add_job(punish_split_job, 'cron', month='1-12', day='1', hour=13, minute=30, second=0)
scheduler.start()
# -*- coding: utf-8 -*-
from apscheduler.schedulers.blocking import BlockingScheduler
from apscheduler.executors.pool import ThreadPoolExecutor, ProcessPoolExecutor
from datetime import datetime
from out_table.cash_loan.guangda_repay import guangda_repay
from out_table.cash_loan.cash_loan_repay import loan_repay
from out_table.cash_loan.old_income_confirm import income_confirm
from out_table.cash_loan.zhongwang2_repay import zhongwang2_repay
from out_table.cash_loan.zhongan_repay import zhongan_repay
from out_table.cash_loan.cash_loan_order import loan_order
from out_table.cash_loan.new_income_confirm import new_income_confirm
from out_table.cash_loan.month_poundage import month_poundage
from out_table.cash_loan.zhongan_loan import zhongan_loan
from out_table.cash_loan.assets_model import asserts
from out_table.cash_loan.bohai_age_of_account import age_of_account
from out_table.cash_loan.bohai_collection_behalf import collection_behalf
from out_table.cash_loan.huijinsuo_repay import huijinsuo_loan_repay
from out_table.cash_loan.xiaoying_repay import xiaoying_repay
from out_table.cash_loan.xingye_loan import xingye_loan
from out_table.cash_loan.xingye_repay import xingye_repay
from out_table.cash_loan.minjin_loan_repay import minjin_loan_repay
executors = {
'default': ThreadPoolExecutor(25),
'processpool': ProcessPoolExecutor(12)
}
# 广达客户还款表
def guangda_repay_job():
print('begin guangda_repay_job :{}'.format(datetime.now().strftime("%Y-%m-%d %H:%M:%S")))
job_instance = guangda_repay()
job_instance.yeepay_guangda_repay_details()
print('end guangda_repay_job :{}'.format(datetime.now().strftime("%Y-%m-%d %H:%M:%S")))
# 现金贷客户还款表
def loan_repay_job():
print('begin loan_repay_job :{}'.format(datetime.now().strftime("%Y-%m-%d %H:%M:%S")))
job_instance = loan_repay()
job_instance.loan_repay_details()
print('end loan_repay_job :{}'.format(datetime.now().strftime("%Y-%m-%d %H:%M:%S")))
# 旧模式收入确认表
def old_income_confirm_job():
print('begin old_income_confirm :{}'.format(datetime.now().strftime("%Y-%m-%d %H:%M:%S")))
job_instance = income_confirm()
job_instance.income_confirm_details()
print('end old_income_confirm :{}'.format(datetime.now().strftime("%Y-%m-%d %H:%M:%S")))
# 众网还款
def zhongwang2_repay_job():
print('begin zhongwang2_repay_job :{}'.format(datetime.now().strftime("%Y-%m-%d %H:%M:%S")))
job_instance = zhongwang2_repay()
job_instance.zhongwang2_repay_detail()
print('end zhongwang2_repay_job :{}'.format(datetime.now().strftime("%Y-%m-%d %H:%M:%S")))
# 众安还款
def zhongan_repay_job():
print('begin zhongan_repay_job :{}'.format(datetime.now().strftime("%Y-%m-%d %H:%M:%S")))
job_instance = zhongan_repay()
job_instance.zhongan_repay_detail()
print('end zhongan_repay_job :{}'.format(datetime.now().strftime("%Y-%m-%d %H:%M:%S")))
# 放款表
def loan_order_job():
job_instance = loan_order()
job_instance.loan_order_details()
# 新模式收入确认
def new_income_confirm_job():
job_instance = new_income_confirm(is_mock=False)
job_instance.income_confirm_details()
# 手续费表
def month_poundage_job():
job_instance = month_poundage()
job_instance.poundage_details()
# 众安放款
def zhongan_loan_job():
job_instance = zhongan_loan(is_mock=False)
job_instance.zhongan_loan_detail()
# assert
def assert_job():
job_instance = asserts()
job_instance.asserts_details()
# 渤海账龄
def bohai_age_job():
job_instance = age_of_account()
job_instance.age_of_account_details()
# 渤海催收和代偿
def bohai_collection_behalf_job():
job_instance = collection_behalf(is_mock=False)
job_instance.collection_behalf_details()
# 惠金所还款表
def huijinsuo_repay_job():
job_instance = huijinsuo_loan_repay()
job_instance.huijinsuo_loan_repay_details()
# 小赢还款
def xiaoying_repay_job():
job_instance = xiaoying_repay()
job_instance.xiaoying_repay_detail()
# 兴业放款
def xingye_loan_job():
job_instance = xingye_loan()
job_instance.xingye_loan_details()
# 兴业还款
def xingye_repay_job():
job_instance = xingye_repay()
job_instance.xingye_repay_details()
# 民金还款
def minjin_loan_repay_job():
job_instance = minjin_loan_repay()
job_instance.minjin_loan_repay_detail()
if __name__ == "__main__":
scheduler = BlockingScheduler(executors=executors)
scheduler.add_job(guangda_repay_job, 'cron', month='1-12', day='1', hour=13, minute=17, second=0)
scheduler.add_job(month_poundage_job, 'cron', month='1-12', day='1', hour=13, minute=17, second=0)
scheduler.add_job(old_income_confirm_job, 'cron', month='1-12', day='1', hour=13, minute=18, second=0)
scheduler.add_job(loan_repay_job, 'cron', month='1-12', day='1', hour=13, minute=37, second=0)
scheduler.add_job(zhongwang2_repay_job, 'cron', month='1-12', day='1', hour=13, minute=57, second=0)
scheduler.add_job(zhongan_repay_job, 'cron', month='1-12', day='1', hour=13, minute=57, second=0)
scheduler.add_job(zhongan_loan_job, 'cron', month='1-12', day='1', hour=14, minute=5, second=0)
scheduler.add_job(loan_order_job, 'cron', month='1-12', day='1', hour=14, minute=10, second=0)
scheduler.add_job(new_income_confirm_job, 'cron', month='1-12', day='1', hour=14, minute=15, second=0)
scheduler.add_job(huijinsuo_repay_job, 'cron', month='1-12', day='1', hour=14, minute=20, second=0)
#小赢还款
scheduler.add_job(xiaoying_repay_job, 'cron', month='1-12', day='1', hour=14, minute=25, second=0)
#todo 小赢赔付
#兴业放款
scheduler.add_job(xingye_loan_job, 'cron', month='1-12', day='1', hour=14, minute=27, second=0)
#兴业还款
scheduler.add_job(xingye_repay_job, 'cron', month='1-12', day='1', hour=14, minute=30, second=0)
#民金还款
scheduler.add_job(minjin_loan_repay_job, 'cron', month='1-12', day='1', hour=14, minute=32, second=0)
scheduler.add_job(assert_job, 'cron', month='1-12', day='1', hour=14, minute=35, second=0)
scheduler.add_job(bohai_age_job, 'cron', month='1-12', day='1', hour=14, minute=45, second=0)
scheduler.add_job(bohai_collection_behalf_job, 'cron', month='1-12', day='1', hour=14, minute=55, second=0)
scheduler.start()
# -*- coding: utf-8 -*-
import os
import sys
import datetime
import numpy as np
import pandas as pd
sys.path.append('../../../finance_out_table')
from db_con.db_connect import sql_engine
conn_w = sql_engine('audit_w', 'audit', echo=True).get_engine()
engine_xyqb = sql_engine('xyqb', 'xyqb', True).get_engine()
query_audit_loan = """
select loan_id from audit.loan_manifest where loan_paid_at >= '2018-04-01' and loan_paid_at<'2018-08-15' and contract_created_at is null order by loan_paid_at;
"""
query_xyqb_contrace = """
SELECT loan_application_history_id 'loan_id',created_at 'contract_created_at'
FROM contract WHERE loan_application_history_id in {}
"""
sql_update = """
update audit.loan_manifest set contract_created_at = %s where loan_id = %s;
"""
if __name__ == '__main__':
df_loan = pd.read_sql(sql=query_audit_loan, con=conn_w)
df_loan.loan_id = df_loan.loan_id.astype(str)
loan_ids = df_loan.loan_id.tolist()
df_xyqb_loan_contract = pd.read_sql(sql=query_xyqb_contrace.format(str(tuple(loan_ids)).replace(',)', ')')),
con=engine_xyqb)
df_xyqb_loan_contract.loan_id = df_xyqb_loan_contract.loan_id.astype(str)
df_audit_loan_manifest = pd.merge(df_loan, df_xyqb_loan_contract, on='loan_id', how='left')
df_not_null = df_audit_loan_manifest.loc[~df_audit_loan_manifest['contract_created_at'].isnull()]
conn_w.execute(sql_update, df_not_null[['contract_created_at', 'loan_id']].values.tolist())
# This file must be used with "source bin/activate" *from bash*
# you cannot run it directly
deactivate () {
# reset old environment variables
if [ -n "${_OLD_VIRTUAL_PATH:-}" ] ; then
PATH="${_OLD_VIRTUAL_PATH:-}"
export PATH
unset _OLD_VIRTUAL_PATH
fi
if [ -n "${_OLD_VIRTUAL_PYTHONHOME:-}" ] ; then
PYTHONHOME="${_OLD_VIRTUAL_PYTHONHOME:-}"
export PYTHONHOME
unset _OLD_VIRTUAL_PYTHONHOME
fi
# This should detect bash and zsh, which have a hash command that must
# be called to get it to forget past commands. Without forgetting
# past commands the $PATH changes we made may not be respected
if [ -n "${BASH:-}" -o -n "${ZSH_VERSION:-}" ] ; then
hash -r
fi
if [ -n "${_OLD_VIRTUAL_PS1:-}" ] ; then
PS1="${_OLD_VIRTUAL_PS1:-}"
export PS1
unset _OLD_VIRTUAL_PS1
fi
unset VIRTUAL_ENV
if [ ! "$1" = "nondestructive" ] ; then
# Self destruct!
unset -f deactivate
fi
}
# unset irrelevant variables
deactivate nondestructive
VIRTUAL_ENV="/Users/chenxiaozhe/quantgroup/py/finance_out_table/venv"
export VIRTUAL_ENV
_OLD_VIRTUAL_PATH="$PATH"
PATH="$VIRTUAL_ENV/bin:$PATH"
export PATH
# unset PYTHONHOME if set
# this will fail if PYTHONHOME is set to the empty string (which is bad anyway)
# could use `if (set -u; : $PYTHONHOME) ;` in bash
if [ -n "${PYTHONHOME:-}" ] ; then
_OLD_VIRTUAL_PYTHONHOME="${PYTHONHOME:-}"
unset PYTHONHOME
fi
if [ -z "${VIRTUAL_ENV_DISABLE_PROMPT:-}" ] ; then
_OLD_VIRTUAL_PS1="${PS1:-}"
if [ "x(venv) " != x ] ; then
PS1="(venv) ${PS1:-}"
else
if [ "`basename \"$VIRTUAL_ENV\"`" = "__" ] ; then
# special case for Aspen magic directories
# see http://www.zetadev.com/software/aspen/
PS1="[`basename \`dirname \"$VIRTUAL_ENV\"\``] $PS1"
else
PS1="(`basename \"$VIRTUAL_ENV\"`)$PS1"
fi
fi
export PS1
fi
# This should detect bash and zsh, which have a hash command that must
# be called to get it to forget past commands. Without forgetting
# past commands the $PATH changes we made may not be respected
if [ -n "${BASH:-}" -o -n "${ZSH_VERSION:-}" ] ; then
hash -r
fi
# This file must be used with "source bin/activate.csh" *from csh*.
# You cannot run it directly.
# Created by Davide Di Blasi <davidedb@gmail.com>.
# Ported to Python 3.3 venv by Andrew Svetlov <andrew.svetlov@gmail.com>
alias deactivate 'test $?_OLD_VIRTUAL_PATH != 0 && setenv PATH "$_OLD_VIRTUAL_PATH" && unset _OLD_VIRTUAL_PATH; rehash; test $?_OLD_VIRTUAL_PROMPT != 0 && set prompt="$_OLD_VIRTUAL_PROMPT" && unset _OLD_VIRTUAL_PROMPT; unsetenv VIRTUAL_ENV; test "\!:*" != "nondestructive" && unalias deactivate'
# Unset irrelevant variables.
deactivate nondestructive
setenv VIRTUAL_ENV "/Users/chenxiaozhe/quantgroup/py/finance_out_table/venv"
set _OLD_VIRTUAL_PATH="$PATH"
setenv PATH "$VIRTUAL_ENV/bin:$PATH"
set _OLD_VIRTUAL_PROMPT="$prompt"
if (! "$?VIRTUAL_ENV_DISABLE_PROMPT") then
if ("venv" != "") then
set env_name = "venv"
else
if (`basename "VIRTUAL_ENV"` == "__") then
# special case for Aspen magic directories
# see http://www.zetadev.com/software/aspen/
set env_name = `basename \`dirname "$VIRTUAL_ENV"\``
else
set env_name = `basename "$VIRTUAL_ENV"`
endif
endif
set prompt = "[$env_name] $prompt"
unset env_name
endif
alias pydoc python -m pydoc
rehash
# This file must be used with ". bin/activate.fish" *from fish* (http://fishshell.org)
# you cannot run it directly
function deactivate -d "Exit virtualenv and return to normal shell environment"
# reset old environment variables
if test -n "$_OLD_VIRTUAL_PATH"
set -gx PATH $_OLD_VIRTUAL_PATH
set -e _OLD_VIRTUAL_PATH
end
if test -n "$_OLD_VIRTUAL_PYTHONHOME"
set -gx PYTHONHOME $_OLD_VIRTUAL_PYTHONHOME
set -e _OLD_VIRTUAL_PYTHONHOME
end
if test -n "$_OLD_FISH_PROMPT_OVERRIDE"
functions -e fish_prompt
set -e _OLD_FISH_PROMPT_OVERRIDE
functions -c _old_fish_prompt fish_prompt
functions -e _old_fish_prompt
end
set -e VIRTUAL_ENV
if test "$argv[1]" != "nondestructive"
# Self destruct!
functions -e deactivate
end
end
# unset irrelevant variables
deactivate nondestructive
set -gx VIRTUAL_ENV "/Users/chenxiaozhe/quantgroup/py/finance_out_table/venv"
set -gx _OLD_VIRTUAL_PATH $PATH
set -gx PATH "$VIRTUAL_ENV/bin" $PATH
# unset PYTHONHOME if set
if set -q PYTHONHOME
set -gx _OLD_VIRTUAL_PYTHONHOME $PYTHONHOME
set -e PYTHONHOME
end
if test -z "$VIRTUAL_ENV_DISABLE_PROMPT"
# fish uses a function instead of an env var to generate the prompt.
# save the current fish_prompt function as the function _old_fish_prompt
functions -c fish_prompt _old_fish_prompt
# with the original prompt function renamed, we can override with our own.
function fish_prompt
# Save the return status of the last command
set -l old_status $status
# Prompt override?
if test -n "(venv) "
printf "%s%s" "(venv) " (set_color normal)
else
# ...Otherwise, prepend env
set -l _checkbase (basename "$VIRTUAL_ENV")
if test $_checkbase = "__"
# special case for Aspen magic directories
# see http://www.zetadev.com/software/aspen/
printf "%s[%s]%s " (set_color -b blue white) (basename (dirname "$VIRTUAL_ENV")) (set_color normal)
else
printf "%s(%s)%s" (set_color -b blue white) (basename "$VIRTUAL_ENV") (set_color normal)
end
end
# Restore the return status of the previous command.
echo "exit $old_status" | .
_old_fish_prompt
end
set -gx _OLD_FISH_PROMPT_OVERRIDE "$VIRTUAL_ENV"
end
#!/Users/chenxiaozhe/quantgroup/py/finance_out_table/venv/bin/python
# EASY-INSTALL-ENTRY-SCRIPT: 'setuptools==39.1.0','console_scripts','easy_install'
__requires__ = 'setuptools==39.1.0'
import re
import sys
from pkg_resources import load_entry_point
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
sys.exit(
load_entry_point('setuptools==39.1.0', 'console_scripts', 'easy_install')()
)
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
File added
./setuptools-39.1.0-py3.7.egg
./pip-10.0.1-py3.7.egg
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment