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.
227 lines
9.1 KiB
227 lines
9.1 KiB
<?php
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
use App\Models\AdminFloor;
|
|
use App\Models\ParkingElectronicMap;
|
|
use App\Models\ParkingLicensePlate;
|
|
use App\Models\ParkingPatternSpace;
|
|
use App\Models\ParkingSpace;
|
|
use App\Models\ParkingSpaceAttributes;
|
|
use App\Models\ParkingSpaceType;
|
|
use App\Models\ParkingSpaceTypeAttr;
|
|
use App\Services\EventCalendarService;
|
|
use App\Services\ParkingPatternSpaceService;
|
|
use App\Services\ParkingSpaceTypeAttrService;
|
|
use App\Services\ParkingSpaceTypeService;
|
|
use Exception;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
|
|
class ParkingSpaceCatMapController extends BaseController
|
|
{
|
|
protected string $menuUri = 'parkingSpaceMap';
|
|
|
|
public function search(): JsonResponse
|
|
{
|
|
try {
|
|
$modeTypeList = ParkingPatternSpaceService::getPatternSpaceTypeData();
|
|
$data = [
|
|
'parking_space_type_list' => ParkingSpaceType::getData(),
|
|
'model_parking_space_type_list' => $modeTypeList,
|
|
'parking_space_attr_list' => ParkingSpaceAttributes::getTypeList()
|
|
];
|
|
return $this->responseService->success($data);
|
|
} catch (Exception $e) {
|
|
$m_prefix = __('exception.exception_handler.resource');
|
|
return $this->responseService->systemError(
|
|
$m_prefix . ':' . $e->getMessage()
|
|
);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 返回占用、控制车位颜色
|
|
* @return JsonResponse
|
|
*/
|
|
public function parkingTypeColor()
|
|
{
|
|
try {
|
|
$modeTypeList = ParkingPatternSpaceService::getPatternSpaceTypeData();
|
|
$colorOccupyList = [];
|
|
$colorVacantList = [];
|
|
$colorArr = ParkingSpaceTypeService::$colorArr;
|
|
foreach ($modeTypeList as $modeTypeItem) {
|
|
$type_id = $modeTypeItem['space_type_id'];
|
|
$space_type = $modeTypeItem['space_type'];
|
|
$colorVacantData = $colorOccupyData = [
|
|
'space_type_id' => $type_id,
|
|
'space_type' => $space_type,
|
|
'space_attr_list' => []
|
|
];
|
|
$typeAttrData = ParkingSpaceTypeAttrService::getTypeAttrData($type_id);
|
|
foreach ($typeAttrData as $typeAttrItem) {
|
|
$space_attr = ParkingSpaceAttributes::getAttr($typeAttrItem['attributes_id']);
|
|
$colorVacantData['space_attr_list'][] = [
|
|
'space_attr' => $space_attr,
|
|
'color' => $colorArr[$typeAttrItem['attr_color_vacant']]
|
|
] ;
|
|
$colorOccupyData['space_attr_list'][] = [
|
|
'space_attr' => $space_attr,
|
|
'color' => $colorArr[$typeAttrItem['attr_color_occupy']]
|
|
];
|
|
}
|
|
$colorOccupyList[] = $colorOccupyData;
|
|
$colorVacantList[] = $colorVacantData;
|
|
}
|
|
$data = [
|
|
'color_occupy_list' => $colorOccupyList,
|
|
'color_vacant_list' => $colorVacantList
|
|
];
|
|
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');
|
|
$pattern_id = EventCalendarService::getTargetModeId();
|
|
$spaceIds = ParkingPatternSpace::getParkingSpaceIds($pattern_id);
|
|
$sum = ParkingSpace::getModeFloorCount($floor_id, $spaceIds);
|
|
$surplus = ParkingSpace::getModeFloorCount($floor_id, $spaceIds, 0);
|
|
$under_repair = ParkingSpace::getModeFloorCount(
|
|
$floor_id,
|
|
$spaceIds,
|
|
2
|
|
);
|
|
$occupancy_rate = get_ratio($sum, $surplus);
|
|
$data = [
|
|
'sum' => $sum,
|
|
'surplus' => $surplus,
|
|
'occupancy_rate' => $occupancy_rate,
|
|
'under_repair' => $under_repair,
|
|
'parking_space_details' => []
|
|
];
|
|
$modeTypeList = ParkingPatternSpaceService::getPatternSpaceTypeData(
|
|
);
|
|
foreach ($modeTypeList as $item) {
|
|
$data['parking_space_details'][] = [
|
|
'space_type_id' => $item['space_type_id'],
|
|
'space_type' => $item['space_type'],
|
|
'sum' => ParkingSpace::getModeFloorCount(
|
|
$floor_id,
|
|
$spaceIds,
|
|
'11',
|
|
$item['space_type_id']
|
|
),
|
|
'surplus' => ParkingSpace::getModeFloorCount(
|
|
$floor_id,
|
|
$spaceIds,
|
|
0,
|
|
$item['space_type_id']
|
|
)
|
|
];
|
|
}
|
|
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');
|
|
|
|
$floorData = AdminFloor::query()->where('id', $floor_id)->whereNull(
|
|
'deleted_at'
|
|
)->first();
|
|
if ($floorData) {
|
|
$floorData['pic_url'] = get_image_url($floorData['image_url']);
|
|
unset($floorData['image_url']);
|
|
}
|
|
|
|
$colorArr = ParkingSpaceTypeService::$colorArr;
|
|
// 获取当前模式车位
|
|
$pattern_id = EventCalendarService::getTargetModeId();
|
|
$spaceIds = ParkingPatternSpace::getParkingSpaceIds($pattern_id);
|
|
// 查询车位所在图上位置
|
|
$model = ParkingElectronicMap::query()->where(
|
|
'floor_id',
|
|
$floor_id
|
|
)->whereIn('space_id', $spaceIds);
|
|
$electronicMapData = $model->select()->get()->toArray();
|
|
foreach ($electronicMapData as &$item) {
|
|
$ParkingSpace = ParkingSpace::query()->find($item['space_id']);
|
|
$space_attr_id = 0;
|
|
$space_type_id = 0;
|
|
$license_plate_id = '';
|
|
if ($ParkingSpace) {
|
|
$space_attr_id = $ParkingSpace['space_attr_id'];
|
|
$space_type_id = $ParkingSpace['space_type_id'];
|
|
$license_plate_id = $ParkingSpace['license_plate_id'];
|
|
}
|
|
$item['parking_space_number'] = $ParkingSpace['number'] ?? '';
|
|
$item['parking_space_id'] = $item['space_id'];
|
|
|
|
$ParkingAttr = ParkingSpaceAttributes::query()->find(
|
|
$space_attr_id
|
|
);
|
|
$item['has_ar'] = !empty($license_plate_id);
|
|
$item['attr_icon'] = get_image_url(
|
|
$ParkingAttr['import_diagram'] ?? ''
|
|
);
|
|
$item['attr_name'] = $ParkingAttr['attributes'] ?? '';
|
|
|
|
$ParkingType = ParkingSpaceType::query()->find($space_type_id)
|
|
?? [
|
|
'name' => '',
|
|
'default_color_vacant' => '',
|
|
'default_color_occupy' => ''
|
|
];
|
|
$item['space_type'] = $ParkingType['name'];
|
|
|
|
$ParkingColor = ParkingSpaceTypeAttr::getSpaceTypeAttrInfo(
|
|
$space_type_id,
|
|
$space_attr_id
|
|
);
|
|
$item['attr_color'] = $ParkingColor
|
|
? $ParkingColor['color_vacant']
|
|
: $ParkingType['default_color_vacant'];
|
|
$item['attr_color_value'] = $colorArr[$item['attr_color']] ?? '';
|
|
$item['car_color'] = '';
|
|
$item['car_no'] = '';
|
|
if ($item['has_ar']) {
|
|
$item['car_color'] = $ParkingColor
|
|
? $ParkingColor['color_occupy']
|
|
: $ParkingType['default_color_occupy'];
|
|
$item['car_color_value'] = $colorArr[$item['car_color']] ?? '';
|
|
$item['car_no'] = ParkingLicensePlate::getNumber(
|
|
$ParkingSpace['license_plate_id']
|
|
);
|
|
}
|
|
unset($item['space_id'], $item['floor_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()
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|