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

card_no=622700000`date +%s`
echo $card_no
card_last=`echo ${card_no:(-4):4}`
mysql -h"$ip" -p"3306" -u"qa" -p"qatest" <<EOF
use payment_center;
delete from payment_center.bank_card where user_id=111112222233333;
delete from payment_center.card_bind_info where user_id=111112222233333;
delete from payment_center.bind_card_order where user_id=111112222233333;
delete from payment_center.bank_card where card_no='$card_no';
delete from payment_center.card_bind_info where card_no='$card_no';
delete from payment_center.bank_card_detail where card_no='$card_no';

INSERT INTO payment_center.bank_card (user_id, card_no, card_top, card_last, card_type, card_holder_name, preserve_phone_no, bank_name, bank_code, branch_no, branch_name, city, province, valid_from, valid_thru)
VALUES
    (111112222233333, '$card_no', '622700', '$card_last', 2, N'小测', '18610271234', N'建设银行', 'CCB', NULL, NULL, '110102', '110000', NULL, NULL);
INSERT INTO payment_center.bank_card_detail (bank_name, bank_code, card_no, account_property, card_type, is_valid)
VALUES
    (N'建设银行', 'CCB', '$card_no', '00', 2, 1);
INSERT INTO payment_center.bind_card_order (user_id, merchant_id, merchant_order_no, pay_approach, ext_data, bind_status, sms_error_code, confirm_error_code, request_id)
VALUES
    (111112222233333, 3, '43779518', 1, '', 5, '', '', 'yeepay1488525851371');
INSERT INTO payment_center.card_bind_info (user_id, pay_approach, bind_id, bank_card_id, is_active, card_no, bind_valid_thru)
VALUES
    (111112222233333, 1, '1488525851371', 1492596, 1, '$card_no', NULL);
 
update payment_center.bank_card t set t.user_id=(select id from payment_center.user where phone_no ='$phone_no') where t.user_id=111112222233333;
update payment_center.bind_card_order t set t.user_id=(select id from payment_center.user where phone_no ='$phone_no') where t.user_id=111112222233333;
update payment_center.card_bind_info t set t.user_id=(select id from payment_center.user where phone_no ='$phone_no'),bank_card_id=(select id from payment_center.bank_card where card_no=$card_no and user_id=(select id from payment_center.user where phone_no ='$phone_no') order by id desc limit 1) where t.user_id=111112222233333;

EOF
echo "done!!!"
