<?php
header("Access-Control-Allow-Origin:*");
 require_once 'Common/Mysql.php';
 require_once 'Common/Function.php';
/**
 * $prodID=$_REQUEST['prodID'];
 * 
 * @var string
 */ 
$pdo = conn();
$sql  ="SELECT run_id FROM `run_bus_station_view_temp`;";
$result=$pdo->query($sql);
 $rowset = $result -> fetchAll(PDO::FETCH_ASSOC);

 foreach ($rowset as $key => $value) {
 	# code...
 	set_memcache('orderList['.$value['run_id'].']',get_memcache('orderList_temp['.$value['run_id'].']'));
 	
 	

 }

die;
die;

$order_id = 475149;// 474466 474296  474103  473925 473899  473896  473442  473287  473258  472591 
// 472534  472486  472425  471569  471171  470954 470342  469288  468900 467973 467407  474325 474214    474544  470384   474879  474892
//  474113  474014  473218  473083467968  466002

$list = Find($order_id);
//echo $list['run_id'];die;

if($list['line_id'] ==449865){
	
	$start =1;
	$end =9;

}elseif($list['line_id'] ==449860){

	$start =0;
	$end =8;
}
 $result =  post2('http://wx.zhizhuchuxing.com/ZZDZ2/application/api/co.php',array(
 				'prodID'=>$list['line_id'],
              'runID' =>$list['run_id'],
              'orderID'=>$order_id,
              'run_date'=>$list['run_time'],
              'num'=>$list['tic_num'],
              'station_start'=>$start,
              'station_end'=>$end
			 ));



echo  json_encode(array($result));





 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 Find($order_id){
    $pdo=  conn();
        $sql = "select  order_description,order_price,order_pay_main_id "
                . "from order_main "
                . "where order_id=".$order_id;
        $result=$pdo->query($sql);
        $rowset = $result -> fetchAll(PDO::FETCH_ASSOC);
        $order_price = $rowset[0];//订单总价格  订单票的数量
        $sql = "SELECT DISTINCT 
            order_description,parent_order_id,run_date,run_id,run_time,run_bus_order_id,prod_id,parent_prod_id,PROD_START_STATION_AREA_NAME,PROD_START_STATION_RES_NAME,PROD_END_STATION_AREA_NAME,PROD_END_STATION_RES_NAME  
            FROM `order_main` 
            where  PARENT_ORDER_ID=".$order_id;
        $result=$pdo->query($sql);
        $rowset = $result -> fetchAll(PDO::FETCH_ASSOC);
        $order_station = $rowset[0];//订单来往地址  订单时间 订单好
        if(empty($order_station))
            return false;
        $array_order_desc=array();

        $arr_temp = explode('|',$order_price['order_description']);
        $arr=array();
        foreach ($arr_temp as $k=>$v2) {
            if(!empty($v2))
            $array_order_desc[]=  explode (',', $v2);   //订单票  * 数量
        }  
        $list = array();  
        //上海(黄浦旅游集散站)    -      乌镇(西栅1号停车场)//反的数组
        $list['station'] = $order_station['PROD_START_STATION_AREA_NAME'].'('.$order_station['PROD_START_STATION_RES_NAME'].')'
                            .'-'.$order_station['PROD_END_STATION_AREA_NAME'].'('.$order_station['PROD_END_STATION_RES_NAME'].')';
        $list['start_station']=$order_station['PROD_START_STATION_AREA_NAME'];
        $list['end_station']=$order_station['PROD_END_STATION_AREA_NAME'];
        $list['start_res_name'] = $order_station['PROD_START_STATION_RES_NAME'];
         $list['end_res_name'] = $order_station['PROD_END_STATION_RES_NAME'];
         $list['run_date'] = $order_station['run_date'];
        $list['run_time'] = $order_station['run_date'].' '.$order_station['run_time'];
         $list['count']='';
         $list['tic_num'] = 0;
        foreach ($array_order_desc as $v){
            $list['count'] .= ' '.$v[0].' × '.$v[2];
            $list['tic_num'] +=$v[2] ;
        }
        
        $list['order_price'] = $order_price['order_price'];
        $sql = "select pay_serial_number from order_pay_detail where pay_main_id =".$order_price['order_pay_main_id'];
        $result=$pdo->query($sql);
        $rowset = $result -> fetchAll(PDO::FETCH_ASSOC);
        $list['pay_num'] = $rowset[0]['pay_serial_number'];
        $list['line_id'] = $order_station['parent_prod_id'];
        $list['run_id'] = $order_station['run_id'];//run_bus_order_id
          $list['run_bus_order_id'] = $order_station['run_bus_order_id'];//parent_order_id
          $list['parent_order_id'] = $order_station['parent_order_id'];
           $list['prod_id'] = $order_station['prod_id'];
        return $list;
}