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.
160 lines
4.8 KiB
160 lines
4.8 KiB
<?php
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
use App\Services\AdminFloorService;
|
|
use App\Services\ApiResponseService;
|
|
use App\Services\ParkingElectronicMapService;
|
|
use App\Services\ParkingSpaceService;
|
|
use Exception;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Validator;
|
|
use Illuminate\Validation\ValidationException;
|
|
|
|
class ParkingElectronicMapController extends BaseController
|
|
{
|
|
|
|
protected ParkingElectronicMapService $service;
|
|
|
|
/**
|
|
* 构造函数
|
|
* @param ApiResponseService $responseService
|
|
* @param ParkingElectronicMapService $service
|
|
*/
|
|
public function __construct(
|
|
ApiResponseService $responseService,
|
|
ParkingElectronicMapService $service
|
|
) {
|
|
parent::__construct($responseService);
|
|
$this->service = $service;
|
|
}
|
|
|
|
/**
|
|
* 查询楼层
|
|
* @param Request $request
|
|
* @return JsonResponse
|
|
*/
|
|
public function floorList(Request $request): JsonResponse
|
|
{
|
|
try {
|
|
$building_floor = $request->get('building_floor', '1');
|
|
$data = [
|
|
'floor_list' => AdminFloorService::getSelectList($building_floor)
|
|
];
|
|
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 buildingFloorList(): JsonResponse
|
|
{
|
|
try {
|
|
$data = [
|
|
'building_floor_list' => get_select_data(
|
|
AdminFloorService::getBuildingFloor()
|
|
)
|
|
];
|
|
return $this->responseService->success($data);
|
|
} catch (Exception $e) {
|
|
$m_prefix = __('exception.exception_handler.resource');
|
|
return $this->responseService->systemError(
|
|
$m_prefix . ':' . $e->getMessage()
|
|
);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 查询车位号码
|
|
* @param $id
|
|
* @return JsonResponse
|
|
*/
|
|
public function getParkingSpaceList($id): JsonResponse
|
|
{
|
|
try {
|
|
$this->saveValidator(['floor_id' => $id]);
|
|
$list = ParkingSpaceService::getSelectList($id);
|
|
$data = [
|
|
'parking_space_list' => $list
|
|
];
|
|
return $this->responseService->success($data);
|
|
} catch (Exception $e) {
|
|
$m_prefix = __('exception.exception_handler.resource');
|
|
return $this->responseService->systemError(
|
|
$m_prefix . ':' . $e->getMessage()
|
|
);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @param array $data
|
|
* @param int $is_save
|
|
* @return void
|
|
* @throws ValidationException
|
|
*/
|
|
protected function saveValidator(array $data, int $is_save = 0): void
|
|
{
|
|
$rules = [
|
|
'floor_id' => 'required|numeric',
|
|
];
|
|
$messages = [
|
|
'floor_id.required' => __('validation.map.f_empty'),
|
|
'floor_id.numeric' => __('validation.map.f_number')
|
|
];
|
|
if ($is_save) {
|
|
$rules['parking_space_id'] = 'required|numeric';
|
|
$messages['parking_space_id.required'] = __('validation.map.p_empty');
|
|
$messages['parking_space_id.numeric'] = __('validation.map.p_number');
|
|
}
|
|
$validator = Validator::make($data, $rules, $messages);
|
|
|
|
if ($validator->fails()) {
|
|
throw new ValidationException($validator);
|
|
}
|
|
}
|
|
|
|
public function save(Request $request): JsonResponse
|
|
{
|
|
try {
|
|
$data = $request->all();
|
|
$saveData = $data['saveData'] ?? [];
|
|
if (empty($saveData)) {
|
|
throw new Exception(__('validation.map.d_empty'));
|
|
}
|
|
foreach ($saveData as $item) {
|
|
$this->saveValidator($item, 1);
|
|
$this->service->saveModel($item);
|
|
}
|
|
return $this->responseService->success([], __('admin.save_succeeded'));
|
|
} catch (Exception $e) {
|
|
$m_prefix = __('admin.save_failed');
|
|
return $this->responseService->systemError(
|
|
$m_prefix . ':' . $e->getMessage()
|
|
);
|
|
}
|
|
|
|
}
|
|
|
|
public function index(Request $request): JsonResponse
|
|
{
|
|
try {
|
|
$data = $request->all();
|
|
$this->saveValidator($data);
|
|
$list = $this->service->getList($data);
|
|
return $this->responseService->success($list);
|
|
} catch (Exception $e) {
|
|
$m_prefix = __('exception.exception_handler.resource');
|
|
return $this->responseService->systemError(
|
|
$m_prefix . ':' . $e->getMessage()
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|