#!/bin/bash
ip=$1
phone_no=$2
fund_id=$3
port=$4
#fund_id:"请输入资金方编号，湖北消金输入290、洋钱罐140，广源小贷210，其他的参考表xyqb.fund_corp:"


	len=`echo $phone_no|awk '{print length($0)}'`
	if [ $len -ne 11 ]
	then
		echo "请输入11位手机号!"
	else
		break
	fi


date=`date "+%Y-%m-%d %H:%M:%S"`

mysql -h"$ip" -P"$port" -u"qa" -p"qatest" <<EOF
use xyqb;
update xyqb.loan_application_history
set xyqb.loan_application_history.progress=9
where business_type=0 and user_id=(select id from xyqb_user.user where phone_no =$phone_no) and is_active=1;

delete from xyqb.loan_application_manifest_history 
where loan_application_history_id =111112222233333;

INSERT INTO xyqb.loan_application_manifest_history (user_id, loan_application_history_id, channel_id, product_id, transaction_flow_id, funding_corp_id, funding_corp_name, contract_loan_amount, contract_term, service_fee_per_term, one_time_service_fee, monthly_interest_rate, total_repayment_amount, monthly_repayment, real_loan_amount, annual_interest_rate, principal_and_interest_per_term, total_principal_and_interest, company_income, loan_received_at, loan_paid_at, transaction_status, remark, red_packet_strategy) 
VALUES (1, 111112222233333, 1, 32, 0, $fund_id, '测试资金方', 2000.00, 3, 150.00, 0.00, 0.011675, 2496.88, 832.29, 2000.00, 0.140100, 682.29, 2046.88, 46.88, '2017-06-08 18:39:33', '1989-09-29 00:00:00', 0, '', NULL);

delete from xyqb.loan_application_manifest_history
where loan_application_history_id=(select id from xyqb.loan_application_history where business_type=0 and user_id=(select id from xyqb_user.user where phone_no =$phone_no) and is_active=1);

update xyqb.loan_application_manifest_history 
set user_id=(select id from xyqb_user.user where phone_no =$phone_no),
loan_application_history_id=(select id from xyqb.loan_application_history where business_type=0 and user_id=(select id from xyqb_user.user where phone_no =$phone_no) and is_active=1),
loan_received_at='$date',
product_id=(select distinct(product_id) from risk_control.product_strategy_dispatcher where funding_corp_id=$fund_id),
loan_paid_at='$date' 
where loan_application_history_id =111112222233333;

update xyqb.page_state_info
set state='AuditedSuccState'
where loan_id=(select id from xyqb.loan_application_history where business_type=0 and user_id=(select id from xyqb_user.user where phone_no =$phone_no) and is_active=1);

update risk_control.review_history
set progress=0
where phone_no=$phone_no

EOF
echo "done!!!"
