From 09d15f09b65722583c74a8a34b99b3ece4b5c7a9 Mon Sep 17 00:00:00 2001 From: sayliraut Date: Wed, 17 Jul 2024 12:37:47 +0530 Subject: [PATCH] changes --- .../CustomerAPIs/RestaurantApiServices.php | 74 +++++++++++++++++-- .../manage_contact.blade.php | 50 ++++++------- 2 files changed, 94 insertions(+), 30 deletions(-) diff --git a/app/Services/APIs/CustomerAPIs/RestaurantApiServices.php b/app/Services/APIs/CustomerAPIs/RestaurantApiServices.php index 25ed6dc..8b67c59 100644 --- a/app/Services/APIs/CustomerAPIs/RestaurantApiServices.php +++ b/app/Services/APIs/CustomerAPIs/RestaurantApiServices.php @@ -540,7 +540,7 @@ Log::info($restAllowedRedeemTime); public function searchRestaurant($customerIamId, $request) { try { - $restaurantsQuery = ManageRestaurant::with(['operatingHours', 'state']) + $restaurantsQuery = ManageRestaurant::with('state') ->where('is_active', '1'); $searchData = $request->input('search_data'); @@ -558,11 +558,74 @@ Log::info($restAllowedRedeemTime); $restaurants = $restaurantsQuery->get(); - foreach ($restaurants as &$res) { - $res['image'] = ListingImageUrl('restaurant_images', $res['image']); - $res['is_favourite'] = CustomerFavouriteRestaurant::where('principal_xid', $customerIamId) - ->where('restaurant_xid', $res->id) + $client = new Client(); + $promises = []; + $googlePlaceApiKey = config('constants.googlePlaces.api_key'); + + foreach ($restaurants as &$restaurant) { + $restaurant['image'] = ListingImageUrl('restaurant_images', $restaurant['image']); + $isFavourite = CustomerFavouriteRestaurant::where('principal_xid', $customerIamId) + ->where('restaurant_xid', $restaurant['id']) ->exists(); + $restaurant['is_favourite'] = $isFavourite; + + $cacheKey = 'restaurant_hours_' . $restaurant['name']; + if (Cache::has($cacheKey)) { + $restaurant['operating_hours'] = Cache::get($cacheKey); + } else { + // Prepare the first request to get the place_id + $promises[$restaurant['name']] = $client->getAsync('https://maps.googleapis.com/maps/api/place/findplacefromtext/json', [ + 'query' => [ + 'fields' => 'place_id', + 'input' => $restaurant['name'], + 'inputtype' => 'textquery', + 'key' => $googlePlaceApiKey + ] + ]); + } + } + + // Execute all the first requests concurrently + $results = Utils::settle($promises)->wait(); + + $detailPromises = []; + foreach ($restaurants as &$restaurant) { + if (isset($results[$restaurant['name']]['value'])) { + $response = $results[$restaurant['name']]['value']; + $placeData = json_decode($response->getBody(), true); + + if (isset($placeData['candidates'][0]['place_id'])) { + $placeId = $placeData['candidates'][0]['place_id']; + + // Prepare the second request to get the operating hours + $detailPromises[$restaurant['name']] = $client->getAsync('https://maps.googleapis.com/maps/api/place/details/json', [ + 'query' => [ + 'fields' => 'opening_hours', + 'place_id' => $placeId, + 'key' => $googlePlaceApiKey + ] + ]); + } else { + $restaurant['operating_hours'] = "N/A"; + } + } + } + + // Execute all the second requests concurrently + $detailResults = Utils::settle($detailPromises)->wait(); + + foreach ($restaurants as &$restaurant) { + if (isset($detailResults[$restaurant['name']]['value'])) { + $response = $detailResults[$restaurant['name']]['value']; + $data = json_decode($response->getBody(), true); + if (isset($data['result']['opening_hours']['weekday_text'])) { + $hours = $data['result']['opening_hours']['weekday_text']; + Cache::put('restaurant_hours_' . $restaurant['name'], $hours, now()->addHours(24)); + $restaurant['operating_hours'] = $hours; + } else { + $restaurant['operating_hours'] = "N/A"; + } + } } return jsonResponseWithSuccessMessageApi(__('auth.restaurant_search'), $restaurants, 200); @@ -573,4 +636,5 @@ Log::info($restAllowedRedeemTime); ], 500); } } + } diff --git a/resources/views/Admin/pages/manage_contact_us/manage_contact.blade.php b/resources/views/Admin/pages/manage_contact_us/manage_contact.blade.php index 6a4c079..dbe47b6 100644 --- a/resources/views/Admin/pages/manage_contact_us/manage_contact.blade.php +++ b/resources/views/Admin/pages/manage_contact_us/manage_contact.blade.php @@ -98,16 +98,16 @@ {{ $querie['email'] }} {{ $querie['created_at']->format('m/d/y') }} - @if ($querie->customer) - @if ($querie->customer->principal_type_xid == 3) - Customer - @else - Restaurant - @endif - @else - No category - @endif - + @if ($querie->customer) + @if ($querie->customer->principal_type_xid == 3) + Customer + @else + Restaurant + @endif + @else + No category + @endif + View - -
-
- - -
-
+ +
+
+ + +
+
+ --> @if (!$querie['is_reply'])
Delete - - @endforeach + + @endforeach
@@ -172,8 +173,7 @@ +