You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

273 lines
14 KiB

  1. <?php
  2. require_once '../Common/Mysql.php';
  3. require_once '../Common/zizai_orderAPI.php';
  4. require_once '../Common/dictionary.php';
  5. $pdo=conn();
  6. $run_id = $_GET['run_id'];
  7. $start_area_id = $_GET['start_id'];
  8. $end_area_id = $_GET['end_id'];
  9. $ticket_num = $_GET['tic_num_'];
  10. $customer = $_GET['customer'];
  11. $customer = str_replace("{",'',$customer);
  12. $customer = str_replace("}",'',$customer);
  13. $customer = explode("^",$customer);
  14. $customer_name = $customer[1];
  15. $customer_mobile = $customer[3];
  16. $customer_id_no = $customer[5];
  17. $passenger_txt = $customer[9];
  18. $from_order_no = $_GET['order_from_org_id'];
  19. $ctrip_order_no = $_GET['outside_order_id'];
  20. $sql = " SELECT * FROM run_main WHERE RUN_ID=".$run_id;
  21. $result=$pdo->query($sql);
  22. $rowset=$result->fetchAll(PDO::FETCH_ASSOC);
  23. $result->closeCursor();
  24. $return_data = array();
  25. if( $result == false ) {
  26. $return_data['errcode']='501';
  27. $return_data['errinfo']='该班次为无效班次';
  28. echo json_encode($return_data);
  29. exit();
  30. }
  31. $run_info = $rowset[0];
  32. if( $run_info["RUN_STATUS"] != 138 ) {
  33. $return_data['errcode']='501';
  34. $return_data['errinfo']='该班次已停止售卖';
  35. echo json_encode($return_data);
  36. exit();
  37. }
  38. $prod_id = $__ary_special_ticket_array[$run_info["PROD_ID"]];
  39. $sql = " SELECT * FROM run_bus WHERE RUN_ID=".$run_id." AND RUN_BUS_STATUS=138 ";
  40. $result=$pdo->query($sql);
  41. $rowset=$result->fetchAll(PDO::FETCH_ASSOC);
  42. $result->closeCursor();
  43. if( $result == false ) {
  44. $return_data['errcode'] = '500';
  45. $return_data['errinfo'] = '该班次剩余库存不足';
  46. echo json_encode($return_data);exit();
  47. }
  48. $remain_count = 0;
  49. foreach( $rowset as $run_bus_info ) {
  50. $remain_count_temp = $run_bus_info["SEAT_COUNT"] - $run_bus_info["SALED_COUNT"];
  51. $remain_count = $remain_count_temp > $remain_count ? $remain_count_temp : $remain_count;
  52. }
  53. if( $remain_count < $ticket_num ) {
  54. $return_data['errcode'] = '500';
  55. $return_data['errinfo'] = '该班次剩余库存不足';
  56. echo json_encode($return_data);exit();
  57. }
  58. $run_code = $run_id;
  59. $userid = 1;
  60. $myprod = '{m'.$prod_id.'p'.$ticket_num.'|r'.$run_id.'}';
  61. $mycustomer = "{,".$customer_name.",,".$customer_mobile.",150,".$customer_id_no.",,,,".$passenger_txt."}";
  62. $start_station_info = $__array_line_info[$run_info["PROD_ID"]]["start"][$start_area_id];
  63. $end_station_info = $__array_line_info[$run_info["PROD_ID"]]["end"][$end_area_id];
  64. $run_start_time = $run_info["RUN_DATE"]." ".$run_info["RUN_TIME"];
  65. $start_time = date("Y-m-d H:i", strtotime( $run_start_time." + ".$start_station_info["alltime"]." minutes "));
  66. $end_time = date("Y-m-d H:i", strtotime($run_start_time." + ".$end_station_info["alltime"]." minutes "));
  67. $result = post2('wx.zhizhuchuxing.com/ZZDZ2/application/custom_made/control.php', array(
  68. 'type' => 'order_submitforout',
  69. 'prod_list' => $myprod,
  70. 'customer_info' => $mycustomer,
  71. 'start_id' => $start_area_id,
  72. 'end_id' => $end_area_id,
  73. 'line_id' => $run_info["PROD_ID"],
  74. 'start_time' => mb_substr($start_time,11,5),
  75. 'end_time' => mb_substr($end_time,11,5)
  76. ));
  77. $result_array = json_decode($result,true);
  78. if( $result_array["code"] == 0 ) {
  79. $order_id = $result_array['order_id'];
  80. $res_content = get_msg_info($order_id);
  81. $name = $res_content[0];
  82. $tel = $res_content[1];
  83. $content = $res_content[2];
  84. $comment_type = 0;
  85. $comment_text = "";
  86. $response = sendTelMessage($tel, $name, $content, $order_id);
  87. $send_success=(int)$response;
  88. $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})";
  89. $result1 = $pdo->query($sql1);
  90. $rowset1 = $result1->fetchAll(PDO::FETCH_ASSOC);
  91. $result1->closeCursor();
  92. $pdo_update = conn();
  93. $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;
  94. $pdo_update->exec($sql_update);
  95. $return_data['errcode'] = 0;
  96. $return_data['order_id'] = $order_id;
  97. $data['errinfo'] = "下单成功";
  98. echo json_encode($return_data);exit();
  99. } else {
  100. $return_data = array();
  101. $return_data['errcode'] = $result_array["code"];
  102. $return_data['errinfo'] = $result_array["info"];
  103. echo json_encode($return_data);exit();
  104. }
  105. exit();
  106. function get_msg_info($ORDER_ID) {
  107. $msg_pdo = conn1();
  108. $msg_sql = "CALL SP_GET_MESSAGE_TEMPLATE('" . $ORDER_ID . "')";
  109. $content = '';
  110. if (is_object($msg_pdo)) {
  111. $msg_result = $msg_pdo -> query($msg_sql);
  112. $i = 1;
  113. $data = array();
  114. if ($msg_result) {
  115. $data['code'] = "0";
  116. $data['info'] = "";
  117. do {
  118. $row = $msg_result -> fetchAll(PDO::FETCH_ASSOC);
  119. if ($i == 1) {
  120. $data['seat'] = isset($row) ? $row : array();
  121. } else if ($i == 2) {
  122. $data['run_info'] = isset($row) ? $row : array();
  123. } else if ($i == 3) {
  124. $data['driver'] = isset($row) ? $row : array();
  125. } else {
  126. }
  127. $i++;
  128. } while($msg_result->nextRowset());
  129. }
  130. $json_obj = json_decode(json_encode($data), TRUE);
  131. $seat = isset($json_obj['seat'][0]) ? $json_obj['seat'][0] : array();
  132. $run_info = isset($json_obj['run_info'][0]) ? $json_obj['run_info'][0] : array();
  133. $driver = isset($json_obj['driver'][0]) ? $json_obj['driver'][0] : array();
  134. $bus_res_id = isset($json_obj['driver'][0]) ? $json_obj['driver'][0]["bus_res_id"] : 0;
  135. $short_url = false;
  136. if( $bus_res_id != 0 ) {
  137. $ary_sell_ary = array(916,917);
  138. if( in_array( $bus_res_id, $ary_sell_ary ) ) {
  139. $ticket_url = TICKET_QR_URL.$ORDER_ID;
  140. $short_url = sinaShortenUrl($ticket_url);
  141. }
  142. }
  143. $extra_message = "";
  144. if( $short_url != false ) {
  145. $extra_message = "或点击以下链接获取您的电子票扫码上车:{$short_url}";
  146. }
  147. //出票成功
  148. // $content = "您预订的{出发日期 出发时间}{出发地}-{目的地}{票种名}{张数}张,已购票成功。乘车订单号为{订单号},请凭订单号或绑定微信(微信服务号“蜘蛛出行”)扫码上车,车牌号{车牌号},司机电话{司机姓司机电话}。";
  149. // 得到明天的时间
  150. date_default_timezone_set('PRC');
  151. //解决时区问题
  152. $tomorrow = date("Y-m-d", strtotime("+1 day"));
  153. $now_time = date('H:i:s', time());
  154. //判断当前时间是否在17:30:00之后
  155. $cur_date = date('Y-m-d', time());
  156. $new_message_array = array(448569,448568);
  157. $new_message_array2 = array( 450036, 449860, 450037, 449865 );
  158. if( in_array( $run_info['parent_prod_id'], $new_message_array ) ) {
  159. $content = "您预订的{出发日期}{出发地}-{目的地}{票种名}{张数}张,已成功出票,请在{出发时间}前十五分钟到达{上车站点}。出行前一天下午的18:00左右将会有导游和您联系,预祝您旅途愉快。";
  160. } else if( in_array( $run_info['parent_prod_id'], $new_message_array2 ) ) {
  161. $content = "您已成功预订{出发地}-{目的地}城际商务车{张数}张车票,车型为奔驰7座,发车时间为{出发日期} {出发时间},请提前10分钟到达{上车站点}。";
  162. if( isset($driver['bus_no']) && isset($driver['driver_name']) ) {
  163. $content .= "您的乘车订单号为{订单号},车牌号{车牌号},司机电话{司机姓司机电话},请凭短信订单号乘车,预祝您旅途愉快。";
  164. } else {
  165. $content .= "车辆和司机联系方式会在出行前一天18:30发送给您。";
  166. }
  167. } else if (($now_time > "18:30:00" && $run_info['start_date'] == $tomorrow) || $cur_date == $run_info['start_date']) {//18:30之后的订单或者下单时间为今天出行为今天下午 发送短信模板
  168. // if("18:30:00">"17:30:00" && $run_info['start_date']==$tomorrow){ //17:30之后的订单 发送短信模板
  169. // $content = "您预订的{出发日期 出发时间}{出发地}-{目的地}{票种名}{张数}张,已购票成功。乘车订单号为{订单号},请凭订单号或绑定微信(微信服务号“蜘蛛出行”)扫码上车,车牌号{车牌号},司机电话{司机姓司机电话}。";
  170. $content = "您预订的{出发日期}{出发地}-{目的地}{票种名}{张数}张,已成功出票,请在{出发时间}前三十分钟到达{上车站点}。您的乘车订单号为{订单号},车牌号{车牌号},司机电话{司机姓司机电话},请凭短信订单号乘车".$extra_message.",预祝您旅途愉快。";
  171. } else {
  172. // $content = "您预订的{出发日期 出发时间}{出发地}-{目的地}{票种名}{张数}张,已购票成功。乘车订单号为{订单号},请凭订单号或绑定微信(微信服务号“蜘蛛出行”)扫码上车。";
  173. $content = "您预订的{出发日期}{出发地}-{目的地}{票种名}{张数}张,已成功出票,请在{出发时间}前三十分钟到达{上车站点}。您的乘车订单号为{订单号},请凭短信订单号乘车".$extra_message."。出行前一天下午的18:30会将车牌号与司机电话发送给您,预祝您旅途愉快。";
  174. }
  175. // $content = "您预订的{出发日期 出发时间}{出发地}-{目的地}{票种名}{张数}张,已购票成功。乘车订单号为{订单号},请凭订单号或绑定微信(微信服务号“蜘蛛出行”)扫码上车。";
  176. if ($seat) {
  177. $seat_x = isset($seat['seat_x']) ? $seat['seat_x'] : "";
  178. $seat_y = isset($seat['seat_y']) ? $seat['seat_y'] : "";
  179. $seat_name = isset($seat['seat_name']) ? $seat['seat_name'] : "";
  180. $order_main_id = isset($seat['order_main_id']) ? $seat['order_main_id'] : "";
  181. } else {
  182. }
  183. if ($run_info) {
  184. $order_count = $run_info['order_count'];
  185. $start_date = $run_info['start_date'];
  186. $start_time = $run_info['start_time'];
  187. $parent_order_id = $run_info['parent_order_id'];
  188. $end_date = $run_info['end_date'];
  189. $start_area = $run_info['start_area'];
  190. $end_area = $run_info['end_area'];
  191. $res_name = $run_info['res_name'];
  192. $prod_name = $run_info['prod_name'];
  193. $prod_name = "标准票";
  194. $customer_name = $run_info['customer_name'];
  195. $customer_mobile = $run_info['customer_mobile'];
  196. $start_end_date = $start_date . "," . $start_time;
  197. $content = str_replace("{出发日期}", $start_date, $content);
  198. $content = str_replace("{出发时间}", $start_time, $content);
  199. $content = str_replace("{上车站点}", $res_name, $content);
  200. $content = str_replace("{出发地}", $start_area, $content);
  201. $content = str_replace("{目的地}", $end_area, $content);
  202. $content = str_replace("{票种名}", $prod_name, $content);
  203. $content = str_replace("{张数}", $order_count, $content);
  204. $content = str_replace("{订单号}", $ORDER_ID, $content);
  205. } else {
  206. $content = str_replace("{出发日期}", "", $content);
  207. $content = str_replace("{出发时间}", "", $content);
  208. $content = str_replace("{出发地}", "", $content);
  209. $content = str_replace("{目的地}", "", $content);
  210. $content = str_replace("{票种名}", "", $content);
  211. $content = str_replace("{张数}", "", $content);
  212. $content = str_replace("{订单号}", "", $content);
  213. }
  214. if ($driver) {
  215. $bus_no = isset($driver['bus_no']) ? $driver['bus_no'] : "";
  216. $driver_name = isset($driver['driver_name']) ? $driver['driver_name'] : "";
  217. $driver_mobile = isset($driver['driver_mobile']) ? $driver['driver_mobile'] : "";
  218. if ($bus_no == "") {
  219. $content = str_replace(",车牌号{车牌号}", "", $content);
  220. } else {
  221. $content = str_replace("{车牌号}", $bus_no, $content);
  222. }
  223. if ($driver_name == "") {
  224. $content = str_replace(",司机电话{司机姓司机电话},", "。", $content);
  225. } else {
  226. $driver_xing = mb_substr($driver_name, 0, 1, 'utf-8');
  227. $driver_name_mobile = $driver_xing . $driver_mobile;
  228. $content = str_replace("{司机姓司机电话}", $driver_name_mobile, $content);
  229. }
  230. } else {
  231. $content = str_replace("车牌号{车牌号},", "", $content);
  232. $content = str_replace("司机电话{司机姓司机电话},", "", $content);
  233. }
  234. return array(isset($customer_name) ? $customer_name : "", isset($customer_mobile) ? $customer_mobile : "", isset($content) ? $content : "短信错误,联系客服!!!");
  235. }
  236. }
  237. function post2($url, $post_data = '', $timeout = 5){//curl
  238. $ch = curl_init();
  239. curl_setopt ($ch, CURLOPT_URL, $url);
  240. curl_setopt ($ch, CURLOPT_POST, 1);
  241. if($post_data != ''){
  242. curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
  243. }
  244. curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
  245. curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  246. curl_setopt($ch, CURLOPT_HEADER, false);
  247. $file_contents = curl_exec($ch);
  248. curl_close($ch);
  249. return $file_contents;
  250. }
  251. ?>