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

去哪儿done

parent f21ad4ea
......@@ -131,6 +131,12 @@ JOIN `repay_detail` t2 ON t1.`fund_code`=t2.`fund_code` AND t1.`product_no`=t2.`
WHERE t1.status=1
#==========step_5================
#====重点校验===
逻辑 债转前的 退还款+债转金额 = 债转前的放款金额
债转后的金额 >= 债转后的退还款
#判断是否有退款时间>债转时间,但资金方ID 非保理
SELECT t1.id,t1.`product_no`,t1.`trans_time`,t2.`refund_time` FROM `baoli_pay_detail` t1
JOIN `refund_detail` t2 ON t1.`product_no` = t2.product_no
......
......@@ -51,8 +51,8 @@ def cal_due_amount(deadline,repaid_at,require_fee,is_new=True):
if __name__ == '__main__':
deadline=datetime.date(2017,6,1)
repaid_at=datetime.date(2017,10,5)
require_fee=1012.34
punish=cal_due_amount(deadline,repaid_at,require_fee)
deadline=datetime.date(2016,1,26)
repaid_at=datetime.date(2016,1,27)
require_fee=79.5
punish=cal_due_amount(deadline,repaid_at,require_fee,is_new=False)
print '----罚息----',punish
\ No newline at end of file
......@@ -253,4 +253,20 @@ if __name__ == '__main__':
# print df['refund_amount'].sum()
# 导入还款数据
# df = load_repay(year,month, insert_db=True)
# print df['repay_amount'].sum()
\ No newline at end of file
# print df['repay_amount'].sum()
#===如果 退款时间在 债转时间之后,那么更新资金方ID ;如果还款时间在 在债转时间之后,那么更新 资金方ID
#===继续执行下面的SQL===
# update_refund='''
# update repay_detail set repay.fund_code=1
# from repay_detail repay
# JOIN baoli_pay_detail t2 on repay.product_no = t2.product_no and repay.repay_status=1 and repay.fund_code != 1
# where date(t2.trans_time) < DATE(repay.repay_time)
# '''
#
# update_refund = '''
# update refund_detail set repay.fund_code=1
# from refund_detail repay
# JOIN baoli_pay_detail t2 on repay.product_no = t2.product_no and repay.refund_status=1 and repay.fund_code != 1
# where date(t2.trans_time) < DATE(repay.refund_time)
# '''
\ No newline at end of file
......@@ -154,36 +154,35 @@ 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 id plan_id,product_no,current_stage_no user_current_stage_no
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')
update_sql='''
update repayment_plan_2017 set fund_code=1 where fund_code = 3 and plan_id = %s
'''
engine_qunaer.execute(update_sql,df_2[['plan_id']].values.tolist())
# 债转校验--
......@@ -226,7 +225,8 @@ if __name__ == '__main__':
#===到期日
# step_4(year,month)
# step_5(year,month)
#TODO ==== 更新,客户的还款计划中的资金方 ID
#更新,客户的还款计划中的资金方 ID
# step_6(year,month)
#--根据客户的还款计划更新保理的还款计划
......
......@@ -222,7 +222,7 @@ if __name__ == '__main__':
# step_6(year,month)
#--根据客户的还款计划更新保理的还款计划
# step_7(year,month)
step_8(year,month)
# step_8(year,month)
......
......@@ -154,7 +154,7 @@ def step_1_1(year,month,product_no='',insert_db = False):
return df
# 单单只有退款服务费的时候,也需要更新下。
# 有退款的订单,更新还款计划-- 更新应还本金,利息
# 还款计划表 repayment_plan_2017
def step_2(year,month,product_no='',insert_db=False):
......
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