diff --git a/app/Http/Controllers/Admin/ParkingSpaceTypeController.php b/app/Http/Controllers/Admin/ParkingSpaceTypeController.php index bfe4f79..49c2c1a 100644 --- a/app/Http/Controllers/Admin/ParkingSpaceTypeController.php +++ b/app/Http/Controllers/Admin/ParkingSpaceTypeController.php @@ -12,13 +12,10 @@ use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Illuminate\Support\Facades\Validator; use Illuminate\Validation\ValidationException; +use Psr\SimpleCache\InvalidArgumentException; class ParkingSpaceTypeController extends BaseController { - /** - * @var ApiResponseService - */ - protected ApiResponseService $responseService; /** * @var ParkingSpaceTypeService */ @@ -31,9 +28,9 @@ class ParkingSpaceTypeController extends BaseController */ public function __construct( ApiResponseService $responseService, - ParkingSpaceTypeService $SpaceTypeService, + ParkingSpaceTypeService $SpaceTypeService ) { - $this->responseService = $responseService; + parent::__construct($responseService); $this->SpaceTypeService = $SpaceTypeService; } @@ -50,7 +47,10 @@ class ParkingSpaceTypeController extends BaseController $perPage = $request->input('per_page', 10); $total = $query->count(); - $items = $query->latest()->forPage($page, $perPage)->get(); + $query->orderBy('id'); + $items = $query->latest()->forPage($page, $perPage)->select( + ['id', 'name'] + )->get(); return $this->responseService->success([ 'items' => $items, @@ -147,13 +147,13 @@ class ParkingSpaceTypeController extends BaseController protected function extracted(string $id): JsonResponse { - try { $this->validateId($id, ParkingSpaceType::class); $data = [ 'color_list' => $this->SpaceTypeService->getColorList(), 'attr_list' => ParkingSpaceAttributes::getList(), - 'item' => ParkingSpaceType::query()->findOrFail($id)->toArray() + 'item' => ParkingSpaceType::query()->findOrFail($id) + ->toArray() ]; return $this->responseService->success($data); } catch (Exception $e) { @@ -221,4 +221,21 @@ class ParkingSpaceTypeController extends BaseController ); } } + + /** + * @return JsonResponse + * @throws InvalidArgumentException + */ + public function rule(): JsonResponse + { + try { + return $this->responseService->success( + $this->methodShow('spaceType') + ); + } catch (Exception $e) { + return $this->responseService->systemError( + __('exception.get_data_failed') . ':' . $e->getMessage() + ); + } + } } diff --git a/app/Models/ParkingSpaceAttributes.php b/app/Models/ParkingSpaceAttributes.php index f113901..013720a 100644 --- a/app/Models/ParkingSpaceAttributes.php +++ b/app/Models/ParkingSpaceAttributes.php @@ -29,7 +29,7 @@ class ParkingSpaceAttributes extends Model public static function getList(): array { return self::query()->get()->select( - ['id as attributes_id', 'attributes'] + ['id', 'attributes'] )->toArray(); } } diff --git a/app/Models/ParkingSpaceType.php b/app/Models/ParkingSpaceType.php index 80b405d..4e0f850 100644 --- a/app/Models/ParkingSpaceType.php +++ b/app/Models/ParkingSpaceType.php @@ -13,7 +13,17 @@ class ParkingSpaceType extends Model protected $fillable = [ 'id', - 'name' + 'name', + 'is_default', + 'default_color_occupy', + 'default_color_vacant', + 'default_color_warning', + 'default_is_warning', + 'default_is_flicker', + 'attributes_id', + 'attr_color_occupy', + 'attr_color_vacant', + 'attr_color_warning' ]; protected $hidden = [ diff --git a/app/Services/ParkingSpaceTypeService.php b/app/Services/ParkingSpaceTypeService.php index 4e2cd0a..6f13c34 100644 --- a/app/Services/ParkingSpaceTypeService.php +++ b/app/Services/ParkingSpaceTypeService.php @@ -2,6 +2,7 @@ namespace App\Services; +use App\Models\ParkingLicensePlate; use App\Models\ParkingSpaceType; use Exception; use Illuminate\Database\Eloquent\Builder; @@ -103,10 +104,7 @@ class ParkingSpaceTypeService $saveData['attr_color_occupy'] = $data['attr_color_occupy'] ?? ''; $saveData['attr_color_vacant'] = $data['attr_color_vacant'] ?? ''; $saveData['attr_color_warning'] = $data['attr_color_warning'] ?? ''; - - if (isset($data['attr_is_warning'])) { - $saveData['attr_is_warning'] = $data['attr_is_warning']; - } + $saveData['attr_is_warning'] = $data['attr_is_warning'] ?? 0; return $saveData; } @@ -160,6 +158,11 @@ class ParkingSpaceTypeService $model = ParkingSpaceType::query()->findOrFail($id); + $count = ParkingLicensePlate::query()->where('space_type_id', $model['id'])->count(); + if ($count > 0) { + throw new Exception(__('service.space_type.license_exists')); + } + $this->logService->logDeleted($model, '删除车位类型'); $model->delete(); diff --git a/resources/lang/zh-CN/service.php b/resources/lang/zh-CN/service.php index 380a972..8e11f22 100644 --- a/resources/lang/zh-CN/service.php +++ b/resources/lang/zh-CN/service.php @@ -28,7 +28,8 @@ return [ 'purple' => '紫色', 'cyan' => '青色', 'white' => '白色', - 'name_exists' => '车位类型名称已存在' + 'name_exists' => '车位类型名称已存在', + 'license_exists' => '请先清空车牌,即可删除' ], 'license_plate' => [ 'number_exists' => '车牌号码已存在' diff --git a/routes/admin/api.php b/routes/admin/api.php index 2360f02..0b958c0 100644 --- a/routes/admin/api.php +++ b/routes/admin/api.php @@ -35,6 +35,10 @@ Route::group(['prefix' => 'admin'], function () { Route::get('/spaceType', [ParkingSpaceTypeController::class, 'index']); Route::get('/spaceType/create', [ParkingSpaceTypeController::class, 'create']); Route::post('/spaceType', [ParkingSpaceTypeController::class, 'store']); + Route::get('/spaceType/{id}', [ParkingSpaceTypeController::class, 'show']); + Route::get('/spaceType/edit/{id}', [ParkingSpaceTypeController::class, 'edit']); + Route::put('/spaceType/{id}', [ParkingSpaceTypeController::class, 'update']); + Route::delete('/spaceType/{id}', [ParkingSpaceTypeController::class, 'destroy']); Route::get('/spaceType/rule', [ParkingSpaceTypeController::class, 'rule']); //车牌管理 Route::get('/licensePlate', [ParkingLicensePlateController::class, 'index']); @@ -57,11 +61,9 @@ Route::group(['prefix' => 'admin'], function () { Route::delete('/vipList/{id}', [VipListController::class, 'destroy']); Route::get('/vipList/rule', [VipListController::class, 'rule']); Route::post('/vipList/import', [VipListController::class, 'import']); - Route::get('/vipList/export', [VipListController::class, 'export']); - Route::get('/vipList/import_template', [VipListController::class, 'importTemplate']); // VIP进出记录 - Route::get('vipAccessRecord', [VipAccessRecordController::class, 'index']); - Route::get('vipAccessRecord/{id}', [VipAccessRecordController::class, 'show']); + Route::get('/vipAccessRecord', [VipAccessRecordController::class, 'index']); + Route::get('/vipAccessRecord/{id}', [VipAccessRecordController::class, 'show']); // 系统日志 Route::get('/operationLog/index', [OperationLogController::class, 'index']); @@ -105,6 +107,6 @@ Route::group(['prefix' => 'admin'], function () { Route::get('/users/rule', [UserController::class, 'rule']); }); // 导出 - Route::get('vip_list/import_template', [VipListController::class, 'importTemplate']); - Route::get('vip_list/export', [VipListController::class, 'export']); + Route::get('/vipList/import_template', [VipListController::class, 'importTemplate']); + Route::get('/vipList/export', [VipListController::class, 'export']); });