#!/bin/bash
ip=$1
phone_no=$2
PORT="3306"
USERNAME="qa"
PASSWORD="qatest"
mysqld="-h${ip} -P${PORT} -u${USERNAME} -p${PASSWORD}"

function baitiaoDeleteOrder(){

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


user_id_sql="select id from user where phone_no='${phone_no}'"
echo $user_id_sql
user_id=`mysql -N $mysqld xyqb_user -e "${user_id_sql}"`
#echo "user_id=$user_id"
order_id_sql="select id  from baitiao_order where user_id=${user_id} LIMIT 1";
#echo $order_id_sql
order_id=`mysql -N $mysqld xyqb -e "${order_id_sql}"`
#echo "order_id=${order_id}"
fund_id_sql="SELECT id from xyqb.baitiao_fund_order WHERE order_id=${order_id} limit 1";
#echo $fund_id_sql
fund_id=`mysql -N $mysqld xyqb -e "${fund_id_sql}"`
#echo "fund_id=$fund_id"

delete1="delete from baitiao_order where xyqb.baitiao_order.user_id=${user_id}";
#echo $delete1;
mysql -N $mysqld xyqb -e "${delete1}"
delete2="delete from baitiao_fund_order where xyqb.baitiao_fund_order.order_id=${order_id}";
#echo $delete2;
mysql -N $mysqld xyqb -e "${delete2}"
delete3="delete from baitiao_bill where xyqb.baitiao_bill.user_id=${user_id}";
#echo $delete3;
mysql -N $mysqld xyqb -e "${delete3}"
delete4="delete from baitiao_bill_repayment_plan where xyqb.baitiao_bill_repayment_plan.user_id=${user_id}";
#echo $delete4;
mysql -N $mysqld xyqb -e "${delete4}"
delete5="delete from baitiao_fund_repayment_plan where baitiao_fund_repayment_plan.fund_order_id=${fund_id}";
#echo $delete5
mysql -N $mysqld xyqb -e "${delete5}"
delete6="delete from baitiao_consume_history where baitiao_consume_history.user_id=${user_id} and baitiao_consume_history.order_id !=-1";
#echo $delete6;
mysql -N $mysqld xyqb -e "${delete6}"

echo "done!!! `date`" 
fi;
}

baitiaoDeleteOrder $ip $phone_no
