Commit db3f6566 authored by Perry_Zhu's avatar Perry_Zhu

Merge remote-tracking branch 'origin/master'

parents f667ec89 98ed28dc
......@@ -154,36 +154,36 @@ def step_5(year,month):
df_fund_repay_no.to_sql('baoli_pay_detail',engine_qunaer,if_exists='append',index=None,chunksize=10000)
# 债转后的保理放款表的还款计划入库
def step_6(year,month):
start_time = datetime.date(year, month, 1)
end_time = start_time + relativedelta(months=+1)
sql_1='''
select t1.product_no,t1.new_stages,t1.stages from qunaer_new.baoli_pay_detail t1
JOIN qunaer_new.pay_detail t2 on t1.product_no = t2.product_no and t2.fund_code = 3
where t1.trans_time >= '%s' and t1.trans_time < '%s'
''' % (start_time,end_time)
df_1=pd.read_sql(sql_1,engine_qunaer)
#还款计划
sql_2='''
select product_no,current_stage_no user_current_stage_no,deadline,rate,principle,fee_amount,due_amount,status
from qunaer_new.repayment_plan_2017 where product_no in %s
''' % str(tuple(df_1['product_no'].astype(str).tolist()))
df_2=pd.read_sql(sql_2,engine_qunaer)
df_2['fund_code']=1
sql_3='''
select product_no,current_stage_no user_current_stage_no,repay_no from qunaer_new.repay_detail
where fund_code = 3 AND product_no in %s
''' % str(tuple(df_1['product_no'].astype(str).tolist()))
df_3=pd.read_sql(sql_3,engine_qunaer)
df_2=pd.merge(df_2,df_3,on=['product_no','user_current_stage_no'],how='left')
df_2=df_2.ix[df_2.repay_no.isnull()]
df_2=pd.merge(df_2,df_1,on='product_no',how='left')
df_2['diff']=np.round(df_2['stages']-df_2['new_stages'],2)
df_2['current_stage_no']=np.round(df_2['user_current_stage_no']-df_2['diff'],2)
df_2=df_2[['product_no','current_stage_no','user_current_stage_no','deadline','rate','principle','fee_amount','due_amount','status']]
# df_2.to_csv('E:/ddd.csv')
df_2.to_sql('baoli_repayment_plan',engine_qunaer,if_exists='append',index=None,chunksize=10000)
# # 债转后的保理放款表的还款计划入库
# def step_6(year,month):
# start_time = datetime.date(year, month, 1)
# end_time = start_time + relativedelta(months=+1)
# sql_1='''
# select t1.product_no,t1.new_stages,t1.stages from qunaer_new.baoli_pay_detail t1
# JOIN qunaer_new.pay_detail t2 on t1.product_no = t2.product_no and t2.fund_code = 3
# where t1.trans_time >= '%s' and t1.trans_time < '%s'
# ''' % (start_time,end_time)
# df_1=pd.read_sql(sql_1,engine_qunaer)
# #还款计划
# sql_2='''
# select product_no,current_stage_no user_current_stage_no,deadline,rate,principle,fee_amount,due_amount,status
# from qunaer_new.repayment_plan_2017 where product_no in %s
# ''' % str(tuple(df_1['product_no'].astype(str).tolist()))
# df_2=pd.read_sql(sql_2,engine_qunaer)
# df_2['fund_code']=1
# sql_3='''
# select product_no,current_stage_no user_current_stage_no,repay_no from qunaer_new.repay_detail
# where fund_code = 3 AND product_no in %s
# ''' % str(tuple(df_1['product_no'].astype(str).tolist()))
# df_3=pd.read_sql(sql_3,engine_qunaer)
# df_2=pd.merge(df_2,df_3,on=['product_no','user_current_stage_no'],how='left')
# df_2=df_2.ix[df_2.repay_no.isnull()]
# df_2=pd.merge(df_2,df_1,on='product_no',how='left')
# df_2['diff']=np.round(df_2['stages']-df_2['new_stages'],2)
# df_2['current_stage_no']=np.round(df_2['user_current_stage_no']-df_2['diff'],2)
# df_2=df_2[['product_no','current_stage_no','user_current_stage_no','deadline','rate','principle','fee_amount','due_amount','status']]
# # df_2.to_csv('E:/ddd.csv')
# df_2.to_sql('baoli_repayment_plan',engine_qunaer,if_exists='append',index=None,chunksize=10000)
# 债转校验--
......@@ -226,7 +226,9 @@ if __name__ == '__main__':
#===到期日
# step_4(year,month)
# step_5(year,month)
# step_6(year,month)
#TODO ==== 更新,客户的还款计划中的资金方 ID
#--根据客户的还款计划更新保理的还款计划
# 更新还款计划---哈银在9月上线,所以就无需更新了,但是之后10月必须更新的。
# check_baoli(year,month)
......
......@@ -243,6 +243,8 @@ if __name__ == '__main__':
# 哈银的还资金方表---,没有进行拆分QG 贴息
# step_3_hy(year,month)
#TODO === 更新还款计划===
# 还款更新时注意下,有提前结清或退货的,一定要注意状态。
# 流水勾稽
......
......@@ -113,13 +113,10 @@ def qunaer_zaidai(listen_time,watch_time,user_plan_2016,user_plan_2017):
join pay_detail t2 on t1.product_no = t2.product_no
where t2.fund_code = 1
''' % user_plan_2017
df_2017=pd.read_sql(sql_2017,engine_qunaer)
sql_baoli='''
select product_no ,date(deadline) deadline,status from baoli_repayment_plan
'''
df_baoli=pd.read_sql(sql_baoli,engine_qunaer)
df_plan=pd.concat([df_2016,df_2017,df_baoli],ignore_index=True)
df_plan=pd.concat([df_2016,df_2017],ignore_index=True)
#===首先提取 status=3 的这部分订单
df_trans_select=df_trans.ix[df_trans.product_no.isin(df_plan.ix[df_plan.status==3].product_no)]
# 将在贷中属于转分期的订单进行合并
......@@ -213,4 +210,9 @@ if __name__ == '__main__':
listen_time = datetime.datetime(year, month + 1, 1, 0, 0, 0)
qunaer_zaidai(listen_time,yuqi_time,user_plan_2016,user_plan_2017)
print(str(year),str(month), 'ends--------')
\ No newline at end of file
print(str(year),str(month), 'ends--------')
......@@ -5,6 +5,8 @@ import pandas as pd
import numpy as np
import datetime
from sqlalchemy import create_engine
import pyexcelerate
max_limit = 800000
reload(sys)
sys.setdefaultencoding('utf8')
......@@ -12,9 +14,12 @@ sys.setdefaultencoding('utf8')
engine_new_transaction = create_engine(
'mysql+mysqldb://internal_r:ArbNgtvlJzZHXsEu@172.16.3.201:3306/all_back_0930?charset=utf8', echo=True)
#假如导出10月份的数据,则end_point 是11月份第一天,watch_point 是10月份最后一天
end_point = '2017-10-01'
watch_point = datetime.date(2017, 9, 30)
out_file_path = u'E:/数据汇总/白条/在贷/'
out_file_path = u'E:/审计出表/11月份开始使用表数据/11月份白条出表/在贷/'
query_loan = """
SELECT
tt.order_no,tt.term_no,
......@@ -195,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)
......@@ -205,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)
......@@ -216,6 +221,9 @@ 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)
# 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',
......@@ -223,12 +231,38 @@ df_out.loc[df_out['order_no'].isin(
'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.to_csv(out_file_path + u'白条在贷按order_no展开_%s.csv' % end_point, index=None, encoding='UTF-8')
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):
temp = df[i:i + max_limit]
temp_list = temp.values.tolist()
temp_list.insert(0, temp.columns.tolist())
all_wb.new_sheet(str(int(i / max_limit + 1)), data=temp_list)
all_wb.save(out_file_path + u'白条在贷按order_no展开_%s.xlsx' % end_point)
# df.to_csv(out_file_path + u'白条在贷按order_no展开_%s.csv' % end_point, index=None, encoding='UTF-8')
......@@ -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