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) {
$request = request();
@ -252,8 +252,8 @@ class MobileApiController extends Controller
$color = Unimodel::model('pipi_auto_colors')->where('code', $request->input('color'))->first()->id;
}
if (!$started_at || !$ended_at || !$modelId) {
return false;
if (!$started_at || !$ended_at || !$modelId || !$color) {
return response()->json(['available' => false]);
}
$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));
return $availableCars->isNotEmpty();
return response()->json(['available' => $availableCars->isNotEmpty()]);
}
public function getAvailableMarksList(Request $request): JsonResponse
@ -362,7 +362,7 @@ class MobileApiController extends Controller
'deposit' => $tariffs_new[0]['deposit'] ?? 30000,
'conditioner' => $mark?->conditioner,
'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,
];
}

View File

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