<?php
if (!defined('BASEPATH')) 
	exit('No direct script access allowed');

class reschedule extends CI_Controller{
	public function __construct(){
        parent::__construct();
		$this->load->helper('train');
		$this->load->model("train_system_model");
    }
	
	public function index(){
		echo 'reschrdule';
	}
	
	//携程改签模块
	public function ctripModel(){
		$orderNumber = $this->input->get_post('orderNumber');
		$orderNumber = 'guilintravel1573543590265';
		if(empty($orderNumber)){
			exit('orderNumber error');
		}else{
			//接收改签的火车参数
			$RescheduleTrainNumber = $this->input->get_post('RescheduleTrainNumber');
			$DepartStationName = $this->input->get_post('DepartStationName');
			$ArriveStationName = $this->input->get_post('ArriveStationName');
			$RescheduleDepartTime = $this->input->get_post('RescheduleDepartTime');
			$RescheduleArriveTime = $this->input->get_post('RescheduleArriveTime');
			$RescheduleTicketPrice = $this->input->get_post('RescheduleTicketPrice');
			$RescheduleSeatName = $this->input->get_post('RescheduleSeatName');
			$RescheduleAcceptSeatName = $this->input->get_post('RescheduleAcceptSeatName');
			$PassagerName = $this->input->get_post('PassagerName');
			$Ticketype = $this->input->get_post('Ticketype');
			$IdentityType = $this->input->get_post('IdentityType');
			$PassagerId = $this->input->get_post('PassagerId');
			$Coach = $this->input->get_post('Coach');
			$Seat = $this->input->get_post('Seat');
			
			//开始改签流
			$postData = array();
			$time = date('Y-m-d H:i:s',time());
			$postData['Authentication'] = new stdClass();
			$postData['Authentication']->TimeStamp = $time;
			$postData['Authentication']->ServiceName = 'order.partnerreschedule';
			$postData['Authentication']->PartnerName = 'Ctrip.Corp';
			$MessageIdentity = md5($time.'order.partnerreschedule'.ORDERKEY);
			$postData['Authentication']->MessageIdentity = $MessageIdentity;
			
			$postData['TrainOrderService'] = new stdClass();
			$postData['TrainOrderService']->OrderNumber = $orderNumber;
			$postData['TrainOrderService']->Operator = 'guilintravel';
			$postData['TrainOrderService']->RescheduleTrainNumber = $RescheduleTrainNumber;
			$postData['TrainOrderService']->DepartStationName = $DepartStationName;
			$postData['TrainOrderService']->ArriveStationName = $ArriveStationName;
			$postData['TrainOrderService']->RescheduleDepartTime = $RescheduleDepartTime;
			$postData['TrainOrderService']->RescheduleArriveTime = $RescheduleArriveTime;
			$postData['TrainOrderService']->RescheduleTicketPrice = $RescheduleTicketPrice;
			$postData['TrainOrderService']->RescheduleSeatName = $RescheduleSeatName['0'];
			//$postData['TrainOrderService']->RescheduleAcceptSeatName = '无座';
			
			$postData['TrainOrderService']->RescheduleTicketPassengerInfos = array();
			
			foreach ($PassagerName as $key=>$name){
				$postData['TrainOrderService']->RescheduleTicketPassengerInfos[$key] = new stdClass();
				$postData['TrainOrderService']->RescheduleTicketPassengerInfos[$key]->eOrderNumber = '';
				if($Ticketype[$key] == '儿童票'){
					$postData['TrainOrderService']->RescheduleTicketPassengerInfos[$key]->eOrderType = 2;
				}else{
					$postData['TrainOrderService']->RescheduleTicketPassengerInfos[$key]->eOrderType = 1;
				}
				$postData['TrainOrderService']->RescheduleTicketPassengerInfos[$key]->realName = $name;
				$postData['TrainOrderService']->RescheduleTicketPassengerInfos[$key]->CarriageNo = $Coach[$key];
				$postData['TrainOrderService']->RescheduleTicketPassengerInfos[$key]->seatNumber = $Seat[$key];
				$postData['TrainOrderService']->RescheduleTicketPassengerInfos[$key]->passportName = $name;
				$postData['TrainOrderService']->RescheduleTicketPassengerInfos[$key]->passport = $PassagerId[$key];
			}
			
			//print_r(json_encode($postData));die();
			$url = 'http://apiproxy.ctrip.com/apiproxy/soa2/13680/PartnerReschedule';
			$responseJson = GetPost_http($url,json_encode($postData),'json');
			print_r($responseJson);
			}
		}
}