Commit 60cf42d0 authored by Data-王博's avatar Data-王博

赔付表

parent 3948774a
......@@ -49,4 +49,4 @@ group by t3.class,date_format(t1.loan_paid_at, '%%y-%%m'),year(t2.deadline),mont
path_out = u'E:/财务/'
df = pd.read_sql(sql=sql, con=engine_financial)
df.to_excel(path_out + u'现金贷应收本金利息汇总.xlsx', index=None)
\ No newline at end of file
df.to_excel(path_out + u'现金贷应收本金利息汇总_15_16.xlsx', index=None)
\ No newline at end of file
......@@ -76,7 +76,7 @@ SELECT
t3.ref_id
FROM
new_transaction.`xjd_repay_plan_repay_record_ref` t1
JOIN new_transaction.`user_repayment_plan` t3 ON t1.plan_id = t3.id
JOIN new_transaction.`user_repayment_plan` t3 ON t1.plan_id = t3.id AND t1.repay_channel IN (1,2,4,6,8,9,10,11,12,20)
AND t3.xyqb_repaid_at >= '%s'
AND t3.xyqb_repaid_at < '%s'
"""
......
......@@ -22,7 +22,7 @@ path = u'C:/Users/wangbo/Desktop/八月份对账/出表数据/'
1、应还资金方本息
'''
sql_fund = '''
select id fund_code,name fund_name from new_transaction.funding_corp WHERE id in (200,290, 330, 340)
select id fund_code,name fund_name from new_transaction.funding_corp WHERE id in (210,300,290,350,390)
'''
sql_repay_channel = '''
select id repay_channel , approach_name channel_name FROM new_transaction.`repay_channel`
......@@ -182,7 +182,7 @@ GROUP BY DATE(urp.deadline)
# 应还本息+ 提前还款(28号之前)- 提前应还款
def ky_table(fund_code, fund_name):
# -------应还---------
if fund_code in (290, 330, 340):
if fund_code in (290, 330, 340, 390):
df_plan = pd.read_sql(sql_fund_hk_user_plan % (fund_code, start_time, end_time), con=engine_new_transaction)
else:
df_plan = pd.read_sql(sql_fund_hk % (fund_code, start_time, end_time), con=engine_new_transaction)
......@@ -278,16 +278,16 @@ def ky_table(fund_code, fund_name):
df_hk_new = pd.merge(df_hk_new, df_tq_1, how='outer', on=['day_hk'])
df_hk_new.fillna(0, inplace=True)
df_hk_new['real_all'] = df_hk_new['zc_prin_inst_total'] + df_hk_new[
'yq_prin_inst_total']+df_hk_new['plan_tq_prin_inst_total']
'yq_prin_inst_total']+df_hk_new['tq_prin_inst_total']
df_hk_new['fund_name'] = fund_name
df_hk_new = df_hk_new[
['fund_name', 'day_hk', 'plan_all', 'real_all', 'zc_prin_inst_total',
'tq_prin_inst_total', 'yq_prin_inst_total']]
df_hk_new['peifu'] = df_hk_new['plan_all']-df_hk_new['real_all']
'tq_prin_inst_total', 'yq_prin_inst_total','plan_tq_prin_inst_total']]
df_hk_new['peifu'] = df_hk_new['plan_all']-df_hk_new['real_all']-df_hk_new['plan_tq_prin_inst_total']+df_hk_new['tq_prin_inst_total']
df_hk_new['fund_name'] = fund_name
df_hk_new.rename(columns={'fund_name':'资金方','day_hk': '日期', 'plan_all': '应还资金方本息', 'real_all': '客户实还本息可用',
'zc_prin_inst_total': '客户正常还款本息', 'yq_prin_inst_total': '当天客户逾期还款本息',
'tq_prin_inst_total': '客户提前还款本息当天到期可用','peifu':'当日不可用累计本息'
'tq_prin_inst_total': '客户提前还款本息当天到期可用','peifu':'当日不可用累计本息','plan_tq_prin_inst_total':"提前应还"
},
inplace=True)
df_hk_new.to_excel(path + str(fund_code) + '.xlsx', index=None, columns=df_hk_new.columns, encoding='utf8')
......@@ -652,7 +652,7 @@ if __name__ == '__main__':
fund_code = int(row['fund_code'])
fund_name = row['fund_name']
print '------begin---', fund_name
if fund_code in (200, 330,290,340):
if fund_code in (200, 330,290,340,390):
ky_table(fund_code, fund_name)
elif fund_code == 150:
hr_table(fund_code, fund_name)
......
# -*- coding:utf-8 -*-
# Author: WuKong
import sys
import datetime
import itertools
import pandas as pd
from sqlalchemy import create_engine
import multiprocessing as mtp
import os
sql_query_fin = """
"""
\ No newline at end of file
# -*- encoding: utf8 -*-
from __future__ import unicode_literals
import pandas as pd
from sqlalchemy import create_engine
import sys
reload(sys)
sys.setdefaultencoding('utf8')
engine_audit = create_engine('mysql+mysqldb://internal_r:ArbNgtvlJzZHXsEu@172.16.3.201:3306/audit?charset=utf8', echo=True)
df_fund_corp = pd.read_sql(sql="select funding_code, name '资金方' from basic.funding_corp", con=engine_audit)
df_loan_account = pd.read_sql(sql="select id loan_account_id, accountName '放款账户' from audit.loan_account", con=engine_audit)
df_repay_channel = pd.read_sql(sql="select id repay_channel_id, approach_name '收款账户' from new_transaction.repay_channel", con=engine_audit)
excel_file = pd.ExcelWriter('放款数据汇总核对表.xlsx')
################################################
# 放款表汇总
sql = """
select year(t1.loan_paid_at) '年', month(t1.loan_paid_at) '月', funding_code , loan_account_id , sum(t1.real_loan_amount) '放款金额', sum(t1.contract_loan_amount) '本金债权',
sum(t1.qg_one_time_service_fee) '一次性扣除手续费QG', sum(t1.funding_one_time_service_fee) ' 一次性扣除手续费点滴',SUM(t2.qg_one_time_service_fee) '应扣趸收服务费' from loan_manifest t1 LEFT JOIN new_transaction.xjd_dunjiao_plan t2 ON t1.ref_id = t2.ref_id where t1.is_active in (1,-2)
group by 1,2,3,4;
"""
df = pd.read_sql(sql=sql, con=engine_audit)
df['funding_code'] = df['funding_code'].astype(int)
df['loan_account_id'] = df['loan_account_id'].astype(int)
df = df.merge(df_fund_corp, on='funding_code', how='left').merge(df_loan_account, on='loan_account_id', how='left')
df.drop(['funding_code', 'loan_account_id'], axis=1, inplace=True)
# df.to_excel(u'放款表汇总.xlsx', index=None)
df.to_excel(excel_file, '放款表汇总', columns=['年', '月', '资金方', '放款账户', '放款金额', '本金债权', '一次性扣除手续费QG', '一次性扣除手续费点滴','应扣趸收服务费'], index=None)
excel_file.save()
\ No newline at end of file
# -*- coding: utf-8 -*-
import os
import sys
import datetime
import threading
from itertools import product
from threading import Thread
import pandas as pd
from dateutil.relativedelta import relativedelta
from sqlalchemy import create_engine
import multiprocessing as mtp
reload(sys)
sys.setdefaultencoding('utf8')
path='./'
sql_query_detail='''
SELECT
'阳光徽商' fund_name,
t2.loan_id,
t2.loan_paid_at,
t1.repay_date,
t2.real_loan_amount,
t1.actual_principle,
t1.actual_interest,
t1.actual_qg_service_fee,
t1.actual_repay_amount,
t1.actual_fund_overdue_interest ,
t1.actual_qg_overdue_interest ,
t1.actual_compound_interest
FROM
yg_huishang_repay_term t1
JOIN audit.loan_manifest t2 ON t1.ref_id = t2.ref_id WHERE repay_date>="%s" AND repay_date<"%s"
'''
sql_query_summary='''
SELECT
'阳光徽商' fund_name,
sum(t1.actual_principle) summary_principle,
sum(t1.actual_interest) summary_interest,
sum(t1.actual_qg_service_fee) summary_qg_service_fee,
sum(t1.actual_repay_amount) summary_repay_amount,
sum(t1.actual_fund_overdue_interest) summary_fund_overdue_interest,
sum(t1.actual_qg_overdue_interest ) summary_qg_overdue_interest,
sum(t1.actual_compound_interest) summary_compound_interest,
YEAR (repay_date) repay_year,
MONTH (repay_date) repay_month
FROM
yg_huishang_repay_term t1 WHERE repay_date>="%s" AND repay_date<"%s" GROUP BY YEAR(repay_date),MONTH(repay_date)
'''
engine_new_transaction = engine_new_transaction = create_engine(
'mysql+mysqldb://internal_r:ArbNgtvlJzZHXsEu@172.16.3.201:3306/test?charset=utf8',
echo=True)
if __name__ == '__main__':
start_time = datetime.datetime(2017, 1, 1, 0, 0, 0)
end_time = datetime.datetime(2017, 8, 1, 0, 0, 0)
df=pd.read_sql(sql_query_detail % (start_time,end_time),engine_new_transaction)
df.rename(columns={'loan_id':u'放款id','loan_paid_at':u'放款时间','repay_date':u'实还款日','real_loan_amount':u'放款金额',
'actual_principle':u'实还本金','actual_interest':u'实还利息','actual_qg_service_fee':u'实还服务费','actual_qg_overdue_interest':u'实还量化派逾期费',
'actual_fund_overdue_interest':u'实还资金方逾期费','actual_compound_interest':u'实还复利','fund_name':u'资金方','actual_repay_amount':u'实还款'},inplace=True)
df.to_excel(path + u'阳光徽商还款明细' + '.xlsx', columns=df.columns, index=None, encoding='utf8')
df_summary = pd.read_sql(sql=sql_query_summary % (start_time,end_time),con=engine_new_transaction)
df_summary.rename(columns={'repay_year': u'年','repay_month': u'月',
'summary_principle': u'实还本金', 'summary_interest': u'实还利息', 'summary_qg_service_fee': u'实还服务费',
'summary_qg_overdue_interest': u'实还量化派逾期费',
'summary_fund_overdue_interest': u'实还资金方逾期费','summary_compound_interest':u'实还复利', 'fund_name': u'资金方', 'summary_repay_amount': u'实还款'},
inplace=True)
df_summary.to_excel(path + u'阳光徽商还款汇总' + '.xlsx', columns=df_summary.columns, index=None, encoding='utf8')
......@@ -22,14 +22,14 @@ sys.setdefaultencoding('utf8')
'''
read_fund_sql = '''
select id fund_corp_id,name fund_name from new_transaction.funding_corp where id not in (0,160,40,60,340)
select id fund_corp_id,name fund_name from new_transaction.funding_corp where id not in (0,160,40,60)
'''
read_repay_sql = '''
SELECT id,`approach_name` FROM new_transaction.`repay_channel`
'''
engine_new_transaction = engine_new_transaction = create_engine(
'mysql+mysqldb://internal_r:ArbNgtvlJzZHXsEu@172.16.3.201:3306/all_back_0731?charset=utf8',
'mysql+mysqldb://internal_r:ArbNgtvlJzZHXsEu@172.16.3.201:3306/new_transaction?charset=utf8',
echo=True)
df_fund = pd.read_sql(read_fund_sql, con=engine_new_transaction)
......@@ -73,7 +73,7 @@ def hk_hz():
join new_transaction.funding_corp t6 on t2.fund_code=t6.id
join new_transaction.repay_channel t7 on t1.repay_channel = t7.id
join audit.loan_manifest t8 on t8.ref_id = t2.ref_id
join repay_record_online t3 on t1.repay_channel < 13 and t3.id = t1.record_id
join repay_record_online t3 on t1.repay_channel = t3.pay_approach and t3.id = t1.record_id
group by 1,2,3,4,5,6"""
df_online = pd.read_sql(sql=sql_online, con=engine_new_transaction)
......@@ -128,7 +128,7 @@ t2.remain_income,t2.`mitigate_principle`,t2.`mitigate_interest`,t2.`mitigate_ser
FROM `xjd_repay_plan_repay_record_ref` t2
JOIN `user_repayment_plan` t1 ON t1.id=t2.plan_id
JOIN audit.`loan_manifest` t3 ON t1.ref_id=t3.ref_id
JOIN repay_record_online t6 ON t2.record_id=t6.id AND t2.repay_channel < 13
JOIN repay_record_online t6 ON t2.record_id=t6.id AND t2.pay_approach = t2.repay_channel
WHERE t6.bill_time >= '%s' and t6.bill_time < '%s'
'''
......
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