#!/bin/bash
ip=$1
phone_no=$2
PORT=$3
# chanpin分配默认值为：QG_FIX0_6000_6，渠道惠金所2
chanpin=$4
USERNAME="qa"
PASSWORD="qatest"
DBNAME="xyqb"
DBNAME1="risk_control"
DBNAME2="xyqb_user"
TABLENAME="waiting_for_assignment"
TABLENAME1="review_history"
TABLENAME2="user"
mysqld="-h${ip} -P${PORT} -u${USERNAME} -p${PASSWORD}"
date=`date "+%Y-%m-%d %H:%M:%S"`

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

	if [ -z "$chanpin" ];then
	chanpin=QG_FIX0_6000_6
	fi

		#查询userID
		select_sql="select id from ${TABLENAME2} where phone_no=${phone_no}"
		user_id=`mysql -N $mysqld ${DBNAME2} -e "${select_sql}"`
		echo "user_id=$user_id"

		update_sql0="update ${TABLENAME} set quantify_product_name='${chanpin}' where xyqb_user_id=$user_id order by id desc limit 1"
		update_sql1="update ${TABLENAME1} set quantify_product_name='${chanpin}' where xyqb_user_id=$user_id order by id desc limit 1"
		# echo "sql0=$update_sql0"
		# echo "sql1=$update_sql1"

		mysql $mysqld ${DBNAME} -e "${update_sql0}"
		mysql $mysqld ${DBNAME1} -e "${update_sql1}"
		echo "done!!! $date"
}

coltho_chanpin $ip $phone_no
