This commit is contained in:
sayliraut
2024-07-17 12:37:47 +05:30
parent 6a32aad513
commit 09d15f09b6
2 changed files with 94 additions and 30 deletions

View File

@@ -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);
}
}
}

View File

@@ -98,16 +98,16 @@
<td class="text-start">{{ $querie['email'] }}</td>
<td class="text-start">{{ $querie['created_at']->format('m/d/y') }}</td>
<td class="text-start">
@if ($querie->customer)
@if ($querie->customer->principal_type_xid == 3)
Customer
@else
Restaurant
@endif
@else
No category
@endif
</td>
@if ($querie->customer)
@if ($querie->customer->principal_type_xid == 3)
Customer
@else
Restaurant
@endif
@else
No category
@endif
</td>
<td>
<a class="view-btn m-0" href="#" data-toggle="modal"
@@ -115,21 +115,22 @@
data-message="{{ $querie['message'] }}">View</a>
</td>
<td class="text-center">
<form>
<div class="switch-btn" id="status-change">
<input type="checkbox" id="switch{{ $querie['id'] }}" switch="bool"
data-id="{{ $querie['id'] }}" name="status" value="1"
{{ $querie['is_reply'] ? 'checked' : '' }} disabled />
<label for="switch{{ $querie['id'] }}" data-on-label="Resolved" data-off-label="Pending"></label>
</div>
</form>
<form>
<div class="switch-btn" id="status-change">
<input type="checkbox" id="switch{{ $querie['id'] }}" switch="bool"
data-id="{{ $querie['id'] }}" name="status" value="1"
{{ $querie['is_reply'] ? 'checked' : '' }} disabled />
<label for="switch{{ $querie['id'] }}" data-on-label="Resolved"
data-off-label="Pending"></label>
</div>
</form>
</td>
<td>
<!-- <div class="dropout">
</div> -->
</div> -->
@if (!$querie['is_reply'])
<div class="action-buttons">
<a href="#" class="action-btn reply-button" data-toggle="modal"
@@ -159,8 +160,8 @@
<img src="{{ asset('public/assets/img/delete-recycle.svg') }}" />
<span>Delete</span>
</a>
</tr>
@endforeach
</tr>
@endforeach
</table>
</div>
@@ -172,8 +173,7 @@
<div class="modal-body">
<div class="modal-header">
<h5 class="modal-title" id="viewMessageModalLabel">Message</h5>
<button type="button" class="close" data-dismiss="mo
dal" aria-label="Close">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
@@ -229,7 +229,7 @@
<div class="col-xxl-12">
<p><span id="reply-message"></span></p>
</div>
</div>
</div>
</div>
</div>
</div>