|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695 |
- <?php
- require_once __DIR__.'/../st-xm/Common/Mysql.php';
- require_once __DIR__.'/../st-xm/Common/config_api.inc';
- require_once __DIR__.'/../st-xm/Common/sinaAPI.php';
- require_once __DIR__.'/../st-xm/Common/zizai_orderAPI.php';
- require_once __DIR__.'/../st-xm/Common/dictionary.php';
- require_once __DIR__.'/../st-xm/Common/api_common.php';
- define("MAKE_ORDER_URL", "http://cs1.zhizhuchuxing.com/api/submit-order");
-
- header("Access-Control-Allow-Origin:*");
- date_default_timezone_set('PRC');
-
- $current_time = time();
- $current_hour = date("H:i:s",$current_time);
- $check_stock_time = date("Y-m-d H:i:s",$current_time);
- $tomorrow_day = date("Y-m-d",strtotime("+1 days"));
- $today = date("Y-m-d");
- $limit_time = date("H:i", strtotime("+1 minutes"));
- $limit_time1 = date("H:i", strtotime("+1 minutes"));
- $limit_time2 = date("H:i", strtotime("+1 minutes"));
- //拼接数组
- $post_data = array();
- $post_data["agentId"] = QUNAR_AGENT_ID;
- $post_data["time"] = $current_time;
- $post_data["auth"] = get_qunar_auth($post_data);
- $return_data = send_post( QUNAR_CHECK_ORDER_URL, $post_data);
- $return_array = json_decode($return_data,true);
- if( !isset($return_array["orderNum"]) || $return_array["orderNum"] <= 0 ) {
- print_r($return_array);
- return;
- }
- //print_r($return_array);exit();//test
- $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);
-
- $limit_sell_prod2 = array( 448568, 448569,450517,450522,450499,450504,448780,448781,450529,450530,450550,450551,450588,450698,450699,450700,450701,450702,450703 );
-
- $userid = 2;
- $current_time = date("Y-m-d H:i:s");
- $pdo=conn1();
- $order_array = $return_array["data"];
- //获取往返优惠
- //$bothway_tickets_discount = array();
- //$bothway_tickets_discount = getTicketsDiscountArray( $pdo, $from_org_id );
-
- foreach( $order_array as $order_info ) {
- writeLog("-----qunar new order info:".json_encode($order_info));
- $run_code = $order_info["coachNo"];
- $run_code_array = explode("_",$run_code);
- $back_run_code = false;
- $back_prod_id = false;
- $back_order_id = false;
- if( isset($run_code_array[1]) ) {
- if( isset($run_code_array[2]) && isset($run_code_array[3]) ) {
- $run_code_array[0] = base_convert($run_code_array[0],36,10);
- $run_code_array[1] = base_convert($run_code_array[1],36,10);
- $run_code_array[2] = base_convert($run_code_array[2],36,10);
- $run_code_array[3] = base_convert($run_code_array[3],36,10);
- $back_run_code = $run_code_array[2];
- $back_prod_id = $run_code_array[3];
- }
- $run_code = $run_code_array[0];
- $prod_id = $run_code_array[1];
- } else {
- //zizai
- //$run_code = $run_code_array[0];
- }
- $ticket_num = $order_info["ticketNum"];
- $all_price = $order_info["ticketPrice"];
- $per_price = $all_price / $ticket_num;
- $customer_name = $order_info["contactName"];
- $customer_mobile = descryption_by_shif($order_info["contactPhone"]);
- $customer_id_no = descryption_by_shif($order_info["contactId"]);
- $out_order_no = $order_info["orderNo"];
- $passengers = $order_info["passengers"];
- $passengers_array = array();
- foreach( $passengers as $passenger_info ) {
- $passengers_array[] = $passenger_info["passengerName"]."*".descryption_by_shif($passenger_info["passengerId"]);
- }
- $passengers_list = implode("/",$passengers_array);
- $sql = " SELECT * FROM order_main WHERE OUTSIDE_ORDER_NO='{$out_order_no}' AND PARENT_ORDER_ID = 0 ";
- $result = $pdo->query($sql);
- $rowset = $result->fetchAll();
- $result->closeCursor();
- if ($rowset != false) {
- continue;
- }
- if( isset($run_code_array[1]) ) {
- $sql = " SELECT * FROM run_main WHERE RUN_ID={$run_code} ";
- $result = $pdo->query($sql);
- $rowset = $result->fetchAll();
- $result->closeCursor();
- $run_main_info = $rowset[0];
-
- if( $run_main_info["RUN_DATE"] != $order_info["date"] ) {
- $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) ";
- $result = $pdo->query($sql);
- $rowset2 = false;
- if( $result != false ) {
- $rowset2 = $result->fetchAll();
- $result->closeCursor();
- $run_main_info = $rowset2[0];
- $run_code = $run_main_info["RUN_ID"];
- }
- if( $rowset2 == false) {
- $post_data = array();
- $post_data["agentId"] = QUNAR_AGENT_ID;
- $post_data["time"] = $current_time;
- $post_data["comment"] = "出票失败:该线路已停售";
- $post_data["ticketInfo"] = json_encode(array( "ret" => false, "data" => array("orderNo" => $out_order_no, "ticketStatu" => 1)) );
- $post_data["auth"] = get_qunar_auth($post_data);
- $complete_result = send_post_qunar( QUNAR_COMPLETE_ORDER_URL, $post_data, __LINE__ );
- continue;
- }
- }
- $run_start_time = $run_main_info["RUN_DATE"]." ".$run_main_info["RUN_TIME"];
- } else {
- //zizai
- $prod_id = $run_code_array[0];
- $sql = " SELECT * FROM outside_run WHERE prod_code='".$prod_id."' AND cancel_flag = 0 ";
- $result=$pdo->query($sql);
- $rowset=$result->fetchAll();
- $result->closeCursor();
- if( false == $rowset ) {
- $post_data = array();
- $post_data["agentId"] = QUNAR_AGENT_ID;
- $post_data["time"] = $current_time;
- $post_data["comment"] = "出票失败:该线路已停售";
- $post_data["ticketInfo"] = json_encode(array( "ret" => false, "data" => array("orderNo" => $out_order_no, "ticketStatu" => 1)) );
- $post_data["auth"] = get_qunar_auth($post_data);
- $complete_result = send_post_qunar( QUNAR_COMPLETE_ORDER_URL, $post_data, __LINE__ );
- continue;
- }
- $run_info = $rowset[0];
- if( $run_info["start_date"] != $order_info["date"] ) {
- $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"]}'";
- $result = $pdo->query($sql);
- $rowset = $result == false ? false : $result->fetchAll();
- $result->closeCursor();
- if( false == $rowset ) {
- $post_data = array();
- $post_data["agentId"] = QUNAR_AGENT_ID;
- $post_data["time"] = $current_time;
- $post_data["comment"] = "出票失败:该线路已停售";
- $post_data["ticketInfo"] = json_encode(array( "ret" => false, "data" => array("orderNo" => $out_order_no, "ticketStatu" => 1)) );
- $post_data["auth"] = get_qunar_auth($post_data);
- $complete_result = send_post_qunar( QUNAR_COMPLETE_ORDER_URL, $post_data, __LINE__ );
- continue;
- }
- $run_info = $rowset[0];
- $prod_id = $run_info["prod_code"];
- }
- $line_code = $run_info["line_code"];
- $run_start_time = $run_info["start_date"]." ".$run_info["start_time"];
- $per_price = $run_info["cus_price"];
- $all_price = $per_price * $ticket_num;
- }
-
- $pdo_insert = conn1();
- $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(" .
- "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}') ";
- $pdo_insert->exec($sql_insert);
-
- if( !isset($run_code_array[1]) ) {
- $remain_count = $run_info["remain_count"];
- $update_date = substr($run_info["update_time"],0,10);
- $can_sale_time = date("Y-m-d H:i:00", strtotime( $run_start_time." -1 hours" ));
- $can_sale_time = $run_start_time.":00";
- if( $check_stock_time > $can_sale_time ) {
- $remain_count = 0;
- }
- if( $remain_count < $ticket_num ) {
- $post_data = array();
- $post_data["agentId"] = QUNAR_AGENT_ID;
- $post_data["time"] = $current_time;
- $post_data["comment"] = "出票失败:该线路余票不足";
- $post_data["ticketInfo"] = json_encode(array( "ret" => false, "data" => array("orderNo" => $out_order_no, "ticketStatu" => 1)) );
- $post_data["auth"] = get_qunar_auth($post_data);
- $complete_result = send_post_qunar( QUNAR_COMPLETE_ORDER_URL, $post_data, __LINE__ );
- continue;
- }
- $run_code = $run_info["run_code"];
- if( $run_info["org_id"] != 1286 ) {
- //自在下票
- $setOrder = new orderService();
- //票务系统锁定
- $zizai_cus = "{|" . $customer_name . "|" . $customer_mobile . "|" . $customer_id_no . "||}";
- $lock_order = $setOrder->createOrder(zizaiArgs::$USER, $prod_id . "P" . $ticket_num . "|", $customer_name, $customer_mobile, $customer_id_no, '', 0);
- //$lock_order = $setOrder->lock(zizaiArgs::$USER, 30, $prod_id."P".$ticket_num."|", $zizai_cus );
- if (false == $lock_order || $lock_order['code'] != 0) {
- $post_data = array();
- $post_data["agentId"] = QUNAR_AGENT_ID;
- $post_data["time"] = $current_time;
- $post_data["comment"] = "出票失败:该线路已停售";
- $post_data["ticketInfo"] = json_encode(array("ret" => false, "data" => array("orderNo" => $out_order_no, "ticketStatu" => 1)));
- $post_data["auth"] = get_qunar_auth($post_data);
- $complete_result = send_post_qunar(QUNAR_COMPLETE_ORDER_URL, $post_data, __LINE__);
- continue;
- }
- $tradeno = $lock_order['tradeno'];
- $customerlist = "";
- foreach ($passengers as $passenger_info) {
- $customerlist .= '{' . $prod_id . '|' . $passenger_info["passengerName"] . '|' . $customer_mobile . '|' . descryption_by_shif($passenger_info["passengerId"]) . '}';
- }
- $return_info = $setOrder->customer(zizaiArgs::$USER, $tradeno, $customerlist);
- $pdo_update3 = conn1();
- $sql_update = " UPDATE outside_submit_order set supply_order_id='{$tradeno}' WHERE outside_order_no='{$out_order_no}'";
- $pdo_update3->exec($sql_update);
-
- $post_data = array();
- $post_data["agentId"] = QUNAR_AGENT_ID;
- $post_data["time"] = $current_time;
- $line_name = str_replace("舟山", "普陀山", $run_info["line_name"]);
- $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";
- if ($line_code == "xn006") {
- $post_data["comment"] = "出票成功:您已成功订购了{$line_name}[{$run_info["prod_name"]}]{$ticket_num}张。订单号为:" . $tradeno . "。出发时间:{$run_info["start_date"]} {$run_info["start_time"]}。请于发车前到慈航广场舟山市旅游集散服务中心服务台报姓名和预定手机号取票,因取票点与上车点(慈航大酒店门口)距离较远,烦请提前20分钟前往取票。咨询电话4008872626。";
- } else if ($line_code == "zsz101") {
- $post_data["comment"] = "出票成功:您已成功订购了{$line_name}[{$run_info["prod_name"]}]{$ticket_num}张。订单号为:" . $tradeno . "。出发时间:{$run_info["start_date"]} {$run_info["start_time"]}。请于发车前到上车站点(城北开发区学运路18号)的服务台报姓名和预定手机号取票。咨询电话4008872626。";
- }
- $ticketCode = sprintf("%d", $tradeno);
- for ($ticket_index = 1; $ticket_index < $ticket_num; $ticket_index++) {
- $ticketCode .= "|" . sprintf("%d", $tradeno);
- }
- $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)));
- $post_data["auth"] = get_qunar_auth($post_data);
- $complete_result = send_post_qunar(QUNAR_COMPLETE_ORDER_URL, $post_data, __LINE__);
- }
- //出发地和目的地的area_id
- $sql = " SELECT ID,AREA_NAME FROM base_area WHERE AREA_NAME like \"".$run_info["start_area"]."%%\" AND cancel_flag = 0 ";
- $result=$pdo->query($sql);
- $rowset=$result->fetchAll();
- $result->closeCursor();
- if( $rowset == false ) {
- $start_area_id = 791;
- } else {
- $start_area_id = $rowset[0]["ID"];
- }
- $sql = " SELECT ID,AREA_NAME FROM base_area WHERE AREA_NAME like \"".$run_info["end_area"]."%%\" AND cancel_flag = 0 ";
- $result=$pdo->query($sql);
- $rowset=$result->fetchAll();
- $result->closeCursor();
- if( $rowset == false ) {
- $end_area_id = 791;
- } else {
- $end_area_id = $rowset[0]["ID"];
- }
-
- $userid = 2;
- $prod_id = 380001;
- $run_code = 0;
- $myprod = '{m'.$prod_id.'p'.$ticket_num.'|r'.$run_code.'}';
- $mycustomer = "{,".$customer_name.",,".$customer_mobile.",150,".$customer_id_no.",,,,".$passengers_list."}";
- $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."}";
- $sql_insert="call sp_make_order_for_zizai(".$userid.",'".$myprod."','".$mycustomer."', 28, '".$out_order_no."',".$run_info["cus_price"].", '".$run_info_txt."')";
- writeLog($sql_insert);
- $result=$pdo->query($sql_insert);
- $rowset=$result->fetchAll(PDO::FETCH_ASSOC);
- $result->closeCursor();
- if (is_array($rowset) && $rowset[0]['errcode'] == 0 ) {
- $order_id=$rowset[0]['order_id'];
- //运游通下单
- if( $run_info["org_id"] == 1286 ) {
- $njyyt_run_code = substr($run_info["prod_code"], 5);
- $njyyt_run_code = str_replace("T","_", $njyyt_run_code);
- $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'] );
- $yyt_result = send_post("http://yytcs.njyunyoutong.com/api1.0/submit_order.php",$send_post_data);
- $yyt_order_info = json_decode($yyt_result,true);
- if( $yyt_order_info["code"] != 201 ) {
-
- $user_id = 2;
- $sql = "CALL SP_CANCEL_ORDER(" . $user_id . "," . $order_id . ")";
- $pdo_cancel = conn1();
- $cancel_result = $pdo_cancel->query($sql);
- $cancel_result->closeCursor();
-
- $post_data = array();
- $post_data["agentId"] = QUNAR_AGENT_ID;
- $post_data["time"] = $current_time;
- $post_data["comment"] = "出票失败:该线路已停售";
- $post_data["ticketInfo"] = json_encode(array("ret" => false, "data" => array("orderNo" => $out_order_no, "ticketStatu" => 1)));
- $post_data["auth"] = get_qunar_auth($post_data);
- $complete_result = send_post_qunar(QUNAR_COMPLETE_ORDER_URL, $post_data, __LINE__);
- continue;
- } else {
- $tradeno = $yyt_order_info["order_no"];
-
- $post_data = array();
- $post_data["agentId"] = QUNAR_AGENT_ID;
- $post_data["time"] = $current_time;
- $line_name = $run_info["line_name"];
- $post_data["comment"] = $yyt_order_info["send_message_array"][0];
- $ticketCode = sprintf("%d", $tradeno);
- for ($ticket_index = 1; $ticket_index < $ticket_num; $ticket_index++) {
- $ticketCode .= "|" . sprintf("%d", $tradeno);
- }
- $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)));
- $post_data["auth"] = get_qunar_auth($post_data);
- $complete_result = send_post_qunar(QUNAR_COMPLETE_ORDER_URL, $post_data, __LINE__);
- }
- }
- //update submit order
- $prod_supply_org_name = $run_info["org_id"] == 1286 ? '南京太平洋' : '自在旅行';
- $pdo_update = conn1();
- $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;
- $pdo_update->exec($sql_update);
- $pdo_update2 = conn1();
- $sql_update = " UPDATE outside_submit_order set submit_status=1 WHERE outside_order_no='{$out_order_no}'";
- $pdo_update2->exec($sql_update);
-
- $opera_per_price = $per_price;
- $opera_all_price = $all_price;
- $pdo_insert2 = conn1();
- $opera_detail = "创建订单,出发日期{$run_info["start_date"]},订单渠道去哪儿汽车票,单价{$opera_per_price},总额{$opera_all_price},联系人信息:{$customer_name},{$customer_mobile},{$customer_id_no},备注信息:";
- $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对接')";
- $pdo_insert2->exec($sql_log);
-
- $status_post_data['order_id'] = "{$order_id}";
- $status_post_data['order_status'] = "451,452,453";
- post2("http://". CS_DOMAIN. "/st-xm/Api/add_order_status_log.php",$status_post_data);
-
- $baseprice_post_array = array();
- $baseprice_post_array["action"] = "update_base_price";
- $baseprice_post_array["order_id"] = $order_id;
- $baseprice_post_array["base_price"] = round($opera_per_price*0.9);
- $baseprice_post_array["people_num"] = $ticket_num;
- post2("http://". CS1_DOMAIN. "/api/submit-order/",$baseprice_post_array);
-
- continue;
- } else {
- /*
- $post_data = array();
- $post_data["agentId"] = QUNAR_AGENT_ID;
- $post_data["time"] = $current_time;
- $post_data["comment"] = "出票失败:该线路已停售";
- $post_data["ticketInfo"] = json_encode(array( "ret" => false, "data" => array("orderNo" => $out_order_no, "ticketStatu" => 1)) );
- $post_data["auth"] = get_qunar_auth($post_data);
- $complete_result = send_post( QUNAR_COMPLETE_ORDER_URL, $post_data );
- */
- continue;
- }
- continue;
- }
-
- if( in_array($run_main_info["PROD_ID"], $__ary_special_line_array) ) {
- $limit_time = $limit_time2;
- } else {
- $limit_time = $limit_time1;
- }
-
- //get current time
- $sql_get_station_time = "SELECT run_station.START_TIME,run_station.STATION_RES_ID,run_prod.END_STATION_RES_ID
- from run_prod
- 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
- where run_prod.run_id = {$run_main_info["RUN_ID"]} and run_prod.prod_id = {$prod_id}";
- $result = $pdo->query($sql_get_station_time);
- $rowset2 = false;
- if( $result != false ) {
- $rowset2 = $result->fetchAll();
- $result->closeCursor();
- }
- if( $rowset2 == false ) {
- $post_data = array();
- $post_data["agentId"] = QUNAR_AGENT_ID;
- $post_data["time"] = $current_time;
- $post_data["comment"] = "出票失败:该线路已停售";
- $post_data["ticketInfo"] = json_encode(array( "ret" => false, "data" => array("orderNo" => $out_order_no, "ticketStatu" => 1)) );
- $post_data["auth"] = get_qunar_auth($post_data);
- $complete_result = send_post_qunar( QUNAR_COMPLETE_ORDER_URL, $post_data , __LINE__);
- continue;
- }
- $station_run_time = $rowset2[0]["START_TIME"];
- $start_station_res_id = $rowset2[0]["STATION_RES_ID"];
- $end_station_res_id = $rowset2[0]["END_STATION_RES_ID"];
- $run_stock_array = array();
- getRunStockArray2( array($run_main_info["RUN_ID"]) , $pdo, $run_stock_array );
- if( isset($run_stock_array[$run_main_info["RUN_ID"]."_".$start_station_res_id."_".$end_station_res_id]) ) {
- $remain_count = $run_stock_array[$run_main_info["RUN_ID"]."_".$start_station_res_id."_".$end_station_res_id];
- } else {
- $remain_count = 0;
- }
-
- 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 )) {
- $post_data = array();
- $post_data["agentId"] = QUNAR_AGENT_ID;
- $post_data["time"] = $current_time;
- $post_data["comment"] = "出票失败:该线路已停售";
- $post_data["ticketInfo"] = json_encode(array( "ret" => false, "data" => array("orderNo" => $out_order_no, "ticketStatu" => 1)) );
- $post_data["auth"] = get_qunar_auth($post_data);
- $complete_result = send_post_qunar( QUNAR_COMPLETE_ORDER_URL, $post_data , __LINE__);
- continue;
- } else if( $run_main_info["RUN_DATE"] == $today && $limit_time >= $station_run_time ) {
- $post_data = array();
- $post_data["agentId"] = QUNAR_AGENT_ID;
- $post_data["time"] = $current_time;
- $post_data["comment"] = "出票失败:该线路已停售";
- $post_data["ticketInfo"] = json_encode(array( "ret" => false, "data" => array("orderNo" => $out_order_no, "ticketStatu" => 1)) );
- $post_data["auth"] = get_qunar_auth($post_data);
- $complete_result = send_post_qunar( QUNAR_COMPLETE_ORDER_URL, $post_data , __LINE__);
- continue;
- }
- if( in_array($prod_id,$no_sell_array) || $remain_count < $ticket_num ) {
- $post_data = array();
- $post_data["agentId"] = QUNAR_AGENT_ID;
- $post_data["time"] = $current_time;
- $post_data["comment"] = "出票失败:该线路已停售";
- $post_data["ticketInfo"] = json_encode(array( "ret" => false, "data" => array("orderNo" => $out_order_no, "ticketStatu" => 1)) );
- $post_data["auth"] = get_qunar_auth($post_data);
- $complete_result = send_post_qunar( QUNAR_COMPLETE_ORDER_URL, $post_data , __LINE__);
- continue;
- }
-
- $myprod = '{m'.$prod_id.'p'.$ticket_num.'|r'.$run_code.'}';
- $mycustomer = '{,'.$customer_name.',,'.$customer_mobile.',150,'.$customer_id_no.',,,,'.$passengers_list.'}';
-
- //add by qius on 2017-05-09
- $customer_info_str = "{{$customer_name},{$customer_mobile},150,{$customer_id_no},$passengers_list}";
- $order_info_str = "{{$userid},0,28,{$out_order_no},1,275,1,去哪儿汽车票}";
- $prod_str = "{1,{$run_code},{$prod_id},{$per_price},{$ticket_num}}";
- if (count($run_code_array) > 2) {
- $back_run_code = $run_code_array[2];
- $back_prod_id = $run_code_array[3];
- $new_per_price = $per_price / 2;
- $prod_str = "{1,{$run_code},{$prod_id},{$new_per_price},{$ticket_num}}{2,{$back_run_code},{$back_prod_id},{$new_per_price},{$ticket_num}}";
- }
- //end of add by qius on 2017-05-09
-
- //if($prod_id== "449862" || $prod_id == "449867" ){
- if( in_array($run_main_info["PROD_ID"], $__ary_special_line_array ) ) {
- $start_end_array = explode( 'X', $prod_id );
- if( count($start_end_array) < 2 ) {
- if( !isset($__ary_new_ticket_array[$prod_id]) ) {
- $post_data = array();
- $post_data["agentId"] = QUNAR_AGENT_ID;
- $post_data["time"] = $current_time;
- $post_data["comment"] = "出票失败:该线路已停售";
- $post_data["ticketInfo"] = json_encode(array( "ret" => false, "data" => array("orderNo" => $out_order_no, "ticketStatu" => 1)) );
- $post_data["auth"] = get_qunar_auth($post_data);
- $complete_result = send_post_qunar( QUNAR_COMPLETE_ORDER_URL, $post_data, __LINE__ );
- continue;
- } else {
- $start_end_array = explode('X', $__ary_new_ticket_array[$prod_id]);
- }
- }
- $start_area_id = $start_end_array[0];
- $end_area_id = $start_end_array[1];
-
- $special_prod_id = $__ary_special_ticket_array[$run_main_info["PROD_ID"]];
- $myprod = '{m'.$special_prod_id.'p'.$ticket_num.'|r'.$run_code.'}';
- $start_station_info = $__array_line_info[$run_main_info["PROD_ID"]]["start"][$start_area_id];
- $end_station_info = $__array_line_info[$run_main_info["PROD_ID"]]["end"][$end_area_id];
- $run_start_time = $run_main_info["RUN_DATE"]." ".$run_main_info["RUN_TIME"];
-
- $start_time = date("Y-m-d H:i", strtotime( $run_start_time." + ".$start_station_info["alltime"]." minutes "));
- $end_time = date("Y-m-d H:i", strtotime($run_start_time." + ".$end_station_info["alltime"]." minutes "));
- $result = post2('wx.zhizhuchuxing.com/ZZDZ2/application/custom_made/control.php', array(
- 'type' => 'order_submitforout',
- 'prod_list' => $myprod,
- 'customer_info' => $mycustomer,
- 'start_id' => $start_area_id,
- 'end_id' => $end_area_id,
- 'line_id' => $run_main_info["PROD_ID"],
- 'start_time' => mb_substr($start_time,11,5),
- 'end_time' => mb_substr($end_time,11,5)
- ));
-
- $result_array = json_decode($result,true);
-
- writeLog("submit order::result=".$result);
- if( $result_array["code"] == 0 ) {
- $order_id = $result_array['order_id'];
- $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;
- $pdo_update2 = conn1();
- $pdo_update2->exec($sql_order_status);
-
- $res_content = get_msg_info($order_id);
- $name = $res_content[0];
- $tel = $res_content[1];
- $content = $res_content[2];
- $post_data = array();
- $post_data["agentId"] = QUNAR_AGENT_ID;
- $post_data["time"] = $current_time;
- $post_data["comment"] = $content;
- /*
- $comment_type = 0;
- $comment_text = "";
- $send_success = 0;
- $sql1 = "CALL HT_ADD_MSG_COMMENT(2,'addmsg'," . $order_id . "," . $comment_type . ",'" . $comment_text . "','" . $tel . "','" . $content . "','" . date("Y-m-d H:i:s") . "',{$send_success})";
- $result1 = $pdo->query($sql1);
- $rowset1 = $result1->fetchAll(PDO::FETCH_ASSOC);
- $result1->closeCursor();*/
- $pdo_update = conn1();
- $sql_update = " UPDATE outside_submit_order set submit_status=1 WHERE outside_order_no='{$out_order_no}'";
- $pdo_update->exec($sql_update);
-
- $ticketCode = sprintf("%d", $order_id);
- for ($ticket_index = 1; $ticket_index < $ticket_num; $ticket_index++) {
- $ticketCode .= "|" . sprintf("%d", $order_id);
- }
- $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)));
- $post_data["auth"] = get_qunar_auth($post_data);
- $complete_result = send_post_qunar(QUNAR_COMPLETE_ORDER_URL, $post_data, __LINE__);
- $complete_result_array = json_decode($complete_result, true);
-
- $opera_per_price = $per_price;
- $opera_all_price = $all_price;
- $pdo_insert2 = conn1();
- $opera_detail = "创建订单,出发日期{$run_main_info["RUN_DATE"]},订单渠道去哪儿汽车票,单价{$opera_per_price},总额{$opera_all_price},联系人信息:{$customer_name},{$customer_mobile},{$customer_id_no},备注信息:";
- $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对接')";
- $pdo_insert2->exec($sql_log);
-
-
- $status_post_data['order_id'] = "{$order_id}";
- $status_post_data['order_status'] = "451,452,453";
- post2("http://". CS_DOMAIN. "/st-xm/Api/add_order_status_log.php",$status_post_data);
-
- continue;
- } else if( $result_array["code"] == 101 ) {
- $post_data = array();
- $post_data["agentId"] = QUNAR_AGENT_ID;
- $post_data["time"] = $current_time;
- $post_data["comment"] = "出票失败:该线路已停售";
- $post_data["ticketInfo"] = json_encode(array( "ret" => false, "data" => array("orderNo" => $out_order_no, "ticketStatu" => 1)) );
- $post_data["auth"] = get_qunar_auth($post_data);
- $complete_result = send_post_qunar( QUNAR_COMPLETE_ORDER_URL, $post_data , __LINE__);
- continue;
- } else {
- $post_data = array();
- $post_data["agentId"] = QUNAR_AGENT_ID;
- $post_data["time"] = $current_time;
- $post_data["comment"] = "出票失败:该线路已停售";
- $post_data["ticketInfo"] = json_encode(array( "ret" => false, "data" => array("orderNo" => $out_order_no, "ticketStatu" => 1)) );
- $post_data["auth"] = get_qunar_auth($post_data);
- $complete_result = send_post_qunar( QUNAR_COMPLETE_ORDER_URL, $post_data, __LINE__ );
- continue;
- }
-
- } else {
- //add by qius on 2017-05-09
- $make_order_array = array(
- "action" => "submit_bus_order",
- "prod_str" => $prod_str,
- "order_info_str" => $order_info_str,
- "customer_info_str" => $customer_info_str,
- "is_send_msg" => 0
- );
- $rowset = post2( MAKE_ORDER_URL, $make_order_array );
- writeLog($rowset);
- $make_order_result = json_decode($rowset, true);
- //end of add by qius on 2017-05-09
-
- $post_data = array();
- $post_data["agentId"] = QUNAR_AGENT_ID;
- $post_data["time"] = $current_time;
- if ( isset($make_order_result["code"]) && $make_order_result["code"] == 0) {
- $order_id_array = explode(",", $make_order_result['data']);
- $order_id = $order_id_array[0];
- $back_order_id = isset( $order_id_array[1] ) ? $order_id_array[1] : false;
-
- $res_content = get_msg_info($order_id);
- $name = $res_content[0];
- $tel = $res_content[1];
- $content = $res_content[2];
- $post_data["comment"] = $content;
- $ticketCode = sprintf("%d", $order_id);
- for ($ticket_index = 1; $ticket_index < $ticket_num; $ticket_index++) {
- $ticketCode .= "|" . sprintf("%d", $order_id);
- }
- $status_post_data['order_id'] = $order_id;
- $opera_per_price = $per_price;
- $opera_all_price = $all_price;
-
- $pdo_insert2 = conn1();
- // $opera_detail = "创建订单,出发日期{$run_main_info["RUN_DATE"]},订单渠道去哪儿汽车票,单价{$opera_per_price},总额{$opera_all_price},联系人信息:{$customer_name},{$customer_mobile},{$customer_id_no},备注信息:";
- // $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对接')";
- // $pdo_insert2->exec($sql_log);
- if( $back_order_id != false ) {
- $sql2 = " SELECT RUN_DATE FROM run_main WHERE RUN_ID = {$back_run_code} ";
- $result=$pdo->query($sql2);
- $bak_rowset=$result->fetchAll();
- $result->closeCursor();
- $back_run_main_info = $bak_rowset[0];
- $pdo_insert3 = conn1();
- // $opera_detail = "创建订单,出发日期{$back_run_main_info["RUN_DATE"]},订单渠道去哪儿汽车票,单价{$opera_per_price}总额,{$opera_all_price},联系人信息:{$customer_name},{$customer_mobile},{$customer_id_no},备注信息:";
- // $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对接')";
- // $pdo_insert3->exec($sql_log);
- $sql_log = "insert into to_from(to_orderid,back_orderid) VALUES ( {$order_id}, {$back_order_id})";
- $pdo_insert3->exec($sql_log);
- }
-
- $status_post_data['order_status'] = "451,452,453";
- post2("http://". CS_DOMAIN. "/st-xm/Api/add_order_status_log.php",$status_post_data);
-
- $send_post_data = array();
- $send_post_data["order_id"] = $order_id;
- $send_post_data["per_price"] = $opera_per_price;
- $send_post_data["ticket_num"] = $ticket_num;
- post2("http://". CS_DOMAIN. "/st-xm/Api/change_order_price.php",$send_post_data);
- if( $back_order_id != false ) {
- $send_post_data = array();
- $send_post_data["order_id"] = $back_order_id;
- $send_post_data["per_price"] = $opera_per_price;
- $send_post_data["ticket_num"] = $ticket_num;
- post2("http://". CS_DOMAIN. "/st-xm/Api/change_order_price.php",$send_post_data);
- }
- // $post_data["comment"] .= "提前一天19点之前,如未收到司机电话,请速与021-52218088联系。";
- //end of both way
- $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)));
- } else {
- $post_data["comment"] = "出票失败:" . $make_order_result["info"];
- if( isset($make_order_result["error"]) ) {
- $post_data["comment"] .= "({$make_order_result["error"]})";
- }
- $post_data["ticketInfo"] = json_encode(array("ret" => false, "data" => array("orderNo" => $out_order_no, "ticketStatu" => 1)));
- }
- $post_data["auth"] = get_qunar_auth($post_data);
- $complete_result = send_post_qunar(QUNAR_COMPLETE_ORDER_URL, $post_data, __LINE__);
- $complete_result_array = json_decode($complete_result, true);
-
- if ( isset($make_order_result["code"]) && $make_order_result["code"] == 0) {
- $comment_type = 0;
- $comment_text = "";
- $send_success = 0;
- //$sql1 = "CALL HT_ADD_MSG_COMMENT(2,'addmsg'," . $order_id . "," . $comment_type . ",'" . $comment_text . "','" . $tel . "','" . $content . "','" . date("Y-m-d H:i:s") . "',{$send_success})";
- //$result1 = $pdo->query($sql1);
- //$rowset1 = $result1->fetchAll(PDO::FETCH_ASSOC);
- //$result1->closeCursor();
-
- $pdo_send_msg = conn1();
- $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}' )";
- $pdo_send_msg->exec( $sql1 );
-
- if( $back_run_code != false ) {
- //$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})";
- //$result1 = $pdo->query($sql1);
- //$rowset1 = $result1->fetchAll(PDO::FETCH_ASSOC);
- //$result1->closeCursor();
- $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}' )";
- $pdo_send_msg->exec( $sql1 );
- }
- $pdo_update = conn1();
- $sql_update = " UPDATE outside_submit_order set submit_status=1 WHERE outside_order_no='{$out_order_no}'";
- $pdo_update->exec($sql_update);
- $sql_order_status = "update order_main set order_status =146 where order_id= " . $order_id . " or parent_order_id = " . $order_id;
- $pdo_update2 = conn1();
- $pdo_update2->exec($sql_order_status);
- if( $back_run_code != false ) {
- $sql_order_status2 = "update order_main set order_status =146 where order_id= " . $back_order_id . " or parent_order_id = " . $back_order_id;
- $pdo_update3 = conn1();
- $pdo_update3->exec($sql_order_status2);
- }
- }
- }
- }
- echo "success";
- exit();
-
- function get_msg_info($ORDER_ID) {
- $url='http://'. CS1_DOMAIN. '/api/msg/get-msg-info';
- $sendInfo=array();
- $sendInfo['order_id']= $ORDER_ID;
- $sendInfo['msg_type']='ota';
- $res_content = httpRequest($url,$sendInfo);
- $result_array = json_decode($res_content,true);
- return array(isset($result_array['name']) ? $result_array['name'] : "", isset($result_array['mobile']) ? $result_array['mobile'] : "", isset($result_array['content']) ? $result_array['content'] : "短信错误,联系客服!!!");
- }
-
- function post2($url, $post_data = '', $timeout = 5){//curl
- $ch = curl_init();
- curl_setopt ($ch, CURLOPT_URL, $url);
- curl_setopt ($ch, CURLOPT_POST, 1);
- if($post_data != ''){
- curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
- }
- curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
- curl_setopt($ch, CURLOPT_HEADER, false);
- $file_contents = curl_exec($ch);
- curl_close($ch);
- return $file_contents;
- }
-
- function send_post_qunar($url, $post_data, $line_no = 0 ) {
- writeLog( "------qunar get order result({$line_no}):".json_encode($post_data) );
- $postdata = http_build_query($post_data);
- $options = array(
- 'http' => array(
- 'method' => 'POST',
- 'header' => 'Content-type:application/x-www-form-urlencoded',
- 'content' => $postdata,
- 'timeout' => 15 * 60 // 超时时间(单位:s)
- )
- );
- $context = stream_context_create($options);
- $result = file_get_contents($url, false, $context);
- return $result;
- }
|