示例#1
0
文件: Main.php 项目: arbi/MyCode
 /**
  * @param $cubilisRateIdDates
  * @param $roomTypeId
  * @param $dates
  * @param $bookingDomain
  * @param $fromCubilisRatesData
  * @param $productId
  * @param $channelResId
  * @param $partnerId
  * @param $isApartel
  * @param $building
  * @param $apartmentListUsed
  * @param $guestCount
  * @return array
  */
 public function getNightlyData($cubilisRateIdDates, $roomTypeId, $dates, $bookingDomain, $fromCubilisRatesData, $productId, $channelResId, $partnerId, $isApartel, $building, $apartmentListUsed, $guestCount)
 {
     /**
      * @var \DDD\Dao\Apartment\General $apartmentDao
      * @var \DDD\Dao\Apartel\Inventory $apartelInventoryDao
      * @var \DDD\Dao\Apartel\General $apartelDao
      * @var \DDD\Service\Reservation\RateSelector $rateSelector
      * @var \DDD\Service\Reservation\RateSelector $rateSelector
      * @var \DDD\Service\Reservation\PartnerSpecific $partnerSpecificService
      * @var \DDD\Dao\Partners\Partners $partnerDao
      * @var \DDD\Service\Apartel\Type $apartelTypeService
      * @var \DDD\Service\Partners $partnerService
      */
     $rateSelector = $this->getServiceLocator()->get('service_reservation_rate_selector');
     $partnerSpecificService = $this->getServiceLocator()->get('service_reservation_partner_specific');
     $apartmentInventoryDao = new Inventory($this->getServiceLocator(), '\\ArrayObject');
     $apartelTypeService = $this->getServiceLocator()->get('service_apartel_type');
     $partnerDao = $this->getServiceLocator()->get('dao_partners_partners');
     $partnerService = $this->getServiceLocator()->get('service_partners');
     $result = ['ratesData' => [], 'overbooking' => false, 'apartel' => false];
     // night count
     $nightCount = Helper::getDaysFromTwoDate($dates['date_from'], $dates['date_to']);
     // Apartel reservation
     if ($isApartel) {
         $apartelInventoryDao = $this->getServiceLocator()->get('dao_apartel_inventory');
         $apartelDao = $this->getServiceLocator()->get('dao_apartel_general');
         $apartelId = $productId;
         $rates = $apartelInventoryDao->getRateByCubilisRateIdDates($cubilisRateIdDates, $roomTypeId);
         // if empty get parent and create task
         if (!count($rates) || count($rates) != $nightCount) {
             $rates = $apartelInventoryDao->getRateByParentRateIdDates($dates, $roomTypeId);
             $result['rateMissingTask'] = true;
         }
         $rates = iterator_to_array($rates);
         $firstApartment = $apartelDao->getApartelCurrency($apartelId);
         $ginosiCurrency = $firstApartment['code'];
         // modification
         if ($bookingDomain) {
             $apartmentId = $bookingDomain->getApartmentIdAssigned();
         } else {
             // new reservation
             // get best apartment for apartel reservation
             $getApartmentForType = $apartelTypeService->getBestApartmentForType($roomTypeId, $dates, $guestCount, $apartmentListUsed, $building);
             if ($getApartmentForType['status'] == 'not-available') {
                 $result['overbooking'] = true;
             }
             $apartmentId = $getApartmentForType['apartment_id'];
         }
     } else {
         $rates = $apartmentInventoryDao->getRateByCubilisRateIdDates($cubilisRateIdDates, $roomTypeId);
         // if empty get parent and create task
         if (!count($rates) || count($rates) != $nightCount) {
             $rates = $apartmentInventoryDao->getRateByParentRateIdDates($dates, $roomTypeId);
             $result['rateMissingTask'] = true;
         }
         $apartmentId = $productId;
         $apartelId = 0;
         $apartmentDao = $this->getServiceLocator()->get('dao_apartment_general');
         $apartmentData = $apartmentDao->getCurrency($apartmentId);
         $ginosiCurrency = $apartmentData['code'];
     }
     $ratesData = [];
     $currencyNotMatch = $ratePriceNotMatch = $rateNameNot = false;
     //  Modification: check has availability this apartment after change date
     if ($bookingDomain && ($dates['date_from'] < $bookingDomain->getDateFrom() || $dates['date_to'] > $bookingDomain->getDateTo())) {
         $oldNightlyData = Helper::getDateListInRange($bookingDomain->getDateFrom(), date('Y-m-d', strtotime('-1 day', strtotime($bookingDomain->getDateTo()))));
         $newDateRange = Helper::getDateListInRange($dates['date_from'], date('Y-m-d', strtotime('-1 day', strtotime($dates['date_to']))));
         $diffDates = array_diff($newDateRange, $oldNightlyData);
         $apartmentAvailability = $apartmentInventoryDao->checkApartmentAvailabilityApartmentDateList($apartmentId, $diffDates);
         if (!$apartmentAvailability) {
             $result['overbooking'] = true;
         }
     }
     // init strategy to get Partner Id if one was not registered in our system
     $partner = ['id' => $partnerService::PARTNER_UNKNOWN, 'commission' => $partnerService::PARTNER_UNKNOWN_COMMISSION];
     if ($partnerId) {
         $changedPartnerId = $partnerSpecificService->changePartnerForSomeCases($partnerId, $apartmentId);
         $partnerId = $changedPartnerId ? $changedPartnerId : $partnerId;
         $isOurPartnerId = $changedPartnerId ? true : false;
         $partnerData = $partnerService->getPartnerDataForReservation($partnerId, $apartmentId, $isOurPartnerId);
         $partner = ['id' => $partnerData->getGid(), 'commission' => $partnerData->getCommission()];
     }
     // check apply fuzzy logic for this partner
     $applyFuzzyLogic = $partnerDao->checkFuzzyLogic($partner['id']);
     foreach ($rates as $rate) {
         $ourPrice = $rate['price'];
         // if modification check rate exist and active if not use fuzzy logic
         if ($bookingDomain && ($bookingDomain->getDateFrom() > $rate['date'] || $bookingDomain->getDateTo() <= $rate['date']) && (!$rate['rate_id'] || !$rate['active'])) {
             $rate = $rateSelector->getSelectorRate($bookingDomain->getId(), $rate['date'], false, $isApartel);
         }
         // check availability in Reservation
         if (!$bookingDomain && !$result['overbooking'] && $rate['availability'] == 0) {
             $result['overbooking'] = true;
         }
         // check rate price mismatch
         if ($applyFuzzyLogic && isset($fromCubilisRatesData[$rate['date']]['price']) && $ourPrice != $fromCubilisRatesData[$rate['date']]['price']) {
             // fuzzy logic for base price
             $priceFuzzyLogic = $partnerSpecificService->getBasePriceByFuzzyLogic($fromCubilisRatesData[$rate['date']]['price'], $partner, $apartmentId, $rate['capacity'], $nightCount);
             $price = $priceFuzzyLogic ? $priceFuzzyLogic : $ourPrice;
         } else {
             $price = $ourPrice;
         }
         $cubilisRateId = isset($fromCubilisRatesData[$rate['date']]['channel_rate_id']) ? $fromCubilisRatesData[$rate['date']]['channel_rate_id'] : 0;
         // check Rate Name
         if (isset($fromCubilisRatesData[$rate['date']]['rate_name']) && $fromCubilisRatesData[$rate['date']]['rate_name']) {
             $rateName = $fromCubilisRatesData[$rate['date']]['rate_name'];
         } else {
             $rateName = $rate['rate_name'];
             // send critical email if not send rate name
             if (!$rateNameNot) {
                 $this->gr2err('Cubilis Not Sending Rate Name', ['cron' => 'ChannelManager', 'apartment_id' => $apartmentId, 'apartel_id' => $apartelId, 'channel_rate_id' => $cubilisRateId, 'channel_res_id' => $channelResId, 'date' => $rate['date']]);
                 $rateNameNot = true;
             }
         }
         $ratesData[$rate['date']] = ['apartment_id' => $apartmentId, 'room_id' => $rate['room_type_id'], 'rate_name' => $rateName, 'price' => $price, 'date' => $rate['date'], 'capacity' => $rate['capacity'], 'rate_id' => $rate['rate_id'], 'availability' => $rate['availability']];
         // send critical email if has currency mismatch
         if (!$currencyNotMatch && (!isset($fromCubilisRatesData[$rate['date']]['currency']) || strtolower($ginosiCurrency) != strtolower($fromCubilisRatesData[$rate['date']]['currency']))) {
             $this->gr2err('Cubilis apartment currency mismatch with our apartment currency', ['cron' => 'ChannelManager', 'apartment_id' => $apartmentId, 'apartel_id' => $apartelId, 'channel_res_id' => $channelResId]);
             $currencyNotMatch = true;
         }
     }
     // extra check if rate not matched
     if (count($rates) != $nightCount) {
         $result['overbooking'] = true;
     }
     // apartel data
     if ($isApartel) {
         $result['apartel']['apartment_id'] = $apartmentId;
         $result['apartel']['apartel_id'] = $apartelId;
     }
     $result['ratesData'] = $ratesData;
     return $result;
 }