public function run($isTab = false) { /** @var TourBuilderForm $tourForm */ $tourForm = Yii::app()->user->getState('tourForm'); $eventId = $tourForm->eventId; $startCities = Yii::app()->user->getState('startCities'); $currentStartCityIndex = Yii::app()->user->getState('startCitiesIndex') - 1; $currentStartCity = City::model()->findByPk($startCities[$currentStartCityIndex]->id); $startCityId = $currentStartCity->id; $event = Event::model()->findByPk($eventId); $tripStorage = new TripStorage(); $order = $tripStorage->saveOrder($event, $startCityId, 'Тур для события "' . $event->title . '" из ' . $currentStartCity->caseGen); $eventOrder = new EventOrder(); $eventOrder->startCityId = $startCityId; $eventOrder->orderId = $order->id; $eventOrder->eventId = $event->id; $eventOrder->save(); $eventPrice = EventPrice::model()->findByAttributes(array('eventId' => $eventId, 'cityId' => $startCityId)); if (!$eventPrice) { $eventPrice = new EventPrice(); } $eventPrice->eventId = $event->id; $eventPrice->cityId = $startCityId; $eventPrice->bestPrice = $tripStorage->getPrice(); if (!$eventPrice->save()) { throw new CHttpException('Could not save price for event - city.' . CVarDumper::dumpAsString($eventPrice)); } $this->controller->redirect($this->controller->createUrl('showEventTrip')); }
public function actionInfo($eventId) { $event = Event::model()->findByPk($eventId); $defaultCityId = 4466; $pricesData = array(); $this->layout = 'static'; foreach ($event->prices as $price) { $pricesData[$price->city->id] = array('price' => floor($price->bestPrice), 'cityName' => $price->city->localRu, 'cityId' => $price->city->id, 'updateTime' => str_replace(' ', 'T', $price->updated)); } $tours = array(); $dataProvider = new TripDataProvider(); $cities = array(); foreach ($event->tours as $tour) { $tours[$tour->startCityId] = array(); $dataProvider->restoreFromDb($tour->orderId); //echo $tour->orderId.'dsf'; //print_r($dataProvider->getSortedCartItemsOnePerGroup(false));//die(); $items = $dataProvider->getWithAdditionalInfo($dataProvider->getSortedCartItemsOnePerGroup(false)); //print_r($items);die(); $tours[$tour->startCityId] = $items; $tours[$tour->startCityId]['city'] = City::getCityByPk($tour->startCityId)->getAttributes(); $eventPrice = EventPrice::model()->findByAttributes(array('eventId' => $eventId, 'cityId' => $tour->startCityId)); if ($eventPrice) { $tours[$tour->startCityId]['price'] = ceil($eventPrice->bestPrice); } $cities[$tour->startCityId] = City::getCityByPk($tour->startCityId)->getAttributes(); } //die(); if (!isset($cities[$defaultCityId])) { foreach ($cities as $defaultCityId => $city) { break; } } //need search params $twoCities = array(); $twoCities[$defaultCityId] = $cities[$defaultCityId]; foreach ($cities as $cityId => $city) { if (!isset($twoCities[$cityId])) { $twoCities[$cityId] = $city; break; } } $pictures = array(); foreach ($event->pictures as $picture) { $pictures[] = array('url' => $picture->getUrl()); } $this->render('info', array('event' => $event, 'priceData' => $pricesData, 'defaultCity' => $defaultCityId, 'tours' => $tours, 'cities' => $cities, 'twoCities' => $twoCities, 'pictures' => $pictures)); }
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(); } } }