request = $request; $this->propertyWebService = $propertyWebService; $this->languageService = $languageService; $this->languageBaseService = $languageBaseService; $this->propertyWebMenuService = $propertyWebMenuService; $this->propertyWebMenuMappingService = $propertyWebMenuMappingService; $this->propertyWebSetupService = $propertyWebSetupService; $this->propertyWebLanguageMappingService = $propertyWebLanguageMappingService; $this->propertyWebColorMappingService = $propertyWebColorMappingService; $this->propertyBrandService = $propertyBrandService; $this->propertyChannelMappingService = $propertyChannelMappingService; $this->propertyGroupMappingService = $propertyGroupMappingService; $this->findCountryCodeService = $findCountryCodeService; $this->propertyWebLogService = $propertyWebLogService; $this->propertyWebMetaService = $propertyWebMetaService; $this->bookingService = $bookingService; $this->propertyWebAboutUsService = $propertyWebAboutUsService; $this->propertyPlaceService = $propertyPlaceService; $this->propertyAdditionalInfoService = $propertyAdditionalInfoService; $this->propertyService = $propertyService; $this->propertyRoomService = $propertyRoomService; $this->propertyWebContentService = $propertyWebContentService; $this->pdf = $pdf; } public function listPropertyWeb(Request $request) { $response = ['status' => false, 'message' => '', 'data' => null, 'statusCode' => 500]; try { if (is_null($request->getContent())) { throw new ApiErrorException(lang('Parameter Error.')); } $params = $request->params; $propertyRequest = [ 'criteria' => [ ['field' => 'property_id', 'condition' => '=', 'value' => fillOnUndefined($params, 'property_id')], ], "orderBy" => [ ["field" => "id", "value" => "DESC"] ], "with" => ['propertyWebTemplate', 'propertyWebLanguage'], ]; $propertyWebs = $this->propertyWebService->select($propertyRequest, ['id', 'domain', 'default_language', 'template_id', 'token', 'status', 'is_published', 'is_dns_checked']); if ($propertyWebs['status'] != 'success') { throw new ApiErrorException($propertyWebs['message']); } $web = []; foreach ($propertyWebs['data'] as $key => $propertyWeb) { //Cache $dashboardCountablePlaceCacheKey = md5('dashboardCountablePlace-' . $params['property_id']); if (Cache::has($dashboardCountablePlaceCacheKey)) { $counts = Cache::get($dashboardCountablePlaceCacheKey); } else { $counts = $this->dashboardCountablePlace($params, $propertyWeb['id']); } if ($counts['status'] === false) { throw new ApiErrorException($counts['message']); } $webData = [ 'live_url' => Config::get('app.mainHostAddress') . '/live/' . $propertyWeb['token'] . '/' . $propertyWeb['default_language'], 'preview_url' => Config::get('app.mainHostAddress') . '/preview/' . $propertyWeb['token'] . '/' . $propertyWeb['default_language'], 'log' => $counts['data'] ]; $web[$key] = array_merge($propertyWeb, $webData); } $web = reset($web); $response = ['status' => 1, 'statusCode' => 200, 'message' => null, 'data' => $web]; } catch (ApiErrorException $e) { $response['message'] = implode(', ', $e->getMessageArr()); $response['statusCode'] = 400; } catch (Exception $e) { $message = $e->getFile() . " " . $e->getLine() . " " . $e->getMessage(); Log::error($message); $response['message'] = $e->getMessage(); $response['statusCode'] = 500; } return apiResponse($response['status'], $response['message'], $response['data'], $response['statusCode']); } public function getPropertyWeb(Request $request) { $response = ['status' => false, 'message' => '', 'data' => null, 'statusCode' => 500]; try { if (is_null($request->getContent())) { throw new ApiErrorException(lang('Parameter Error.')); } $params = $request->params; $propertyWebRequest = [ 'id' => fillOnUndefined($params, 'property_web_id'), 'property_id' => fillOnUndefined($params, 'property_id') ]; $propertyWeb = $this->propertyWebService->getPropertyWeb($propertyWebRequest); if ($propertyWeb['status'] != 'success') { throw new ApiErrorException($propertyWeb['message']); } $propertyWeb = $propertyWeb['data']; $webData = [ 'live_url' => Config::get('app.mainHostAddress') . '/live/' . $propertyWeb['token'] . '/' . $propertyWeb['default_language'], 'preview_url' => Config::get('app.mainHostAddress') . '/preview/' . $propertyWeb['token'] . '/' . $propertyWeb['default_language'], ]; $propertyWeb = array_merge($propertyWeb, $webData); $response = ['status' => 1, 'statusCode' => 200, 'message' => null, 'data' => $propertyWeb]; } catch (ApiErrorException $e) { $response['message'] = implode(', ', $e->getMessageArr()); $response['statusCode'] = 400; } catch (Exception $e) { $message = $e->getFile() . " " . $e->getLine() . " " . $e->getMessage(); Log::error($message); $response['message'] = $e->getMessage(); $response['statusCode'] = 500; } return apiResponse($response['status'], $response['message'], $response['data'], $response['statusCode']); } public function createPropertyWeb(Request $request) { $response = ['status' => false, 'message' => '', 'data' => null, 'statusCode' => 500]; try { if (is_null($this->request->getContent())) { throw new ApiErrorException(lang('Parameter Error.')); } $params = $this->request->params; $requestParams = $params; $requestParams['user_id'] = $this->request->auth->id; $storePropertyWeb = $this->propertyWebService->create($requestParams); if ($storePropertyWeb['status'] != 'success') { throw new ApiErrorException($storePropertyWeb['message']); } $propertyWebRequest = [ 'id' => $storePropertyWeb['data']['id'], 'property_id' => fillOnUndefined($params, 'property_id'), 'user_id' => $this->request->auth->id ]; $storePropertyWebPhotos = $this->propertyWebService->insertAllPropertyWebPhotosToMapping($propertyWebRequest); if ($storePropertyWebPhotos['status'] != 'success') { throw new ApiErrorException($storePropertyWebPhotos['message']); } $propertyWeb = $this->propertyWebService->getPropertyWeb($propertyWebRequest); if ($propertyWeb['status'] != 'success') { throw new ApiErrorException($propertyWeb['message']); } $propertyWeb['data']['log'] = [ 'active_user_count' => 0, 'booking_count' => 0, 'country_count' => [], 'mobile_count' => 0, 'web_count' => 0 ]; $response = ['status' => 1, 'statusCode' => 200, 'message' => null, 'data' => $propertyWeb['data']]; } catch (ApiErrorException $e) { $response['message'] = implode(', ', $e->getMessageArr()); $response['statusCode'] = 400; } catch (Exception $e) { $message = $e->getFile() . " " . $e->getLine() . " " . $e->getMessage(); Log::error($message); $response['message'] = $e->getMessage(); $response['statusCode'] = 500; } return apiResponse($response['status'], $response['message'], $response['data'], $response['statusCode']); } public function updatePropertyWeb(Request $request) { $response = ['status' => false, 'message' => '', 'data' => null, 'statusCode' => 500]; try { if (is_null($this->request->getContent())) { throw new ApiErrorException(lang('Parameter Error.')); } $params = $this->request->params; $requestParams = $params; $requestParams['user_id'] = $this->request->auth->id; $propertyWebId = $params['property_web_id']; $storePropertyWeb = $this->propertyWebService->update($propertyWebId, $requestParams); if ($storePropertyWeb['status'] != 'success') { throw new ApiErrorException($storePropertyWeb['message']); } $propertyWebRequest = [ 'id' => $propertyWebId, 'property_id' => fillOnUndefined($params, 'property_id') ]; $propertyWeb = $this->propertyWebService->getPropertyWeb($propertyWebRequest); if ($propertyWeb['status'] != 'success') { throw new ApiErrorException($propertyWeb['message']); } $response = ['status' => 1, 'statusCode' => 200, 'message' => null, 'data' => $propertyWeb['data']]; } catch (ApiErrorException $e) { $response['message'] = implode(', ', $e->getMessageArr()); $response['statusCode'] = 400; } catch (Exception $e) { $message = $e->getFile() . " " . $e->getLine() . " " . $e->getMessage(); Log::error($message); $response['message'] = $e->getMessage(); $response['statusCode'] = 500; } return apiResponse($response['status'], $response['message'], $response['data'], $response['statusCode']); } public function checkDomain(Request $request) { $response = ['status' => false, 'message' => '', 'data' => null, 'statusCode' => 500]; try { if (is_null($request->getContent())) { throw new ApiErrorException(lang('Parameter Error.')); } $params = $request->params; $params['mode'] = fillOnUndefined($params, 'mode', null); $propertyRequest = [ 'criteria' => [ ['field' => 'domain', 'condition' => '=', 'value' => fillOnUndefined($params, 'domain')], ['field' => 'status', 'condition' => '=', 'value' => 1], ['field' => 'is_published', 'condition' => '=', 'value' => 1], ], 'firstRow' => true, "with" => [ 'property', 'property.propertyAwardsCertificates.awardsCertificateCategory', 'propertyWebTemplate', 'propertyBookingEngine', 'propertyWebMenuMenuMapping', 'propertyWebLanguageMapping', 'propertyGroupMapping.propertyGroup', 'propertyWebAbout', 'propertyWebPopup', 'propertyWebWeather', 'propertyWebComponent', 'propertyWebRoomMapping.roomDetail', 'propertyWebColorMapping' ] ]; $propertyWeb = $this->propertyWebService->select($propertyRequest, ['id', 'property_id', 'domain', 'default_language', 'template_id', 'token', 'is_ssl_active', 'weather_active', 'cover_video_id']); $propertyGroupId = NULL; $propertyBookingEngineGroupId = NULL; if (isset($propertyWeb['data']['property_group_mapping'])) { foreach ($propertyWeb['data']['property_group_mapping'] as $propertyGroupMapping) { if (!empty($propertyGroupMapping['property_group'] && $propertyGroupMapping['property_group']['type'] === "MYW")) { $propertyGroupId = $propertyGroupMapping['property_group']['id']; } if (!empty($propertyGroupMapping['property_group'] && $propertyGroupMapping['property_group']['type'] === "MYW")) { $propertyBookingEngineGroupId = $propertyGroupMapping['property_group']['id']; } } } if (!isset($propertyWeb['data']['property'])) { throw new ApiErrorException('Property is not active!', 101); //101: Passive Property } if ($propertyWeb['data']['property']['status'] != 1) { throw new ApiErrorException('Property is not active!', 101); //101: Passive Property } $propertyGroupMappingRequest = [ 'criteria' => [ ['field' => 'status', 'condition' => '=', 'value' => 1], ['field' => 'property_group_id', 'condition' => '=', 'value' => $propertyGroupId], ['field' => 'property_id', 'condition' => '!=', 'value' => fillOnUndefined($propertyWeb['data'], 'property_id')] ], 'orderBy' => [ ["field" => "order_number", "value" => "ASC"] ], "with" => ['property.propertyWeb'] ]; $propertyGroupWebSiteResult = $this->propertyGroupMappingService->getPropertyGroupMapping($propertyGroupMappingRequest); if ($propertyGroupWebSiteResult['status'] != 'success') { throw new ApiErrorException($propertyGroupWebSiteResult['message']); } $propertyGroupWebSites = $propertyGroupWebSiteResult['data']; $groupWebSites = []; foreach ($propertyGroupWebSites as $propertyGroupWebSite) { if ($propertyGroupWebSite['property'] && $propertyGroupWebSite['property']['property_web']) { $propertyGroupWebSite['property']['property_web']['name'] = $propertyGroupWebSite['property']['name']; $groupWebSites[] = $propertyGroupWebSite['property']['property_web']; } } $groupWebSites = collect($groupWebSites)/*->where('is_published', 1)*/ ->values()->toArray(); if (!empty($propertyWeb['data'])) { $propertyWeb['data']['property_group_web_sites'] = $groupWebSites; unset($propertyWeb['data']['property_group_mapping']); } $propertyBookingGroupMappingRequest = [ 'criteria' => [ ['field' => 'status', 'condition' => '=', 'value' => 1], ['field' => 'property_group_id', 'condition' => '=', 'value' => $propertyBookingEngineGroupId], ], 'orderBy' => [ ["field" => "order_number", "value" => "ASC"] ], "with" => [ 'property.propertyBookingEngineToken', 'property.propertyWeb.propertyWebPhotoMapping.propertyPhoto' ] ]; $propertyGroupBookingResult = $this->propertyGroupMappingService->getPropertyGroupMapping($propertyBookingGroupMappingRequest); if ($propertyGroupBookingResult['status'] != 'success') { throw new ApiErrorException($propertyGroupBookingResult['message']); } $propertyGroupBookings = $propertyGroupBookingResult['data']; $bookingGroupProperties = []; foreach ($propertyGroupBookings as $key => $propertyGroupBooking) { if ($propertyGroupBooking['property']) { $bookingGroupProperties[$key]['property_id'] = $propertyGroupBooking['property']['id']; $bookingGroupProperties[$key]['name'] = $propertyGroupBooking['property']['name']; $bookingGroupProperties[$key]['name'] = $propertyGroupBooking['property']['name']; if ($propertyGroupBooking['property']['property_booking_engine_token']) { $bookingGroupProperties[$key]['token'] = $propertyGroupBooking['property']['property_booking_engine_token']['token']; } else { $bookingGroupProperties[$key]['token'] = null; } $bookingGroupProperties[$key]['web'] = null; if (!empty($propertyGroupBooking['property']['property_web'])) { if ($propertyGroupBooking['property']['property_web']['status'] && $propertyGroupBooking['property']['property_web']['is_published']) { $bookingGroupProperties[$key]['web'] = $propertyGroupBooking['property']['property_web']['webProtocolUrl']; } } $propertyWebPhotoMapping = collect($propertyGroupBooking['property']['property_web']['property_web_photo_mapping']) ->where('status', 1) ->where('is_cover', 1) ->toArray(); $bookingGroupProperties[$key]['coverPhoto'] = []; foreach ($propertyWebPhotoMapping as $propertyWebPhoto) { $bookingGroupProperties[$key]['coverPhoto'][] = $propertyWebPhoto['property_photo']['photoUrl']; } } } if (!empty($bookingGroupProperties)) { $propertyWeb['data']['property_booking_group'] = collect($bookingGroupProperties)->where('token', '!=', NULL)->toArray(); } if (!empty($propertyWeb['data']['property_booking_engine'])) { $propertyChannelMappingRequestData = [ 'property_id' => $propertyWeb['data']['property_booking_engine']['property_id'], 'channel_id' => $propertyWeb['data']['property_booking_engine']['channel_id'] ]; $propertyChannelMappingData = $this->propertyChannelMappingService->checkPropertyChannelMapping($propertyChannelMappingRequestData); if ($propertyChannelMappingData['data'] === "") { $propertyWeb['data']['property_booking_engine']['token'] = NULL; } } $propertyWebPreviewOrLiveMenus = []; if (isset($propertyWeb['data']['property_web_menu_menu_mapping'])) { $propertyWebPreviewOrLiveMenus = collect($propertyWeb['data']['property_web_menu_menu_mapping']) ->where('status', 1)->toArray(); // live } if ($propertyWeb['status'] != 'success' || !$propertyWeb['data']) { throw new ApiErrorException('Domain not found'); } $availableLanguageRequest = [ 'criteria' => [ ['field' => 'status', 'condition' => '=', 'value' => 1], ['field' => 'is_application', 'condition' => '=', 'value' => 1], ['field' => 'is_published', 'condition' => '=', 'value' => 1] ], ]; $availableLanguages = $this->languageService->select($availableLanguageRequest, ['code', 'name', 'language_key']); $propertyWebLanguageMappings = $propertyWeb['data']['property_web_language_mapping'] ? $propertyWeb['data']['property_web_language_mapping'] : []; $propertyWebLanguageMappings = collect($propertyWebLanguageMappings)->keyBy('language_code')->toArray(); if ($propertyWebLanguageMappings) { foreach ($availableLanguages['data'] as $language) { if (array_key_exists($language['code'], $propertyWebLanguageMappings)) { $propertyWeb['data']['available_language_codes'][$language['code']] = $language; } } } else { foreach ($availableLanguages['data'] as $language) { $propertyWeb['data']['available_language_codes'][$language['code']] = $language; } } $webMenu = []; if (empty($propertyWebPreviewOrLiveMenus)) { $myWebMenus = $this->propertyWebMenuService->getPropertyWebMenu(); if ($myWebMenus['status'] != 'success') { throw new ApiErrorException($myWebMenus['message']); } $propertyWeb['data']['web_menu']['LVL1'] = collect($myWebMenus['data']['property_web_menus'])->where('type', '=', '1')->keyBy('alias')->toArray(); $propertyWeb['data']['web_menu']['LEGAL'] = collect($myWebMenus['data']['property_web_menus'])->where('type', '=', '3')->keyBy('alias')->toArray(); unset($propertyWeb['data']['property_web_menu_menu_mapping']); } else { $webMenuTypes = collect($propertyWeb['data']['property_web_menu_menu_mapping']) ->where('status', 1) ->groupBy('menu_code')->toArray(); $allLevelData = []; $allTopData = []; foreach ($webMenuTypes as $menuTypeKey => $webMenuType) { if ($menuTypeKey === self::MENU_CODE_LVL1) { $allLevelData = $this->getTypeMenus($webMenuType, $menuTypeKey); } elseif ($menuTypeKey === self::MENU_CODE_TOP) { $allTopData = $this->getTypeMenus($webMenuType, $menuTypeKey); } } $staticMenu = $this->propertyWebMenuService->getPropertyWebMenu(); if ($staticMenu['status'] != 'success') { throw new ApiErrorException($staticMenu['message']); } unset($propertyWeb['data']['property_web_menu_menu_mapping']); $propertyWeb['data']['web_menu'] = array_merge($allTopData, $allLevelData); $propertyWeb['data']['web_menu']['LEGAL'] = collect($staticMenu['data']['property_web_menus'])->where('type', '=', '3')->keyBy('alias')->toArray(); } if ($propertyWeb['data']['property']['country'] == 'TR') { unset($propertyWeb['data']['web_menu']['LEGAL']['Protection']); } else { unset($propertyWeb['data']['web_menu']['LEGAL']['Kvkk']); } //property_web_room_mapping $propertyWebRoomMapping = []; $propertyWebRoomMappingTemp = $propertyWeb['data']['property_web_room_mapping']; unset($propertyWeb['data']['property_web_room_mapping']); foreach ($propertyWebRoomMappingTemp as $propertyWebRoom) { $propertyWebRoomMapping[] = [ 'id' => $propertyWebRoom['room_detail']['id'], 'name' => $propertyWebRoom['room_detail']['name'], 'slug' => Str::slug($propertyWebRoom['room_detail']['name'], $separator = '-', $language = 'en') . '-' . $propertyWebRoom['room_detail']['id'] ]; } $propertyWeb['data']['property_web_room_mapping'] = $propertyWebRoomMapping; //property_web_room_mapping $agentIp = !empty($params['agentInfo']) && $params['agentInfo']['ip'] ? $params['agentInfo']['ip'] : NULL; if ($agentIp !== NULL) { // Find Country Code with IP $ipResponse = $this->findCountryCodeService->findCountryWithIpAddress($agentIp); if ($ipResponse['status'] !== 'success') { //throw new ApiErrorException('IP Not Found'); } // Create or Update Web Log if (!empty($params['agentInfo']) && !empty($ipResponse['data']) && !empty($ipResponse['data']['code']) && $ipResponse['status']) { $agentParams = [ 'web_id' => fillOnUndefined($propertyWeb['data'], 'id'), 'ip' => $agentIp, 'country_code' => $ipResponse['data'] ? $ipResponse['data']['code'] : null, 'isRobot' => $params['agentInfo']['isRobot'] === true ? $params['agentInfo']['isRobot'] : false, 'isDesktop' => $params['agentInfo']['isDesktop'] === true ? $params['agentInfo']['isDesktop'] : false, 'isPhone' => $params['agentInfo']['isPhone'] === true ? $params['agentInfo']['isPhone'] : false ]; if ($agentParams['isRobot'] === false) { $webLogResponse = $this->propertyWebLogService->createPropertyWebLog($agentParams); if ($webLogResponse['status'] != 'success') { throw new ApiErrorException('Property Web Log Not Created'); } } } } //PropertyWebPopUp $propertyWebPopUp = null; if ($propertyWeb['data']['property_web_popup']) { $propertyWebPopUp = collect($propertyWeb['data']['property_web_popup']) ->where('start_date', '<=', Carbon::now()->toDateString()) ->where('end_date', '>=', Carbon::now()->toDateString()) ->toArray(); $propertyWebPopUp = array_values($propertyWebPopUp); } $propertyWeb['data']['property_web_popup'] = $propertyWebPopUp; //PropertyWebPopUp //PropertyWebContent $propertyWebContent = null; $propertyWebContentCriteria = [ 'criteria' => [ ['field' => 'property_id', 'condition' => '=', 'value' => $propertyWeb['data']['property_id']], ['field' => 'status', 'condition' => '=', 'value' => 1] ], //'with' => ['ContentCategory'], 'orderBy' => [ ['field' => 'id', 'value' => 'DESC'] ] ]; $propertyWebContentCriteria['skip'] = 0; $propertyWebContentCriteria['take'] = 100; $propertyWebContent = $this->propertyWebContentService->select($propertyWebContentCriteria, ['id', 'title', 'property_id', 'content_category_id', 'slug', 'language_code', 'image']); $propertyWebContent = ($propertyWebContent['status'] == 'success' && !empty($propertyWebContent['data'])) ? array_values($propertyWebContent['data']) : []; $propertyWebContentGrouped = null; foreach ($propertyWebContent as $content) { if (isset($propertyWebContentGrouped[$content['language_code']]) && count($propertyWebContentGrouped[$content['language_code']]) > 2) { continue; } $propertyWebContentGrouped[$content['language_code']][] = $content; } $propertyWeb['data']['property_web_content'] = $propertyWebContentGrouped; //PropertyWebContent //property_web_weather $propertyWeb['data']['property_web_weather'] = $propertyWeb['data']['weather_active'] == 1 ? $propertyWeb['data']['property_web_weather'] : null; //PropertyWebComponent if ($propertyWeb['data']['property_web_component']) { $propertyWebComponent = $propertyWeb['data']['property_web_component']; unset($propertyWeb['data']['property_web_component']); $propertyWebComponentGoogleTagManager = collect($propertyWebComponent) ->where('component_id', 1) ->first(); if ($propertyWebComponentGoogleTagManager) { $propertyWeb['data']['property_web_component']['google_tag_manager'] = $propertyWebComponentGoogleTagManager['parameterArray']; } $propertyWebComponentGoogleAnalytics = collect($propertyWebComponent) ->where('component_id', 4) ->first(); if ($propertyWebComponentGoogleAnalytics) { $propertyWeb['data']['property_web_component']['google_analytics'] = $propertyWebComponentGoogleAnalytics['parameterArray']; } $propertyWebComponentJotform = collect($propertyWebComponent) ->where('component_id', 5) ->first(); if ($propertyWebComponentJotform) { $propertyWeb['data']['property_web_component']['jotform'] = $propertyWebComponentJotform['parameterArray']; } $propertyWebComponentMetaPixel = collect($propertyWebComponent) ->where('component_id', 6) ->first(); if ($propertyWebComponentMetaPixel) { $propertyWeb['data']['property_web_component']['metapixel'] = $propertyWebComponentMetaPixel['parameterArray']; } $propertyWebComponentTawkTo = collect($propertyWebComponent) ->where('component_id', 7) ->first(); if ($propertyWebComponentTawkTo) { $propertyWeb['data']['property_web_component']['tawkto'] = $propertyWebComponentTawkTo['parameterArray']; } $propertyWebComponentGoogleSiteVerification = collect($propertyWebComponent) ->where('component_id', 8) ->first(); if ($propertyWebComponentGoogleSiteVerification) { $propertyWeb['data']['property_web_component']['googlesiteverification'] = $propertyWebComponentGoogleSiteVerification['parameterArray']; } $propertyWebComponentSojernWeb = collect($propertyWebComponent) ->where('component_id', 9) ->first(); if ($propertyWebComponentSojernWeb) { $propertyWeb['data']['property_web_component']['sojernweb'] = $propertyWebComponentSojernWeb['parameterArray']; } $propertyWebComponentSojernBookingEngine = collect($propertyWebComponent) ->where('component_id', 10) ->first(); if ($propertyWebComponentSojernBookingEngine) { $propertyWeb['data']['property_web_component']['sojernbookingengine'] = $propertyWebComponentSojernBookingEngine['parameterArray']; } $propertyWebComponentGoogleAds = collect($propertyWebComponent) ->where('component_id', 11) ->first(); if ($propertyWebComponentGoogleAds) { $propertyWeb['data']['property_web_component']['googleads'] = $propertyWebComponentGoogleAds['parameterArray']; } $propertyWebComponentMetaVerification = collect($propertyWebComponent) ->where('component_id', 12) ->first(); if ($propertyWebComponentMetaVerification) { $propertyWeb['data']['property_web_component']['metaverification'] = $propertyWebComponentMetaVerification['parameterArray']; } $propertyWebComponentClarityweb = collect($propertyWebComponent) ->where('component_id', 13) ->first(); if ($propertyWebComponentClarityweb) { $propertyWeb['data']['property_web_component']['clarityweb'] = $propertyWebComponentClarityweb['parameterArray']; } $propertyWebComponentClarityBookingEngine = collect($propertyWebComponent) ->where('component_id', 14) ->first(); if ($propertyWebComponentClarityBookingEngine) { $propertyWeb['data']['property_web_component']['claritybookingengine'] = $propertyWebComponentClarityBookingEngine['parameterArray']; } } //PropertyWebComponent //PropertyAwardsCertificates if (!empty($propertyWeb['data']['property']['property_awards_certificates'])) { $staticPolicyIds = [134, 177, 211, 232]; $staticPolicyGroup = []; $propertyAwardsCertificates = collect($propertyWeb['data']['property']['property_awards_certificates'])->where('status', 1)->whereIn('category_id', $staticPolicyIds)->sortByDesc('id')->toArray(); if ($propertyAwardsCertificates) { foreach ($propertyAwardsCertificates as $propertyAwardsCertificate) { if (isset($staticPolicyGroup[$propertyAwardsCertificate['category_id']]['language'][$propertyAwardsCertificate['language_code']])) { continue; } $staticPolicyGroup[$propertyAwardsCertificate['category_id']]['name'] = $propertyAwardsCertificate['awards_certificate_category']['name']; $staticPolicyGroup[$propertyAwardsCertificate['category_id']]['language_key'] = $propertyAwardsCertificate['awards_certificate_category']['language_key']; if (empty($propertyAwardsCertificate['language_code'])) { $propertyAwardsCertificate['language_code'] = 'default'; } $staticPolicyGroup[$propertyAwardsCertificate['category_id']]['language'][$propertyAwardsCertificate['language_code']] = [ 'file' => $propertyAwardsCertificate['file_path'], 'url' => Config::get('app.imageUrl') . '/property-photos/' . $propertyWeb['data']['property']['id'] . '/awards-certificates/' . $propertyAwardsCertificate['file_path'] ]; } } $propertyWeb['data']['static_policy'] = !empty($staticPolicyGroup) ? $staticPolicyGroup : null; unset($propertyWeb['data']['property']['property_awards_certificates']); } //PropertyAwardsCertificates $propertyRequest = [ 'criteria' => [ ['field' => 'id', 'condition' => '=', 'value' => $propertyWeb['data']['property_id']], ['field' => 'status', 'condition' => '=', 'value' => 1], ], 'with' => [ 'propertyBrand', 'propertyContact', 'propertyPhotos', 'propertyType', 'propertyChain', 'propertyRooms', 'propertyWeb', 'propertyAwardsCertificates.awardsCertificateCategory', 'propertyPaymentMapping' ], 'firstRow' => true ]; $getPropertyFields = ['id', 'name', 'property_type_id', 'chain_id', 'rating', 'official_name', 'tax_office', 'tax_number', 'currency_type', 'country']; $propertyDetail = $this->propertyService->select($propertyRequest, $getPropertyFields); $propertyDetail = $propertyDetail['data']; $propertyDetail['property_brand']['logo_url'] = isset($propertyDetail['property_brand']) ? Config::get('app.imageUrl') . '/property-photos/' . $propertyDetail['id'] . "/logo/" . $propertyDetail['property_brand']['logo_name'] . '_250x250.' . $propertyDetail['property_brand']['logo_file_ext'] : null; $propertyDetail['property_contact']['social_media_addresses'] = json_decode($propertyDetail['property_contact']['social_media_addresses'], 1); $colorCodes = []; foreach ($propertyWeb['data']['property_web_color_mapping'] as $color) { $colorCodes[] = [ 'color_number' => $color['order_number'], 'color_code' => $color['color_code'], ]; } $colorCodes = $colorCodes ? $colorCodes : json_decode($propertyDetail['property_brand']['color_codes'], 1); $propertyDetail['property_brand']['color_codes'] = $colorCodes; $propertyAdditionalInfo = null; $propertyAdditionalInfoRequest = $this->propertyAdditionalInfoService->getPropertyAdditionalInfo2KeyBy(['property_id' => $propertyDetail['id']]); if (isset($propertyAdditionalInfoRequest['data'])) { $propertyAdditionalInfo = $propertyAdditionalInfoRequest['data']; } //coverPhotos $coverPhotosParam = [ 'property_id' => $propertyWeb['data']['property']['id'], 'property_web_id' => $propertyWeb['data']['id'], 'mode' => $params['mode'], ]; $landingPhoto = $this->coverPhotos($coverPhotosParam); //coverPhotos $propertyWeb['data']['property']['name'] = $propertyDetail['name']; $propertyWeb['data']['property']['property_type'] = $propertyDetail['property_type']['name']; $propertyWeb['data']['property']['property_type_key'] = $propertyDetail['property_type']['language_key']; $propertyWeb['data']['property']['property_chain'] = $propertyDetail['property_chain']['name']; $propertyWeb['data']['property']['official_name'] = $propertyDetail['official_name']; $propertyWeb['data']['property']['tax_office'] = $propertyDetail['tax_office']; $propertyWeb['data']['property']['tax_number'] = $propertyDetail['tax_number']; $propertyWeb['data']['property']['currency_type'] = $propertyDetail['currency_type']; $propertyWeb['data']['property']['property_brand'] = $propertyDetail['property_brand']; $propertyWeb['data']['property']['property_contact'] = $propertyDetail['property_contact']; $propertyWeb['data']['property']['description'] = $propertyDetail['name']; $propertyWeb['data']['property']['additional_info'] = $propertyAdditionalInfo; $propertyWeb['data']['property']['landing_photo'] = $landingPhoto; $propertyWeb['data']['is_virtual_payment_active'] = collect($propertyDetail['property_payment_mapping'])->where('status', 1)->count() > 0 ? true : false; $response = ['status' => 1, 'statusCode' => 200, 'message' => null, 'data' => $propertyWeb['data']]; } catch (ApiErrorException $e) { $response['message'] = implode(', ', $e->getMessageArr()); $response['statusCode'] = 400; $response['errorCode'] = $e->getCode(); } catch (Exception $e) { $message = $e->getFile() . " " . $e->getLine() . " " . $e->getMessage(); Log::error($message); $response['message'] = $e->getMessage(); $response['statusCode'] = 500; } return apiResponse($response['status'], $response['message'], $response['data'], $response['statusCode'], fillOnUndefined($response, 'errorCode', null)); } public function checkDomainToken(Request $request) { $response = ['status' => false, 'message' => '', 'data' => null, 'statusCode' => 500]; try { if (is_null($request->getContent())) { throw new ApiErrorException(lang('Parameter Error.')); } $params = $request->params; $propertyRequest = [ 'criteria' => [ ['field' => 'token', 'condition' => '=', 'value' => fillOnUndefined($params, 'token')], ['field' => 'status', 'condition' => '=', 'value' => 1], ], 'firstRow' => true, "with" => [ 'property', 'propertyWebTemplate', 'propertyBookingEngine', 'propertyWebMenuMenuMapping', 'propertyWebLanguageMapping', 'propertyGroupMapping.propertyGroup', 'propertyWebAbout', 'propertyWebPopup', 'propertyWebWeather', 'propertyWebComponent', 'propertyWebRoomMapping.roomDetail' ] ]; $propertyWeb = $this->propertyWebService->select($propertyRequest, ['id', 'property_id', 'domain', 'default_language', 'template_id', 'token', 'is_ssl_active', 'weather_active', 'cover_video_id']); $propertyGroupId = NULL; $propertyBookingEngineGroupId = NULL; if (isset($propertyWeb['data']['property_group_mapping'])) { foreach ($propertyWeb['data']['property_group_mapping'] as $propertyGroupMapping) { if (!empty($propertyGroupMapping['property_group'] && $propertyGroupMapping['property_group']['type'] === "MYW")) { $propertyGroupId = $propertyGroupMapping['property_group']['id']; } if (!empty($propertyGroupMapping['property_group'] && $propertyGroupMapping['property_group']['type'] === "BEN")) { $propertyBookingEngineGroupId = $propertyGroupMapping['property_group']['id']; } } } $propertyGroupMappingRequest = [ 'criteria' => [ ['field' => 'status', 'condition' => '=', 'value' => 1], ['field' => 'property_group_id', 'condition' => '=', 'value' => $propertyGroupId], ['field' => 'property_id', 'condition' => '!=', 'value' => fillOnUndefined($propertyWeb['data'], 'property_id')] ], 'orderBy' => [ ["field" => "order_number", "value" => "ASC"] ], "with" => ['property.propertyWeb'] ]; $propertyGroupWebSiteResult = $this->propertyGroupMappingService->getPropertyGroupMapping($propertyGroupMappingRequest); if ($propertyGroupWebSiteResult['status'] != 'success') { throw new ApiErrorException($propertyGroupWebSiteResult['message']); } $propertyGroupWebSites = $propertyGroupWebSiteResult['data']; $groupWebSites = []; foreach ($propertyGroupWebSites as $propertyGroupWebSite) { if ($propertyGroupWebSite['property'] && $propertyGroupWebSite['property']['property_web']) { $propertyGroupWebSite['property']['property_web']['name'] = $propertyGroupWebSite['property']['name']; $groupWebSites[] = $propertyGroupWebSite['property']['property_web']; } } $groupWebSites = collect($groupWebSites)/*->where('is_published', 1)*/ ->values()->toArray(); if (!empty($propertyWeb['data'])) { $propertyWeb['data']['property_group_web_sites'] = $groupWebSites; unset($propertyWeb['data']['property_group_mapping']); } $propertyBookingGroupMappingRequest = [ 'criteria' => [ ['field' => 'status', 'condition' => '=', 'value' => 1], ['field' => 'property_group_id', 'condition' => '=', 'value' => $propertyBookingEngineGroupId], ], 'orderBy' => [ ["field" => "order_number", "value" => "ASC"] ], "with" => ['property.propertyBookingEngineToken', 'property.propertyWeb'] ]; $propertyGroupBookingResult = $this->propertyGroupMappingService->getPropertyGroupMapping($propertyBookingGroupMappingRequest); if ($propertyGroupBookingResult['status'] != 'success') { throw new ApiErrorException($propertyGroupBookingResult['message']); } $propertyGroupBookings = $propertyGroupBookingResult['data']; $bookingGroupProperties = []; foreach ($propertyGroupBookings as $key => $propertyGroupBooking) { if ($propertyGroupBooking['property']) { $bookingGroupProperties[$key]['property_id'] = $propertyGroupBooking['property']['id']; $bookingGroupProperties[$key]['name'] = $propertyGroupBooking['property']['name']; if ($propertyGroupBooking['property']['property_booking_engine_token']) { $bookingGroupProperties[$key]['token'] = $propertyGroupBooking['property']['property_booking_engine_token']['token']; } else { $bookingGroupProperties[$key]['token'] = NULL; } $bookingGroupProperties[$key]['web'] = null; if (!empty($propertyGroupBooking['property']['property_web'])) { if ($propertyGroupBooking['property']['property_web']['status'] && $propertyGroupBooking['property']['property_web']['is_published']) { $bookingGroupProperties[$key]['web'] = $propertyGroupBooking['property']['property_web']['webProtocolUrl']; } } } } if (!empty($bookingGroupProperties)) { $propertyWeb['data']['property_booking_group'] = collect($bookingGroupProperties)->where('token', '!=', NULL)->toArray(); } $mywebServiceMode = fillOnUndefined($params, 'serviceMode', 'live'); // preview or live $mywebServiceModeStatus = $mywebServiceMode === "live" ? 1 : 2; if (!empty($propertyWeb['data']['property_booking_engine'])) { $propertyChannelMappingRequestData = [ 'property_id' => $propertyWeb['data']['property_booking_engine']['property_id'], 'channel_id' => $propertyWeb['data']['property_booking_engine']['channel_id'] ]; $propertyChannelMappingData = $this->propertyChannelMappingService->checkPropertyChannelMapping($propertyChannelMappingRequestData); if ($propertyChannelMappingData['data'] === "") { $propertyWeb['data']['property_booking_engine']['token'] = NULL; } } $propertyWebPreviewOrLiveMenus = []; if (isset($propertyWeb['data']['property_web_menu_menu_mapping'])) { $propertyWebPreviewOrLiveMenus = collect($propertyWeb['data']['property_web_menu_menu_mapping']) ->where('status', $mywebServiceModeStatus)->toArray(); } if ($propertyWeb['status'] != 'success' || !$propertyWeb['data']) { throw new ApiErrorException('Domain not found'); } $availableLanguageRequest = [ 'criteria' => [ ['field' => 'status', 'condition' => '=', 'value' => 1], ['field' => 'is_application', 'condition' => '=', 'value' => 1], ['field' => 'is_published', 'condition' => '=', 'value' => 1] ], ]; $availableLanguages = $this->languageService->select($availableLanguageRequest, ['code', 'name', 'language_key']); $propertyWebLanguageMappings = $propertyWeb['data']['property_web_language_mapping'] ? $propertyWeb['data']['property_web_language_mapping'] : []; $propertyWebLanguageMappings = collect($propertyWebLanguageMappings) ->keyBy('language_code') ->where('status', $mywebServiceModeStatus) ->toArray(); if ($propertyWebLanguageMappings) { foreach ($availableLanguages['data'] as $language) { if (array_key_exists($language['code'], $propertyWebLanguageMappings)) { $propertyWeb['data']['available_language_codes'][$language['code']] = $language; } } } else { foreach ($availableLanguages['data'] as $language) { $propertyWeb['data']['available_language_codes'][$language['code']] = $language; } } $webMenu = []; if (empty($propertyWebPreviewOrLiveMenus)) { $myWebMenus = $this->propertyWebMenuService->getPropertyWebMenu(); if ($myWebMenus['status'] != 'success') { throw new ApiErrorException($myWebMenus['message']); } $propertyWeb['data']['web_menu']['LVL1'] = collect($myWebMenus['data']['property_web_menus'])->where('type', '=', '1')->keyBy('alias')->toArray(); $propertyWeb['data']['web_menu']['LEGAL'] = collect($myWebMenus['data']['property_web_menus'])->where('type', '=', '3')->keyBy('alias')->toArray(); unset($propertyWeb['data']['property_web_menu_menu_mapping']); } else { $webMenuTypes = collect($propertyWeb['data']['property_web_menu_menu_mapping']) ->where('status', $mywebServiceModeStatus) ->groupBy('menu_code')->toArray(); $allLevelData = []; $allTopData = []; foreach ($webMenuTypes as $menuTypeKey => $webMenuType) { if ($menuTypeKey === self::MENU_CODE_LVL1) { $allLevelData = $this->getTypeMenus($webMenuType, $menuTypeKey); } elseif ($menuTypeKey === self::MENU_CODE_TOP) { $allTopData = $this->getTypeMenus($webMenuType, $menuTypeKey); } } unset($propertyWeb['data']['property_web_menu_menu_mapping']); $propertyWeb['data']['web_menu'] = array_merge($allTopData, $allLevelData); } //property_web_room_mapping $propertyWebRoomMapping = []; $propertyWebRoomMappingTemp = $propertyWeb['data']['property_web_room_mapping']; unset($propertyWeb['data']['property_web_room_mapping']); foreach ($propertyWebRoomMappingTemp as $propertyWebRoom) { $propertyWebRoomMapping[] = [ 'id' => $propertyWebRoom['room_detail']['id'], 'name' => $propertyWebRoom['room_detail']['name'], 'slug' => Str::slug($propertyWebRoom['room_detail']['name'], $separator = '-', $language = 'en') . '-' . $propertyWebRoom['room_detail']['id'] ]; } $propertyWeb['data']['property_web_room_mapping'] = $propertyWebRoomMapping; //property_web_room_mapping //PropertyWebPopUp $propertyWebPopUp = null; if ($propertyWeb['data']['property_web_popup']) { $propertyWebPopUp = collect($propertyWeb['data']['property_web_popup']) ->where('start_date', '<=', Carbon::now()->toDateString()) ->where('end_date', '>=', Carbon::now()->toDateString()) ->toArray(); $propertyWebPopUp = array_values($propertyWebPopUp); } $propertyWeb['data']['property_web_popup'] = $propertyWebPopUp; //PropertyWebPopUp //PropertyWebContent $propertyWebContent = null; $propertyWebContentCriteria = [ 'criteria' => [ ['field' => 'property_id', 'condition' => '=', 'value' => $propertyWeb['data']['property_id']], ['field' => 'status', 'condition' => '=', 'value' => 1] ], //'with' => ['ContentCategory'], 'orderBy' => [ ['field' => 'id', 'value' => 'DESC'] ] ]; $propertyWebContentCriteria['skip'] = 0; $propertyWebContentCriteria['take'] = 100; $propertyWebContent = $this->propertyWebContentService->select($propertyWebContentCriteria, ['id', 'title', 'property_id', 'slug', 'content_category_id', 'language_code', 'image']); $propertyWebContent = ($propertyWebContent['status'] == 'success' && !empty($propertyWebContent['data'])) ? array_values($propertyWebContent['data']) : []; $propertyWebContentGrouped = null; foreach ($propertyWebContent as $content) { if (isset($propertyWebContentGrouped[$content['language_code']]) && count($propertyWebContentGrouped[$content['language_code']]) > 2) { continue; } $propertyWebContentGrouped[$content['language_code']][] = $content; } $propertyWeb['data']['property_web_content'] = $propertyWebContentGrouped; //PropertyWebContent //property_web_weather $propertyWeb['data']['property_web_weather'] = $propertyWeb['data']['weather_active'] == 1 ? $propertyWeb['data']['property_web_weather'] : null; //PropertyWebComponent if ($propertyWeb['data']['property_web_component']) { $propertyWebComponent = $propertyWeb['data']['property_web_component']; unset($propertyWeb['data']['property_web_component']); $propertyWebComponentGoogleTagManager = collect($propertyWebComponent) ->where('component_id', 1) ->first(); if ($propertyWebComponentGoogleTagManager) { $propertyWeb['data']['property_web_component']['google_tag_manager'] = $propertyWebComponentGoogleTagManager['parameterArray']; } $propertyWebComponentGoogleAnalytics = collect($propertyWebComponent) ->where('component_id', 4) ->first(); if ($propertyWebComponentGoogleAnalytics) { $propertyWeb['data']['property_web_component']['google_analytics'] = $propertyWebComponentGoogleAnalytics['parameterArray']; } $propertyWebComponentJotform = collect($propertyWebComponent) ->where('component_id', 5) ->first(); if ($propertyWebComponentJotform) { $propertyWeb['data']['property_web_component']['jotform'] = $propertyWebComponentJotform['parameterArray']; } $propertyWebComponentMetaPixel = collect($propertyWebComponent) ->where('component_id', 6) ->first(); if ($propertyWebComponentMetaPixel) { $propertyWeb['data']['property_web_component']['metapixel'] = $propertyWebComponentMetaPixel['parameterArray']; } $propertyWebComponentTawkTo = collect($propertyWebComponent) ->where('component_id', 7) ->first(); if ($propertyWebComponentTawkTo) { $propertyWeb['data']['property_web_component']['tawkto'] = $propertyWebComponentTawkTo['parameterArray']; } $propertyWebComponentGoogleSiteVerification = collect($propertyWebComponent) ->where('component_id', 8) ->first(); if ($propertyWebComponentGoogleSiteVerification) { $propertyWeb['data']['property_web_component']['googlesiteverification'] = $propertyWebComponentGoogleSiteVerification['parameterArray']; } $propertyWebComponentMetaVerification = collect($propertyWebComponent) ->where('component_id', 12) ->first(); if ($propertyWebComponentMetaVerification) { $propertyWeb['data']['property_web_component']['metaverification'] = $propertyWebComponentMetaVerification['parameterArray']; } } //PropertyWebComponent $propertyRequest = [ 'criteria' => [ ['field' => 'id', 'condition' => '=', 'value' => $propertyWeb['data']['property_id']], ['field' => 'status', 'condition' => '=', 'value' => 1], ], 'with' => [ 'propertyBrand', 'propertyContact', 'propertyPhotos', 'propertyType', 'propertyChain', 'propertyRooms', 'propertyWeb', 'propertyAwardsCertificates.awardsCertificateCategory', 'propertyPaymentMapping' ], 'firstRow' => true ]; $getPropertyFields = ['id', 'name', 'property_type_id', 'chain_id', 'rating', 'official_name', 'tax_office', 'tax_number', 'currency_type', 'country']; $propertyDetail = $this->propertyService->select($propertyRequest, $getPropertyFields); $propertyDetail = $propertyDetail['data']; $propertyDetail['property_brand']['logo_url'] = $propertyDetail['property_brand'] ? Config::get('app.imageUrl') . '/property-photos/' . $propertyDetail['id'] . "/logo/" . $propertyDetail['property_brand']['logo_name'] . '_250x250.' . $propertyDetail['property_brand']['logo_file_ext'] : null; $propertyDetail['property_contact']['social_media_addresses'] = json_decode($propertyDetail['property_contact']['social_media_addresses'], 1); $colorCodes = json_decode($propertyDetail['property_brand']['color_codes'], 1); $propertyDetail['property_brand']['color_codes'] = $colorCodes; $propertyAdditionalInfo = null; $propertyAdditionalInfoRequest = $this->propertyAdditionalInfoService->getPropertyAdditionalInfo2KeyBy(['property_id' => $propertyDetail['id']]); if (isset($propertyAdditionalInfoRequest['data'])) { $propertyAdditionalInfo = $propertyAdditionalInfoRequest['data']; } //coverPhotos $coverPhotosParam = [ 'property_id' => $propertyWeb['data']['property']['id'], 'property_web_id' => $propertyWeb['data']['id'], 'mode' => $mywebServiceModeStatus, ]; $landingPhoto = $this->coverPhotos($coverPhotosParam); //coverPhotos $propertyWeb['data']['property']['name'] = $propertyDetail['name']; $propertyWeb['data']['property']['property_type'] = $propertyDetail['property_type']['name']; $propertyWeb['data']['property']['property_type_key'] = $propertyDetail['property_type']['language_key']; $propertyWeb['data']['property']['property_chain'] = $propertyDetail['property_chain']['name']; $propertyWeb['data']['property']['official_name'] = $propertyDetail['official_name']; $propertyWeb['data']['property']['tax_office'] = $propertyDetail['tax_office']; $propertyWeb['data']['property']['tax_number'] = $propertyDetail['tax_number']; $propertyWeb['data']['property']['currency_type'] = $propertyDetail['currency_type']; $propertyWeb['data']['property']['property_brand'] = $propertyDetail['property_brand']; $propertyWeb['data']['property']['property_contact'] = $propertyDetail['property_contact']; $propertyWeb['data']['property']['description'] = $propertyDetail['name']; $propertyWeb['data']['property']['additional_info'] = $propertyAdditionalInfo; $propertyWeb['data']['property']['landing_photo'] = $landingPhoto; $propertyWeb['data']['is_virtual_payment_active'] = collect($propertyDetail['property_payment_mapping'])->where('status', 1)->count() > 0 ? true : false; $response = ['status' => 1, 'statusCode' => 200, 'message' => null, 'data' => $propertyWeb['data']]; } catch (ApiErrorException $e) { $response['message'] = implode(', ', $e->getMessageArr()); $response['statusCode'] = 400; } catch (Exception $e) { $message = $e->getFile() . " " . $e->getLine() . " " . $e->getMessage(); Log::error($message); $response['message'] = $e->getMessage(); $response['statusCode'] = 500; } return apiResponse($response['status'], $response['message'], $response['data'], $response['statusCode']); } public function checkDomainWebGroup(Request $request) { $response = ['status' => false, 'message' => '', 'data' => null, 'statusCode' => 500]; try { if (is_null($request->getContent())) { throw new ApiErrorException(lang('Parameter Error.')); } $params = $request->params; $propertyRequest = [ 'criteria' => [ ['field' => 'domain', 'condition' => '=', 'value' => fillOnUndefined($params, 'domain')], ['field' => 'status', 'condition' => '=', 'value' => 1], ['field' => 'is_published', 'condition' => '=', 'value' => 1], ], 'with' => [ 'propertyGroupMapping.property.propertyWeb.propertyWebPhotoMapping.propertyPhoto', 'propertyGroupMapping.property.propertyBrand', 'propertyGroupMapping.property.propertyContact', 'propertyGroupMapping.property.propertyBookingEngineToken' ], 'firstRow' => true, ]; $propertyWebGroup = $this->propertyWebService->selectWebGroup($propertyRequest, [ 'id', 'title', 'property_group_id', 'domain', 'default_language', 'logo', 'is_ssl_active', 'address', 'email', 'phone', 'template', 'slogan' ]); if ($propertyWebGroup['status'] != 'success') { throw new ApiErrorException(lang('Domain not found.')); } $propertyWebGroup = !empty($propertyWebGroup['data']) ? $propertyWebGroup['data'] : null; if (empty($propertyWebGroup)) { throw new ApiErrorException(lang('Domain not found.')); } $propertyWebGroupData = []; $propertyWebGroupData['title'] = $propertyWebGroup['title']; $propertyWebGroupData['domain'] = $propertyWebGroup['domain']; $propertyWebGroupData['template'] = $propertyWebGroup['template']; $propertyWebGroupData['default_language'] = $propertyWebGroup['default_language']; $propertyWebGroupData['logo'] = $propertyWebGroup['logo']; $propertyWebGroupData['logoUrl'] = $propertyWebGroup['logoUrl']; $propertyWebGroupData['address'] = $propertyWebGroup['address']; $propertyWebGroupData['email'] = $propertyWebGroup['email']; $propertyWebGroupData['phone'] = $propertyWebGroup['phone']; $propertyWebGroupData['is_ssl_active'] = $propertyWebGroup['is_ssl_active']; $propertyWebGroupData['slogan'] = $propertyWebGroup['slogan']; if (!empty($propertyWebGroup['property_group_mapping'])) { $propertyWebGroup['property_group_mapping'] = collect($propertyWebGroup['property_group_mapping'])->sortBy('order_number')->toArray(); } $propertyGroupMapping = []; foreach ($propertyWebGroup['property_group_mapping'] as $property) { if (empty($property['property']['property_web'])) { continue; } if ($property['property']['property_web']['status'] != 1 || $property['property']['property_web']['is_published'] != 1) { continue; } $propertyGroupMapping[$property['property_id']]['id'] = $property['property']['id']; $propertyGroupMapping[$property['property_id']]['title'] = $property['property']['name']; $propertyGroupMapping[$property['property_id']]['domain'] = $property['property']['property_web']['domain']; $propertyGroupMapping[$property['property_id']]['webProtocolUrl'] = $property['property']['property_web']['webProtocolUrl']; $propertyGroupMapping[$property['property_id']]['logoUrl'] = $property['property']['property_brand']['logoUrl']; $propertyGroupMapping[$property['property_id']]['address'] = $property['property']['property_contact']['address']; $propertyGroupMapping[$property['property_id']]['email'] = $property['property']['property_contact']['email']; $propertyGroupMapping[$property['property_id']]['phone'] = $property['property']['property_contact']['view_full_phone']; $propertyGroupMapping[$property['property_id']]['content_code'] = $property['property']['content_code']; $propertyGroupMapping[$property['property_id']]['token'] = $property['property']['property_booking_engine_token']['token']; $colorCodes = json_decode($property['property']['property_brand']['color_codes'], 1); $propertyGroupMapping[$property['property_id']]['colorCodes'] = $colorCodes; $propertyWebPhotoMapping = collect($property['property']['property_web']['property_web_photo_mapping']) ->where('status', 1) ->where('is_cover', 1) ->toArray(); $propertyGroupMapping[$property['property_id']]['coverPhoto'] = []; foreach ($propertyWebPhotoMapping as $propertyWebPhoto) { $propertyGroupMapping[$property['property_id']]['coverPhoto'][] = $propertyWebPhoto['property_photo']['photoUrl']; } } $propertyWebGroupData['propertyGroupMapping'] = array_values($propertyGroupMapping); $availableLanguageRequest = [ 'criteria' => [ ['field' => 'status', 'condition' => '=', 'value' => 1], ['field' => 'is_application', 'condition' => '=', 'value' => 1], ['field' => 'is_published', 'condition' => '=', 'value' => 1] ], ]; $availableLanguages = $this->languageService->select($availableLanguageRequest, ['code', 'name', 'language_key']); foreach ($availableLanguages['data'] as $language) { $propertyWebGroupData['available_language_codes'][$language['code']] = $language; } $response = ['status' => 1, 'statusCode' => 200, 'message' => null, 'data' => $propertyWebGroupData]; } catch (ApiErrorException $e) { $response['message'] = implode(', ', $e->getMessageArr()); $response['statusCode'] = 400; } catch (Exception $e) { $message = $e->getFile() . " " . $e->getLine() . " " . $e->getMessage(); Log::error($message); $response['message'] = $e->getMessage(); $response['statusCode'] = 500; } return apiResponse($response['status'], $response['message'], $response['data'], $response['statusCode']); } public function contentDomainWebGroup(Request $request) { $response = ['status' => false, 'message' => '', 'data' => null, 'statusCode' => 500]; try { if (is_null($request->getContent())) { throw new ApiErrorException(lang('Parameter Error.')); } $params = $request->params; $propertyRequest = [ 'criteria' => [ ['field' => 'domain', 'condition' => '=', 'value' => fillOnUndefined($params, 'domain')], ['field' => 'status', 'condition' => '=', 'value' => 1], ['field' => 'is_published', 'condition' => '=', 'value' => 1], ], 'with' => [ 'propertyGroupMapping.property.propertyWeb.propertyWebPhotoMapping.propertyPhoto', 'propertyGroupMapping.property.propertyWeb.propertyWebContentSummary.ContentCategory', 'propertyGroupMapping.property.propertyBrand', 'propertyGroupMapping.property.propertyContact', 'propertyGroupMapping.property.propertyBookingEngineToken', 'propertyGroupMapping.property.propertyWeb.propertyWebPlaceMapping.placeDetail.propertyPlaceCategory', 'propertyGroupMapping.property.propertyWeb.propertyWebPlaceMapping.placeDetail.propertyPlaceWorkingHour', 'propertyGroupMapping.property.propertyWeb.propertyWebPlaceMapping.placeDetail.propertyPlacePhotoMapping.propertyPlacePhoto', 'propertyGroupMapping.property.propertyWeb.propertyWebPlaceMapping.placeDetail.propertyPlaceFactMapping.propertyPlaceFactTitleFactMapping.placeFact', 'propertyGroupMapping.property.propertyWeb.propertyWebPlaceMapping.placeDetail.propertyPlaceFactMapping.propertyPlaceFactTitleFactMapping.placeFactTitle', 'propertyGroupMapping.property.propertyWeb.propertyWebPlaceMapping.placeDetail.propertyPlacePhotoMapping', ], 'firstRow' => true, ]; $propertyWebGroup = $this->propertyWebService->selectWebGroup($propertyRequest, [ 'id', 'title', 'property_group_id', 'domain', 'default_language', 'logo', 'is_ssl_active', 'address', 'email', 'phone', 'template', 'slogan' ]); if ($propertyWebGroup['status'] != 'success') { throw new ApiErrorException(lang('Domain not found.')); } $propertyWebGroup = !empty($propertyWebGroup['data']) ? $propertyWebGroup['data'] : null; if (empty($propertyWebGroup)) { throw new ApiErrorException(lang('Domain not found.')); } $propertyWebGroupData = []; $propertyWebGroupData['title'] = $propertyWebGroup['title']; $propertyWebGroupData['domain'] = $propertyWebGroup['domain']; $propertyWebGroupData['template'] = $propertyWebGroup['template']; $propertyWebGroupData['default_language'] = $propertyWebGroup['default_language']; $propertyWebGroupData['logo'] = $propertyWebGroup['logo']; $propertyWebGroupData['logoUrl'] = $propertyWebGroup['logoUrl']; $propertyWebGroupData['address'] = $propertyWebGroup['address']; $propertyWebGroupData['email'] = $propertyWebGroup['email']; $propertyWebGroupData['phone'] = $propertyWebGroup['phone']; $propertyWebGroupData['is_ssl_active'] = $propertyWebGroup['is_ssl_active']; $propertyWebGroupData['slogan'] = $propertyWebGroup['slogan']; if (!empty($propertyWebGroup['property_group_mapping'])) { $propertyWebGroup['property_group_mapping'] = collect($propertyWebGroup['property_group_mapping'])->sortBy('order_number')->toArray(); } $propertyGroupMapping = []; foreach ($propertyWebGroup['property_group_mapping'] as $property) { //dd($property); if (empty($property['property']['property_web'])) { continue; } if ($property['property']['property_web']['status'] != 1 || $property['property']['property_web']['is_published'] != 1) { continue; } $propertyGroupMapping[$property['property_id']]['id'] = $property['property']['id']; $propertyGroupMapping[$property['property_id']]['title'] = $property['property']['name']; $propertyGroupMapping[$property['property_id']]['domain'] = $property['property']['property_web']['domain']; $propertyGroupMapping[$property['property_id']]['webProtocolUrl'] = $property['property']['property_web']['webProtocolUrl']; $propertyGroupMapping[$property['property_id']]['logoUrl'] = $property['property']['property_brand']['logoUrl']; $propertyGroupMapping[$property['property_id']]['address'] = $property['property']['property_contact']['address']; $propertyGroupMapping[$property['property_id']]['email'] = $property['property']['property_contact']['email']; $propertyGroupMapping[$property['property_id']]['phone'] = $property['property']['property_contact']['view_full_phone']; $propertyGroupMapping[$property['property_id']]['content_code'] = $property['property']['content_code']; $propertyGroupMapping[$property['property_id']]['token'] = $property['property']['property_booking_engine_token']['token']; $propertyGroupMapping[$property['property_id']]['property_place'] = $property['property']['property_web']['property_web_place_mapping']; $propertyGroupMapping[$property['property_id']]['property_web_content'] = $property['property']['property_web']['property_web_content_summary']; $colorCodes = json_decode($property['property']['property_brand']['color_codes'], 1); $propertyGroupMapping[$property['property_id']]['colorCodes'] = $colorCodes; $propertyWebPhotoMapping = collect($property['property']['property_web']['property_web_photo_mapping']) ->where('status', 1) ->toArray(); $propertyGroupMapping[$property['property_id']]['propertyWebPhoto'] = []; foreach ($propertyWebPhotoMapping as $propertyWebPhoto) { $propertyGroupMapping[$property['property_id']]['propertyWebPhoto'][] = $propertyWebPhoto['property_photo']['photoUrl']; } $propertyWebPhotoMapping = collect($property['property']['property_web']['property_web_photo_mapping']) ->where('status', 1) ->where('is_cover', 1) ->toArray(); $propertyGroupMapping[$property['property_id']]['coverPhoto'] = []; foreach ($propertyWebPhotoMapping as $propertyWebPhoto) { $propertyGroupMapping[$property['property_id']]['coverPhoto'][] = $propertyWebPhoto['property_photo']['photoUrl']; } } $propertyWebGroupData['propertyGroupMapping'] = array_values($propertyGroupMapping); $availableLanguageRequest = [ 'criteria' => [ ['field' => 'status', 'condition' => '=', 'value' => 1], ['field' => 'is_application', 'condition' => '=', 'value' => 1], ['field' => 'is_published', 'condition' => '=', 'value' => 1] ], ]; $availableLanguages = $this->languageService->select($availableLanguageRequest, ['code', 'name', 'language_key']); foreach ($availableLanguages['data'] as $language) { $propertyWebGroupData['available_language_codes'][$language['code']] = $language; } $response = ['status' => 1, 'statusCode' => 200, 'message' => null, 'data' => $propertyWebGroupData]; } catch (ApiErrorException $e) { $response['message'] = implode(', ', $e->getMessageArr()); $response['statusCode'] = 400; } catch (Exception $e) { $message = $e->getFile() . " " . $e->getLine() . " " . $e->getMessage(); Log::error($message); $response['message'] = $e->getMessage(); $response['statusCode'] = 500; } return apiResponse($response['status'], $response['message'], $response['data'], $response['statusCode']); } public function test(Request $request) { $response = ['status' => false, 'message' => '', 'data' => null, 'statusCode' => 500]; try { if (is_null($request->getContent())) { throw new ApiErrorException(lang('Parameter Error.')); } $params = $request->params; $response = ['status' => 1, 'statusCode' => 200, 'message' => null, 'data' => $params]; } catch (ApiErrorException $e) { $response['message'] = implode(', ', $e->getMessageArr()); $response['statusCode'] = 400; } catch (Exception $e) { $message = $e->getFile() . " " . $e->getLine() . " " . $e->getMessage(); Log::error($message); $response['message'] = $e->getMessage(); $response['statusCode'] = 500; } return apiResponse($response['status'], $response['message'], $response['data'], $response['statusCode']); } public function getLanguages(Request $request) { $response = ['status' => false, 'message' => '', 'data' => null, 'statusCode' => 500]; try { $languageData = $this->languageBaseService->createApplicationLanguageData(); $response = ['status' => 1, 'statusCode' => 200, 'message' => null, 'data' => $languageData['data']]; } catch (ApiErrorException $e) { $response['message'] = implode(', ', $e->getMessageArr()); $response['statusCode'] = 400; } catch (Exception $e) { $message = $e->getFile() . " " . $e->getLine() . " " . $e->getMessage(); Log::error($message); $response['message'] = $e->getMessage(); $response['statusCode'] = 500; } return apiResponse($response['status'], $response['message'], $response['data'], $response['statusCode']); } public function getPropertyWebEditContent(Request $request) { $response = ['status' => false, 'message' => '', 'data' => null, 'statusCode' => 500]; try { if (is_null($request->getContent())) { throw new ApiErrorException(lang('Parameter Error.')); } $params = $request->params; $propertyWebRequest = [ 'id' => fillOnUndefined($params, 'property_web_id'), 'property_id' => fillOnUndefined($params, 'property_id') ]; $propertyWeb = $this->propertyWebService->getPropertyWeb($propertyWebRequest); if ($propertyWeb['status'] != 'success') { throw new ApiErrorException($propertyWeb['message']); } $propertyWebPhotos = $this->propertyWebService->getPropertyWebPhotos($propertyWebRequest); if ($propertyWeb['status'] != 'success') { throw new ApiErrorException($propertyWeb['message']); } $languages = $this->languageService->getApplicationLanguages(); if ($languages['status'] != 'success') { throw new ApiErrorException($languages['message']); } $myWebMenus = $this->propertyWebMenuService->getPropertyWebMenu(); if ($myWebMenus['status'] != 'success') { throw new ApiErrorException($myWebMenus['message']); } $myWebMenus = collect($myWebMenus['data']['property_web_menus'])->where('type', '!=', '3')->toArray(); $placeRequest = [ 'property_id' => $params['property_id'] ]; $myPlaces = $this->propertyPlaceService->webMenuPlaceCategoriesAndPlaces($placeRequest); if ($myPlaces['status'] != 'success') { throw new ApiErrorException($myPlaces['message']); } $myPlaces = $myPlaces['data']; $myWebMenus = array_merge($myWebMenus, $myPlaces); $myWebMenuMappingRequest = [ 'property_web_id' => fillOnUndefined($params, 'property_web_id'), 'property_id' => fillOnUndefined($params, 'property_id') ]; $myWebMenuMapping = $this->propertyWebMenuMappingService->getPropertyWebMenuMapping($myWebMenuMappingRequest); if ($myWebMenuMapping['status'] != 'success') { throw new ApiErrorException($myWebMenuMapping['message']); } $menuIndex = 1; $responseMenus = []; $myWebMenuMappingCollection = collect($myWebMenuMapping['data']['property_web_menu_mapping']); foreach ($myWebMenus as $myWebMenu) { $checkMenuMapping = $myWebMenuMappingCollection->where('type', '=', $myWebMenu['menu_type']) ->where('property_web_menu_id', '=', $myWebMenu['id'])->first(); if ($checkMenuMapping) { $myWebMenu['is_selected'] = true; $myWebMenu['order_number_mapping'] = $checkMenuMapping['order_number']; $myWebMenu['order_number'] = $menuIndex; $myWebMenu['menu_code'] = $checkMenuMapping['menu_code']; } else { $myWebMenu['is_selected'] = false; $myWebMenu['order_number_mapping'] = null; $myWebMenu['order_number'] = $menuIndex; } $menuIndex++; $responseMenus[] = $myWebMenu; } $myWebMenus = $responseMenus; $myWebLanguageMapping = $this->propertyWebLanguageMappingService->getPropertyWebLanguageMapping($myWebMenuMappingRequest); if ($myWebLanguageMapping['status'] != 'success') { throw new ApiErrorException($myWebLanguageMapping['message']); } $myWebLanguageMapping = collect($myWebLanguageMapping['data']['property_web_language_mapping'])->keyBy('language_code')->toArray(); $myWebColorMapping = $this->propertyWebColorMappingService->getPropertyWebColorMapping($myWebMenuMappingRequest); if ($myWebColorMapping['status'] != 'success') { throw new ApiErrorException($myWebColorMapping['message']); } $myWebColors = []; if ($myWebColorMapping['data']['property_web_color_mapping']) { $myWebColorMapping = $myWebColorMapping['data']['property_web_color_mapping']; foreach ($myWebColorMapping as $key => $myWebColorMappingData) { $myWebColors[$key]['color_number'] = $myWebColorMappingData['order_number']; $myWebColors[$key]['color_code'] = $myWebColorMappingData['color_code']; } } else { $brandParam = [ 'property_id' => fillOnUndefined($params, 'property_id') ]; $propertyBrand = $this->propertyBrandService->getPropertyBrand($brandParam); if ($propertyBrand['status'] != 'success') { throw new ApiErrorException($propertyBrand['message']); } $myWebColors = collect($propertyBrand['data']['color_codes'])->take(3)->toArray(); } $propertyWebAboutUsParams = [ 'property_id' => fillOnUndefined($params, 'property_id'), 'property_web_id' => fillOnUndefined($params, 'property_web_id'), 'mode' => 1, // live ]; $propertyWebAboutUs = $this->propertyWebAboutUsService->getPropertyWebAboutUs($propertyWebAboutUsParams); if ($propertyWebAboutUs['status'] != 'success') { throw new ApiErrorException($propertyWebAboutUs['message']); } $languages = $languages['data']; $propertyWebColors = $myWebColors ? $myWebColors : []; foreach ($languages as &$language) { if (array_key_exists($language['code'], $myWebLanguageMapping)) { $language['is_selected'] = true; } else { $language['is_selected'] = false; } } $propertyWeb = $propertyWeb['data']; $webData = [ 'live_url' => Config::get('app.mainHostAddress') . '/live/' . $propertyWeb['token'] . '/' . $propertyWeb['default_language'], 'preview_url' => Config::get('app.mainHostAddress') . '/preview/' . $propertyWeb['token'] . '/' . $propertyWeb['default_language'], ]; $propertyWeb = array_merge($propertyWeb, $webData); $propertyAdditionalInfo = $this->propertyAdditionalInfoService->getPropertyAdditionalInfo2KeyBy($params); if ($propertyAdditionalInfo['status'] != 'success') { throw new ApiErrorException('api-unknown-error'); } $propertyRequest = [ 'property_id' => fillOnUndefined($params, 'property_id') ]; $property = $this->propertyService->getProperty($propertyRequest); if ($property['status'] != 'success') { throw new ApiErrorException('api-unknown-error'); } $propertyData = $property['data'] ? $property['data'] : []; $propertyCountryCode = $propertyData['get_property']['property_info']['country']; $myWebContactEmail = isset($propertyAdditionalInfo['data']['myweb_contact_email']) ? $propertyAdditionalInfo['data']['myweb_contact_email'] : null; $kvkkMersisNo = isset($propertyAdditionalInfo['data']['kvkk_mersis_no']) ? $propertyAdditionalInfo['data']['kvkk_mersis_no'] : null; $kvkkDataController = isset($propertyAdditionalInfo['data']['kvkk_data_controller']) ? $propertyAdditionalInfo['data']['kvkk_data_controller'] : null; $kvkkContactPerson = isset($propertyAdditionalInfo['data']['kvkk_contact_person']) ? $propertyAdditionalInfo['data']['kvkk_contact_person'] : null; $kvkkAddress = isset($propertyAdditionalInfo['data']['kvkk_address']) ? $propertyAdditionalInfo['data']['kvkk_address'] : null; $kvkkPhone = isset($propertyAdditionalInfo['data']['kvkk_phone']) ? $propertyAdditionalInfo['data']['kvkk_phone'] : null; $kvkkTaxOffice = isset($propertyAdditionalInfo['data']['kvkk_tax_office']) ? $propertyAdditionalInfo['data']['kvkk_tax_office'] : null; $kvkkTaxNumber = isset($propertyAdditionalInfo['data']['kvkk_tax_number']) ? $propertyAdditionalInfo['data']['kvkk_tax_number'] : null; $kvkkEmail = isset($propertyAdditionalInfo['data']['kvkk_email']) ? $propertyAdditionalInfo['data']['kvkk_email'] : null; $kvkkWebSite = isset($propertyAdditionalInfo['data']['kvkk_web_site']) ? $propertyAdditionalInfo['data']['kvkk_web_site'] : null; $kvkkContactEmail = isset($propertyAdditionalInfo['data']['kvkk_contact_email']) ? $propertyAdditionalInfo['data']['kvkk_contact_email'] : null; $kvkkContactAddress = isset($propertyAdditionalInfo['data']['kvkk_contact_address']) ? $propertyAdditionalInfo['data']['kvkk_contact_address'] : null; $propertyWeb['languages'] = $languages; $propertyWeb['colors'] = $propertyWebColors; $propertyWeb['property_country_code'] = $propertyCountryCode; $propertyWeb['menus'] = $myWebMenus; $propertyWeb['property_web_photos'] = $propertyWebPhotos['data']; $propertyWeb['property_web_about_us'] = $propertyWebAboutUs['data']; $propertyWeb['additional_info']['myweb_contact_email'] = $myWebContactEmail; $propertyWeb['additional_info']['kvkk_mersis_no'] = $kvkkMersisNo; $propertyWeb['additional_info']['kvkk_data_controller'] = $kvkkDataController; $propertyWeb['additional_info']['kvkk_contact_person'] = $kvkkContactPerson; $propertyWeb['additional_info']['kvkk_address'] = $kvkkAddress; $propertyWeb['additional_info']['kvkk_phone'] = $kvkkPhone; $propertyWeb['additional_info']['kvkk_tax_office'] = $kvkkTaxOffice; $propertyWeb['additional_info']['kvkk_tax_number'] = $kvkkTaxNumber; $propertyWeb['additional_info']['kvkk_email'] = $kvkkEmail; $propertyWeb['additional_info']['kvkk_web_site'] = $kvkkWebSite; $propertyWeb['additional_info']['kvkk_contact_email'] = $kvkkContactEmail; $propertyWeb['additional_info']['kvkk_contact_address'] = $kvkkContactAddress; $propertyRooms = []; $getPropertyRoomCriteria = [ 'criteria' => [ ['field' => 'property_id', 'condition' => '=', 'value' => fillOnUndefined($params, 'property_id')], ['field' => 'status', 'condition' => '=', 'value' => 1], ], 'orderBy' => [ ['field' => 'id', 'value' => 'ASC'] ], 'with' => ['propertyRoomType', 'propertyWebRoomMapping'], ]; $getPropertyRoom = $this->propertyRoomService->select($getPropertyRoomCriteria); if ($getPropertyRoom['status'] == 'success') { $getPropertyRoom = $getPropertyRoom['data']; foreach ($getPropertyRoom as $propertyRoom) { $propertyRooms[] = [ 'id' => $propertyRoom['id'], 'name' => $propertyRoom['name'], 'type' => $propertyRoom['property_room_type']['language_key'], 'is_selected' => !empty($propertyRoom['property_web_room_mapping']) ? true : false ]; } } $propertyWeb['rooms'] = $propertyRooms; $propertyPlaces = []; $getPropertyPlaceCriteria = [ 'criteria' => [ ['field' => 'property_id', 'condition' => '=', 'value' => fillOnUndefined($params, 'property_id')], ['field' => 'status', 'condition' => '=', 'value' => 1], ], 'orderBy' => [ ['field' => 'id', 'value' => 'ASC'] ], 'with' => ['propertyPlaceCategory', 'propertyWebPlaceMapping'], ]; $getPropertyPlace = $this->propertyPlaceService->select($getPropertyPlaceCriteria); if ($getPropertyPlace['status'] == 'success') { $getPropertyPlace = $getPropertyPlace['data']; foreach ($getPropertyPlace as $propertyPlace) { $propertyPlaces[] = [ 'id' => $propertyPlace['id'], 'name' => $propertyPlace['name'], 'type' => $propertyPlace['property_place_category']['language_key'], 'is_selected' => !empty($propertyPlace['property_web_place_mapping']) ? true : false ]; } } $propertyWeb['places'] = $propertyPlaces; $response = ['status' => 1, 'statusCode' => 200, 'message' => null, 'data' => $propertyWeb]; } catch (ApiErrorException $e) { $response['message'] = implode(', ', $e->getMessageArr()); $response['statusCode'] = 400; } catch (Exception $e) { $message = $e->getFile() . " " . $e->getLine() . " " . $e->getMessage(); Log::error($message); $response['message'] = $e->getMessage(); $response['statusCode'] = 500; } return apiResponse($response['status'], $response['message'], $response['data'], $response['statusCode']); } public function updatePropertyWebContent(Request $request) { $response = ['status' => false, 'message' => '', 'data' => null, 'statusCode' => 500]; try { if (is_null($request->getContent())) { throw new ApiErrorException(lang('Parameter Error.')); } $params = $request->params; $params['user_id'] = $this->request->auth->id; $updateWeb = $this->propertyWebService->updatePropertyWebContent($params); if ($updateWeb['status'] != 'success') { throw new ApiErrorException($updateWeb['message']); } $response = ['status' => 1, 'statusCode' => 200, 'message' => null, 'data' => $updateWeb['data']]; } catch (ApiErrorException $e) { $response['message'] = implode(', ', $e->getMessageArr()); $response['statusCode'] = 400; } catch (Exception $e) { $message = $e->getFile() . " " . $e->getLine() . " " . $e->getMessage(); Log::error($message); $response['message'] = $e->getMessage(); $response['statusCode'] = 500; } return apiResponse($response['status'], $response['message'], $response['data'], $response['statusCode']); } public function setPublishWeb(Request $request) { $response = ['status' => false, 'message' => '', 'data' => null, 'statusCode' => 500]; try { if (is_null($request->getContent())) { throw new ApiErrorException(lang('Parameter Error.')); } $params = $request->params; $params['user_id'] = $this->request->auth->id; $updateWeb = $this->propertyWebService->setPublishWeb($params); if ($updateWeb['status'] != 'success') { throw new ApiErrorException($updateWeb['message']); } $response = ['status' => 1, 'statusCode' => 200, 'message' => null, 'data' => $updateWeb['data']]; } catch (ApiErrorException $e) { $response['message'] = implode(', ', $e->getMessageArr()); $response['statusCode'] = 400; } catch (Exception $e) { $message = $e->getFile() . " " . $e->getLine() . " " . $e->getMessage(); Log::error($message); $response['message'] = $e->getMessage(); $response['statusCode'] = 500; } return apiResponse($response['status'], $response['message'], $response['data'], $response['statusCode']); } public function getPropertyWebMeta(Request $request) { $response = ['status' => false, 'message' => '', 'data' => null, 'statusCode' => 500]; try { $params = $request->params ?? []; $result = $this->propertyWebMetaService->select($params, ['id', 'name', 'status']); if ($result['status'] != 'success') { throw new ApiErrorException($result['message']); } foreach ($result['data'] as $key => $datum) { $dataArray = null; if ($datum['name'] == 'ContentDetail') { $propertyWebContentCriteria = [ 'criteria' => [ ['field' => 'property_id', 'condition' => '=', 'value' => $params['property_id']], ['field' => 'status', 'condition' => '=', 'value' => 1] ], 'orderBy' => [ ['field' => 'id', 'value' => 'DESC'] ] ]; $propertyWebContent = $this->propertyWebContentService->select($propertyWebContentCriteria, ['id', 'title']); $propertyWebContent = ($propertyWebContent['status'] == 'success' && !empty($propertyWebContent['data'])) ? array_values($propertyWebContent['data']) : []; foreach ($propertyWebContent as $propertyWebContentData) { $dataArray[] = [ 'code' => $propertyWebContentData['id'], 'name' => $propertyWebContentData['title'], ]; } } if ($datum['name'] == 'PlaceDetail') { $propertyPlacetCriteria = [ 'criteria' => [ ['field' => 'property_id', 'condition' => '=', 'value' => $params['property_id']], ['field' => 'status', 'condition' => '=', 'value' => 1] ], 'orderBy' => [ ['field' => 'id', 'value' => 'DESC'] ] ]; $propertyPlaces = $this->propertyPlaceService->select($propertyPlacetCriteria, ['id', 'name', 'language_name']); $propertyPlaces = ($propertyPlaces['status'] == 'success' && !empty($propertyPlaces['data'])) ? array_values($propertyPlaces['data']) : []; foreach ($propertyPlaces as $propertyPlacesData) { $dataArray[] = [ 'code' => $propertyPlacesData['id'], 'name' => $propertyPlacesData['name'], ]; } } if ($datum['name'] == 'RoomDetail') { $propertyRoomtCriteria = [ 'criteria' => [ ['field' => 'property_id', 'condition' => '=', 'value' => $params['property_id']], ['field' => 'status', 'condition' => '=', 'value' => 1] ], 'orderBy' => [ ['field' => 'id', 'value' => 'DESC'] ] ]; $propertyRooms = $this->propertyRoomService->select($propertyRoomtCriteria, ['id', 'name']); $propertyRooms = ($propertyRooms['status'] == 'success' && !empty($propertyRooms['data'])) ? array_values($propertyRooms['data']) : []; foreach ($propertyRooms as $propertyRoomsData) { $dataArray[] = [ 'code' => $propertyRoomsData['id'], 'name' => $propertyRoomsData['name'], ]; } } $result['data'][$key]['detail'] = $dataArray; } //dd($result); $response = ['status' => 1, 'statusCode' => 200, 'message' => null, 'data' => $result['data']]; } catch (ApiErrorException $e) { $response['message'] = implode(', ', $e->getMessageArr()); $response['statusCode'] = 400; } catch (Exception $e) { $message = $e->getFile() . " " . $e->getLine() . " " . $e->getMessage(); Log::error($message); $response['message'] = $e->getMessage(); $response['statusCode'] = 500; } return apiResponse($response['status'], $response['message'], $response['data'], $response['statusCode']); } public function getPropertyWebMetaTag(Request $request) { $response = ['status' => false, 'message' => '', 'data' => null, 'statusCode' => 500]; try { $params = $request->params ?? []; $result = $this->propertyWebMetaService->selectTag($params, ['id', 'name', 'status']); if ($result['status'] != 'success') { throw new ApiErrorException($result['message']); } $response = ['status' => 1, 'statusCode' => 200, 'message' => null, 'data' => $result['data']]; } catch (ApiErrorException $e) { $response['message'] = implode(', ', $e->getMessageArr()); $response['statusCode'] = 400; } catch (Exception $e) { $message = $e->getFile() . " " . $e->getLine() . " " . $e->getMessage(); Log::error($message); $response['message'] = $e->getMessage(); $response['statusCode'] = 500; } return apiResponse($response['status'], $response['message'], $response['data'], $response['statusCode']); } public function syncPropertyWebMetaTag(Request $request) { $response = ['status' => false, 'message' => '', 'data' => null, 'statusCode' => 500]; try { $params = $request->params ?? []; $params['user_id'] = $this->request->auth->id; $result = $this->propertyWebMetaService->syncTag($params); if ($result['status'] != 'success') { throw new ApiErrorException($result['message']); } $response = ['status' => 1, 'statusCode' => 200, 'message' => $result['message'], 'data' => $result['data']]; } catch (ApiErrorException $e) { $response['message'] = implode(', ', $e->getMessageArr()); $response['statusCode'] = 400; } catch (Exception $e) { $message = $e->getFile() . " " . $e->getLine() . " " . $e->getMessage(); Log::error($message); $response['message'] = $e->getMessage(); $response['statusCode'] = 500; } return apiResponse($response['status'], $response['message'], $response['data'], $response['statusCode']); } public function listPropertyWebMetaTagMapping(Request $request) { $response = ['status' => false, 'message' => '', 'data' => null, 'statusCode' => 500]; try { $params = $request->params ?? []; $result = $this->propertyWebMetaService->selectMapping($params); if ($result['status'] != 'success') { throw new ApiErrorException($result['message']); } $response = ['status' => 1, 'statusCode' => 200, 'message' => null, 'data' => $result['data']]; } catch (ApiErrorException $e) { $response['message'] = implode(', ', $e->getMessageArr()); $response['statusCode'] = 400; } catch (Exception $e) { $message = $e->getFile() . " " . $e->getLine() . " " . $e->getMessage(); Log::error($message); $response['message'] = $e->getMessage(); $response['statusCode'] = 500; } return apiResponse($response['status'], $response['message'], $response['data'], $response['statusCode']); } public function dashboardCountablePlace($params, $propertyWebId) { $response = ["status" => false, "data" => null, "message" => ""]; try { $propertyWebLog = DB::select(" SELECT property_web_log.country_code 'country_code', ip_nation_countries.country 'country', property_web_log.device_type 'device_type', count(property_web_log.id) 'count' FROM property_web_log INNER JOIN ip_nation_countries ON ip_nation_countries.code = property_web_log.country_code WHERE property_web_log.web_id = $propertyWebId AND property_web_log.status = 1 GROUP BY property_web_log.country_code,ip_nation_countries.country, property_web_log.device_type; "); $propertyWebLog = json_decode(json_encode($propertyWebLog), true); $bookingCount = $this->bookingService->getBookingListCount(['property_id' => fillOnUndefined($params, 'property_id'), 'channel_id' => 1]); if ($bookingCount['status'] != 'success') { throw new ApiErrorException($bookingCount['message']); } $countryGroups = collect($propertyWebLog)->groupBy('country_code')->toArray(); $countyGroupCount = []; foreach ($countryGroups as $countryGroupKey => $countryGroup) { foreach ($countryGroup as $key => $groupData) { if (!isset($countyGroupCount[$countryGroupKey]['value'])) { $countyGroupCount[$countryGroupKey]['value'] = 0; } $countyGroupCount[$countryGroupKey]['value'] += $groupData['count']; $countyGroupCount[$countryGroupKey]['country'] = $groupData['country_code']; $countyGroupCount[$countryGroupKey]['country_name'] = $groupData['country']; } } array_multisort(array_column($countyGroupCount, 'value'), SORT_DESC, $countyGroupCount ); $activeUser = DB::select("SELECT count(id) 'count' FROM property_web_log WHERE web_id = $propertyWebId AND created_at > " . Carbon::now()->subMinutes(self::WEB_ACTIVE_USER_MINUTE)->timestamp); $activeUser = json_decode(json_encode($activeUser), true); $activeUser = reset($activeUser); $response['data'] = [ 'web_count' => collect($propertyWebLog)->where('device_type', 'web')->sum('count'), 'mobile_count' => collect($propertyWebLog)->where('device_type', 'mobile')->sum('count'), 'active_user_count' => $activeUser['count'], 'booking_count' => $bookingCount['data'], 'country_count' => collect($countyGroupCount)->values()->toArray(), ]; $response['status'] = true; } catch (ApiErrorException $e) { $response['message'] = implode(', ', $e->getMessageArr()); $response['status'] = false; } catch (Exception $e) { $message = $e->getFile() . " " . $e->getLine() . " " . $e->getMessage(); Log::error($message); $response['message'] = "Raw Query Error"; $response['status'] = false; } return $response; } private function getTypeMenus($menuType, $menuTypeKey) { $webMenuTypes = collect($menuType)->groupBy('type')->toArray(); $allData = []; $allData[$menuTypeKey] = []; foreach ($webMenuTypes as $webMenuTypeKey => $webMenuType) { if ($webMenuTypeKey === self::PLACE) { $placesIds = collect($webMenuTypes[$webMenuTypeKey])->pluck('property_web_menu_id')->toArray(); $checkPropertyMappingRequest = [ 'criteria' => [['field' => 'status', 'condition' => '=', 'value' => 1]], "whereIn" => [["field" => "id", "value" => $placesIds]] ]; $propertyPlaces = $this->propertyPlaceService->select($checkPropertyMappingRequest, ['id', 'name', 'order_number', 'language_name']); if ($propertyPlaces['status'] != 'success') { throw new ApiErrorException('Have a problem in Get Property Place '); } $myWebMenuMapping = collect($webMenuTypes[$webMenuTypeKey])->keyBy('property_web_menu_id')->toArray(); foreach ($propertyPlaces['data'] as $propertyPlace) { $propertyPlace['order_number'] = $myWebMenuMapping[$propertyPlace['id']]['order_number']; $propertyPlace['type'] = $myWebMenuMapping[$propertyPlace['id']]['type']; $propertyPlace['menu_code'] = $myWebMenuMapping[$propertyPlace['id']]['menu_code']; $propertyPlace['route'] = '/place/' . Str::slug($propertyPlace['name'], $separator = '-', $language = 'en') . '-' . $propertyPlace['id']; $alias = $myWebMenuMapping[$propertyPlace['id']]['type'] . '-' . $propertyPlace['id']; $propertyPlace['alias'] = $alias; $propertyPlace['name'] = $this->appearanceTitle($menuTypeKey, $propertyPlace['name']); $allData[$menuTypeKey][] = $propertyPlace; } } elseif ($webMenuTypeKey === self::MAIN) { $myWebMenus = $this->propertyWebMenuService->getPropertyWebMenu(); $webMenus = $myWebMenus['data']['property_web_menus']; $webMenuLevelIds = collect($webMenuTypes[$webMenuTypeKey])->keyBy('property_web_menu_id')->toArray(); foreach ($webMenus as $webMenu) { if (isset($webMenuLevelIds[$webMenu['id']])) { $webMenu['order_number'] = $webMenuLevelIds[$webMenu['id']]['order_number']; $webMenu['name'] = $this->appearanceTitle($menuTypeKey, $webMenu['name']); $allData[$menuTypeKey][] = $webMenu; } } } elseif ($webMenuTypeKey === self::PLACE_CATEGORY) { $placesIds = collect($webMenuTypes[$webMenuTypeKey])->pluck('property_web_menu_id')->toArray(); $checkPropertyMappingRequest = [ 'criteria' => [['field' => 'status', 'condition' => '=', 'value' => 1]], "whereIn" => [["field" => "id", "value" => $placesIds]] ]; $propertyPlaceCategories = $this->propertyPlaceService->propertyPlaceCategories($checkPropertyMappingRequest, ['id', 'name', 'language_key', 'order_number']); if ($propertyPlaceCategories['status'] != 'success') { throw new ApiErrorException('Have a problem in Get Property Place Category '); } $myWebMenuMapping = collect($webMenuTypes[$webMenuTypeKey])->keyBy('property_web_menu_id')->toArray(); foreach ($propertyPlaceCategories['data'] as $propertyPlaceCategory) { $propertyPlaceCategory['order_number'] = $myWebMenuMapping[$propertyPlaceCategory['id']]['order_number']; $propertyPlaceCategory['type'] = $myWebMenuMapping[$propertyPlaceCategory['id']]['type']; $propertyPlaceCategory['menu_code'] = $myWebMenuMapping[$propertyPlaceCategory['id']]['menu_code']; $propertyPlaceCategory['route'] = '/place-category/' . Str::slug($propertyPlaceCategory['name'], $separator = '-', $language = 'en') . '-' . $propertyPlaceCategory['id']; $alias = $myWebMenuMapping[$propertyPlaceCategory['id']]['type'] . '-' . $propertyPlaceCategory['id']; $propertyPlaceCategory['alias'] = $alias; $propertyPlaceCategory['name'] = $this->appearanceTitle($menuTypeKey, $propertyPlaceCategory['name']); $allData[$menuTypeKey][] = $propertyPlaceCategory; } } $allData[$menuTypeKey] = collect($allData[$menuTypeKey])->sortBy('order_number')->keyBy('alias')->toArray(); } return $allData; } private function appearanceTitle($type, $title) { if ($type === self::MENU_CODE_LVL1) { $title = Str::upper($title); } elseif ($type === self::MENU_CODE_TOP) { $title = Str::title($title); } return $title; } public function coverPhotos($params = []) { $propertyWebPhotoMappingRequest = [ 'criteria' => [ ['field' => 'property_id', 'condition' => '=', 'value' => fillOnUndefined($params, 'property_id')], ['field' => 'property_web_id', 'condition' => '=', 'value' => fillOnUndefined($params, 'property_web_id')], ['field' => 'is_cover', 'condition' => '=', 'value' => 1], ['field' => 'status', 'condition' => '=', 'value' => $params['mode'] == 'preview' ? 2 : 1], ], 'with' => ['propertyPhoto'] ]; $propertyWebMappingPhotos = $this->propertyWebService->selectPropertyWebPhotos($propertyWebPhotoMappingRequest); $propertyWebMappingPhotos = $propertyWebMappingPhotos['status'] == 'success' && !empty($propertyWebMappingPhotos['status']) ? $propertyWebMappingPhotos['data'] : []; $coverPhotos = []; foreach ($propertyWebMappingPhotos as $key => $photo) { $photoUrlFilePath = Config::get('app.fileSystemDriver') . '/property-photos/' . $params['property_id'] . '/' . $photo['property_photo']['photo_name'] . '_1024x768.' . $photo['property_photo']['file_ext']; $photoUrlThumbFilePath = Config::get('app.fileSystemDriver') . '/property-photos/' . $params['property_id'] . '/' . $photo['property_photo']['photo_name'] . '_200x200.' . $photo['property_photo']['file_ext']; if (File::exists($photoUrlFilePath)) { $photoUrlFilePath = Config::get('app.imageUrl') . '/property-photos/' . $params['property_id'] . '/' . $photo['property_photo']['photo_name'] . '_1024x768.' . $photo['property_photo']['file_ext']; } else { $photoUrlFilePath = Config::get('app.imageUrl') . '/property-photos/' . $params['property_id'] . '/' . $photo['property_photo']['photo_name'] . '_medium.' . $photo['property_photo']['file_ext']; } if (File::exists($photoUrlThumbFilePath)) { $photoUrlThumbFilePath = Config::get('app.imageUrl') . '/property-photos/' . $params['property_id'] . '/' . $photo['property_photo']['photo_name'] . '_200x200.' . $photo['property_photo']['file_ext']; } else { $photoUrlThumbFilePath = Config::get('app.imageUrl') . '/property-photos/' . $params['property_id'] . '/' . $photo['property_photo']['photo_name'] . '_thumbnail.' . $photo['property_photo']['file_ext']; } $coverPhotos[$key]['default'] = Config::get('app.imageUrl') . '/property-photos/' . $params['property_id'] . '/' . $photo['property_photo']['photo_name'] . '.' . $photo['property_photo']['file_ext']; $coverPhotos[$key]['fixed'] = $photoUrlFilePath; $coverPhotos[$key]['thumb'] = $photoUrlThumbFilePath; } return $coverPhotos; } public function propertyComparison(Request $request, $weekKey, $userId = null) { $daysCount = [1, 15, 45, 90]; $comparisonChannels = ['BookingEngine', 'Agoda.com', 'etstur.com', 'Booking.com']; $response = ['status' => false, 'message' => '', 'data' => null]; try { $userDetail = null; $propertyPriceComparison = PropertyPriceComparison::where('week_key', $weekKey)->with('propertyDetail.propertyContractUser')->orderBy('property_id')->get(); $propertyPriceComparison = $propertyPriceComparison ? $propertyPriceComparison->toArray() : []; if (!empty($userId)) { $propertyPriceComparison = collect($propertyPriceComparison)->where('property_detail.property_contract_user.id', $userId)->toArray(); $userDetail = isset(reset($propertyPriceComparison)['property_detail']['property_contract_user']) ? reset($propertyPriceComparison)['property_detail']['property_contract_user'] : null; } $response = [ 'status' => true ]; } catch (ApiErrorException $e) { $response['message'] = implode(', ', $e->getMessageArr()); } catch (Exception $e) { $message = $e->getFile() . " " . $e->getLine() . " " . $e->getMessage(); Log::error($message); $response['message'] = $e->getMessage(); } if (!is_null($userId)) { $pdf = $this->pdf ->setOptions(['isRemoteEnabled' => false, 'isHtml5ParserEnabled' => true, 'isFontSubsettingEnabled' => true]) //->setPaper('A4', 'landscape') ->loadView('pdf.priceComparison', compact('response', 'daysCount', 'comparisonChannels', 'propertyPriceComparison', 'userDetail'), [], 'UTF8'); return $pdf->stream(); } return view('pdf.priceComparison', compact('response', 'daysCount', 'comparisonChannels', 'propertyPriceComparison', 'userDetail')); } }