#!/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}"`
		echo "user_id=$user_id"

		#插入授信数据0和3
		insert_sql0="insert into ${TABLENAME} ("user_id","auth_type","auth_status") values ('$user_id','0',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_sql3}"
		echo "done!!! $date"
	fi
}

authorization $ip $phone_no
