示例#1
0
文件: Booking.php 项目: arbi/MyCode
 /**
  * @param array $data
  * @return string
  */
 private function filterReservationData($data)
 {
     $currentDate = date('Y-m-d');
     $cityDao = new City($this->getServiceLocator(), 'ArrayObject');
     if (isset($data['city']) && ClassicValidator::checkCityName($data['city'])) {
         $cityResp = $cityDao->getCityByName(Helper::urlForSearch($data['city']));
         if ($cityResp) {
             /* @var $websiteSearchService \DDD\Service\Website\Search */
             $websiteSearchService = $this->getServiceLocator()->get('service_website_search');
             $diffHours = $websiteSearchService->getDiffHoursForDate();
             $currentDate = Helper::getCurrenctDateByTimezone($cityResp['timezone'], 'd-m-Y', $diffHours);
         }
     }
     if (!isset($data['city']) || !ClassicValidator::checkCityName($data['city']) || !isset($data['apartment']) || !ClassicValidator::checkApartmentTitle($data['apartment']) || !isset($data['guest']) || !is_numeric($data['guest']) || !isset($data['apartment_id']) || !is_numeric($data['apartment_id']) || !isset($data['arrival']) || !ClassicValidator::validateDate($data['arrival'], 'd M Y') || !isset($data['departure']) || !ClassicValidator::validateDate($data['departure'], 'd M Y') || strtotime($data['arrival']) >= strtotime($data['departure']) || strtotime($currentDate) - strtotime($data['arrival']) > 129600 || !isset($data['rate-for-booking']) || !is_numeric($data['rate-for-booking']) || isset($data['apartel_id']) && !is_numeric($data['apartel_id'])) {
         return false;
     }
     return true;
 }
示例#2
0
文件: Search.php 项目: arbi/MyCode
 /**
  *
  * @param array $data
  * @return array
  */
 public function getFixedDate($data)
 {
     $currentDate = date('Y-m-d');
     $cityDao = new City($this->getServiceLocator(), 'ArrayObject');
     if (isset($data['city']) && ClassicValidator::checkCityName($data['city'])) {
         $cityResp = $cityDao->getCityBySlug($data['city']);
         if ($cityResp) {
             $diffHousr = $this->getDiffHoursForDate();
             $currentDate = Helper::getCurrenctDateByTimezone($cityResp['timezone'], 'd-m-Y', $diffHousr);
         }
     }
     $arrival = isset($data['arrival']) && $data['arrival'] && ClassicValidator::validateDate($data['arrival']) ? date('Y-m-d', strtotime($data['arrival'])) : '';
     $departure = isset($data['departure']) && $data['departure'] && ClassicValidator::validateDate($data['departure']) ? date('Y-m-d', strtotime($data['departure'])) : '';
     if ($arrival && $departure && strtotime($arrival) > strtotime($departure)) {
         $arrival = $departure = '';
     } elseif ($arrival && strtotime($currentDate) > strtotime($arrival) || $departure && strtotime($currentDate) > strtotime($departure)) {
         $arrival = $departure = '';
     } elseif (!$arrival && $departure) {
         $departure = '';
     } elseif ($arrival && !$departure) {
         $departure = date('Y-m-d', strtotime($arrival . '+1 day'));
     }
     return ['arrival' => $arrival, 'departure' => $departure];
 }
