Exemplo n.º 1
0
 public function actionCitiesReadable(array $codes)
 {
     $cacheKey = 'apiAutocompleteCitiesReadable4' . md5(serialize($codes));
     $citiesCache = Yii::app()->cache->get($cacheKey);
     if ($citiesCache) {
         $this->send($citiesCache);
         Yii::app()->end();
     }
     $result = array();
     foreach ($codes as $cityCode) {
         $city = City::getCityByCode($cityCode);
         $element = array();
         $element['id'] = $city->id;
         $result[$cityCode] = $element;
     }
     $result = $this->addMoreInfo($result);
     Yii::app()->cache->set($cacheKey, $result, appParams('autocompleteCacheTime'));
     $this->send($result);
 }
Exemplo n.º 2
0
 public function actionRTFlight($countryCode = '', $cityCodeFrom = '', $cityCodeTo = '')
 {
     if (!($country = $this->testCountry($countryCode))) {
         return false;
     }
     $this->morphy = Yii::app()->morphy;
     $countryUp = mb_strtoupper($country->localRu, 'utf-8');
     $countryMorph = array('caseAcc' => $this->getCase($countryUp, 'ВН'));
     if (!$cityCodeFrom) {
         $currentCity = City::getCityByCode('LED');
     } else {
         $currentCity = City::getCityByCode($cityCodeFrom);
     }
     $city = City::getCityByCode($cityCodeTo);
     $citiesFrom = array();
     $this->addCityFrom($citiesFrom, 4466);
     // Moscow
     $this->addCityFrom($citiesFrom, 5185);
     // Spb
     $this->addCityFrom($citiesFrom, $currentCity->id);
     Yii::import('site.common.modules.hotel.models.*');
     $hotelClient = new HotelBookClient();
     /*$criteria = new CDbCriteria();
             $criteria->addCondition('countAirports > 0');
             $criteria->addCondition('countryId = '.$country->id);
             $cities = City::model()->findAll($criteria);
             $cityIds = array();
             foreach($cities as $city){
                 $cityIds[$city->id] = $city->id;
             }
     
             if(isset($cityIds[$currentCity->id])){
                 unset($cityIds[$currentCity->id]);
             }*/
     $criteria = new CDbCriteria();
     $criteria->addCondition('`to` = ' . $city->id);
     $criteria->addCondition('`from` = ' . $currentCity->id);
     //$criteria->group = 'dateBack';
     //$criteria->addCondition('`from` = '.$currentCity->id);
     $criteria->addCondition('`dateFrom` >= ' . date("'Y-m-d'"));
     $criteria->addCondition('`dateFrom` <= ' . date("'Y-m-d'", time() + 3600 * 24 * 18));
     $criteria->addCondition('`dateBack` >= ' . date("'Y-m-d'"));
     $criteria->addCondition('`dateBack` <= ' . date("'Y-m-d'", time() + 3600 * 24 * 18));
     //$criteria->addCondition("`dateBack` <> '0000-00-00'");
     $criteria->order = 'priceBestPrice';
     //$criteria->limit = 18;
     $flightCache = FlightCache::model()->findAll($criteria);
     /*$sortFc = array();
       foreach($flightCache as $fc){
           $k = strtotime($fc->dateFrom);
           $sortFc[$k] = $fc;//array('price'=>$fc->priceBestPrice,'date'=>$fc->dateFrom,'dateBack'=>$fc->dateBack);
       }
       ksort($sortFc);*/
     //$sortFc = array_slice($sortFc,0,18);
     $minPrice = false;
     $maxPrice = false;
     $activeMin = null;
     $activeMax = null;
     foreach ($flightCache as $k => $fc) {
         $k = strtotime($fc->dateFrom);
         if (!$minPrice) {
             $minPrice = $fc->priceBestPrice;
             $maxPrice = $fc->priceBestPrice;
         } else {
             if ($fc->priceBestPrice < $minPrice) {
                 $minPrice = $fc->priceBestPrice;
                 $activeMin = $k;
             }
             if ($fc->priceBestPrice > $maxPrice) {
                 $maxPrice = $fc->priceBestPrice;
                 $activeMax = $k;
             }
         }
     }
     $sortFc = array();
     foreach ($flightCache as $fc) {
         //$k = strtotime($fc->dateFrom);
         $sortFc[] = array('price' => $fc->priceBestPrice, 'date' => $fc->dateFrom, 'dateBack' => $fc->dateBack);
     }
     //print_r($flightCache);die();
     $criteria = new CDbCriteria();
     //$criteria->addInCondition('`cityId`',$cityIds);
     $criteria->addCondition('cityId = ' . $city->id);
     $criteria->limit = 15;
     $hotelCache = HotelDb::model()->findAll($criteria);
     $hotelsInfo = array();
     foreach ($hotelCache as $hc) {
         $hotelInfo = $hotelClient->hotelDetail($hc->id);
         $hotelInfo->price = $hc->minPrice;
         $hotelInfo->hotelName = $hc->name;
         $hotelInfo->hotelId = $hc->id;
         $hotelsInfo[] = $hotelInfo;
     }
     $criteria = new CDbCriteria();
     //$criteria->addInCondition('`to`',$cityIds);
     $criteria->addCondition('`from` = ' . $currentCity->id);
     $criteria->addCondition('`dateFrom` > \'' . date('Y-m-d') . "'");
     $criteria->order = 'priceBestPrice';
     $criteria->limit = 14;
     $criteria->group = '`to`';
     $flightCacheFromCurrent = FlightCache::model()->findAll($criteria);
     $this->layout = 'static';
     //$this->render('landing');
     $this->render('rtflight', array('city' => $city, 'citiesFrom' => $citiesFrom, 'hotelsInfo' => $hotelsInfo, 'currentCity' => $currentCity, 'flightCache' => $sortFc, 'maxPrice' => $maxPrice, 'minPrice' => $minPrice, 'activeMin' => $activeMin, 'flightCacheFromCurrent' => $flightCacheFromCurrent));
 }
