Commit cb2d7b6f authored by data—王林芳's avatar data—王林芳

Merge remote-tracking branch 'origin/master'

parents 52020acf db3f6566
......@@ -16,8 +16,8 @@ engine_new_transaction = create_engine(
#假如导出10月份的数据,则end_point 是11月份第一天,watch_point 是10月份最后一天
end_point = '2017-11-01'
watch_point = datetime.date(2017, 10, 31)
end_point = '2017-10-01'
watch_point = datetime.date(2017, 9, 30)
out_file_path = u'E:/审计出表/11月份开始使用表数据/11月份白条出表/在贷/'
query_loan = """
......@@ -200,7 +200,6 @@ select tt.order_no,tt.term_no,tt.paid_principle from(
GROUP BY 1,2
)tt
GROUP BY 1,2
"""
df_info = pd.read_sql(loan_info, engine_new_transaction)
......@@ -210,6 +209,7 @@ df_ali = pd.read_sql(repay_ali % end_point, engine_new_transaction)
df_bank = pd.read_sql(repay_bank % end_point, engine_new_transaction)
df_cash = pd.read_sql(repay_cash % (end_point, end_point), engine_new_transaction)
df_repay = pd.concat([df_online, df_ali, df_bank, df_cash], axis=0, ignore_index=True)
df_repay.dropna(axis=0, inplace=True)
df_loan = df_loan.loc[df_loan['principle'] > 0]
df_info.order_no = df_info.order_no.astype(str)
......@@ -221,22 +221,41 @@ df_repay = df_repay.groupby(['order_no', 'term_no'])['paid_principle'].agg({'sum
df_out = pd.merge(df_loan, df_repay, on=['order_no', 'term_no'], how='left')
df_out['deadline'] = pd.to_datetime(df_out.deadline)
df_out.fillna(0, inplace=True)
df_out['zaidai'] = df_out['principle'] - df_out['paid_principle']
# watch_point = datetime.date(2017, 9, 30)
df_out['flag'] = (watch_point-df_out['deadline']).dt.days
df_out['zaidai'] = df_out['principle'] - df_out['paid_principle']
df_out.loc[df_out['order_no'].isin(
['trainmall1483695024282', 'trainmall1484301600672', 'trainmall1486362269554', 'trainmall1487920296689',
'trainmall1491536200793', 'trainmall1483695024282',
'trainmall1484301600672', 'trainmall1486362269554', 'grabtrainmall1484650405321', 'trainmall1495785791995',
'trainmall1499935282194', 'trainmall16008368458050561', 'trainmall16008408858634241',
'trainmall16112348780571649', 'trainmall16112552463312897']), 'zaidai'] = 0
#只在17年使用的部分,调账使用
'''
df_out.loc[df_out['product_no']=='300156290067001502503609','flag'] = 1
'''
df_out.loc[(df_out['flag']<=0),'0'] = df_out['zaidai']
df_out.loc[(df_out['flag']>=1) &(df_out['flag']<=30),'01-30'] = df_out['zaidai']
df_out.loc[(df_out['flag']>=31) &(df_out['flag']<=60),'31-60'] = df_out['zaidai']
df_out.loc[(df_out['flag']>=61) &(df_out['flag']<=90),'61-90'] = df_out['zaidai']
df_out.loc[(df_out['flag']>=91) &(df_out['flag']<=120),'91-120'] = df_out['zaidai']
df_out.loc[(df_out['flag']>=121) &(df_out['flag']<=150),'121-150'] = df_out['zaidai']
df_out.loc[(df_out['flag']>=151) &(df_out['flag']<=180),'151-180'] = df_out['zaidai']
df_out.loc[(df_out['flag']>=181) &(df_out['flag']<=360),'181-360'] = df_out['zaidai']
df_out.loc[(df_out['flag']>=361),'361+'] = df_out['zaidai']
# df_out['zaidai'] = df_out['zaidai'].apply(lambda x: np.round(x, 2))
df = df_out.groupby(['order_no'])['zaidai'].agg({'sum'}).reset_index().rename(columns={'sum': u'未还本金'})
df = df_out.groupby(['order_no'])['0','01-30','31-60','61-90','91-120','121-150','151-180','181-360','361+'].sum().reset_index()
df.fillna(0,inplace=True)
df_loan.order_no = df_loan.order_no.astype(str)
df = pd.merge(df, df_info, on='order_no', how='left')
df = df[[u'商户', 'order_no', u'订单金额', u'合同期数', u'放款时间', u'未还本金']]
df[u'未还本金'].fillna(0, inplace=True)
df.rename(columns={'order_no': u'订单号'}, inplace=True)
df.rename(columns={'order_no': u'订单号'
}, inplace=True)
df = df[[u'商户', u'订单号', u'订单金额', u'合同期数', u'放款时间','0','01-30','31-60','61-90','91-120','121-150','151-180','181-360','361+']]
all_wb = pyexcelerate.Workbook()
for i in xrange(0, len(df), max_limit):
......
......@@ -11,6 +11,10 @@ from sqlalchemy import create_engine
import multiprocessing as mtp
from dateutil.relativedelta import relativedelta
import datetime
columns = ['plan_id', '白条商家', '产品编号', '放款日期', '总期数', '放款金额', '本金债权', '当期应还期数', '当期应还款日', '当期本金', '还款时间', '坏账统计时间']
# years = (2017,)
# months = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)
path = u'E:/审计出表/11月份开始使用表数据/11月份白条出表/坏账'
engine_audit = create_engine('mysql+mysqldb://internal_r:ArbNgtvlJzZHXsEu@172.16.3.201:3306/audit?charset=utf8',
echo=True)
......@@ -18,7 +22,7 @@ engine_audit = create_engine('mysql+mysqldb://internal_r:ArbNgtvlJzZHXsEu@172.16
sql_plan = """select plan.id plan_id, loan.order_no 产品编号,
loan.real_loan_amount 放款金额, plan.term_no 当期应还期数,date(plan.deadline) deadline, plan.principle
from new_transaction.user_bt_repayment_plan plan
join baitiao_audit.baitiao_order loan on loan.ref_id = plan.ref_id
join baitiao_audit.baitiao_order loan on loan.ref_id = plan.ref_id AND loan.funding_corp_id=1
where plan.deadline < date_sub('%s', interval 90 day)
and loan.is_active in(1,-2)"""
......@@ -29,7 +33,7 @@ join new_transaction.repay_record_online t2 on t1.record_id = t2.id and t1.repay
JOIN (
select plan.id plan_id
from new_transaction.user_bt_repayment_plan plan
join baitiao_audit.baitiao_order loan on loan.ref_id = plan.ref_id
join baitiao_audit.baitiao_order loan on loan.ref_id = plan.ref_id AND loan.funding_corp_id=1
where plan.deadline < date_sub('%s', interval 90 day)
and loan.is_active in(1,-2)
)t3 ON t1.plan_id =t3.plan_id
......@@ -42,7 +46,7 @@ join new_transaction.offline_alipay_record t2 on t1.record_id = t2.id and t1.rep
JOIN (
select plan.id plan_id
from new_transaction.user_bt_repayment_plan plan
join baitiao_audit.baitiao_order loan on loan.ref_id = plan.ref_id
join baitiao_audit.baitiao_order loan on loan.ref_id = plan.ref_id AND loan.funding_corp_id=1
where plan.deadline < date_sub('%s', interval 90 day)
and loan.is_active in(1,-2)
)t3 ON t1.plan_id =t3.plan_id
......@@ -55,17 +59,12 @@ join new_transaction.offline_bank_repay_record t2 on t1.record_id = t2.id and t1
JOIN (
select plan.id plan_id
from new_transaction.user_bt_repayment_plan plan
join baitiao_audit.baitiao_order loan on loan.ref_id = plan.ref_id
join baitiao_audit.baitiao_order loan on loan.ref_id = plan.ref_id AND loan.funding_corp_id=1
where plan.deadline < date_sub('%s', interval 90 day)
and loan.is_active in(1,-2)
)t3 ON t1.plan_id =t3.plan_id
WHERE t2.transfer_time < '%s'
'''
columns = ['plan_id', '白条商家', '产品编号', '放款日期', '总期数', '放款金额', '本金债权', '当期应还期数', '当期应还款日', '当期本金', '还款时间', '坏账统计时间']
years = (2017,)
months = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)
path = u'E:/数据汇总/白条/坏账/'
def bad_debt(year, month):
end_time = datetime.date(year, month, 1) + relativedelta(months=+1)
......@@ -91,7 +90,7 @@ def bad_debt(year, month):
df_plan.to_excel(path + u'%s-%s_白条坏账.xlsx' % (year, month), index=None)
bad_debt(2017, 9)
bad_debt(2017, 10)
# if __name__ == '__main__':
# pool = mtp.Pool(processes=8)
# for year, month in product(years, months):
......
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