示例#3
0
 /**
  * @param $reservationId
  * @param $dateFrom
  * @param $dateTo
  * @param bool $isGetInfo
  * @return array
  */
 public function changeReservationDate($reservationId, $dateFrom, $dateTo, $isGetInfo = false)
 {
     /**
      * @var ReservationNightly $reservationNightlyDao
      * @var \DDD\Service\Reservation\Main $reservationService
      * @var \DDD\Service\Reservation\RateSelector $rateSelector
      * @var \DDD\Dao\Apartment\Inventory $inventoryDao
      * @var \DDD\Dao\Booking\Booking $bookingDao
      */
     $inventoryDao = $this->getServiceLocator()->get('dao_apartment_inventory');
     $reservationNightlyDao = $this->getServiceLocator()->get('dao_booking_reservation_nightly');
     $reservationService = $this->getServiceLocator()->get('service_reservation_main');
     $rateSelector = $this->getServiceLocator()->get('service_reservation_rate_selector');
     $bookingDao = $this->getServiceLocator()->get('dao_booking_booking');
     $reservationData = $bookingDao->getReservationDataForChangeDate($reservationId);
     $today = Helper::getCurrenctDateByTimezone($reservationData['timezone']);
     $bookingDao->setEntity(new \ArrayObject());
     // Data check
     if (!$reservationData || !$dateFrom || !ClassicValidator::validateDate($dateFrom, 'Y-m-d') || !$dateTo || !ClassicValidator::validateDate($dateTo, 'Y-m-d') || strtotime($dateFrom) >= strtotime($dateTo)) {
         return ['status' => 'error', 'msg' => TextConstants::MODIFICATION_BAD_DATA_FOR_CHANGE];
     }
     $error = '';
     if ($reservationData['date_from'] != $dateFrom && strtotime($today) > strtotime($dateFrom)) {
         $error .= TextConstants::MODIFICATION_DATE_NOT_PAST;
     }
     if ($reservationData['status'] != BookingService::BOOKING_STATUS_BOOKED) {
         $error .= TextConstants::MODIFICATION_STATUS_BOOKED;
     }
     if ($reservationData['date_from'] == $dateFrom && $reservationData['date_to'] == $dateTo) {
         $error .= TextConstants::MODIFICATION_NO_INDICATED;
     }
     if (strtotime($today) > strtotime($dateTo)) {
         $error .= TextConstants::MODIFICATION_DATE_SHOULD_FUTURE;
     }
     if ($error) {
         return ['status' => 'error', 'msg' => $error];
     }
     // check is apartel
     $apartel = $reservationData['apartel_id'] && $reservationData['channel_res_id'] > 0 ? $reservationData['apartel_id'] : false;
     // New Date generation
     $resNightlyData = $reservationNightlyDao->fetchAll(['reservation_id' => $reservationId, 'status' => ReservationMainService::STATUS_BOOKED], [], 'date ASC');
     $existingNightlyData = $startRateApartment = $lastRateApartment = $existingDate = $newNightlyData = [];
     $existingNightCount = $resNightlyData->count();
     if (!$existingNightCount) {
         return ['status' => 'error', 'msg' => TextConstants::MODIFICATION_BAD_DATA_FOR_CHANGE];
     }
     foreach ($resNightlyData as $key => $night) {
         $existingNightlyData[$night['date']] = $night;
     }
     // existing date array
     $existingDate = array_keys($existingNightlyData);
     $startRateApartment = $existingNightlyData[current($existingDate)];
     $lastRateApartment = $existingNightlyData[end($existingDate)];
     $dateFromTime = strtotime($dateFrom);
     $dateToTime = strtotime($dateTo);
     while ($dateFromTime < $dateToTime) {
         $date = date('Y-m-d', $dateFromTime);
         if (in_array($date, $existingDate)) {
             // existing date
             $newFromData = $existingNightlyData[$date];
         } else {
             if (strtotime($date) < strtotime($reservationData['date_from'])) {
                 // get rate data from start date
                 $newFromData = $startRateApartment;
                 $rateIdForChangeDate = $startRateApartment['rate_id'];
             } else {
                 // get rate data from last date
                 $rateIdForChangeDate = $lastRateApartment['rate_id'];
                 $newFromData = $lastRateApartment;
             }
             if ($apartel) {
                 /**
                  * @var \DDD\Dao\Apartel\Rate $apartelRateDao
                  * @var \DDD\Dao\Apartel\Inventory $apartelInventoryDao
                  */
                 $apartelRateDao = $this->getServiceLocator()->get('dao_apartel_rate');
                 $apartelInventoryDao = $this->getServiceLocator()->get('dao_apartel_inventory');
                 // rate exist and active if not use fuzzy logic
                 if (!$apartelRateDao->checkRateExistAndActive($rateIdForChangeDate)) {
                     $newFromData = $rateSelector->getSelectorRate($reservationId, $date, $isGetInfo, $apartel);
                     $rateIdForChangeDate = $newFromData['rate_id'];
                 }
                 // check apartment availability
                 if (!$inventoryDao->checkApartmentAvailabilityApartmentDateList($newFromData['apartment_id'], [$date])) {
                     return ['status' => 'error', 'msg' => TextConstants::ERROR_NO_AVAILABILITY];
                 }
                 // check apartel availability and get price
                 $priceApartel = $apartelInventoryDao->getPriceByRateIdDate($rateIdForChangeDate, $date);
                 $newPrice = $priceApartel['price'];
             } else {
                 /** @var \DDD\Dao\Apartment\Rate $rateDao */
                 $rateDao = $this->getServiceLocator()->get('dao_apartment_rate');
                 // rate exist and active if not use fuzzy logic
                 if (!$rateDao->checkRateExistAndActive($rateIdForChangeDate)) {
                     $newFromData = $rateSelector->getSelectorRate($reservationId, $date, $isGetInfo);
                     $rateIdForChangeDate = $newFromData['rate_id'];
                 }
                 $changeDatePrice = $inventoryDao->fetchOne(['rate_id' => $rateIdForChangeDate, 'date' => $date, 'availability' => 1], ['price']);
                 if (!$changeDatePrice) {
                     return ['status' => 'error', 'msg' => TextConstants::ERROR_NO_AVAILABILITY];
                 }
                 $newPrice = $changeDatePrice->getPrice();
             }
             $newFromData['price'] = $newPrice;
         }
         $newNightlyData[$date] = ['apartment_id' => $newFromData['apartment_id'], 'room_id' => $newFromData['room_id'], 'rate_id' => $newFromData['rate_id'], 'rate_name' => $newFromData['rate_name'], 'price' => $newFromData['price'], 'date' => $date, 'capacity' => $newFromData['capacity']];
         $dateFromTime = strtotime('+1 day', $dateFromTime);
     }
     if (empty($newNightlyData)) {
         return ['status' => 'error', 'msg' => 'Bad Data for change Date'];
     }
     $changeDateProcess = $reservationService->changeDateForModification($newNightlyData, $reservationId, $isGetInfo, $apartel);
     // for view
     if ($isGetInfo && $changeDateProcess['status'] == 'success') {
         $addonDao = $this->getServiceLocator()->get('dao_booking_addons');
         $forViewInfo = [];
         $type = 'Other';
         foreach ($changeDateProcess['data'] as $date => $chargeType) {
             foreach ($chargeType['data'] as $row) {
                 if (isset($row['view_charge_name'])) {
                     $type = $row['view_charge_name'];
                 } elseif (isset($row['addons_type'])) {
                     $addonName = $addonDao->fetchOne(['id' => $row['addons_type']], ['name']);
                     if ($addonName) {
                         $type = $addonName->getName();
                     }
                 }
                 $forViewInfo[] = ['date' => $date, 'rate_name' => isset($row['rate_name']) ? $row['rate_name'] : '', 'price' => $chargeType['type'] == 'insert' ? $row['acc_amount'] : -1 * $row['acc_amount'], 'type' => $type];
             }
         }
         return ['status' => 'success', 'data' => $forViewInfo];
     }
     return $changeDateProcess;
 }
