|
- <?php
- require_once '../Common/Mysql.php';
- require_once '../Common/zizai_orderAPI.php';
- require_once '../Common/dictionary.php';
- $pdo=conn();
- $run_id = $_GET['run_id'];
- $start_area_id = $_GET['start_id'];
- $end_area_id = $_GET['end_id'];
- $ticket_num = $_GET['tic_num_'];
-
- $customer = $_GET['customer'];
- $customer = str_replace("{",'',$customer);
- $customer = str_replace("}",'',$customer);
- $customer = explode("^",$customer);
- $customer_name = $customer[1];
- $customer_mobile = $customer[3];
- $customer_id_no = $customer[5];
- $passenger_txt = $customer[9];
-
-
- $from_order_no = $_GET['order_from_org_id'];
- $ctrip_order_no = $_GET['outside_order_id'];
-
-
- $sql = " SELECT * FROM run_main WHERE RUN_ID=".$run_id;
- $result=$pdo->query($sql);
- $rowset=$result->fetchAll(PDO::FETCH_ASSOC);
- $result->closeCursor();
- $return_data = array();
- if( $result == false ) {
- $return_data['errcode']='501';
- $return_data['errinfo']='该班次为无效班次';
- echo json_encode($return_data);
- exit();
- }
- $run_info = $rowset[0];
-
- if( $run_info["RUN_STATUS"] != 138 ) {
- $return_data['errcode']='501';
- $return_data['errinfo']='该班次已停止售卖';
- echo json_encode($return_data);
- exit();
- }
- $prod_id = $__ary_special_ticket_array[$run_info["PROD_ID"]];
-
- $sql = " SELECT * FROM run_bus WHERE RUN_ID=".$run_id." AND RUN_BUS_STATUS=138 ";
- $result=$pdo->query($sql);
- $rowset=$result->fetchAll(PDO::FETCH_ASSOC);
- $result->closeCursor();
- if( $result == false ) {
- $return_data['errcode'] = '500';
- $return_data['errinfo'] = '该班次剩余库存不足';
- echo json_encode($return_data);exit();
- }
- $remain_count = 0;
- foreach( $rowset as $run_bus_info ) {
- $remain_count_temp = $run_bus_info["SEAT_COUNT"] - $run_bus_info["SALED_COUNT"];
- $remain_count = $remain_count_temp > $remain_count ? $remain_count_temp : $remain_count;
- }
- if( $remain_count < $ticket_num ) {
- $return_data['errcode'] = '500';
- $return_data['errinfo'] = '该班次剩余库存不足';
- echo json_encode($return_data);exit();
- }
- $run_code = $run_id;
-
- $userid = 1;
- $myprod = '{m'.$prod_id.'p'.$ticket_num.'|r'.$run_id.'}';
- $mycustomer = "{,".$customer_name.",,".$customer_mobile.",150,".$customer_id_no.",,,,".$passenger_txt."}";
-
- $start_station_info = $__array_line_info[$run_info["PROD_ID"]]["start"][$start_area_id];
- $end_station_info = $__array_line_info[$run_info["PROD_ID"]]["end"][$end_area_id];
- $run_start_time = $run_info["RUN_DATE"]." ".$run_info["RUN_TIME"];
-
- $start_time = date("Y-m-d H:i", strtotime( $run_start_time." + ".$start_station_info["alltime"]." minutes "));
- $end_time = date("Y-m-d H:i", strtotime($run_start_time." + ".$end_station_info["alltime"]." minutes "));
-
- $result = post2('wx.zhizhuchuxing.com/ZZDZ2/application/custom_made/control.php', array(
- 'type' => 'order_submitforout',
- 'prod_list' => $myprod,
- 'customer_info' => $mycustomer,
- 'start_id' => $start_area_id,
- 'end_id' => $end_area_id,
- 'line_id' => $run_info["PROD_ID"],
- 'start_time' => mb_substr($start_time,11,5),
- 'end_time' => mb_substr($end_time,11,5)
- ));
-
- $result_array = json_decode($result,true);
- if( $result_array["code"] == 0 ) {
- $order_id = $result_array['order_id'];
- $res_content = get_msg_info($order_id);
- $name = $res_content[0];
- $tel = $res_content[1];
- $content = $res_content[2];
-
- $comment_type = 0;
- $comment_text = "";
- $response = sendTelMessage($tel, $name, $content, $order_id);
- $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();
- $pdo_update = conn();
- $sql_update = " UPDATE order_main set order_status =146,OUTSIDE_SALE_ORG_ID=".$from_order_no.",OUTSIDE_ORDER_NO='".$ctrip_order_no."' WHERE ORDER_ID=".$order_id." OR PARENT_ORDER_ID=".$order_id;
- $pdo_update->exec($sql_update);
- $return_data['errcode'] = 0;
- $return_data['order_id'] = $order_id;
- $data['errinfo'] = "下单成功";
-
- echo json_encode($return_data);exit();
- } else {
- $return_data = array();
- $return_data['errcode'] = $result_array["code"];
- $return_data['errinfo'] = $result_array["info"];
- echo json_encode($return_data);exit();
- }
- exit();
-
- function get_msg_info($ORDER_ID) {
- $msg_pdo = conn1();
- $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();
- $bus_res_id = isset($json_obj['driver'][0]) ? $json_obj['driver'][0]["bus_res_id"] : 0;
-
- $short_url = false;
- if( $bus_res_id != 0 ) {
- $ary_sell_ary = array(916,917);
- if( in_array( $bus_res_id, $ary_sell_ary ) ) {
- $ticket_url = TICKET_QR_URL.$ORDER_ID;
- $short_url = sinaShortenUrl($ticket_url);
- }
- }
- $extra_message = "";
- if( $short_url != false ) {
- $extra_message = "或点击以下链接获取您的电子票扫码上车:{$short_url}";
- }
-
- //出票成功
- // $content = "您预订的{出发日期 出发时间}{出发地}-{目的地}{票种名}{张数}张,已购票成功。乘车订单号为{订单号},请凭订单号或绑定微信(微信服务号“蜘蛛出行”)扫码上车,车牌号{车牌号},司机电话{司机姓司机电话}。";
- // 得到明天的时间
- date_default_timezone_set('PRC');
- //解决时区问题
- $tomorrow = date("Y-m-d", strtotime("+1 day"));
- $now_time = date('H:i:s', time());
- //判断当前时间是否在17:30:00之后
- $cur_date = date('Y-m-d', time());
- $new_message_array = array(448569,448568);
- $new_message_array2 = array( 450036, 449860, 450037, 449865 );
- if( in_array( $run_info['parent_prod_id'], $new_message_array ) ) {
- $content = "您预订的{出发日期}{出发地}-{目的地}{票种名}{张数}张,已成功出票,请在{出发时间}前十五分钟到达{上车站点}。出行前一天下午的18:00左右将会有导游和您联系,预祝您旅途愉快。";
- } else if( in_array( $run_info['parent_prod_id'], $new_message_array2 ) ) {
- $content = "您已成功预订{出发地}-{目的地}城际商务车{张数}张车票,车型为奔驰7座,发车时间为{出发日期} {出发时间},请提前10分钟到达{上车站点}。";
- if( isset($driver['bus_no']) && isset($driver['driver_name']) ) {
- $content .= "您的乘车订单号为{订单号},车牌号{车牌号},司机电话{司机姓司机电话},请凭短信订单号乘车,预祝您旅途愉快。";
- } else {
- $content .= "车辆和司机联系方式会在出行前一天18:30发送给您。";
- }
- } else if (($now_time > "18:30:00" && $run_info['start_date'] == $tomorrow) || $cur_date == $run_info['start_date']) {//18:30之后的订单或者下单时间为今天出行为今天下午 发送短信模板
- // if("18:30:00">"17:30:00" && $run_info['start_date']==$tomorrow){ //17:30之后的订单 发送短信模板
- // $content = "您预订的{出发日期 出发时间}{出发地}-{目的地}{票种名}{张数}张,已购票成功。乘车订单号为{订单号},请凭订单号或绑定微信(微信服务号“蜘蛛出行”)扫码上车,车牌号{车牌号},司机电话{司机姓司机电话}。";
- $content = "您预订的{出发日期}{出发地}-{目的地}{票种名}{张数}张,已成功出票,请在{出发时间}前三十分钟到达{上车站点}。您的乘车订单号为{订单号},车牌号{车牌号},司机电话{司机姓司机电话},请凭短信订单号乘车".$extra_message.",预祝您旅途愉快。";
-
- } else {
- // $content = "您预订的{出发日期 出发时间}{出发地}-{目的地}{票种名}{张数}张,已购票成功。乘车订单号为{订单号},请凭订单号或绑定微信(微信服务号“蜘蛛出行”)扫码上车。";
- $content = "您预订的{出发日期}{出发地}-{目的地}{票种名}{张数}张,已成功出票,请在{出发时间}前三十分钟到达{上车站点}。您的乘车订单号为{订单号},请凭短信订单号乘车".$extra_message."。出行前一天下午的18:30会将车牌号与司机电话发送给您,预祝您旅途愉快。";
- }
- // $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'];
- $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_date, $content);
- $content = str_replace("{出发时间}", $start_time, $content);
- $content = str_replace("{上车站点}", $res_name, $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);
- $content = str_replace("{订单号}", "", $content);
- }
- if ($driver) {
- $bus_no = isset($driver['bus_no']) ? $driver['bus_no'] : "";
- $driver_name = isset($driver['driver_name']) ? $driver['driver_name'] : "";
- $driver_mobile = isset($driver['driver_mobile']) ? $driver['driver_mobile'] : "";
-
- if ($bus_no == "") {
- $content = str_replace(",车牌号{车牌号}", "", $content);
- } else {
- $content = str_replace("{车牌号}", $bus_no, $content);
- }
- if ($driver_name == "") {
- $content = str_replace(",司机电话{司机姓司机电话},", "。", $content);
- } else {
- $driver_xing = mb_substr($driver_name, 0, 1, 'utf-8');
- $driver_name_mobile = $driver_xing . $driver_mobile;
- $content = str_replace("{司机姓司机电话}", $driver_name_mobile, $content);
- }
- } else {
- $content = str_replace("车牌号{车牌号},", "", $content);
- $content = str_replace("司机电话{司机姓司机电话},", "", $content);
- }
- return array(isset($customer_name) ? $customer_name : "", isset($customer_mobile) ? $customer_mobile : "", isset($content) ? $content : "短信错误,联系客服!!!");
- }
- }
- function post2($url, $post_data = '', $timeout = 5){//curl
- $ch = curl_init();
- curl_setopt ($ch, CURLOPT_URL, $url);
- curl_setopt ($ch, CURLOPT_POST, 1);
- if($post_data != ''){
- curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
- }
- curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
- curl_setopt($ch, CURLOPT_HEADER, false);
- $file_contents = curl_exec($ch);
- curl_close($ch);
- return $file_contents;
- }
-
-
- ?>
|