예제 #1
0
 public function cancelBooking($bookingId)
 {
     $nemo = new GDSNemoAgency();
     $response = $nemo->CancelBooking($bookingId);
     return $response;
 }
예제 #2
0
 public function getIsValid()
 {
     $request = new GDSNemoAgency();
     return $request->checkFlight($this->flightKey);
 }
예제 #3
0
 public function stageTicketingRepeat()
 {
     $this->status('ticketingError');
     return;
     //pass;
     $this->flightBooker->tryCount++;
     $this->flightBooker->save();
     if ($this->flightBooker->tryCount > 3) {
         $this->status('ticketingError');
     } else {
         $flightTicketingParams = new FlightTicketingParams();
         $flightTicketingParams->nemoBookId = $this->flightBooker->nemoBookId;
         $flightTicketingParams->pnr = $this->flightBooker->pnr;
         /** @var FlightTicketingResponse $flightTicketingResponse  */
         $flightTicketingResponse = Yii::app()->gdsAdapter->FlightTicketing($flightTicketingParams);
         SWLogActiveRecord::$requestIds = array_merge(SWLogActiveRecord::$requestIds, GDSNemoAgency::$requestIds);
         GDSNemoAgency::$requestIds = array();
         if ($flightTicketingResponse->status == 1) {
             $this->status('ticketReady');
         } else {
             //TODO: переставить стутус через время T + считать количество раз.
             $res = Yii::app()->cron->add(time() + appParams('flight_repeat_time'), 'flightbooking', 'ChangeState', array('flightBookerId' => $this->flightBooker->id, 'newState' => 'ticketingRepeat'));
             if ($res) {
                 $this->flightBooker->saveTaskInfo('ticketingRepeat', $res);
                 return true;
             }
             //$this->status('ticketingRepeat');
         }
     }
 }
