master
Rustem 2025-08-10 00:34:46 +05:00
parent 142c65cedc
commit bc4c00d967
2 changed files with 7 additions and 20 deletions

View File

@ -242,7 +242,7 @@ class MobileApiController extends Controller
} }
} }
public function checkAvailableCar($started_at = null, $ended_at = null, $modelId = null, $color = null): bool|JsonResponse public function checkAvailableCar($started_at = null, $ended_at = null, $modelId = null, $color = null): JsonResponse
{ {
if (!$started_at || !$ended_at || !$modelId || !$color) { if (!$started_at || !$ended_at || !$modelId || !$color) {
$request = request(); $request = request();
@ -252,8 +252,8 @@ class MobileApiController extends Controller
$color = Unimodel::model('pipi_auto_colors')->where('code', $request->input('color'))->first()->id; $color = Unimodel::model('pipi_auto_colors')->where('code', $request->input('color'))->first()->id;
} }
if (!$started_at || !$ended_at || !$modelId) { if (!$started_at || !$ended_at || !$modelId || !$color) {
return false; return response()->json(['available' => false]);
} }
$started_at = Carbon::parse($started_at)->format('Y-m-d'); $started_at = Carbon::parse($started_at)->format('Y-m-d');
@ -270,7 +270,7 @@ class MobileApiController extends Controller
$availableCars = $cars->reject(fn($car) => in_array($car->id, $busyCars)); $availableCars = $cars->reject(fn($car) => in_array($car->id, $busyCars));
return $availableCars->isNotEmpty(); return response()->json(['available' => $availableCars->isNotEmpty()]);
} }
public function getAvailableMarksList(Request $request): JsonResponse public function getAvailableMarksList(Request $request): JsonResponse
@ -362,7 +362,7 @@ class MobileApiController extends Controller
'deposit' => $tariffs_new[0]['deposit'] ?? 30000, 'deposit' => $tariffs_new[0]['deposit'] ?? 30000,
'conditioner' => $mark?->conditioner, 'conditioner' => $mark?->conditioner,
'photo' => $colorPath, 'photo' => $colorPath,
'free' => $this->checkAvailableCar($started_at, $ended_at, $mark->id, $carColor->id), 'available' => $this->checkAvailableCar($started_at, $ended_at, $mark->id, $carColor->id)->getData()->available,
'tariffs' => $tariffs_new, 'tariffs' => $tariffs_new,
]; ];
} }

View File

@ -471,23 +471,10 @@ $address = \A7kz\Platform\Models\UniModel::model('pipi_address')->get();
}) })
}) })
.then(async response => { .then(async response => {
const contentType = response.headers.get('content-type');
if (contentType && contentType.includes('application/json')) {
return response.json(); return response.json();
} else {
const text = await response.text();
if (text === 'true') return true;
if (text === 'false') return false;
throw new Error(text || 'Неверный формат ответа');
}
}) })
.then(result => { .then(result => {
const isAvailable = let isAvailable = result.available;
result === true ||
(typeof result === 'object' && result?.return?.success) ||
(typeof result === 'string' && result.toLowerCase() === 'true');
if (isAvailable) { if (isAvailable) {
bookButton.style.display = 'block'; bookButton.style.display = 'block';
} else { } else {