Commit 91cbf631 authored by Data-韩正辉's avatar Data-韩正辉

增加了客户实还时间

parent 82dac760
......@@ -5,10 +5,13 @@ import pandas as pd
from sqlalchemy import create_engine
from dateutil.relativedelta import relativedelta
from itertools import product
import pyexcelerate
reload(sys)
sys.setdefaultencoding("utf-8")
pd.options.mode.chained_assignment = None
max_limit = 800000
#
# 表名称:
......@@ -26,26 +29,26 @@ pd.options.mode.chained_assignment = None
# (本、利、服、罚)需要:t1.principle-t1.mitigate_principle 本金
#
file_path = u'E:/审计出表/非去哪儿白条-客户实还表(1月份-6月份)/'
file_path = u'E:/审计出表/非去哪儿白条-客户实还表-1023版/'
# 注意修改数据源
engine_new_transaction = create_engine(
engine_all_back_0831 = create_engine(
'mysql+mysqldb://internal_r:ArbNgtvlJzZHXsEu@172.16.3.201:3306/?charset=utf8',
echo=True)
read_merchant_sql = '''SELECT merchant_id,merchant_name FROM baitiao_audit.merchant'''
df_merchant = pd.read_sql(read_merchant_sql, con=engine_new_transaction)
read_merchant_sql = '''SELECT merchant_id,merchant_name FROM all_back_0831.merchant'''
df_merchant = pd.read_sql(read_merchant_sql, con=engine_all_back_0831)
df_merchant['merchant_id'] = df_merchant['merchant_id'].astype(int)
read_repay_sql = '''
SELECT id,`approach_name` FROM new_transaction.`repay_channel`
'''
df_approach = pd.read_sql(read_repay_sql, engine_new_transaction)
df_approach = pd.read_sql(read_repay_sql, engine_all_back_0831)
df_approach['id'] = df_approach['id'].astype(int)
read_fund_sql = '''
SELECT id,fund_name FROM baitiao_audit.`fund_corp`
SELECT id,fund_name FROM all_back_0831.`fund_corp`
'''
df_fund = pd.read_sql(read_fund_sql, engine_new_transaction)
df_fund = pd.read_sql(read_fund_sql, engine_all_back_0831)
df_fund['id'] = df_fund['id'].astype(int)
......@@ -55,69 +58,79 @@ def hk_hz(year, month):
end_time = start_time + relativedelta(months=+1)
sql_alipay = """
SELECT t5.funding_corp_id,t5.order_no 产品编号,t6.merchant_name,t5.contract_term 放款期数,t2.term_no 当前期数,
SELECT t5.funding_corp_id,t5.order_no 产品编号,t6.merchant_name,t5.contract_term 放款期数,t2.term_no 当前期数,date(t3.transfer_time) 客户实还时间,
t1.ref_amount 总额, t1.principle-t1.mitigate_principle 本金, t1.interest-t1.mitigate_interest 利息, t1.service_fee-t1.mitigate_service_fee 服务费,
t1.red_package_fee 红包减免,
t1.punish-t1.mitigate_collection_relief 逾期罚款收益,
t1.remain_income 其他收益,
t7.approach_name,
t3.business_flow 流水号
FROM new_transaction.baitiao_repay_plan_repay_record_ref t1
JOIN new_transaction.user_bt_repayment_plan t2 ON t2.id = t1.plan_id
JOIN new_transaction.offline_alipay_record t3 ON t1.repay_channel =13 AND t3.id = t1.record_id
JOIN baitiao_audit.baitiao_order t5 ON t2.ref_id=t5.ref_id
JOIN baitiao_audit.merchant t6 ON t6.`merchant_id` = t5.`merchantId`
JOIN new_transaction.repay_channel t7 ON t1.repay_channel = t7.id
FROM all_back_0831.baitiao_repay_plan_repay_record_ref t1
JOIN all_back_0831.user_bt_repayment_plan t2 ON t2.id = t1.plan_id
JOIN all_back_0831.offline_alipay_record t3 ON t1.repay_channel =13 AND t3.id = t1.record_id
JOIN all_back_0831.baitiao_order t5 ON t2.ref_id=t5.ref_id
JOIN all_back_0831.merchant t6 ON t6.`merchant_id` = t5.`merchantId`
JOIN new_transaction.`repay_channel` t7 ON t1.repay_channel = t7.id
where t3.transfer_time >='%s' and t3.transfer_time<'%s'
""" % (start_time, end_time)
df_alipay = pd.read_sql(sql=sql_alipay, con=engine_new_transaction)
df_alipay = pd.read_sql(sql=sql_alipay, con=engine_all_back_0831)
# 银行还款
sql_bank = """
SELECT t5.funding_corp_id,t5.order_no 产品编号,t6.merchant_name,t5.contract_term 放款期数, t2.term_no 当前期数,
SELECT t5.funding_corp_id,t5.order_no 产品编号,t6.merchant_name,t5.contract_term 放款期数, t2.term_no 当前期数,date(t3.transfer_time) 客户实还时间,
t1.ref_amount 总额, t1.principle-t1.mitigate_principle 本金, t1.interest-t1.mitigate_interest 利息, t1.service_fee-t1.mitigate_service_fee 服务费,
t1.punish-t1.mitigate_collection_relief 逾期罚款收益,
t1.remain_income 其他收益,
t7.approach_name,
t3.serial_number 流水号
FROM new_transaction.baitiao_repay_plan_repay_record_ref t1
JOIN new_transaction.user_bt_repayment_plan t2 ON t2.id = t1.plan_id
JOIN new_transaction.offline_bank_repay_record t3 ON t1.repay_channel in (14,15,16) AND t3.id = t1.record_id
JOIN baitiao_audit.baitiao_order t5 ON t2.ref_id=t5.ref_id
JOIN baitiao_audit.merchant t6 ON t6.`merchant_id` = t5.`merchantId`
JOIN new_transaction.repay_channel t7 ON t1.repay_channel = t7.id
FROM all_back_0831.baitiao_repay_plan_repay_record_ref t1
JOIN all_back_0831.user_bt_repayment_plan t2 ON t2.id = t1.plan_id
JOIN all_back_0831.offline_bank_repay_record t3 ON t1.repay_channel in (14,15,16) AND t3.id = t1.record_id
JOIN all_back_0831.baitiao_order t5 ON t2.ref_id=t5.ref_id
JOIN all_back_0831.merchant t6 ON t6.`merchant_id` = t5.`merchantId`
JOIN new_transaction.`repay_channel` t7 ON t1.repay_channel = t7.id
where t3.transfer_time>= '%s' and t3.transfer_time<'%s'
""" % (start_time, end_time)
df_bank = pd.read_sql(sql=sql_bank, con=engine_new_transaction)
df_bank = pd.read_sql(sql=sql_bank, con=engine_all_back_0831)
# 线上还款
sql_online = """
SELECT t5.funding_corp_id,t5.order_no 产品编号,t6.merchant_name,t5.contract_term 放款期数,t2.term_no 当前期数,
SELECT t5.funding_corp_id,t5.order_no 产品编号,t6.merchant_name,t5.contract_term 放款期数,t2.term_no 当前期数,date(t3.bill_time) 客户实还时间,
t1.ref_amount 总额, t1.principle-t1.mitigate_principle 本金, t1.interest-t1.mitigate_interest 利息, t1.service_fee-t1.mitigate_service_fee 服务费,
t1.punish-t1.mitigate_collection_relief 逾期罚款收益,
t1.remain_income 其他收益,
t7.approach_name,
t3.order_id 流水号
FROM new_transaction.baitiao_repay_plan_repay_record_ref t1
JOIN new_transaction.user_bt_repayment_plan t2 ON t2.id = t1.plan_id
JOIN new_transaction.repay_record_online t3 ON t1.repay_channel < 13 AND t3.id = t1.record_id
JOIN baitiao_audit.baitiao_order t5 ON t2.ref_id=t5.ref_id
JOIN baitiao_audit.merchant t6 ON t6.`merchant_id` = t5.`merchantId`
JOIN new_transaction.repay_channel t7 ON t1.repay_channel = t7.id
FROM all_back_0831.baitiao_repay_plan_repay_record_ref t1
JOIN all_back_0831.user_bt_repayment_plan t2 ON t2.id = t1.plan_id
JOIN all_back_0831.repay_record_online t3 ON t1.repay_channel < 13 AND t3.id = t1.record_id
JOIN all_back_0831.baitiao_order t5 ON t2.ref_id=t5.ref_id
JOIN all_back_0831.merchant t6 ON t6.`merchant_id` = t5.`merchantId`
JOIN new_transaction.`repay_channel` t7 ON t1.repay_channel = t7.id
where t3.bill_time>='%s' and t3.bill_time<'%s'
""" % (start_time, end_time)
df_online = pd.read_sql(sql=sql_online, con=engine_new_transaction)
df_online = pd.read_sql(sql=sql_online, con=engine_all_back_0831)
df = pd.concat([df_alipay, df_bank, df_online], ignore_index=True)
df[u'资金方'] = u'保理'
# df.sort_values(['r_year', 'r_month', 'merchant_name', 'approach_name', u'总额', u'本金', u'利息', u'服务费', u'逾期罚款收益', u'其他收益',u'总减免',u'红包减免', u'减免本金', u'减免利息', u'减免服务费', u'减免罚息'], inplace=True)
df = df[
[ u'产品编号', u'放款期数', 'merchant_name', 'approach_name', u'总额', u'本金', u'利息', u'服务费', u'逾期罚款收益',
[u'资金方', u'产品编号', u'放款期数', 'merchant_name', 'approach_name', u'客户实还时间',u'总额', u'本金', u'利息', u'服务费', u'逾期罚款收益',
u'其他收益', u'流水号']]
df.rename(columns={'merchant_name': '商户', 'approach_name': '收款账户'}, inplace=True)
# columns = ['年', '月', '商户', '收款账户', '总额', '本金', '利息', '服务费', '红包减免金额', '逾期罚款收益', '其他收益']
print(sum(df[u'总额']))
df.to_excel(file_path+u'白条还款明细表-__%s_%s.xlsx' %(year,month), index=None)
# df.to_excel(file_path+u'白条还款明细表_%s_%s.xlsx' %(year,month), index=None)
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(file_path + u'白条还款明细表_%s_%s.xlsx' %(year,month))
# df.to_csv(file_path + u'白条还款明细表-2222__%s_%s.csv' %(year,month), index=None, encoding='gb18030')
......@@ -125,7 +138,7 @@ if __name__ == '__main__':
# 还款明细
years = [2017]
months = range(1, 6, 1)
months = range(2, 7, 1)
for year, month in product(years, months):
print('-----%s--%s') % (year, month)
hk_hz(year, month)
......
......@@ -7,13 +7,15 @@ from itertools import product
import pandas as pd
from dateutil.relativedelta import relativedelta
from sqlalchemy import create_engine
import pyexcelerate
reload(sys)
sys.setdefaultencoding('utf8')
path = u'E:/'
# 注意修改数据源
file_path = u'E:/审计出表/非去哪儿白条-客户实还表-1023版/'
# 注意修改数据源
max_limit = 800000
engine_new_transaction = create_engine(
'mysql+mysqldb://internal_r:ArbNgtvlJzZHXsEu@172.16.3.201:3306/new_transaction?charset=utf8',
echo=True)
......@@ -51,6 +53,7 @@ def hk_hz(year,month):
t5.order_no 产品编号,
t5.contract_term 放款期数,
t6.merchant_name 白条商家,
date(t3.transfer_time) 客户实还时间,
ifnull(t1.ref_amount,0) 总额,
ifnull(t1.principle,0) - ifnull(t1.mitigate_principle,0)本金,
ifnull(t1.interest,0)-ifnull(t1.mitigate_interest,0)利息,
......@@ -77,6 +80,7 @@ def hk_hz(year,month):
t5.order_no 产品编号,
t5.contract_term 放款期数,
t6.merchant_name 白条商家,
date(t3.transfer_time) 客户实还时间,
ifnull(t1.ref_amount,0) 总额,
ifnull(t1.principle,0) - ifnull(t1.mitigate_principle,0) 本金,
ifnull(t1.interest,0) - ifnull(t1.mitigate_interest,0) 利息,
......@@ -88,8 +92,7 @@ def hk_hz(year,month):
FROM
baitiao_repay_plan_repay_record_ref t1
JOIN user_bt_repayment_plan t2 ON t2.id = t1.plan_id
JOIN offline_bank_repay_record t3 ON t1.repay_channel IN (14, 15, 16)
AND t3.id = t1.record_id
JOIN offline_bank_repay_record t3 ON t1.repay_channel IN (14, 15, 16) AND t3.id = t1.record_id
JOIN baitiao_audit.baitiao_order t5 ON t2.ref_id = t5.ref_id
JOIN baitiao_audit.merchant t6 ON t6.`merchant_id` = t5.`merchantId`
JOIN new_transaction.repay_channel t7 ON t1.repay_channel = t7.id
......@@ -104,6 +107,7 @@ def hk_hz(year,month):
t5.order_no 产品编号,
t5.contract_term 放款期数,
t6.merchant_name 白条商家,
date(t3.bill_time) 客户实还时间,
ifnull(t1.ref_amount,0) 总额,
ifnull(t1.principle,0) - ifnull(t1.mitigate_principle,0) 本金,
ifnull(t1.interest,0) - ifnull(t1.mitigate_interest,0) 利息,
......@@ -130,6 +134,7 @@ def hk_hz(year,month):
t5.order_no 产品编号,
t5.contract_term 放款期数,
t6.merchant_name 白条商家,
date(t3.bill_time) 客户实还时间,
ifnull(t1.ref_amount,0) 总额,
ifnull(t5.real_loan_amount,0) 本金,
0.0 利息,
......@@ -156,6 +161,7 @@ def hk_hz(year,month):
t5.order_no 产品编号,
t5.contract_term 放款期数,
t6.merchant_name 白条商家,
date(t3.transfer_time) 客户实还时间,
ifnull(t1.ref_amount,0) 总额,
ifnull(t5.real_loan_amount,0) 本金,
0.0 利息,
......@@ -181,15 +187,24 @@ def hk_hz(year,month):
df_cash_alipay = pd.read_sql(sql=sql_cash_alipay, con=engine_new_transaction)
df = pd.concat([df_alipay, df_bank, df_online, df_cash_onlie, df_cash_alipay], ignore_index=True)
df = df[
[u'资金方',u'产品编号',u'放款期数',u'白条商家', u'总额', u'本金', u'利息', u'服务费', u'逾期罚款收益',
[u'资金方',u'产品编号',u'放款期数',u'白条商家',u'客户实还时间', u'总额', u'本金', u'利息', u'服务费', u'逾期罚款收益',
u'其他收益',u'收款账户',u'流水号']]
df.to_excel(path + u'白条还款汇总表_%s_%s.xlsx' %(year,month), index=None)
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(file_path + u'白条还款明细表_%s_%s.xlsx' % (year, month))
# df.to_excel(file_path + u'白条还款汇总表_%s_%s.xlsx' %(year,month), index=None)
if __name__ == '__main__':
# 还款汇总
years = [2017]
months = [8]
months = [7,8,9]
for year, month in product(years, months):
print('-----%s--%s') % (year, month)
hk_hz(year, month)
\ No newline at end of file
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