Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 

690 рядки
39 KiB

  1. <?php
  2. require_once __DIR__.'/../st-xm/Common/Mysql.php';
  3. require_once __DIR__.'/../st-xm/Common/config_api.inc';
  4. require_once __DIR__.'/../st-xm/Common/sinaAPI.php';
  5. require_once __DIR__.'/../st-xm/Common/zizai_orderAPI.php';
  6. require_once __DIR__.'/../st-xm/Common/dictionary.php';
  7. //require_once __DIR__.'/../st-xm/Common/api_common.php';
  8. header("Access-Control-Allow-Origin:*");
  9. date_default_timezone_set('PRC');
  10. $current_time = time();
  11. $current_hour = date("H:i:s",$current_time);
  12. $check_stock_time = date("Y-m-d H:i:s",$current_time);
  13. $tomorrow_day = date("Y-m-d",strtotime("+1 days"));
  14. $today = date("Y-m-d");
  15. $limit_time = date("H:i", strtotime("+1 minutes"));
  16. $limit_time1 = date("H:i", strtotime("+1 minutes"));
  17. $limit_time2 = date("H:i", strtotime("+1 minutes"));
  18. //拼接数组
  19. $post_data = array();
  20. $post_data["agentId"] = QUNAR_AGENT_ID;
  21. $post_data["time"] = $current_time;
  22. $post_data["auth"] = get_qunar_auth($post_data);
  23. $return_data = send_post( QUNAR_CHECK_ORDER_URL, $post_data);
  24. $return_array = json_decode($return_data,true);
  25. if( !isset($return_array["orderNum"]) || $return_array["orderNum"] <= 0 ) {
  26. print_r($return_array);
  27. return;
  28. }
  29. //print_r($return_array);exit();//test
  30. $no_sell_array = array(152739,152740,152741,152691,152697,152715,152709,152715,153133,153135,153137,152569,152570,152571,152572,152573,152575,152577,152579,152581,152582,152695,152696,152706,152707,448587,449825,449827,449829,449831,449832,449843,449847,449825,449827,449829,449831, 449876,449881);
  31. $limit_sell_prod2 = array( 448568, 448569,450517,450522,450499,450504,448780,448781,450529,450530,450550,450551,450588,450698,450699,450700,450701,450702,450703 );
  32. $userid = 2;
  33. $current_time = date("Y-m-d H:i:s");
  34. $pdo=conn1();
  35. $order_array = $return_array["data"];
  36. //获取往返优惠
  37. //$bothway_tickets_discount = array();
  38. //$bothway_tickets_discount = getTicketsDiscountArray( $pdo, $from_org_id );
  39. foreach( $order_array as $order_info ) {
  40. writeLog("-----qunar new order info:".json_encode($order_info));
  41. $run_code = $order_info["coachNo"];
  42. $run_code_array = explode("_",$run_code);
  43. $back_run_code = false;
  44. $back_prod_id = false;
  45. $back_order_id = false;
  46. if( isset($run_code_array[1]) ) {
  47. if( isset($run_code_array[2]) && isset($run_code_array[3]) ) {
  48. $run_code_array[0] = base_convert($run_code_array[0],36,10);
  49. $run_code_array[1] = base_convert($run_code_array[1],36,10);
  50. $run_code_array[2] = base_convert($run_code_array[2],36,10);
  51. $run_code_array[3] = base_convert($run_code_array[3],36,10);
  52. $back_run_code = $run_code_array[2];
  53. $back_prod_id = $run_code_array[3];
  54. }
  55. $run_code = $run_code_array[0];
  56. $prod_id = $run_code_array[1];
  57. } else {
  58. //zizai
  59. //$run_code = $run_code_array[0];
  60. }
  61. $ticket_num = $order_info["ticketNum"];
  62. $all_price = $order_info["ticketPrice"];
  63. $per_price = $all_price / $ticket_num;
  64. $customer_name = $order_info["contactName"];
  65. $customer_mobile = descryption_by_shif($order_info["contactPhone"]);
  66. $customer_id_no = descryption_by_shif($order_info["contactId"]);
  67. $out_order_no = $order_info["orderNo"];
  68. $passengers = $order_info["passengers"];
  69. $passengers_array = array();
  70. foreach( $passengers as $passenger_info ) {
  71. $passengers_array[] = $passenger_info["passengerName"]."*".descryption_by_shif($passenger_info["passengerId"]);
  72. }
  73. $passengers_list = implode("/",$passengers_array);
  74. $sql = " SELECT * FROM order_main WHERE OUTSIDE_ORDER_NO='{$out_order_no}' AND PARENT_ORDER_ID = 0 ";
  75. $result = $pdo->query($sql);
  76. $rowset = $result->fetchAll();
  77. $result->closeCursor();
  78. if ($rowset != false) {
  79. continue;
  80. }
  81. if( isset($run_code_array[1]) ) {
  82. $sql = " SELECT * FROM run_main WHERE RUN_ID={$run_code} ";
  83. $result = $pdo->query($sql);
  84. $rowset = $result->fetchAll();
  85. $result->closeCursor();
  86. $run_main_info = $rowset[0];
  87. if( $run_main_info["RUN_DATE"] != $order_info["date"] ) {
  88. $sql = " SELECT * FROM run_main WHERE PROD_ID={$run_main_info["PROD_ID"]} AND RUN_DATE='{$order_info["date"]}' AND RUN_TIME= '{$run_main_info["RUN_TIME"]}' AND RUN_STATUS IN (138,139) ";
  89. $result = $pdo->query($sql);
  90. $rowset2 = false;
  91. if( $result != false ) {
  92. $rowset2 = $result->fetchAll();
  93. $result->closeCursor();
  94. $run_main_info = $rowset2[0];
  95. $run_code = $run_main_info["RUN_ID"];
  96. }
  97. if( $rowset2 == false) {
  98. $post_data = array();
  99. $post_data["agentId"] = QUNAR_AGENT_ID;
  100. $post_data["time"] = $current_time;
  101. $post_data["comment"] = "出票失败:该线路已停售";
  102. $post_data["ticketInfo"] = json_encode(array( "ret" => false, "data" => array("orderNo" => $out_order_no, "ticketStatu" => 1)) );
  103. $post_data["auth"] = get_qunar_auth($post_data);
  104. $complete_result = send_post_qunar( QUNAR_COMPLETE_ORDER_URL, $post_data );
  105. continue;
  106. }
  107. }
  108. $run_start_time = $run_main_info["RUN_DATE"]." ".$run_main_info["RUN_TIME"];
  109. } else {
  110. //zizai
  111. $prod_id = $run_code_array[0];
  112. $sql = " SELECT * FROM outside_run WHERE prod_code='".$prod_id."' AND cancel_flag = 0 ";
  113. $result=$pdo->query($sql);
  114. $rowset=$result->fetchAll();
  115. $result->closeCursor();
  116. if( false == $rowset ) {
  117. $post_data = array();
  118. $post_data["agentId"] = QUNAR_AGENT_ID;
  119. $post_data["time"] = $current_time;
  120. $post_data["comment"] = "出票失败:该线路已停售";
  121. $post_data["ticketInfo"] = json_encode(array( "ret" => false, "data" => array("orderNo" => $out_order_no, "ticketStatu" => 1)) );
  122. $post_data["auth"] = get_qunar_auth($post_data);
  123. $complete_result = send_post_qunar( QUNAR_COMPLETE_ORDER_URL, $post_data );
  124. continue;
  125. }
  126. $run_info = $rowset[0];
  127. if( $run_info["start_date"] != $order_info["date"] ) {
  128. $sql = " SELECT * FROM outside_run WHERE line_code='{$run_info["line_code"]}' AND start_date='{$order_info["date"]}' AND start_time='{$order_info["startTime"]}' AND prod_name='{$run_info["prod_name"]}'";
  129. $result = $pdo->query($sql);
  130. $rowset = $result == false ? false : $result->fetchAll();
  131. $result->closeCursor();
  132. if( false == $rowset ) {
  133. $post_data = array();
  134. $post_data["agentId"] = QUNAR_AGENT_ID;
  135. $post_data["time"] = $current_time;
  136. $post_data["comment"] = "出票失败:该线路已停售";
  137. $post_data["ticketInfo"] = json_encode(array( "ret" => false, "data" => array("orderNo" => $out_order_no, "ticketStatu" => 1)) );
  138. $post_data["auth"] = get_qunar_auth($post_data);
  139. $complete_result = send_post_qunar( QUNAR_COMPLETE_ORDER_URL, $post_data );
  140. continue;
  141. }
  142. $run_info = $rowset[0];
  143. $prod_id = $run_info["prod_code"];
  144. }
  145. $line_code = $run_info["line_code"];
  146. $run_start_time = $run_info["start_date"]." ".$run_info["start_time"];
  147. $per_price = $run_info["cus_price"];
  148. $all_price = $per_price * $ticket_num;
  149. }
  150. $pdo_insert = conn1();
  151. $sql_insert = " INSERT INTO outside_submit_order (from_org_id,outside_order_no,prod_id,ticket_num,per_price,all_price,customer_name,customer_mobile,customer_id_no,submit_status,opera_time,passenger) VALUE(" .
  152. "28,'{$out_order_no}','{$order_info["coachNo"]}',{$ticket_num},{$per_price},{$all_price},'{$customer_name}','{$customer_mobile}','{$customer_id_no}',0,'{$current_time}','{$passengers_list}') ";
  153. $pdo_insert->exec($sql_insert);
  154. if( !isset($run_code_array[1]) ) {
  155. $remain_count = $run_info["remain_count"];
  156. $update_date = substr($run_info["update_time"],0,10);
  157. $can_sale_time = date("Y-m-d H:i:00", strtotime( $run_start_time." -1 hours" ));
  158. $can_sale_time = $run_start_time.":00";
  159. if( $check_stock_time > $can_sale_time ) {
  160. $remain_count = 0;
  161. }
  162. if( $remain_count < $ticket_num ) {
  163. $post_data = array();
  164. $post_data["agentId"] = QUNAR_AGENT_ID;
  165. $post_data["time"] = $current_time;
  166. $post_data["comment"] = "出票失败:该线路余票不足";
  167. $post_data["ticketInfo"] = json_encode(array( "ret" => false, "data" => array("orderNo" => $out_order_no, "ticketStatu" => 1)) );
  168. $post_data["auth"] = get_qunar_auth($post_data);
  169. $complete_result = send_post_qunar( QUNAR_COMPLETE_ORDER_URL, $post_data );
  170. continue;
  171. }
  172. $run_code = $run_info["run_code"];
  173. if( $run_info["org_id"] != 1286 ) {
  174. //自在下票
  175. $setOrder = new orderService();
  176. //票务系统锁定
  177. $zizai_cus = "{|" . $customer_name . "|" . $customer_mobile . "|" . $customer_id_no . "||}";
  178. $lock_order = $setOrder->createOrder(zizaiArgs::$USER, $prod_id . "P" . $ticket_num . "|", $customer_name, $customer_mobile, $customer_id_no, '', 0);
  179. //$lock_order = $setOrder->lock(zizaiArgs::$USER, 30, $prod_id."P".$ticket_num."|", $zizai_cus );
  180. if (false == $lock_order || $lock_order['code'] != 0) {
  181. $post_data = array();
  182. $post_data["agentId"] = QUNAR_AGENT_ID;
  183. $post_data["time"] = $current_time;
  184. $post_data["comment"] = "出票失败:该线路已停售";
  185. $post_data["ticketInfo"] = json_encode(array("ret" => false, "data" => array("orderNo" => $out_order_no, "ticketStatu" => 1)));
  186. $post_data["auth"] = get_qunar_auth($post_data);
  187. $complete_result = send_post_qunar(QUNAR_COMPLETE_ORDER_URL, $post_data);
  188. continue;
  189. }
  190. $tradeno = $lock_order['tradeno'];
  191. $customerlist = "";
  192. foreach ($passengers as $passenger_info) {
  193. $customerlist .= '{' . $prod_id . '|' . $passenger_info["passengerName"] . '|' . $customer_mobile . '|' . descryption_by_shif($passenger_info["passengerId"]) . '}';
  194. }
  195. $return_info = $setOrder->customer(zizaiArgs::$USER, $tradeno, $customerlist);
  196. $pdo_update3 = conn1();
  197. $sql_update = " UPDATE outside_submit_order set supply_order_id='{$tradeno}' WHERE outside_order_no='{$out_order_no}'";
  198. $pdo_update3->exec($sql_update);
  199. $post_data = array();
  200. $post_data["agentId"] = QUNAR_AGENT_ID;
  201. $post_data["time"] = $current_time;
  202. $line_name = str_replace("舟山", "普陀山", $run_info["line_name"]);
  203. $post_data["comment"] = "出票成功:您已成功订购了{$line_name}[{$run_info["prod_name"]}]{$ticket_num}张。订单号为:" . $tradeno . "。出发时间:{$run_info["start_date"]} {$run_info["start_time"]}。上车地点:{$run_info["start_res"]}。请于发车前到上车站点的服务台领票。咨询电话4008872626";
  204. if ($line_code == "xn006") {
  205. $post_data["comment"] = "出票成功:您已成功订购了{$line_name}[{$run_info["prod_name"]}]{$ticket_num}张。订单号为:" . $tradeno . "。出发时间:{$run_info["start_date"]} {$run_info["start_time"]}。请于发车前到慈航广场舟山市旅游集散服务中心服务台报姓名和预定手机号取票,因取票点与上车点(慈航大酒店门口)距离较远,烦请提前20分钟前往取票。咨询电话4008872626。";
  206. } else if ($line_code == "zsz101") {
  207. $post_data["comment"] = "出票成功:您已成功订购了{$line_name}[{$run_info["prod_name"]}]{$ticket_num}张。订单号为:" . $tradeno . "。出发时间:{$run_info["start_date"]} {$run_info["start_time"]}。请于发车前到上车站点(城北开发区学运路18号)的服务台报姓名和预定手机号取票。咨询电话4008872626。";
  208. }
  209. $ticketCode = sprintf("%d", $tradeno);
  210. for ($ticket_index = 1; $ticket_index < $ticket_num; $ticket_index++) {
  211. $ticketCode .= "|" . sprintf("%d", $tradeno);
  212. }
  213. $post_data["ticketInfo"] = json_encode(array("ret" => true, "data" => array("orderNo" => $out_order_no, "ticketStatu" => 0, "ticketNum" => sprintf("%d", $ticket_num), "ticketPassword" => $ticketCode, "ticketCode" => $ticketCode)));
  214. $post_data["auth"] = get_qunar_auth($post_data);
  215. $complete_result = send_post_qunar(QUNAR_COMPLETE_ORDER_URL, $post_data);
  216. }
  217. //出发地和目的地的area_id
  218. $sql = " SELECT ID,AREA_NAME FROM base_area WHERE AREA_NAME like \"".$run_info["start_area"]."%%\" AND cancel_flag = 0 ";
  219. $result=$pdo->query($sql);
  220. $rowset=$result->fetchAll();
  221. $result->closeCursor();
  222. if( $rowset == false ) {
  223. $start_area_id = 791;
  224. } else {
  225. $start_area_id = $rowset[0]["ID"];
  226. }
  227. $sql = " SELECT ID,AREA_NAME FROM base_area WHERE AREA_NAME like \"".$run_info["end_area"]."%%\" AND cancel_flag = 0 ";
  228. $result=$pdo->query($sql);
  229. $rowset=$result->fetchAll();
  230. $result->closeCursor();
  231. if( $rowset == false ) {
  232. $end_area_id = 791;
  233. } else {
  234. $end_area_id = $rowset[0]["ID"];
  235. }
  236. $userid = 2;
  237. $prod_id = 380001;
  238. $run_code = 0;
  239. $myprod = '{m'.$prod_id.'p'.$ticket_num.'|r'.$run_code.'}';
  240. $mycustomer = "{,".$customer_name.",,".$customer_mobile.",150,".$customer_id_no.",,,,".$passengers_list."}";
  241. $run_info_txt = "{0,普通座票,".$run_info["line_name"].",".$run_info["start_date"].",".$run_info["start_time"].",".$run_info["start_res"].",".$run_info["start_date"].",".$run_info["start_time"].",".$run_info["start_area"].",".$run_info["end_res"].",,,".$run_info["end_area"].",".$start_area_id.",".$end_area_id."}";
  242. $sql_insert="call sp_make_order_for_zizai(".$userid.",'".$myprod."','".$mycustomer."', 28, '".$out_order_no."',".$run_info["cus_price"].", '".$run_info_txt."')";
  243. writeLog($sql_insert);
  244. $result=$pdo->query($sql_insert);
  245. $rowset=$result->fetchAll(PDO::FETCH_ASSOC);
  246. $result->closeCursor();
  247. if (is_array($rowset) && $rowset[0]['errcode'] == 0 ) {
  248. $order_id=$rowset[0]['order_id'];
  249. //运游通下单
  250. if( $run_info["org_id"] == 1286 ) {
  251. $njyyt_run_code = substr($run_info["prod_code"], 5);
  252. $njyyt_run_code = str_replace("T","_", $njyyt_run_code);
  253. $send_post_data = array( "auth_code" => "pM3E9XdSeOndP2kV", 'run_code' => $njyyt_run_code, 'ticket_num' => $ticket_num, 'per_price' => $per_price, 'all_price' => $all_price, 'customer_name' => $customer_name, 'customer_mobile' => $customer_mobile, 'customer_id_no' => $customer_id_no, 'ctrip_order_no' => "ZZCX".$order_id, 'passengers' => $_POST['passengers'] );
  254. $yyt_result = send_post("http://yytcs.njyunyoutong.com/api1.0/submit_order.php",$send_post_data);
  255. $yyt_order_info = json_decode($yyt_result,true);
  256. if( $yyt_order_info["code"] != 201 ) {
  257. $user_id = 2;
  258. $sql = "CALL SP_CANCEL_ORDER(" . $user_id . "," . $order_id . ")";
  259. $pdo_cancel = conn1();
  260. $cancel_result = $pdo_cancel->query($sql);
  261. $cancel_result->closeCursor();
  262. $post_data = array();
  263. $post_data["agentId"] = QUNAR_AGENT_ID;
  264. $post_data["time"] = $current_time;
  265. $post_data["comment"] = "出票失败:该线路已停售";
  266. $post_data["ticketInfo"] = json_encode(array("ret" => false, "data" => array("orderNo" => $out_order_no, "ticketStatu" => 1)));
  267. $post_data["auth"] = get_qunar_auth($post_data);
  268. $complete_result = send_post_qunar(QUNAR_COMPLETE_ORDER_URL, $post_data);
  269. continue;
  270. } else {
  271. $tradeno = $yyt_order_info["order_no"];
  272. $post_data = array();
  273. $post_data["agentId"] = QUNAR_AGENT_ID;
  274. $post_data["time"] = $current_time;
  275. $line_name = $run_info["line_name"];
  276. $post_data["comment"] = $yyt_order_info["send_message_array"][0];
  277. $ticketCode = sprintf("%d", $tradeno);
  278. for ($ticket_index = 1; $ticket_index < $ticket_num; $ticket_index++) {
  279. $ticketCode .= "|" . sprintf("%d", $tradeno);
  280. }
  281. $post_data["ticketInfo"] = json_encode(array("ret" => true, "data" => array("orderNo" => $out_order_no, "ticketStatu" => 0, "ticketNum" => sprintf("%d", $ticket_num), "ticketPassword" => $ticketCode, "ticketCode" => $ticketCode)));
  282. $post_data["auth"] = get_qunar_auth($post_data);
  283. $complete_result = send_post_qunar(QUNAR_COMPLETE_ORDER_URL, $post_data);
  284. }
  285. }
  286. //update submit order
  287. $pdo_update = conn1();
  288. $sql_update = " UPDATE order_main set order_status =146,PROD_SUPPLY_ORG_NAME='自在旅行' WHERE ORDER_ID=".$order_id." OR PARENT_ORDER_ID=".$order_id;
  289. $pdo_update->exec($sql_update);
  290. $pdo_update2 = conn1();
  291. $sql_update = " UPDATE outside_submit_order set submit_status=1 WHERE outside_order_no='{$out_order_no}'";
  292. $pdo_update2->exec($sql_update);
  293. $opera_per_price = $per_price;
  294. $opera_all_price = $all_price;
  295. $pdo_insert2 = conn1();
  296. $opera_detail = "创建订单,出发日期{$run_info["start_date"]},订单渠道去哪儿汽车票,单价{$opera_per_price},总额{$opera_all_price},联系人信息:{$customer_name},{$customer_mobile},{$customer_id_no},备注信息:";
  297. $sql_log = "insert into order_opera_log(order_id,opera_user_id,opera_type,opera_time,opera_detail,opera_platform) VALUES ({$order_id},2,1,'{$current_time}','{$opera_detail}','OTA对接')";
  298. $pdo_insert2->exec($sql_log);
  299. $status_post_data['order_id'] = "{$order_id}";
  300. $status_post_data['order_status'] = "451,452,453";
  301. post2("http://". CS_DOMAIN. "/st-xm/Api/add_order_status_log.php",$status_post_data);
  302. $baseprice_post_array = array();
  303. $baseprice_post_array["action"] = "update_base_price";
  304. $baseprice_post_array["order_id"] = $order_id;
  305. $baseprice_post_array["base_price"] = round($opera_per_price*0.9);
  306. $baseprice_post_array["people_num"] = $ticket_num;
  307. post2("http://". CS1_DOMAIN. "/api/submit-order/",$baseprice_post_array);
  308. continue;
  309. } else {
  310. /*
  311. $post_data = array();
  312. $post_data["agentId"] = QUNAR_AGENT_ID;
  313. $post_data["time"] = $current_time;
  314. $post_data["comment"] = "出票失败:该线路已停售";
  315. $post_data["ticketInfo"] = json_encode(array( "ret" => false, "data" => array("orderNo" => $out_order_no, "ticketStatu" => 1)) );
  316. $post_data["auth"] = get_qunar_auth($post_data);
  317. $complete_result = send_post( QUNAR_COMPLETE_ORDER_URL, $post_data );
  318. */
  319. continue;
  320. }
  321. continue;
  322. }
  323. if( in_array($run_main_info["PROD_ID"], $__ary_special_line_array) ) {
  324. $limit_time = $limit_time2;
  325. } else {
  326. $limit_time = $limit_time1;
  327. }
  328. //get current time
  329. $sql_get_station_time = "SELECT run_station.START_TIME
  330. from run_prod
  331. left join run_station on run_station.run_id = run_prod.run_id and run_station.STATION_RES_ID = run_prod.START_STATION_RES_ID
  332. where run_prod.run_id = {$run_main_info["RUN_ID"]} and run_prod.prod_id = {$prod_id}";
  333. $result = $pdo->query($sql_get_station_time);
  334. $rowset2 = false;
  335. if( $result != false ) {
  336. $rowset2 = $result->fetchAll();
  337. $result->closeCursor();
  338. }
  339. if( $rowset2 == false ) {
  340. $post_data = array();
  341. $post_data["agentId"] = QUNAR_AGENT_ID;
  342. $post_data["time"] = $current_time;
  343. $post_data["comment"] = "出票失败:该线路已停售";
  344. $post_data["ticketInfo"] = json_encode(array( "ret" => false, "data" => array("orderNo" => $out_order_no, "ticketStatu" => 1)) );
  345. $post_data["auth"] = get_qunar_auth($post_data);
  346. $complete_result = send_post_qunar( QUNAR_COMPLETE_ORDER_URL, $post_data );
  347. continue;
  348. }
  349. $station_run_time = $rowset2[0]["START_TIME"];
  350. if( in_array($run_main_info["PROD_ID"], $limit_sell_prod2) && (($current_hour >= "16:00" && $run_main_info["RUN_DATE"] <= $tomorrow_day) || $run_main_info["RUN_DATE"] < $tomorrow_day )) {
  351. $post_data = array();
  352. $post_data["agentId"] = QUNAR_AGENT_ID;
  353. $post_data["time"] = $current_time;
  354. $post_data["comment"] = "出票失败:该线路已停售";
  355. $post_data["ticketInfo"] = json_encode(array( "ret" => false, "data" => array("orderNo" => $out_order_no, "ticketStatu" => 1)) );
  356. $post_data["auth"] = get_qunar_auth($post_data);
  357. $complete_result = send_post_qunar( QUNAR_COMPLETE_ORDER_URL, $post_data );
  358. continue;
  359. } else if( $run_main_info["RUN_DATE"] == $today && $limit_time >= $station_run_time ) {
  360. $post_data = array();
  361. $post_data["agentId"] = QUNAR_AGENT_ID;
  362. $post_data["time"] = $current_time;
  363. $post_data["comment"] = "出票失败:该线路已停售";
  364. $post_data["ticketInfo"] = json_encode(array( "ret" => false, "data" => array("orderNo" => $out_order_no, "ticketStatu" => 1)) );
  365. $post_data["auth"] = get_qunar_auth($post_data);
  366. $complete_result = send_post_qunar( QUNAR_COMPLETE_ORDER_URL, $post_data );
  367. continue;
  368. }
  369. if( in_array($prod_id,$no_sell_array) ) {
  370. $post_data = array();
  371. $post_data["agentId"] = QUNAR_AGENT_ID;
  372. $post_data["time"] = $current_time;
  373. $post_data["comment"] = "出票失败:该线路已停售";
  374. $post_data["ticketInfo"] = json_encode(array( "ret" => false, "data" => array("orderNo" => $out_order_no, "ticketStatu" => 1)) );
  375. $post_data["auth"] = get_qunar_auth($post_data);
  376. $complete_result = send_post_qunar( QUNAR_COMPLETE_ORDER_URL, $post_data );
  377. continue;
  378. }
  379. $myprod = '{m'.$prod_id.'p'.$ticket_num.'|r'.$run_code.'}';
  380. $mycustomer = '{,'.$customer_name.',,'.$customer_mobile.',150,'.$customer_id_no.',,,,'.$passengers_list.'}';
  381. //if($prod_id== "449862" || $prod_id == "449867" ){
  382. if( in_array($run_main_info["PROD_ID"], $__ary_special_line_array ) ) {
  383. $start_end_array = explode( 'X', $prod_id );
  384. if( count($start_end_array) < 2 ) {
  385. if( !isset($__ary_new_ticket_array[$prod_id]) ) {
  386. $post_data = array();
  387. $post_data["agentId"] = QUNAR_AGENT_ID;
  388. $post_data["time"] = $current_time;
  389. $post_data["comment"] = "出票失败:该线路已停售";
  390. $post_data["ticketInfo"] = json_encode(array( "ret" => false, "data" => array("orderNo" => $out_order_no, "ticketStatu" => 1)) );
  391. $post_data["auth"] = get_qunar_auth($post_data);
  392. $complete_result = send_post_qunar( QUNAR_COMPLETE_ORDER_URL, $post_data );
  393. continue;
  394. } else {
  395. $start_end_array = explode('X', $__ary_new_ticket_array[$prod_id]);
  396. }
  397. }
  398. $start_area_id = $start_end_array[0];
  399. $end_area_id = $start_end_array[1];
  400. $special_prod_id = $__ary_special_ticket_array[$run_main_info["PROD_ID"]];
  401. $myprod = '{m'.$special_prod_id.'p'.$ticket_num.'|r'.$run_code.'}';
  402. $start_station_info = $__array_line_info[$run_main_info["PROD_ID"]]["start"][$start_area_id];
  403. $end_station_info = $__array_line_info[$run_main_info["PROD_ID"]]["end"][$end_area_id];
  404. $run_start_time = $run_main_info["RUN_DATE"]." ".$run_main_info["RUN_TIME"];
  405. $start_time = date("Y-m-d H:i", strtotime( $run_start_time." + ".$start_station_info["alltime"]." minutes "));
  406. $end_time = date("Y-m-d H:i", strtotime($run_start_time." + ".$end_station_info["alltime"]." minutes "));
  407. $result = post2('wx.zhizhuchuxing.com/ZZDZ2/application/custom_made/control.php', array(
  408. 'type' => 'order_submitforout',
  409. 'prod_list' => $myprod,
  410. 'customer_info' => $mycustomer,
  411. 'start_id' => $start_area_id,
  412. 'end_id' => $end_area_id,
  413. 'line_id' => $run_main_info["PROD_ID"],
  414. 'start_time' => mb_substr($start_time,11,5),
  415. 'end_time' => mb_substr($end_time,11,5)
  416. ));
  417. $result_array = json_decode($result,true);
  418. writeLog("submit order::result=".$result);
  419. if( $result_array["code"] == 0 ) {
  420. $order_id = $result_array['order_id'];
  421. $sql_order_status = "update order_main set order_status =146,OUTSIDE_SALE_ORG_ID=28,OUTSIDE_ORDER_NO='".$out_order_no."' where order_id= " . $order_id . " or parent_order_id = " . $order_id;
  422. $pdo_update2 = conn1();
  423. $pdo_update2->exec($sql_order_status);
  424. $res_content = get_msg_info($order_id);
  425. $name = $res_content[0];
  426. $tel = $res_content[1];
  427. $content = $res_content[2];
  428. $post_data = array();
  429. $post_data["agentId"] = QUNAR_AGENT_ID;
  430. $post_data["time"] = $current_time;
  431. $post_data["comment"] = $content;
  432. /*
  433. $comment_type = 0;
  434. $comment_text = "";
  435. $send_success = 0;
  436. $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})";
  437. $result1 = $pdo->query($sql1);
  438. $rowset1 = $result1->fetchAll(PDO::FETCH_ASSOC);
  439. $result1->closeCursor();*/
  440. $pdo_update = conn1();
  441. $sql_update = " UPDATE outside_submit_order set submit_status=1 WHERE outside_order_no='{$out_order_no}'";
  442. $pdo_update->exec($sql_update);
  443. $ticketCode = sprintf("%d", $order_id);
  444. for ($ticket_index = 1; $ticket_index < $ticket_num; $ticket_index++) {
  445. $ticketCode .= "|" . sprintf("%d", $order_id);
  446. }
  447. $post_data["ticketInfo"] = json_encode(array("ret" => true, "data" => array("orderNo" => $out_order_no, "ticketStatu" => 0, "ticketNum" => sprintf("%d", $ticket_num), "ticketPassword" => $ticketCode, "ticketCode" => $ticketCode)));
  448. $post_data["auth"] = get_qunar_auth($post_data);
  449. $complete_result = send_post_qunar(QUNAR_COMPLETE_ORDER_URL, $post_data);
  450. $complete_result_array = json_decode($complete_result, true);
  451. $opera_per_price = $per_price;
  452. $opera_all_price = $all_price;
  453. $pdo_insert2 = conn1();
  454. $opera_detail = "创建订单,出发日期{$run_main_info["RUN_DATE"]},订单渠道去哪儿汽车票,单价{$opera_per_price},总额{$opera_all_price},联系人信息:{$customer_name},{$customer_mobile},{$customer_id_no},备注信息:";
  455. $sql_log = "insert into order_opera_log(order_id,opera_user_id,opera_type,opera_time,opera_detail,opera_platform) VALUES ({$order_id},2,1,'{$current_time}','{$opera_detail}','OTA对接')";
  456. $pdo_insert2->exec($sql_log);
  457. $status_post_data['order_id'] = "{$order_id}";
  458. $status_post_data['order_status'] = "451,452,453";
  459. post2("http://". CS_DOMAIN. "/st-xm/Api/add_order_status_log.php",$status_post_data);
  460. continue;
  461. } else if( $result_array["code"] == 101 ) {
  462. $post_data = array();
  463. $post_data["agentId"] = QUNAR_AGENT_ID;
  464. $post_data["time"] = $current_time;
  465. $post_data["comment"] = "出票失败:该线路已停售";
  466. $post_data["ticketInfo"] = json_encode(array( "ret" => false, "data" => array("orderNo" => $out_order_no, "ticketStatu" => 1)) );
  467. $post_data["auth"] = get_qunar_auth($post_data);
  468. $complete_result = send_post_qunar( QUNAR_COMPLETE_ORDER_URL, $post_data );
  469. continue;
  470. } else {
  471. $post_data = array();
  472. $post_data["agentId"] = QUNAR_AGENT_ID;
  473. $post_data["time"] = $current_time;
  474. $post_data["comment"] = "出票失败:该线路已停售";
  475. $post_data["ticketInfo"] = json_encode(array( "ret" => false, "data" => array("orderNo" => $out_order_no, "ticketStatu" => 1)) );
  476. $post_data["auth"] = get_qunar_auth($post_data);
  477. $complete_result = send_post_qunar( QUNAR_COMPLETE_ORDER_URL, $post_data );
  478. continue;
  479. }
  480. } else {
  481. $sql_insert = "call sp_make_order(" . $userid . ",'" . $myprod . "','" . $mycustomer . "', 28, '" . $out_order_no . "')";
  482. $result = $pdo->query($sql_insert);
  483. $rowset = $result->fetchAll(PDO::FETCH_ASSOC);
  484. $result->closeCursor();
  485. $post_data = array();
  486. $post_data["agentId"] = QUNAR_AGENT_ID;
  487. $post_data["time"] = $current_time;
  488. if (is_array($rowset) && $rowset[0]['errcode'] == 0) {
  489. $order_id = $rowset[0]['order_id'];
  490. $res_content = get_msg_info($order_id);
  491. $name = $res_content[0];
  492. $tel = $res_content[1];
  493. $content = $res_content[2];
  494. $post_data["comment"] = $content;
  495. $ticketCode = sprintf("%d", $order_id);
  496. for ($ticket_index = 1; $ticket_index < $ticket_num; $ticket_index++) {
  497. $ticketCode .= "|" . sprintf("%d", $order_id);
  498. }
  499. $status_post_data['order_id'] = $order_id;
  500. $opera_per_price = $per_price;
  501. $opera_all_price = $all_price;
  502. //both way
  503. if( $back_run_code != false ) {
  504. $opera_per_price = $per_price / 2;
  505. $opera_all_price = $all_price / 2;
  506. $myprod2 = '{m'.$back_prod_id.'p'.$ticket_num.'|r'.$back_run_code.'}';
  507. $sql_insert2 = "call sp_make_order(" . $userid . ",'" . $myprod2 . "','" . $mycustomer . "', 28, '" . $out_order_no . "')";
  508. $result = $pdo->query($sql_insert2);
  509. if( $result != false ) {
  510. $rowset_back = $result->fetchAll(PDO::FETCH_ASSOC);
  511. $result->closeCursor();
  512. } else {
  513. $rowset_back = false;
  514. }
  515. if (is_array($rowset_back) && $rowset_back[0]['errcode'] == 0) {
  516. $back_order_id = $rowset_back[0]['order_id'];
  517. $res_content2 = get_msg_info($back_order_id);
  518. $content2 = $res_content2[2];
  519. $post_data["comment"] .= $content2 ;
  520. $status_post_data['order_id'] = "{$order_id},{$back_order_id}";
  521. } else {
  522. $sql = "CALL SP_CANCEL_ORDER(" . $user_id . "," . $order_id . ")";
  523. $result = $pdo->query($sql);
  524. $result->closeCursor();
  525. $post_data["comment"] = "出票失败:" . $rowset[0]['errinfo'];
  526. $post_data["ticketInfo"] = json_encode(array("ret" => false, "data" => array("orderNo" => $out_order_no, "ticketStatu" => 1)));
  527. $post_data["auth"] = get_qunar_auth($post_data);
  528. $complete_result = send_post_qunar(QUNAR_COMPLETE_ORDER_URL, $post_data);
  529. $complete_result_array = json_decode($complete_result, true);
  530. continue;
  531. }
  532. } else {
  533. $back_order_id = false;
  534. }
  535. $pdo_insert2 = conn1();
  536. $opera_detail = "创建订单,出发日期{$run_main_info["RUN_DATE"]},订单渠道去哪儿汽车票,单价{$opera_per_price},总额{$opera_all_price},联系人信息:{$customer_name},{$customer_mobile},{$customer_id_no},备注信息:";
  537. $sql_log = "insert into order_opera_log(order_id,opera_user_id,opera_type,opera_time,opera_detail,opera_platform) VALUES ({$order_id},2,1,'{$current_time}','{$opera_detail}','OTA对接')";
  538. $pdo_insert2->exec($sql_log);
  539. if( $back_order_id != false ) {
  540. $sql2 = " SELECT RUN_DATE FROM run_main WHERE RUN_ID = {$back_run_code} ";
  541. $result=$pdo->query($sql2);
  542. $bak_rowset=$result->fetchAll();
  543. $result->closeCursor();
  544. $back_run_main_info = $bak_rowset[0];
  545. $pdo_insert3 = conn1();
  546. $opera_detail = "创建订单,出发日期{$back_run_main_info["RUN_DATE"]},订单渠道去哪儿汽车票,单价{$opera_per_price}总额,{$opera_all_price},联系人信息:{$customer_name},{$customer_mobile},{$customer_id_no},备注信息:";
  547. $sql_log = "insert into order_opera_log(order_id,opera_user_id,opera_type,opera_time,opera_detail,opera_platform) VALUES ({$back_order_id},2,1,'{$current_time}','{$opera_detail}','OTA对接')";
  548. $pdo_insert3->exec($sql_log);
  549. $sql_log = "insert into to_from(to_orderid,back_orderid) VALUES ( {$order_id}, {$back_order_id})";
  550. $pdo_insert3->exec($sql_log);
  551. }
  552. $status_post_data['order_status'] = "451,452,453";
  553. post2("http://". CS_DOMAIN. "/st-xm/Api/add_order_status_log.php",$status_post_data);
  554. $send_post_data = array();
  555. $send_post_data["order_id"] = $order_id;
  556. $send_post_data["per_price"] = $opera_per_price;
  557. $send_post_data["ticket_num"] = $ticket_num;
  558. post2("http://". CS_DOMAIN. "/st-xm/Api/change_order_price.php",$send_post_data);
  559. if( $back_order_id != false ) {
  560. $send_post_data = array();
  561. $send_post_data["order_id"] = $back_order_id;
  562. $send_post_data["per_price"] = $opera_per_price;
  563. $send_post_data["ticket_num"] = $ticket_num;
  564. post2("http://". CS_DOMAIN. "/st-xm/Api/change_order_price.php",$send_post_data);
  565. }
  566. $post_data["comment"] .= "提前一天19点之前,如未收到司机电话,请速与021-52218088联系。";
  567. //end of both way
  568. $post_data["ticketInfo"] = json_encode(array("ret" => true, "data" => array("orderNo" => $out_order_no, "ticketStatu" => 0, "ticketNum" => sprintf("%d", $ticket_num), "ticketPassword" => $ticketCode, "ticketCode" => $ticketCode)));
  569. } else {
  570. $post_data["comment"] = "出票失败:" . $rowset[0]['errinfo'];
  571. $post_data["ticketInfo"] = json_encode(array("ret" => false, "data" => array("orderNo" => $out_order_no, "ticketStatu" => 1)));
  572. }
  573. $post_data["auth"] = get_qunar_auth($post_data);
  574. $complete_result = send_post_qunar(QUNAR_COMPLETE_ORDER_URL, $post_data);
  575. $complete_result_array = json_decode($complete_result, true);
  576. if (is_array($rowset) && $rowset[0]['errcode'] == 0) {
  577. $comment_type = 0;
  578. $comment_text = "";
  579. $send_success = 0;
  580. //$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})";
  581. //$result1 = $pdo->query($sql1);
  582. //$rowset1 = $result1->fetchAll(PDO::FETCH_ASSOC);
  583. //$result1->closeCursor();
  584. $pdo_send_msg = conn1();
  585. $sql1 = "insert into order_send_message(ORDER_ID,SEND_MOBILE,SEND_MESSAGE,SEND_TIME,SEND_ERROR,CREATE_USER_ID,CREATE_TIME,UPDATE_USER_ID,UPDATE_TIME) VALUES ({$order_id},'{$tel}', '{$content}','{$current_time}', {$send_success}, 2,'{$current_time}', 2,'{$current_time}' )";
  586. $pdo_send_msg->exec( $sql1 );
  587. if( $back_run_code != false ) {
  588. //$sql1 = "CALL HT_ADD_MSG_COMMENT(2,'addmsg'," . $back_order_id . "," . $comment_type . ",'" . $comment_text . "','" . $tel . "','" . $content2 . "','" . date("Y-m-d H:i:s") . "',{$send_success})";
  589. //$result1 = $pdo->query($sql1);
  590. //$rowset1 = $result1->fetchAll(PDO::FETCH_ASSOC);
  591. //$result1->closeCursor();
  592. $sql1 = "insert into order_send_message(ORDER_ID,SEND_MOBILE,SEND_MESSAGE,SEND_TIME,SEND_ERROR,CREATE_USER_ID,CREATE_TIME,UPDATE_USER_ID,UPDATE_TIME) VALUES ({$back_order_id},'{$tel}', '{$content2}','{$current_time}', {$send_success}, 2,'{$current_time}', 2,'{$current_time}' )";
  593. $pdo_send_msg->exec( $sql1 );
  594. }
  595. $pdo_update = conn1();
  596. $sql_update = " UPDATE outside_submit_order set submit_status=1 WHERE outside_order_no='{$out_order_no}'";
  597. $pdo_update->exec($sql_update);
  598. $sql_order_status = "update order_main set order_status =146 where order_id= " . $order_id . " or parent_order_id = " . $order_id;
  599. $pdo_update2 = conn1();
  600. $pdo_update2->exec($sql_order_status);
  601. if( $back_run_code != false ) {
  602. $sql_order_status2 = "update order_main set order_status =146 where order_id= " . $back_order_id . " or parent_order_id = " . $back_order_id;
  603. $pdo_update3 = conn1();
  604. $pdo_update3->exec($sql_order_status2);
  605. }
  606. }
  607. }
  608. }
  609. echo "success";
  610. exit();
  611. function get_msg_info($ORDER_ID) {
  612. $url='http://'. CS1_DOMAIN. '/api/msg/get-msg-info';
  613. $sendInfo=array();
  614. $sendInfo['order_id']= $ORDER_ID;
  615. $sendInfo['msg_type']='ota';
  616. $res_content = httpRequest($url,$sendInfo);
  617. $result_array = json_decode($res_content,true);
  618. return array(isset($result_array['name']) ? $result_array['name'] : "", isset($result_array['mobile']) ? $result_array['mobile'] : "", isset($result_array['content']) ? $result_array['content'] : "短信错误,联系客服!!!");
  619. }
  620. function post2($url, $post_data = '', $timeout = 5){//curl
  621. $ch = curl_init();
  622. curl_setopt ($ch, CURLOPT_URL, $url);
  623. curl_setopt ($ch, CURLOPT_POST, 1);
  624. if($post_data != ''){
  625. curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
  626. }
  627. curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
  628. curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  629. curl_setopt($ch, CURLOPT_HEADER, false);
  630. $file_contents = curl_exec($ch);
  631. curl_close($ch);
  632. return $file_contents;
  633. }
  634. function send_post_qunar($url, $post_data) {
  635. writeLog( "------qunar get order result:".json_encode($post_data) );
  636. $postdata = http_build_query($post_data);
  637. $options = array(
  638. 'http' => array(
  639. 'method' => 'POST',
  640. 'header' => 'Content-type:application/x-www-form-urlencoded',
  641. 'content' => $postdata,
  642. 'timeout' => 15 * 60 // 超时时间(单位:s)
  643. )
  644. );
  645. $context = stream_context_create($options);
  646. $result = file_get_contents($url, false, $context);
  647. return $result;
  648. }