예제 #4
0
 public function FlightSearch(FlightSearchParams $flightSearchParams)
 {
     if (!$flightSearchParams instanceof FlightSearchParams) {
         throw new CException(Yii::t('application', 'Parameter oFlightSearchParams not type of FlightSearchParams'));
     }
     //VarDumper::dump($flightSearchParams);
     //prepare request  structure
     $flightClass = 'all';
     switch ($flightSearchParams->flight_class) {
         case 'E':
             $flightClass = 'economy';
             break;
         case 'B':
             $flightClass = 'business';
             break;
         case 'F':
             $flightClass = 'first';
             break;
     }
     $params = array('Request' => array('SearchFlights' => array('ODPairs' => array('Type' => 'OW', 'Direct' => false, 'AroundDates' => "0", 'ODPair' => array('DepDate' => '2012-06-13T00:00:00', 'DepAirp' => 'MOW', 'ArrAirp' => 'IJK')), 'Travellers' => array('Traveller' => array(array('Type' => 'ADT', 'Count' => '1'))), 'Restrictions' => array('ClassPref' => $flightClass, 'OnlyAvail' => true, 'AirVPrefs' => '', 'IncludePrivateFare' => false, 'CurrencyCode' => 'RUB'))), 'Source' => array('ClientId' => Yii::app()->params['GDSNemo']['agencyId'], 'APIKey' => Yii::app()->params['GDSNemo']['agencyApiKey'], 'Language' => 'RU', 'Currency' => 'RUB'));
     self::$lastRequestDescription = '';
     $pairs = array();
     foreach ($flightSearchParams->routes as $route) {
         //todo: think how to name it
         $ODPair = array();
         $ODPair['DepDate'] = $route->departureDate . 'T00:00:00';
         $ODPair['DepAirp'] = $route->departureCity->code;
         $ODPair['ArrAirp'] = $route->arrivalCity->code;
         self::$lastRequestDescription .= "{$route->departureDate}: {$route->departureCity->code} - {$route->arrivalCity->code}; ";
         $pairs[] = $ODPair;
     }
     $flightType = 'OW';
     if (count($flightSearchParams->routes) == 2) {
         $equalFrom = $flightSearchParams->routes[0]->departureCityId === $flightSearchParams->routes[1]->arrivalCityId;
         $equalTo = $flightSearchParams->routes[0]->arrivalCityId === $flightSearchParams->routes[1]->departureCityId;
         if ($equalFrom && $equalTo) {
             $flightType = 'RT';
         } else {
             $flightType = 'CR';
         }
     } elseif (count($flightSearchParams->routes) > 2) {
         $flightType = 'CR';
     }
     $params['Request']['SearchFlights']['ODPairs']['Type'] = $flightType;
     $params['Request']['SearchFlights']['ODPairs']['ODPair'] = UtilsHelper::normalizeArray($pairs);
     unset($pairs);
     $traveller = array();
     if ($flightSearchParams->adultCount > 0) {
         $traveller[] = array('Type' => 'ADT', 'Count' => $flightSearchParams->adultCount);
         self::$lastRequestDescription .= "ADT: {$flightSearchParams->adultCount}; ";
     }
     if ($flightSearchParams->childCount > 0) {
         $traveller[] = array('Type' => 'CNN', 'Count' => $flightSearchParams->childCount);
         self::$lastRequestDescription .= "CNN: {$flightSearchParams->childCount}; ";
     }
     if ($flightSearchParams->infantCount > 0) {
         $traveller[] = array('Type' => 'INF', 'Count' => $flightSearchParams->infantCount);
         self::$lastRequestDescription .= "INF: {$flightSearchParams->infantCount}; ";
     }
     $params['Request']['SearchFlights']['Travellers']['Traveller'] = UtilsHelper::normalizeArray($traveller);
     unset($traveller);
     $soapResponse = self::request('Search', $params);
     $errorDescription = '';
     if (!$soapResponse) {
         if (GDSNemoSoapClient::$lastCurlError) {
             $errorDescription = GDSNemoSoapClient::$lastCurlError;
             throw new CException($errorDescription);
         }
     }
     //processing response
     if (!isset($soapResponse->Response->SearchFlights->Flights->Flight)) {
         $soapResponse = $this->humanReadable($soapResponse);
         if ($soapResponse) {
             Yii::trace(CVarDumper::dumpAsString($soapResponse), 'Gds.GdsNemoAgency.request');
             throw new CException('Incorrect soap response: ' . CVarDumper::dumpAsString($soapResponse));
         }
     }
     $flights = array();
     $errorCode = 0;
     $searchId = '';
     if (isset($soapResponse->Response->SearchFlights->Flights)) {
         $searchId = $soapResponse->Response->SearchFlights->Flights->SearchId;
     }
     if (isset($soapResponse->Response->SearchFlights->Flights->Flight)) {
         Yii::beginProfile('processingSoap');
         UtilsHelper::soapObjectsArray($soapResponse->Response->SearchFlights->Flights->Flight);
         foreach ($soapResponse->Response->SearchFlights->Flights->Flight as $oSoapFlight) {
             $aParts = array();
             //flag of valid flight
             $needSave = true;
             $eTicket = true;
             //Yii::beginProfile('processingSegments');
             $supposedValAirlineCode = '';
             UtilsHelper::soapObjectsArray($oSoapFlight->Segments->Segment);
             foreach ($oSoapFlight->Segments->Segment as $arrKey => $oSegment) {
                 $oPart = new stdClass();
                 //Yii::beginProfile('loadAirportData');
                 if (!isset($oSegment->DepAirp)) {
                     Yii::log(print_r($oSegment, true) . '|||' . $arrKey, 'info');
                 }
                 try {
                     $oPart->departure_airport = Airport::getAirportByCode(UtilsHelper::soapElementValue($oSegment->DepAirp));
                     $oPart->departure_city = $oPart->departure_airport->city;
                     $oPart->arrival_airport = Airport::getAirportByCode(UtilsHelper::soapElementValue($oSegment->ArrAirp));
                     $oPart->arrival_city = $oPart->arrival_airport->city;
                     $oPart->departure_terminal_code = isset($oSegment->DepTerminal) ? UtilsHelper::soapElementValue($oSegment->DepTerminal) : '';
                     $oPart->arrival_terminal_code = isset($oSegment->ArrTerminal) ? UtilsHelper::soapElementValue($oSegment->ArrTerminal) : '';
                     if (strlen($supposedValAirlineCode) == 0) {
                         $supposedValAirlineCode = $oSegment->MarkAirline;
                     }
                     $oPart->markAirline = Airline::getAirlineByCode($oSegment->MarkAirline);
                     if ($oSegment->OpAirline == '**') {
                         $oPart->opAirline = $oPart->markAirline;
                         $oPart->transport_airline = $oPart->markAirline;
                     } else {
                         $oPart->opAirline = Airline::getAirlineByCode($oSegment->OpAirline);
                         $oPart->transport_airline = Airline::getAirlineByCode($oSegment->OpAirline);
                     }
                     $oPart->code = $oSegment->FlightNumber;
                     $oPart->duration = $oSegment->FlightTime * 60;
                     $oPart->datetime_begin = UtilsHelper::soapElementValue($oSegment->DepDateTime);
                     $oPart->datetime_end = UtilsHelper::soapElementValue($oSegment->ArrDateTime);
                     $oPart->stopNum = UtilsHelper::soapElementValue($oSegment->StopNum);
                     $oPart->aircraft_code = $oSegment->AircraftType;
                     $oPart->aTariffs = array();
                     $oPart->aTaxes = array();
                     $oPart->aBookingCodes = array();
                     UtilsHelper::soapObjectsArray($oSegment->BookingCodes->BookingCode);
                     foreach ($oSegment->BookingCodes->BookingCode as $sBookingCode) {
                         $oPart->aBookingCodes[] = UtilsHelper::soapElementValue($sBookingCode);
                     }
                     $aParts[$oSegment->SegNum] = $oPart;
                     $eTicket = $eTicket && $oSegment->ETicket;
                 } catch (Exception $e) {
                     Yii::log('Error while parsing gds nemo results: ' . $e->getMessage());
                     $needSave = false;
                 }
             }
             //Yii::endProfile('processingSegments');
             $full_sum = 0;
             $aPassengers = array();
             $aTariffs = array();
             //Yii::beginProfile('processingPassengers');
             $refundable = $oSoapFlight->PricingInfo->Refundable;
             if ($refundable == 'true' or $refundable === true) {
                 $refundable = true;
             } else {
                 $refundable = false;
             }
             UtilsHelper::soapObjectsArray($oSoapFlight->PricingInfo->PassengerFare);
             foreach ($oSoapFlight->PricingInfo->PassengerFare as $oFare) {
                 $sType = $oFare->Type;
                 $aPassengers[$sType]['count'] = $oFare->Quantity;
                 $aPassengers[$sType]['base_fare'] = $oFare->BaseFare->Amount;
                 if ($oFare->BaseFare->Currency != 'RUB') {
                     $aPassengers[$sType]['base_fare'] = $oFare->EquiveFare->Amount;
                 }
                 $aPassengers[$sType]['total_fare'] = $oFare->TotalFare->Amount;
                 $full_sum += $oFare->TotalFare->Amount * $oFare->Quantity;
                 if (isset($oFare->LastTicketDateTime)) {
                     $aPassengers[$sType]['LastTicketDateTime'] = $oFare->LastTicketDateTime;
                 } else {
                     Yii::log('!!DONT have LastTicketDate flight:' . $oSoapFlight->FlightId, 'info');
                 }
                 $aPassengers[$sType]['aTaxes'] = array();
                 if (isset($oFare->Taxes->Tax)) {
                     UtilsHelper::soapObjectsArray($oFare->Taxes->Tax);
                     foreach ($oFare->Taxes->Tax as $oTax) {
                         if (isset($oTax->CurCode) == 'RUB') {
                             $aPassengers[$sType]['aTaxes'][$oTax->TaxCode] = $oTax->Amount;
                         } else {
                             Yii::log(print_r($oTax, true) . '!!!' . $oSoapFlight->FlightId, 'info');
                             throw new CException(Yii::t('application', 'Valute code unexpected. Code: {code}. Expected RUB', array('{code}' => $oTax->CurCode)));
                         }
                     }
                 } else {
                     Yii::log('Flight dont have Taxes. FlightId:' . $oSoapFlight->FlightId, 'info');
                 }
                 //VarDumper::dump($oSoapFlight);die();
                 if (isset($oFare->Tariffs->Tariff)) {
                     UtilsHelper::soapObjectsArray($oFare->Tariffs->Tariff);
                     foreach ($oFare->Tariffs->Tariff as $oTariff) {
                         //VarDumper::dump($oTariff);die();SEARCH_WITHOUT_ADULTS_BANNED
                         $aParts[$oTariff->SegNum]->aTariffs[$oTariff->Code] = $oTariff->Code;
                     }
                 }
             }
             //Yii::endProfile('processingPassengers');
             $aNewParts = array();
             //print_r($aParts);
             $oPart = reset($aParts);
             foreach ($flightSearchParams->routes as $route) {
                 $aSubParts = array();
                 $aCities = array();
                 while ($oPart) {
                     $aSubParts[] = $oPart;
                     $aCities[] = $oPart->arrival_city->code;
                     if ($route->arrivalCity->code === $oPart->arrival_city->code) {
                         $oPart = next($aParts);
                         break;
                     }
                     $oPart = next($aParts);
                 }
                 if (!$oPart) {
                     $oPart = end($aParts);
                     if ($route->arrivalCity->code !== $oPart->arrival_city->code) {
                         /*throw new CException(Yii::t('application', 'Not found segment with code arrival city {code}. Segment cityes: {codes}', array(
                               '{code}' => $route->arrivalCity->code,
                               '{codes}' => implode(', ', $aCities)
                           )));*/
                         Yii::log(Yii::t('application', 'Not found segment with code arrival city {code}. Segment cityes: {codes}. FlightId: {flightId}', array('{code}' => $route->arrivalCity->code, '{codes}' => implode(', ', $aCities), '{flightId}' => $oSoapFlight->FlightId)), 'info', 'nemo');
                         $needSave = false;
                     }
                 }
                 $aNewParts[] = $aSubParts;
             }
             $oFlight = new stdClass();
             $oFlight->full_sum = $full_sum;
             $oFlight->full_sum = UtilsHelper::soapElementValue($oSoapFlight->TotalPrice);
             $oFlight->commission_price = UtilsHelper::soapElementValue($oSoapFlight->Commission);
             $oFlight->charges = UtilsHelper::soapElementValue($oSoapFlight->Charges);
             $oFlight->webService = UtilsHelper::soapElementValue($oSoapFlight->WebService);
             if (isset($oSoapFlight->ValCompany) && strlen($oSoapFlight->ValCompany) > 0) {
                 $oFlight->valAirline = Airline::getAirlineByCode($oSoapFlight->ValCompany);
             } else {
                 $oFlight->valAirline = Airline::getAirlineByCode($supposedValAirlineCode);
             }
             $oFlight->flight_key = $oSoapFlight->FlightId;
             $oFlight->parts = $aNewParts;
             $oFlight->passengersInfo = $aPassengers;
             $oFlight->refundable = $refundable;
             //$oFlight->searchId = $searchId;
             if (!$eTicket) {
                 Yii::log(Yii::t('application', 'One or more segments dont have eticketing. FlightId:{flightId}', array('{flightId}' => $oSoapFlight->FlightId)));
                 $needSave = $needSave && $eTicket;
             }
             if ($needSave) {
                 $flights[] = $oFlight;
             }
         }
         Yii::endProfile('processingSoap');
     } else {
         $errorCode |= self::ERROR_CODE_EMPTY;
     }
     //print_r($aFlights);
     if ($errorCode > 0) {
         return array('flights' => array(), 'searchId' => '', 'errorCode' => $errorCode, 'errorDescription' => '');
     } else {
         return array('flights' => $flights, 'searchId' => $searchId, 'errorCode' => 0, 'errorDescription' => '');
     }
 }