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

class callback extends CI_Controller{
	public function __construct(){
        parent::__construct();
		$this->load->helper('train');
		$this->load->model("train_system_model");
		$this->load->model("BIZ_train_model");
		$this->train_certificateType = $this->config->item('train_certificateType');
		$this->train_refundType = $this->config->item('train_refundType');
    }
	
	public function juhecallback(){
		$data_post = $this->input->post();
		if(empty($data_post)){
			header("HTTP/1.1 404 Not Found");
			exit('{"reason":"empty infos","status":"404"}');
		}
		
		//调试代码
		/*$test_post = '{"data":"{\"from_station_name\":\"\u897f\u5b89\u5317\",\"from_station_code\":\"EAY\",\"to_station_name\":\"\u6210\u90fd\u4e1c\",\"to_station_code\":\"ICW\",\"train_date\":\"2019-08-28\",\"orderid\":\"JH156560045168263\",\"user_orderid\":\"488142637\",\"orderamount\":\"526.00\",\"ordernumber\":\"EF88544299\",\"checi\":\"D1905\",\"msg\":\"\u51fa\u7968\u6210\u529f\",\"status\":\"4\",\"passengers\":[{\"passengerid\":1,\"passengersename\":\"SAIES ALLEN\",\"piaotype\":\"1\",\"piaotypename\":\"\u6210\u4eba\u7968\",\"passporttypeseid\":\"B\",\"passporttypeseidname\":\"\u62a4\u7167\",\"passportseno\":\"LT192822\",\"price\":\"263.0\",\"zwcode\":\"O\",\"zwname\":\"\u4e8c\u7b49\u5ea7\",\"ticket_no\":\"EF88544299108007A\",\"cxin\":\"08\u8f66\u53a2,07A\u5ea7\",\"reason\":0},{\"passengerid\":2,\"passengersename\":\"WOODCROFT\",\"piaotype\":\"1\",\"piaotypename\":\"\u6210\u4eba\u7968\",\"passporttypeseid\":\"B\",\"passporttypeseidname\":\"\u62a4\u7167\",\"passportseno\":\"516130469\",\"price\":\"263.0\",\"zwcode\":\"O\",\"zwname\":\"\u4e8c\u7b49\u5ea7\",\"ticket_no\":\"EF88544299102008F\",\"cxin\":\"02\u8f66\u53a2,08F\u5ea7\",\"reason\":0}],\"refund_money\":null,\"sign\":\"4c4a581e1f5205254e22e6ca1dde59bb\"}"}';
		$data_post["data"] = json_decode($test_post)->data;*/
		
		log_message('error','聚合回调：'.json_encode($data_post));
		$data = json_decode($data_post["data"]);
		//print_r($data);die();
		$update_data = new StdClass();
		$update_data->OrderStatus = $data->status;
		$update_data->ordernumber = $data->orderid;
		$update_data->OrderTotleFee = $data->orderamount;
		$update_data->seatsinfo = '';
		$update_data->TicketCheck = '';
		$update_data->bookcallback = '';
		$update_data->confirmcallback = '';
		$update_data->returncallback = '';
		$update_data->ElectronicOrderNumber = $data->ordernumber;
		$update_data->reschedulecallback = '';
		$update_data->ErrorMsg = $data->msg;
		$update_data->OrderTicketTime = '';

		//如果返回2则发送出票请求
		if($data->status == "1"){
			$update_data->bookcallback = $data_post["data"];
		}elseif($data->status == "2"){
			$coach = array();
			$seats = array();
			$string = '';
			$passagers = $data->passengers;
			foreach($passagers as $item){
				foreach(explode(',',$item->cxin) as $item_seat){
					if(strpos($item_seat,'车厢')){
						$item_seat = str_replace('车厢','',$item_seat);
						array_push($coach,$item_seat);
					}else{
						$find = array('座上铺','座中铺','座下铺','座');
						$replace = array(' upper',' middle',' lower','');
						$item_seat = str_replace($find,$replace,$item_seat);
						array_push($seats,$item_seat);
					}
				}
				
				//对订票乘客进行存储
				$data_passager = new stdClass();
				$data_passager->ordernumber = $data->orderid;
				$data_passager->realname = $item->passengersename;
				$data_passager->identitytype = $item->passporttypeseidname;
				$data_passager->numberid = $item->passportseno;
				$data_passager->ticketype = $item->piaotypename;
				$data_passager->ticketprice = $item->price;
				$data_passager->seatype = $item->zwname;
				$data_passager->seatdetail = $item->cxin;
				$data_passager->status = '4';
				$this->train_system_model->add_passagers($data_passager);
			}
			
			//判断车厢是否唯一，如果不唯一的话，分成两个车厢
			if(count(array_unique($coach)) == 1){
				$onlycoach = array_unique($coach);
				$string .= 'Coach '.$onlycoach[0].',Seat ';
				foreach($seats as $item_seat){
					$string .= $item_seat.',';
				}
			}else{
				for ($i=0;$i<count($coach);$i++){
					if($i == 0){
						$string .= 'Coach '.$coach[$i].',Seat '.$seats[$i].',';
					}else{
						if($coach[$i] == $coach[$i-1]){
							$string .= $seats[$i].',';
						}else{
							$string .= 'Coach '.$coach[$i].',Seat '.$seats[$i].',';
						}
					}
				}
			}
			
			$update_data->seatsinfo = substr($string,0,strlen($string)-1);
			
            $post_data = array(
                        "key"=>JUHE_TRAIN_API_KEY,
                        "orderid"=>$data->orderid
                            );
            $back_json = GetPost_http(JUHE_TRAIN_PAY_API,$post_data);
            $update_data->bookcallback = $data_post["data"];
		}elseif($data->status == "4"){
			$add_train_order_data = new stdClass();
			$add_train_order_data->TOC_Memo = $data->orderid." 聚合出票";
            $add_train_order_data->TOC_COLD_SN = $data->user_orderid;
            $add_train_order_data->TOC_TrainNumber = $data->checi;
            $add_train_order_data->TOC_DepartureDate = $data->train_date;
            $add_train_order_data->TOC_TicketCost = $data->orderamount;
            $add_train_order_data->poundage = (count($data->passengers)*2)."";//手续费，每人两块，转换成字符串
            $add_train_order_data->FOI_TrainNetOrderNo = $data->ordernumber;
			$add_train_order_data->TOC_VEI_SN = 30427;
			$this->BIZ_train_model->add_train_payment($add_train_order_data);
			
			$update_data->confirmcallback = $data_post["data"];
			$this->BIZ_train_model->update_cold_planvei_sn($data->user_orderid,'30427');
			
			//查询子订单状态,如果为41标记过问题订单的就把状态置位42,反之不操作
			$coldState = $this->BIZ_train_model->getColdState($data->user_orderid);
			if($coldState->COLD_State == 41){
				$this->BIZ_train_model->updateColdState($data->user_orderid);
			}
		}elseif($data->status=="5"){
			$update_data->confirmcallback = $data_post["data"];
		}elseif($data->status=="7"){
			//退票成功 写入TOC表
            $newtime = "";//记录最新操作时间
            $refund_passportseno = "";//退票人护照号
            $refund_money = "";//退票金额
            foreach ($data->passengers as $p) {
                if(isset($p->returntickets)){
					$refund_passportseno = $p->refundTimeline[count($p->refundTimeline)-1]->detail->passportseno;
					$refund_money = $p->refundTimeline[count($p->refundTimeline)-1]->detail->returnmoney;
					//退票时还需要单独对对每个乘客存储回调信息
					$passpager_info = new stdClass();
					$passpager_info->returncallback = $data_post["data"];
					$passpager_info->status = '7';
					$passpager_info->ordernumber = $data->orderid;
					$passpager_info->realname = $p->refundTimeline[count($p->refundTimeline)-1]->detail->passengername;
					$passpager_info->numberid = $refund_passportseno;
					$this->train_system_model->update_passpager_info($passpager_info);
					
					//添加退款记录
					$add_train_order_data = new stdClass();
					$add_train_order_data->TOC_COLD_SN = $data->user_orderid;
					$add_train_order_data->TOC_Memo = $data->orderid." ".$refund_passportseno;
					$add_train_order_data->ordernumber = $data->user_orderid;
					$add_train_order_data->TOC_TrainNumber = $data->checi;
					$add_train_order_data->TOC_DepartureDate = $data->train_date;
					$add_train_order_data->TOC_TicketCost = -$refund_money;
					$add_train_order_data->FOI_TrainNetOrderNo = null;//退票不用更新取票号，以此在模型里面判断是否为退票消息
					$add_train_order_data->TOC_VEI_SN = 30427;
					$this->BIZ_train_model->add_train_payment($add_train_order_data);
				}else{
					//有可能提交了退票或者还没有退票
					
				}
            }
			
			$update_data->returncallback = $data_post["data"];
		}
		//print_r($update_data);die();
		//更新订单信息(出票系统)
		$this->train_system_model->update_orders($update_data);
	}
	
