Commit 1e004421 authored by Data-韩正辉's avatar Data-韩正辉

调整退款汇总的逻辑,将退款按照还款计划拆分与应还相加

parent 50bcd663
......@@ -19,10 +19,11 @@ pd.options.mode.chained_assignment = None
# user_bt_repayment_plan,baitiao_order,fund_corp
# 注意事项:
# 出来的表为汇总表
#
# 笑脸直投应还本金会有140的差距,是由于下单后使用红包金额导致。查询代码:
# SELECT SUM(funding_loan_amount),SUM(real_loan_amount) FROM baitiao_order WHERE funding_corp_id=5 AND funding_loan_amount!=real_loan_amount;
file_path = u'E:/审计出表/非去哪儿白条-放款表(1月份-6月份)/'
engine_bt = create_engine('mysql+mysqldb://internal_r:ArbNgtvlJzZHXsEu@172.16.3.201:3306/audit?charset=utf8',
engine_bt = create_engine('mysql+mysqldb://internal_r:ArbNgtvlJzZHXsEu@172.16.4.60:3306/audit?charset=utf8',
echo=False).connect()
def bt_principle_interest():
......@@ -48,8 +49,8 @@ def bt_principle_interest():
sql_bt_refund = '''
SELECT
fc.fund_name 资金方,
YEAR (bo.train_cancel_at) 放款年,
MONTH (bo.train_cancel_at) 放款月,
YEAR (bo.loan_paid_at) 放款年,
MONTH (bo.loan_paid_at) 放款月,
YEAR (plan.deadline) 到期年,
MONTH (plan.deadline) 到期月,
sum(plan.principle) 客户应还本金,
......@@ -59,7 +60,7 @@ def bt_principle_interest():
JOIN baitiao_audit.baitiao_order bo ON bo.ref_id = plan.ref_id
JOIN baitiao_audit.fund_corp fc ON fc.id = bo.funding_corp_id
WHERE
bo.is_active IN (-2) AND bo.funding_corp_id = 1
bo.is_active IN (-2) AND bo.funding_corp_id in (1,5) AND bo.train_cancel_at<'2017-11-01'
GROUP BY
1,2,3,4,5;
'''
......@@ -75,7 +76,8 @@ def bt_principle_interest():
0 客户应还利息
from baitiao_audit.baitiao_order t1
join baitiao_audit.fund_corp fc ON fc.id = t1.funding_corp_id
where t1.baitiao_type=1;
where t1.baitiao_type=1
GROUP BY 1,2,3,4,5;
'''
df_bt = pd.read_sql(sql_bt,engine_bt)
......@@ -83,7 +85,11 @@ def bt_principle_interest():
df_cash = pd.read_sql(sql_cash_bt,engine_bt)
df = pd.concat([df_bt,df_bt_refund,df_cash],ignore_index=True)
df.to_excel(file_path+u'非去哪儿白条每月到期本金利息-V6.xlsx',index=False)
df.fillna(0,inplace=True)
result = df.groupby([u'资金方',u'放款年',u'放款月',u'到期年',u'到期月'])[u'客户应还本金',u'客户应还利息'].sum().reset_index()
result.to_excel(file_path+u'非去哪儿白条每月到期本金利息-V7.xlsx',index=False)
df.to_excel(file_path+u'非去哪儿白条每月到期本金利息明细版本-V7.xlsx',index=False)
if __name__ == '__main__':
print '--------main begin'
......
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