You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
107 lines
3.7 KiB
107 lines
3.7 KiB
<?php
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
use App\Models\AdminFloor;
|
|
use App\Models\ParkingElectronicMap;
|
|
use App\Models\ParkingSpace;
|
|
use App\Models\ParkingSpaceType;
|
|
use Exception;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
|
|
class ParkingSpaceCatMapController extends BaseController
|
|
{
|
|
|
|
public function search(): JsonResponse
|
|
{
|
|
try {
|
|
$data = [
|
|
'parking_space_type_list' => ParkingSpaceType::getData()
|
|
];
|
|
return $this->responseService->success($data);
|
|
} catch (Exception $e) {
|
|
$m_prefix = __('exception.exception_handler.resource');
|
|
return $this->responseService->systemError(
|
|
$m_prefix . ':' . $e->getMessage()
|
|
);
|
|
}
|
|
}
|
|
|
|
public function floorOverview(Request $request): JsonResponse
|
|
{
|
|
try {
|
|
$floor_id = $request->input('floor_id');
|
|
$where = ['floor_id' => $floor_id];
|
|
$sum = ParkingSpace::query()->where($where)->count();
|
|
$surplus = ParkingSpace::query()->where($where)->where('status', 0)
|
|
->count();
|
|
$under_repair = ParkingSpace::query()->where($where)->where(
|
|
'status',
|
|
2
|
|
)->count();
|
|
$occupancy_rate = get_ratio($sum, $surplus);
|
|
$data = [
|
|
'sum' => $sum,
|
|
'surplus' => $surplus,
|
|
'occupancy_rate' => $occupancy_rate,
|
|
'under_repair' => $under_repair,
|
|
'parking_space_details' => 45
|
|
];
|
|
return $this->responseService->success($data);
|
|
} catch (Exception $e) {
|
|
$m_prefix = __('exception.exception_handler.resource');
|
|
return $this->responseService->systemError(
|
|
$m_prefix . ':' . $e->getMessage()
|
|
);
|
|
}
|
|
}
|
|
|
|
public function map(Request $request): JsonResponse
|
|
{
|
|
try {
|
|
$floor_id = $request->input('floor_id');
|
|
$parking_space_type = $request->input('parking_space_type');
|
|
$floorData = AdminFloor::query()->where('id', $floor_id)->whereNull(
|
|
'deleted_at'
|
|
)->first();
|
|
if ($floorData) {
|
|
$floorData['pic_url'] = env('app_url')
|
|
. $floorData['image_url'];
|
|
unset($floorData['image_url']);
|
|
}
|
|
$model = ParkingElectronicMap::query()->where(
|
|
'floor_id',
|
|
$floor_id
|
|
);
|
|
if (isset($parking_space_type) && $parking_space_type) {
|
|
$type_arr = explode(',', $parking_space_type);
|
|
$space_ids = ParkingSpace::query()->whereIn(
|
|
'space_type_id',
|
|
$type_arr
|
|
)->pluck('id');
|
|
if ($space_ids) {
|
|
$model->whereIn('space_id', $space_ids);
|
|
}
|
|
}
|
|
$electronicMapData = $model->select()->get()->toArray();
|
|
foreach ($electronicMapData as &$item) {
|
|
$item['parking_space_number'] = ParkingSpace::getNumber(
|
|
$item['space_id']
|
|
);
|
|
unset($item['space_id']);
|
|
}
|
|
$data = [
|
|
'floor_data' => $floorData,
|
|
'electronic_map_data' => $electronicMapData
|
|
];
|
|
|
|
return $this->responseService->success($data);
|
|
} catch (Exception $e) {
|
|
$m_prefix = __('exception.exception_handler.resource');
|
|
return $this->responseService->systemError(
|
|
$m_prefix . ':' . $e->getMessage()
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|