#!/bin/bash
ip=$1
phone_no=$2
PORT=$3
USERNAME="qa"
PASSWORD="qatest"
DBNAME="xyqb"
TABLENAME="loan_application_history"
DBNAME1="xyqb_user"
TABLENAME1="user"
mysqld="-h${ip} -P${PORT} -u${USERNAME} -p${PASSWORD}"
date=`date "+%Y-%m-%d %H:%M:%S"`

function closeloan()
{
	len=`echo $phone_no|awk '{print length($0)}'`
	if [ $len -ne 11 ]
	then
		echo "请输入11位手机号!"     
	else
		#查询userID
		select_sql="select id from ${TABLENAME1} where phone_no=${phone_no}"
		user_id=`mysql -N $mysqld ${DBNAME1} -e "${select_sql}"`
		echo "user_id=$user_id"

		#更新loan_application_history表中的is_active=0
		update_sql="update ${TABLENAME} set is_active=0,set progress=16 where user_id=${user_id} and is_active=1 and business_type=0"
		mysql $mysqld ${DBNAME} -e "${update_sql}"
		echo "done!!! $date"
		break
	fi
	
}

closeloan $ip $phone_no
