#!/bin/bash
ip=$1
phone_no=$2
amount=$3

len=`echo $phone_no |awk '{print length}'`
if [ $len -ne 11 ]
then
        echo "请输入11位的手机号"
        exit -1  #exit命令同于退出shell，状态值0代表执行成功，其它值代表执行失败
fi

b=0
if [ $amount -le $b ]
then 
  echo "请输入正确的金额"
  exit -1
fi

orderId=aektxyqbmallceshi`date +%s%N`
merchantId=merchantOrderNo`date +%s%N`
difference=50
supplierAmount=`expr $amount - $difference`
seq=`date "+%Y-%m-%d %H:%M:%S"`

mysql -h"$ip" -p"3306" -u"qa" -p"qatest" <<EOF
use mall;

insert into mall.mall_order
(order_id, user_id, order_state, is_active, product_id,  pay_approach,  pay_amount, created_at, updated_at)
values
('$orderId',(select id from mall.user where phone_no='$phone_no'),
11,1,1170,0,'$amount','$seq','$seq');

insert into mall.digital_order_detail
(order_id, pay_time, customer_service_phone, logistics_delivery_time, contact_name, contact_id_no, contact_phone,
contact_province, contact_city, contact_area, contact_street, product_id, user_ip, fillnum, group_id, supplier_id,
refunded_time, canceled_time, traded_time, confirm_time, refund_close_time, real_amount,  user_percent, merchant_percent)
values
((select id from mall.mall_order where order_id='$orderId'),'$seq','400-002-0061','$seq','张晋','632132197909064776','$phone_no',
'北京市','海淀区','三环以内','丹棱街',205741,'61.50.0.0',1,'3845',13,
'$seq','$seq','$seq','$seq','$seq','$amount',1.00,0.03);

use merchant;

insert into merchant.supplier_order
(order_no,mall_order_no,supplier_id,mall_order_time,order_status,created_at,updated_at, goods_name,
goods_amount,supplier_amount,user_name,user_phone,user_address,user_id_no,
receive_name, real_pay_amount, payment_type)
values
( '$merchantId', '$orderId', '13', '$seq', '0', '$seq', '$seq','匡威男女帆布经典学生情侣休闲高帮常青款硫化鞋 42.5 M9613',
'$amount', '$supplierAmount', '张晋', '$phone_no',"北京市\$\$\$ 海淀区\$\$\$ 三环以内\$\$\$ 123", '632132197909064776',
'张晋', '$amount','0');

EOF
echo "mall.mall_order、digital_order_detail表插入一条订单"
echo "mall.supplier_order表插入一条订单"



