Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

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