Exemplo n.º 3
0
 public function actionUpdateEvent()
 {
     print_r($_POST);
     $event = Event::model()->findByPk($_POST['eventId']);
     if (isset($_POST['startCity'])) {
         $startCity = City::getCityByCode($_POST['startCity']);
     }
     foreach ($event->tours as $tour) {
         if ($tour->startCityId == $startCity->id) {
             echo "find startCity";
             break;
         } else {
             echo "cid : " . $tour->startCityId;
         }
         $tour = null;
     }
     if ($tour) {
         //print_r($tour);
     }
     if ($tour->order) {
         //print_r($tour->order);
     }
     $items = $_POST['items'];
     $priceSum = 0;
     foreach ($items as $item) {
         if ($item['type'] == 'hotel') {
             $item['data']['cityId'] = City::getCityByCode($item['data']['cityCode'])->hotelbookId;
             $item['data']['rubPrice'] = $item['data']['discountPrice'];
             $item['data']['comparePrice'] = $item['data']['discountPrice'];
             $priceSum += $item['data']['discountPrice'];
             $hotel = new Hotel($item['data']);
             //print_r($hotel->getJsonObject());
             $cityId = $hotel->city->id;
             /** var OrderHotel $hotelItem */
             foreach ($tour->order->hotelItems as $hotelItem) {
                 //$hotelItem = new OrderHotel();
                 if ($hotelItem->cityId == $cityId || $hotelItem->checkIn == $hotel->checkIn) {
                     $hotelItem->object = serialize($hotel);
                     $hotelItem->isNewRecord = false;
                     echo "update " . $hotelItem->id . " orderHotel" . $hotel->checkIn . serialize($hotel);
                     $hotelItem->save();
                 }
                 //print_r($hotelItem);
             }
         } else {
             $flight = new FlightVoyage($item['data']);
             $priceSum += $flight->price;
             //print_r($flight);
             foreach ($flight->flights as $flightKey => $fl) {
                 foreach ($tour->order->flightItems as $flightItem) {
                     if ($flightItem->departureCity == $flight->getDepartureCity($flightKey)->id && $flightItem->arrivalCity == $flight->getArrivalCity($flightKey)->id && $flightItem->departureDate == date('Y-m-d', strtotime($flight->getDepartureDate($flightKey)))) {
                         $flightItem->object = serialize($flight);
                         $flightItem->isNewRecord = false;
                         echo "update " . $flightItem->id . " flight\n";
                         $flightItem->save();
                         break;
                     } else {
                         echo "notUpdate " . $flightItem->id . " flight " . $flightItem->departureCity . '|' . $flight->getDepartureCity()->id . '|' . $flightItem->arrivalCity . '|' . $flight->getArrivalCity()->id . '|' . $flightItem->departureDate . '|' . $flight->getDepartureDate() . "\n";
                         //print_r($flight->getJsonObject());die();
                     }
                 }
             }
         }
     }
     if ($priceSum) {
         $eventPrice = EventPrice::model()->findByAttributes(array('eventId' => $event->id, 'cityId' => $startCity->id));
         if ($eventPrice) {
             $eventPrice->bestPrice = $priceSum;
             $eventPrice->save();
         }
     }
 }
Exemplo n.º 4
0
 private function getPriceForCity($cityCode, $forceUpdate)
 {
     try {
         $from = City::getCityByCode($cityCode)->id;
         $to = $this->cityId;
         $dateStart = self::getFlightFromDate($this->startDate);
         $priceTo = FlightSearcher::getOptimalPrice($from, $to, $dateStart, false, $forceUpdate);
         $dateEnd = self::getFlightToDate($this->endDate);
         $priceBack = FlightSearcher::getOptimalPrice($to, $from, $dateEnd, false, $forceUpdate);
         $priceToBack = FlightSearcher::getOptimalPrice($from, $to, $dateStart, $dateEnd, $forceUpdate);
         return min($priceTo + $priceBack, $priceToBack);
     } catch (Exception $e) {
         return 'N/A';
     }
 }