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.
 
 
 
 

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