"907903_453318", "ticketNum" => 1, "contactName" => "测试001", "ticketPrice" => 69, "orderNo" => "BXcnfp2H".rand(0,999999), "contactPhone" => "13816608252", "contactId" => "310104198308317232", "date" => "2017-04-21", "startTime" => "13:30", "passengers" => array() ); //end of test 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 = $order_info["contactPhone"]; $customer_id_no = $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"]."*".$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"] = "出票失败:该线路已停售".__LINE__."|".$sql; $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 ); 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 ); 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"]}'"; $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 ); 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"] = "出票失败:该线路余票不足".__LINE__; $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 ); continue; } $run_code = $run_info["run_code"]; echo "outside run".__LINE__;exit(); 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); 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); } //出发地和目的地的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); 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); } } //update submit order $pdo_update = conn1(); $sql_update = " UPDATE order_main set order_status =146,PROD_SUPPLY_ORG_NAME='自在旅行' 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 ); 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 ); 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"] = "出票失败:该线路已停售".__LINE__."|".$limit_time."|".$station_run_time; $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 ); 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"] = "出票失败:该线路已停售".__LINE__; $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 ); continue; } $myprod = '{m'.$prod_id.'p'.$ticket_num.'|r'.$run_code.'}'; $mycustomer = '{,'.$customer_name.',,'.$customer_mobile.',150,'.$customer_id_no.',,,,'.$passengers_list.'}'; //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"] = "出票失败:该线路已停售".__LINE__; $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 ); 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); $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 ); 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 ); continue; } } else { $sql_insert = "call sp_make_order(" . $userid . ",'" . $myprod . "','" . $mycustomer . "', 28, '" . $out_order_no . "')"; $result = $pdo->query($sql_insert); $rowset = $result->fetchAll(PDO::FETCH_ASSOC); $result->closeCursor(); $post_data = array(); $post_data["agentId"] = QUNAR_AGENT_ID; $post_data["time"] = $current_time; if (is_array($rowset) && $rowset[0]['errcode'] == 0) { $order_id = $rowset[0]['order_id']; $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; //both way if( $back_run_code != false ) { $opera_per_price = $per_price / 2; $opera_all_price = $all_price / 2; $myprod2 = '{m'.$back_prod_id.'p'.$ticket_num.'|r'.$back_run_code.'}'; $sql_insert2 = "call sp_make_order(" . $userid . ",'" . $myprod2 . "','" . $mycustomer . "', 28, '" . $out_order_no . "')"; $result = $pdo->query($sql_insert2); if( $result != false ) { $rowset_back = $result->fetchAll(PDO::FETCH_ASSOC); $result->closeCursor(); } else { $rowset_back = false; } if (is_array($rowset_back) && $rowset_back[0]['errcode'] == 0) { $back_order_id = $rowset_back[0]['order_id']; $res_content2 = get_msg_info($back_order_id); $content2 = $res_content2[2]; $post_data["comment"] .= $content2 ; $status_post_data['order_id'] = "{$order_id},{$back_order_id}"; } else { $sql = "CALL SP_CANCEL_ORDER(" . $user_id . "," . $order_id . ")"; $result = $pdo->query($sql); $result->closeCursor(); $post_data["comment"] = "出票失败:" . $rowset[0]['errinfo']; $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); $complete_result_array = json_decode($complete_result, true); continue; } } else { $back_order_id = false; } $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"] = "出票失败:" . $rowset[0]['errinfo']; $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); $complete_result_array = json_decode($complete_result, true); if (is_array($rowset) && $rowset[0]['errcode'] == 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) { //writeLog( "------qunar get order result:".json_encode($post_data) ); echo 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; */ }