停车场管理系统
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.
 
 

132 lines
3.9 KiB

<?php
namespace App\Http\Controllers\Admin;
use App\Models\ParkingElectronicMap;
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;
}
/**
* 查询楼层
* @return JsonResponse
*/
public function floorList(): JsonResponse
{
try {
$data = [
'floor_list' => AdminFloorService::getSelectList()
];
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();
$this->saveValidator($data, 1);
$this->service->saveModel($data);
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()
);
}
}
}