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

function authorization()
{
	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 ${DBNAME} -e "${select_sql}"`
		uuid=`mysql -N $mysqld ${DBNAME} -e "select uuid from ${TABLENAME1} where phone_no=${phone_no}"`
		echo "user_id=$user_id"
		echo "uuid=$uuid"

		#插入授信数据0和3
		insert_sql0="insert into ${TABLENAME} ("user_id","auth_type","auth_status") values ('$user_id','0',1)"
		insert_sql00="insert into user_auth_info ("auth_type","last_auth_time","auth_account_name","user_id","auth_status") values ('0',$date,$phone_no,$uuid,'1')"
		insert_sql3="insert into ${TABLENAME} ("user_id","auth_type","auth_status") values ('$user_id','3',1)"

		#echo "$insert_sql0"
		#echo "$insert_sql3"
		mysql $mysqld ${DBNAME} -e "${insert_sql0}"
		#mysql $mysqld ${DBNAME} -e "${insert_sql00}"
		mysql $mysqld ${DBNAME} -e "${insert_sql3}"
		echo "done!!! $date"
	fi
}

authorization $ip $phone_no