	public function shuntucallback(){
		$back_json = file_get_contents('php://input');
		log_message('error','携程顺途回调信息：'.$back_json);

		
		$ctrip_backdata = json_decode($back_json);
		// print_r($ctrip_backdata);
		// die();

		if(!empty($ctrip_backdata)){

			//判断回调信息是否正确，主要判断是否是本企业的回调信息
			$TimeStamp = $ctrip_backdata->authentication->timeStamp;
			$serviceName = $ctrip_backdata->authentication->serviceName; //每个接口都有自己名称
			$companyId = COMPANYID;
			$key = CTRIPKEY;

			/** 测试服务器 */
			$strSign = $TimeStamp.$serviceName.$companyId.$key; //加密前的令牌
			$Sign = md5($strSign);
			$messageIdentity = $ctrip_backdata->authentication->messageIdentity;
			$ResultNoticeResponse = new stdClass();
			if ($Sign == $messageIdentity){
				$ResultNoticeResponse->returnCode = 1;
				$ResultNoticeResponse->returnMsg = "success";
			}else {
				$ResultNoticeResponse->returnCode = 0;
				$ResultNoticeResponse->returnMsg = "messageIdentity is error!";
			}
			echo json_encode($ResultNoticeResponse);

			//处理回调的内容，保存到本地及翰特
			$update_data = new stdClass();
			$update_data->ServiceName = $ctrip_backdata->authentication->serviceName;
			$update_data->ordernumber = '';
			$update_data->seatsinfo = '';
			$update_data->TicketCheck = '';
			$update_data->bookcallback = '';
			$update_data->confirmcallback = '';
			$update_data->returncallback = '';
			$update_data->OrderTotleFee = 0;
			$update_data->ElectronicOrderNumber = '';
			$update_data->reschedulecallback = '';
			$update_data->OrderTicketTime = '';
			//新字段
			$update_data->operateTradeNo ="";

			
			if($update_data->ServiceName == 'notice.ticketresult'){
				if ( $ctrip_backdata->ticketResult->resultCode == 1){
					$update_data->OrderStatus = '4';
					if (isset($ctrip_backdata->ticketResult->resultMsg)){
						$update_data->ErrorMsg =   $ctrip_backdata->ticketResult->resultMsg;
					} else {
						$update_data->ErrorMsg =  '出票成功';
					}
				}else{
					$update_data->OrderStatus = '5';
					if (isset($ctrip_backdata->ticketResult->resultMsg)){
						$update_data->ErrorMsg = $ctrip_backdata->ticketResult->resultMsg;  
					}else{
						$update_data->ErrorMsg = '出票失败';
					}
				}				
				$update_data->ordernumber = $ctrip_backdata->ticketResult->companyOrderId;
				if (isset($ctrip_backdata->ticketResult->orderMasterInfo->totalPayAmount)){
					$update_data->OrderTotleFee = $ctrip_backdata->ticketResult->orderMasterInfo->totalPayAmount;   //总价
				}		
				if (isset($ctrip_backdata->ticketResult->operateTradeNo))	{
					$update_data->operateTradeNo = $ctrip_backdata->ticketResult->operateTradeNo;  //操作流水号   如产生差额退款或者无票退款，退款通知里会有相同的操作流水号做对应。
				}	
				
				$update_data->ticketresultcallback = $back_json;
				//$update_data->OrderTicketTime = $ctrip_backdata->TrainOrderService->OrderInfo->TicketInfo->OrderTicketTime;

				//新接口数据,不一定保存到数据库里面，原订单已有，做个记录
				if (isset( $ctrip_backdata->ticketResult->ticketSuccTime)){
					$update_data->ticketSuccTime = $ctrip_backdata->ticketResult->ticketSuccTime;  //出票成功时间
				}
				$update_data->orderType = $ctrip_backdata->ticketResult->orderMasterInfo->orderType; //订单类型 0电子票 1配送票 2人工客票 3抢票订单
				$update_data->contactName = $ctrip_backdata->ticketResult->orderMasterInfo->contactName; //联系人
				$update_data->mobileNo = des_decrypt($ctrip_backdata->ticketResult->orderMasterInfo->mobileNo,$key); //联系电话 (DES加密）
				
				//人员及车票
				$data_passager = new stdClass();

				foreach ( $ctrip_backdata->ticketResult->passengerInfoList as $pItems) {
					$data_passager->ordernumber = $ctrip_backdata->ticketResult->companyOrderId;
					//人员列表
					$data_passager->status = '4';
					$certificateType = $this->train_certificateType[ $pItems->certificateType]; //证件类型，身份证传1、护照2、回乡证7、台胞证8、外国人永久居留身份证28、港澳台居民居住证32；
					$data_passager->identitytype = $certificateType;
					$data_passager->realname = $pItems->certificateName;
					$data_passager->numberid =  des_decrypt($pItems->certificateNo,$key) ;   //证件号码 (DES加密）
					$data_passager->birthday = $pItems->birthday;
					if ($pItems->passengerType==2){
						$passengerType = "儿童";
					}else{
						$passengerType = "成人";
					}
					$data_passager->ticketype = $passengerType;  //乘客类型  1成人 2儿童
					$passengerId = $pItems->passengerId;
					foreach ( $ctrip_backdata->ticketResult->orderRouteInfoList as $rItems ){
						//行程，目前我们都是单程提交，所以这里应该只有单程
						$routeId = $rItems->routeId;

						if (isset($rItems->elecNo)){
							$elecNo = $rItems->elecNo; //电子订单号，即12306取票号
							$update_data->ElectronicOrderNumber = $elecNo ;
						}
						if (isset($rItems->checkWindow)){
							$checkWindow = $rItems->checkWindow; //检票口
							$update_data->TicketCheck = $checkWindow;
						}
						$data_passager->seatype =  $rItems->ticketSeat;

						$update_data->trainNo = $rItems->trainNo; //车次
						$update_data->departTime = $rItems->departTime; //车次出发时间	
						
						
						$orderTicketInfoList = $ctrip_backdata->ticketResult->orderTicketInfoList ;
						if (!empty($orderTicketInfoList)){
							foreach ($orderTicketInfoList as $tItems) {
								//对应的车票列表
								if ($passengerId == $tItems->passengerId && $routeId==$tItems->routeId){
	
									$data_passager->ticketprice = $tItems->realTicketPrice;
									$SeatNo = "";
									if (isset($tItems->carriageNo)){
										$SeatNo.=$tItems->carriageNo."车厢";
									}
									if (isset($tItems->seatNo)){
										$SeatNo.=$tItems->seatNo;
									}
									$data_passager->seatdetail = $SeatNo;
									$data_passager->longtrainno =  $tItems->longElecNo;
									$data_passager->lanhaiData = ""; //对应澜海那边的数据，这边设置为空
	
									//入库
									$this->train_system_model->add_passagers($data_passager);
								}
							}
						}

					}


				}


				/****************************************************************************************/
				//添加支付记录
				$add_train_payment_data = new stdClass();
				$add_train_payment_data->TOC_Memo = $update_data->ordernumber.'出票费';
				$add_train_payment_data->TOC_VEI_SN = "28209";
				
				//根据订单号获取cold_sn
				$order_info = $this->train_system_model->get_order_info($update_data->ordernumber);
				$cold_sn = $order_info->ts_cold_sn;
				$add_train_payment_data->TOC_COLD_SN = $cold_sn;
				$add_train_payment_data->TOC_TrainNumber = $update_data->trainNo;
				$add_train_payment_data->TOC_DepartureDate = date('Y-m-d',strtotime($update_data->departTime ));
				$add_train_payment_data->TOC_TicketCost = $update_data->OrderTotleFee;
				$add_train_payment_data->poundage = "0";
				$add_train_payment_data->FOI_TrainNetOrderNo = $update_data->ElectronicOrderNumber; //电子票号
				//print_r($add_train_order_data);die();
				$this->BIZ_train_model->add_train_payment($add_train_payment_data);
				//记录供应商(瀚特)
				$this->BIZ_train_model->update_cold_planvei_sn($cold_sn,'28209');
			}else if($update_data->ServiceName == 'notice.ordercancel'){ //订单取消
				$update_data->ordernumber = $ctrip_backdata->cancelResult->companyOrderId;
				$update_data->OrderStatus = '12';
				$update_data->ErrorMsg = '订单取消'.$ctrip_backdata->cancelResult->cancelTime;
				$update_data->confirmcallback = $back_json;
			}else if($update_data->ServiceName == 'notice.refundresult'){ //退款通知
				$refundType =  $ctrip_backdata->refundResult->refundType; //退款类型int
				$reason =  $ctrip_backdata->refundResult->reason; //退款原因
				$refundTime = $ctrip_backdata->refundResult->refundTime; //退款时间
				$return_money = $ctrip_backdata->refundResult->refundAmount; //退款金额

				$update_data->ordernumber = $ctrip_backdata->refundResult->companyOrderId;
				if ($refundType=="1"){
					$update_data->OrderStatus = '10';
				}else{
					$update_data->OrderStatus = '11';
				}
				$update_data->ErrorMsg = '退款:'.$this->train_refundType[$refundType]." 金额:".$return_money."  time:". $refundTime;
				$update_data->refundcallback = $back_json;

				//翰特添加退款记录
				$refund_train_payment = new stdClass();
				$return_order = $ctrip_backdata->refundResult->companyOrderId;
			
				$refund_train_payment->TOC_VEI_SN = "28209";
					
				//根据订单号获取cold_sn
				$order_info = $this->train_system_model->get_order_info($return_order);
				$cold_sn = $order_info->ts_cold_sn;
				//print_r($order_info);

				//获取longElecNo（长电子订单号）用来判断是否是多张票退款
				$longElecNo="";
				if (isset($ctrip_backdata->refundResult->refundDetailInfoList)){
					$refundDetailInfoList = $ctrip_backdata->refundResult->refundDetailInfoList;
					$longElecNo = $refundDetailInfoList[0]->longElecNo;
				}
				

				$memo = $return_order.'_'.$this->train_refundType[$refundType].'_长电子订单号:'. $longElecNo . '_' . $refundTime; //退款集合信息
				$refund_train_payment->TOC_Memo = $memo;
				$refund_train_payment->TOC_COLD_SN = $cold_sn;
				$refund_train_payment->TOC_TrainNumber = $order_info->ts_checi;
				$refund_train_payment->TOC_DepartureDate = $order_info->ts_startdate;
				$refund_train_payment->TOC_TicketCost = -$return_money;
				//print_r($add_train_payment_data);die();
				$this->BIZ_train_model->refund_train_payment($refund_train_payment);

			}else if($update_data->ServiceName == 'notice.returnresult'){ //退票
				$update_data->ordernumber = $ctrip_backdata->returnResult->companyOrderId;
				$resultCode = $ctrip_backdata->returnResult->resultCode;			
				$update_data->ErrorMsg = $ctrip_backdata->returnResult->resultMsg;
				$longElecNo = $ctrip_backdata->returnResult->longElecNo;
				$returnSuccTime = $ctrip_backdata->returnResult->returnSuccTime; //退票成功时间 yyyy-MM-dd hh:mm:ss
				$printStatus = $ctrip_backdata->returnResult->printStatus;  //1 已取票  2未取票  0未知
				$preRefundAmount =  $ctrip_backdata->returnResult->preRefundAmount;  // 预计退票退款
				$sxfAmount= $ctrip_backdata->returnResult->sxfAmount;  //退票手续费
				$operateTradeNo = $ctrip_backdata->returnResult->operateTradeNo; //操作流水号   退款通知里会有相同的操作流水号做对应。
				$update_data->operateTradeNo=$operateTradeNo;

				$passpager_info = new stdClass();
				$passpager_info->returncallback = $back_json;
				$passpager_info->ordernumber = $ctrip_backdata->returnResult->companyOrderId;
				$passpager_info->longElecNo = $longElecNo;
				if ($resultCode=="1"){
					//退票成功
					$update_data->OrderStatus = '7';
					//退票时还需要单独对对每个乘客存储回调信息
					$passpager_info->status = '7';
					//保存退票成功信息到trainsystem
					if ($printStatus==1){
						$pintmsg="已取票";
					}else if($printStatus==2){
						$pintmsg="未取票";
					}else{
						$pintmsg="";
					}
					$msg = "退票成功:".$ctrip_backdata->returnResult->resultMsg."(".$returnSuccTime.",".$pintmsg.",预计退票退款:".$preRefundAmount.",手续费:".$sxfAmount.")";
					$update_data->ErrorMsg=$msg;

					//退票手续费保存到数据库
					//翰特添加退款记录
					$returnticket = new stdClass();
					$return_order = $ctrip_backdata->returnResult->companyOrderId;
				
					$returnticket->TOC_VEI_SN = "28209";
						
					//根据订单号获取cold_sn
					$order_info = $this->train_system_model->get_order_info($return_order);
					$cold_sn = $order_info->ts_cold_sn;
					//print_r($order_info);

					//获取longElecNo（长电子订单号）用来判断是否是多张票
					$longElecNo=$ctrip_backdata->returnResult->longElecNo;
					$returnSuccTime = $ctrip_backdata->returnResult->returnSuccTime;

					$memo = $return_order.'_长电子订单号:'. $longElecNo . '_' . $returnSuccTime; //退款集合信息
					$returnticket->TOC_Memo = $memo;
					$returnticket->TOC_COLD_SN = $cold_sn;
					$returnticket->TOC_TrainNumber = $order_info->ts_checi;
					$returnticket->TOC_DepartureDate = $order_info->ts_startdate;
					$returnticket->TOC_TicketCost = -$sxfAmount>0?$sxfAmount:15;
					//print_r($add_train_payment_data);die();
					$this->BIZ_train_model->returnticket_train($returnticket);

					
				}else{
					//退票失败
					$update_data->OrderStatus = '8';
					//失败也保存下信息
					$passpager_info->status = '8';
					
				}
				$this->train_system_model->return_update_passpager_info($passpager_info);
				$update_data->returncallback = $back_json;	


			}elseif($update_data->ServiceName == 'web.order.returnRescheduleResult'){
				$update_data->ordernumber = $ctrip_backdata->TrainOrderService->OrderNumber;
				$update_data->OrderStatus = '7';
				$update_data->ErrorMsg = $ctrip_backdata->TrainOrderService->refundRescheduleTicket->reason;
				$update_data->returncallback = $back_json;
				
				$passpager_info = new stdClass();
				$passpager_info->returncallback = $back_json;
				$passpager_info->status = '7';
				$passpager_info->ordernumber = $ctrip_backdata->TrainOrderService->OrderNumber;
				$passpager_info->realname = $ctrip_backdata->TrainOrderService->refundRescheduleTicket->realName;
				$passpager_info->numberid = $ctrip_backdata->TrainOrderService->refundRescheduleTicket->passport;
				$this->train_system_model->update_passpager_info($passpager_info);
			}else if($update_data->ServiceName == 'web.order.requestRefund'){
				// $return_order = $ctrip_backdata->TrainOrderService->OrderInfo->OrderNumber;
				// $return_money = $ctrip_backdata->TrainOrderService->TotalRefundAmount;
					
				// //根据订单号获取cold_sn
				// $order_info = $this->train_system_model->get_order_info($return_order);
				// $cold_sn = $order_info->ts_cold_sn;
				// //print_r($order_info);
				
				// $add_train_payment_data->TOC_Memo = $return_order.'_'.$ctrip_backdata->TrainOrderService->OrderInfo->OrderTid;
				// $add_train_payment_data->TOC_COLD_SN = $cold_sn;
				// $add_train_payment_data->TOC_TrainNumber = $order_info->ts_checi;
				// $add_train_payment_data->TOC_DepartureDate = $order_info->ts_startdate;
				// $add_train_payment_data->TOC_TicketCost = -$ctrip_backdata->TrainOrderService->TotalRefundAmount;
				// $add_train_payment_data->FOI_TrainNetOrderNo=null;
				// //print_r($add_train_payment_data);die();
				// $this->BIZ_train_model->add_train_payment($add_train_payment_data);
				// return false;
			}else if ($update_data->ServiceName == 'web.order.rescheduleResult'){
				$update_data->ordernumber = $ctrip_backdata->TrainOrderService->OrderInfo->OrderNumber;
				$reschedule_status = $ctrip_backdata->TrainOrderService->OrderInfo->RescheduleTicketInfo->RescheduleTickets->RescheduleTicket->status;
				if($reschedule_status){
					$update_data->OrderStatus = '9';
					$update_data->ErrorMsg = '改签成功';
					
					$passpager_info = new stdClass();
					$passpager_info->returncallback = $back_json;
					$passpager_info->status = '9';
					$passpager_info->ordernumber = $ctrip_backdata->TrainOrderService->OrderInfo->OrderNumber;
					$passpager_info->realname = $ctrip_backdata->TrainOrderService->OrderInfo->RescheduleTicketInfo->RescheduleTickets->RescheduleTicket->passportName;
					$passpager_info->numberid = $ctrip_backdata->TrainOrderService->OrderInfo->RescheduleTicketInfo->RescheduleTickets->RescheduleTicket->passport;
					$this->train_system_model->update_passpager_info($passpager_info);
				}else{
					$update_data->OrderStatus = '5';
					$update_data->ErrorMsg = '改签失败';
				}
				$update_data->reschedulecallback = $back_json;
			}
			//更新订单信息(出票系统)
			$this->train_system_model->update_orders($update_data);

			// //返回结果
			// $returnResult = new stdClass();
			// $returnResult->returnCode = 1;
			// $returnResult->returnMsg = "";
			// echo(json_encode($returnResult));
		}
	}
}