|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232 |
- <?php
- require_once '../st-xm/Common/Mysql.php';
- header("Access-Control-Allow-Origin:*");
-
- //test
- //$_POST['auth_code'] = "abcdefg";
- //$_POST['run_code'] = "201743_152691";
- //$_POST['ticket_num'] = 3;
- //$_POST['per_price'] = 17.50;
- //$_POST['all_price'] = 52.50;
- //$_POST['customer_name'] = "测试员001";
- //$_POST['customer_mobile'] = "13816608252";
- //$_POST['customer_id_no'] = "12345678901245678";
- //$_POST['ctrip_order_no'] = "abcdefg";
- //end of test
- $auth_code=isset($_POST['auth_code'])? $_POST['auth_code']:false;
- $run_code=isset($_POST['run_code'])? $_POST['run_code']:false;
- $ticket_num=isset($_POST['ticket_num'])? $_POST['ticket_num']:false;
- $per_price=isset($_POST['per_price'])? $_POST['per_price']:false;
- $all_price=isset($_POST['all_price'])? $_POST['all_price']:false;
- $customer_name=isset($_POST['customer_name'])? $_POST['customer_name']:false;
- $customer_mobile=isset($_POST['customer_mobile'])? $_POST['customer_mobile']:false;
- $customer_id_no=isset($_POST['customer_id_no'])? $_POST['customer_id_no']:false;
- $ctrip_order_no=isset($_POST['ctrip_order_no'])? $_POST['ctrip_order_no']:false;
-
-
- $return_data = array();
- $return_data['code']='201';
-
- if( $auth_code == false || $run_code == false || $ticket_num == false || $per_price == false || $all_price == false || $customer_name == false || $customer_id_no == false || $ctrip_order_no == false ) {
- $return_data['code']='401';
- echo json_encode($return_data);
- exit();
- }
-
- $pdo=conn();
- $sql=" SELECT user_name,user_psd,user_auth_code FROM api_auth_code WHERE user_auth_code='".$auth_code."' ";
-
- $result=$pdo->query($sql);
- $rowset=$result->fetchAll();
- $result->closeCursor();
- if( false == $rowset ) {
- $return_data['code']='400';
- echo json_encode($return_data);
- exit();
- }
- $param_run_code = $run_code;
- $run_code_array = explode("_",$run_code);
- $run_code = $run_code_array[0];
- $prod_id = $run_code_array[1];
-
- $sql2 = " SELECT * FROM run_main WHERE RUN_ID = {$run_code} ";
- $result=$pdo->query($sql2);
- $rowset=$result->fetchAll();
- $result->closeCursor();
-
- $return_data['code']='201';
- if( $rowset == false ) {
- $return_data['code']='501';
- $return_data['msg']='该班次为无效班次';
- echo json_encode($return_data);
- exit();
- }
- $run_main_info = $rowset[0];
-
- $sql3 = " SELECT * FROM run_bus WHERE RUN_ID = {$run_code} ";
- $result=$pdo->query($sql3);
- $result_array=$result->fetchAll();
- $result->closeCursor();
- if( $result == false ) {
- $return_data['code'] = '402';
- $return_data['msg'] = '发送参数不符合定义';
- echo json_encode($return_data);exit();
- }
- $run_bus_array = array();
- foreach( $result_array as $run_bus_info ) {
- if( !isset($run_bus_array[$run_bus_info["RUN_ID"]]) ) {
- $run_bus_array[$run_bus_info["RUN_ID"]] = array();
- }
- $run_bus_array[$run_bus_info["RUN_ID"]][] = $run_bus_info;
- }
-
- $data_array = array();
- if( !$run_bus_array[$run_main_info["RUN_ID"]] ) {
- $total_count = 0;
- $saled_count = 0;
- $remain_count = 0;
- } else {
- $total_count = 0;
- $saled_count = 0;
- $remain_count = 0;
- foreach( $run_bus_array[$run_main_info["RUN_ID"]] as $run_bus_info ) {
- $total_count += $run_bus_info["SEAT_COUNT"];
- $saled_count += $run_bus_info["SALED_COUNT"];
- }
- $remain_count = $total_count - $saled_count;
- }
-
- if( $remain_count < $ticket_num ) {
- $return_data['code'] = '500';
- $return_data['msg'] = '该班次剩余库存不足';
- echo json_encode($return_data);exit();
- }
-
- $sql4 = " SELECT opera_product.PROD_ID FROM opera_product WHERE PARENT_ID={$run_main_info["PROD_ID"]} AND PROD_TYPE=82";
- $result=$pdo->query($sql4);
- $result_array=$result->fetchAll();
- $result->closeCursor();
- if( $result_array == false ) {
- $return_data['code'] = '500';
- $return_data['msg'] = '该班次剩余库存不足';
- echo json_encode($return_data);exit();
- }
- $match_prod_flag = 0;
- foreach( $result_array as $ticket_info ) {
- if( $ticket_info["PROD_ID"] == $prod_id ) {
- $match_prod_flag = 1;
- break;
- }
- }
- if( $match_prod_flag == 0 ) {
- $return_data['code'] = '402';
- $return_data['msg'] = '发送参数不符合定义';
- echo json_encode($return_data);exit();
- }
-
- $userid = 1;
- $myprod = '{m'.$prod_id.'p'.$ticket_num.'|r'.$run_code.'}';
- $mycustomer = '{,'.$customer_name.',,'.$customer_mobile.',150,'.$customer_id_no.',,,,}';
- $sql_insert="call sp_make_order(".$userid.",'".$myprod."','".$mycustomer."', 17, '".$ctrip_order_no."')";
- $result=$pdo->query($sql_insert);
- $rowset=$result->fetchAll(PDO::FETCH_ASSOC);
- $result->closeCursor();
-
- if (is_array($rowset) && $rowset[0]['errcode'] == 0 ) {
- $order_id=$rowset[0]['order_id'];
- $res_content=get_msg_info($order_id);
- $name=$res_content[0];
- $tel=$res_content[1];
- $content=$res_content[2];
- $response = sendTelMessage($tel, $name, $content, $order_id);
-
- $comment_type=0;
- $comment_text="";
- $send_success = (int)$response;
- $sql1 = "CALL HT_ADD_MSG_COMMENT(2,'addmsg'," . $order_id . "," . $comment_type . ",'" . $comment_text . "','" . $tel . "','" . $content . "','" . date("Y-m-d H:i:s") . "',{$send_success})";
- $result1 = $pdo -> query($sql1);
- $rowset1 = $result1 -> fetchAll(PDO::FETCH_ASSOC);
- $result1 -> closeCursor();
- } else {
- $return_data["code"] = $rowset[0]['errcode'];
- $return_data["msg"] = $rowset[0]['errinfo'];
- echo json_encode($return_data);
- exit();
- }
- $return_data["code"] = "201";
- $return_data["order_no"] = $rowset[0]['order_id'];
- $return_data["msg"] = "";
- echo json_encode($return_data);
- exit();
-
-
- function get_msg_info($ORDER_ID) {
- $msg_pdo = conn();
- $msg_sql = "CALL SP_GET_MESSAGE_TEMPLATE('" . $ORDER_ID . "')";
- $content='';
- if (is_object($msg_pdo)) {
- $msg_result = $msg_pdo -> query($msg_sql);
- $i = 1;
- $data = array();
- if ($msg_result) {
- $data['code'] = "0";
- $data['info'] = "";
- do {
- $row = $msg_result -> fetchAll(PDO::FETCH_ASSOC);
- if ($i == 1) {
- $data['seat'] = isset($row) ? $row : array();
- } else if ($i == 2) {
- $data['run_info'] = isset($row) ? $row : array();
- } else if ($i == 3) {
- $data['driver'] = isset($row) ? $row : array();
- } else {
- }
- $i++;
- } while($msg_result->nextRowset());
- }
- $json_obj = json_decode(json_encode($data), TRUE);
- $seat = isset($json_obj['seat'][0])?$json_obj['seat'][0]:array();
- $run_info = isset($json_obj['run_info'][0])?$json_obj['run_info'][0]:array();
- $driver = isset($json_obj['driver'][0])?$json_obj['driver'][0]:array();
- //出票成功
- $content = "您预订的{出发日期 出发时间}{出发地}-{目的地}{票种名}{张数}张,已购票成功。乘车订单号为{订单号},凭短信上车。";
-
- if ($seat) {
- $seat_x = isset($seat['seat_x'])?$seat['seat_x']:"";
- $seat_y = isset($seat['seat_y'])?$seat['seat_y']:"";
- $seat_name = isset($seat['seat_name'])?$seat['seat_name']:"";
- $order_main_id = isset($seat['order_main_id'])?$seat['order_main_id']:"";
- }else{
-
- }
- if ($run_info) {
- $order_count = $run_info['order_count'];
- $start_date = $run_info['start_date'];
- $start_time = $run_info['start_time'];
- $parent_order_id = $run_info['parent_order_id'];
- $end_date = $run_info['end_date'];
- $start_area = $run_info['start_area'];
- $end_area = $run_info['end_area'];
- $res_name = $run_info['res_name'];
- $prod_name=$run_info['prod_name'];
- $customer_name=$run_info['customer_name'];
- $customer_mobile=$run_info['customer_mobile'];
- $start_end_date = $start_date . "," . $start_time;
- $content = str_replace("{出发日期 出发时间}", $start_end_date, $content);
- $content = str_replace("{出发地}", $start_area, $content);
- $content = str_replace("{目的地}", $end_area, $content);
- $content = str_replace("{票种名}", $prod_name, $content);
- $content = str_replace("{张数}", $order_count, $content);
- $content = str_replace("{订单号}", $ORDER_ID, $content);
- }else{
- $content = str_replace("{出发日期 出发时间}", "", $content);
- $content = str_replace("{出发地}", "", $content);
- $content = str_replace("{目的地}", "", $content);
- $content = str_replace("{票种名}", "", $content);
- $content = str_replace("{张数}", "", $content);
- $content = str_replace("{订单号}", "", $content);
- }
- return array(isset($customer_name)?$customer_name:"",isset($customer_mobile)?$customer_mobile:"",isset($content)?$content:"短信错误!!!");
- }
-
- }
|