示例#1
0
文件: Booking.php 项目: arbi/MyCode
 /**
  * @param array $data
  * @return array
  */
 public function bookingDataByCCPassword($data)
 {
     /**
      * @var \DDD\Service\Website\Apartment $apartmentService
      * @var \DDD\Service\Booking\Charge $chargeService
      */
     $apartmentService = $this->getServiceLocator()->get('service_website_apartment');
     $chargeService = $this->getServiceLocator()->get('service_booking_charge');
     if (!isset($data['code']) || !ClassicValidator::checkCCPdateCode($data['code'])) {
         return false;
     }
     /**
      * @var \DDD\Dao\Booking\Booking $bookingDao
      */
     $bookingDao = $this->getServiceLocator()->get('dao_booking_booking');
     $bookingDao->setEntity(new \ArrayObject());
     $resData = $bookingDao->getResDataByCCUpdateCode($data['code']);
     if (!$resData) {
         return false;
     }
     $img = Helper::getImgByWith($resData['img1'], WebSite::IMG_WIDTH_SEARCH, true, true);
     if ($img) {
         $resData['image'] = $img;
     }
     $resData['user_currency'] = $resData['guest_currency_code'];
     $bookNightCount = Helper::getDaysFromTwoDate($resData['date_from'], $resData['date_to']);
     $resData['night_count'] = $bookNightCount;
     $resData['totalNigthCount'] = $bookNightCount;
     // Cancelation Policy
     $cancelationDate = $resData;
     $cancelationDate['penalty_percent'] = $cancelationDate['penalty_fixed_amount'] = $cancelationDate['penalty_nights'] = $resData['penalty_val'];
     $cancelationDate['night_count'] = $bookNightCount;
     $cancelationDate['code'] = $resData['apartment_currency_code'];
     $cancelationPolicy = $apartmentService->cancelationPolicy($cancelationDate);
     $resData['cancelation_type'] = $cancelationPolicy['type'];
     $resData['cancelation_policy'] = $cancelationPolicy['description'];
     $paymentDetails = $chargeService->getCharges($resData['id']);
     // When showing to customers we don't really want to show base and additional parts of taxes separately
     // This part of code runs through payment details and combines same type of taxes for same day into a single unit
     $floatPattern = '/-?(?:\\d+|\\d*\\.\\d+)/';
     $smarterPaymentDetails = [];
     if ($paymentDetails) {
         foreach ($paymentDetails as $payment) {
             if ($payment['type'] != 'tax') {
                 array_push($smarterPaymentDetails, $payment);
             } else {
                 $paymentKey = $payment['type_id'] . '-' . $payment['date'];
                 if (!isset($smarterPaymentDetails[$paymentKey])) {
                     $smarterPaymentDetails[$paymentKey] = $payment;
                 } else {
                     preg_match($floatPattern, $smarterPaymentDetails[$paymentKey]['label'], $match);
                     $currValue = $match[0];
                     $currPrice = $smarterPaymentDetails[$paymentKey]['price'];
                     preg_match($floatPattern, $payment['label'], $match);
                     $additionalValue = $match[0];
                     $additionalPrice = $payment['price'];
                     $smarterPaymentDetails[$paymentKey]['label'] = str_replace($currValue, $currValue + $additionalValue, $smarterPaymentDetails[$paymentKey]['label']);
                     $smarterPaymentDetails[$paymentKey]['price'] = str_replace($currPrice, $currPrice + $additionalPrice, $smarterPaymentDetails[$paymentKey]['price']);
                     $smarterPaymentDetails[$paymentKey]['price_view'] = str_replace($currPrice, $currPrice + $additionalPrice, $smarterPaymentDetails[$paymentKey]['price_view']);
                 }
             }
         }
     }
     $resData['paymentDetails']['payments'] = $smarterPaymentDetails;
     return $resData;
 }