示例#4
0
文件: Apartment.php 项目: arbi/MyCode
 /**
  * @param array $data
  * @return string
  */
 public function filterQueryData($data)
 {
     $currentDate = date('Y-m-d');
     $cityDao = new City($this->getServiceLocator(), 'ArrayObject');
     if (!isset($data['city'])) {
         $pageSlugExp = explode('--', $data['slug']);
         $citySlug = $pageSlugExp[1];
     } else {
         $citySlug = $data['city'];
     }
     if (isset($citySlug) && ClassicValidator::checkCityName($citySlug)) {
         $cityResp = $cityDao->getCityBySlug(Helper::urlForSearch($citySlug, TRUE));
         if ($cityResp) {
             /* @var $websiteSearchService \DDD\Service\Website\Search */
             $websiteSearchService = $this->getServiceLocator()->get('service_website_search');
             $diffHours = $websiteSearchService->getDiffHoursForDate();
             $currentDate = Helper::getCurrenctDateByTimezone($cityResp['timezone'], 'd-m-Y', $diffHours);
         }
     }
     if (!isset($data['arrival']) || !ClassicValidator::validateDate($data['arrival']) || !isset($data['departure']) || !ClassicValidator::validateDate($data['departure']) || strtotime($data['arrival']) < strtotime($currentDate) || strtotime($data['arrival']) >= strtotime($data['departure'])) {
         return false;
     }
     return true;
 }