From 81d008654f784e7f8328f13f8c9610748d683b1d Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq.com> Date: Mon, 27 Apr 2026 16:30:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B8=85=E9=99=A4=E5=85=A8=E9=83=A8=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Admin/ParkingInformationController.php | 20 ++++++++++++++++- app/Services/ParkingInformationService.php | 22 +++++++++++++++++++ resources/lang/zh-CN/log.php | 3 ++- routes/admin/api.php | 1 + 4 files changed, 44 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/Admin/ParkingInformationController.php b/app/Http/Controllers/Admin/ParkingInformationController.php index 80652fa..78bd72a 100644 --- a/app/Http/Controllers/Admin/ParkingInformationController.php +++ b/app/Http/Controllers/Admin/ParkingInformationController.php @@ -210,6 +210,24 @@ class ParkingInformationController extends BaseController } } + public function clear(): JsonResponse + { + try { + $this->service->clearModel(); + return $this->responseService->success( + null, + __('admin.delete_succeeded') + ); + } catch (ValidationException|CustomException $e) { + throw $e; + } catch (Exception $e) { + return $this->responseService->systemError( + __('exception.license_plate.destroy_failed') . ':' + . $e->getMessage() + ); + } + } + /** * @return JsonResponse * @throws InvalidArgumentException @@ -218,7 +236,7 @@ class ParkingInformationController extends BaseController { try { return $this->responseService->success( - $this->methodShow('information') + $this->methodShow('information', ['clear']), ); } catch (Exception $e) { return $this->responseService->systemError( diff --git a/app/Services/ParkingInformationService.php b/app/Services/ParkingInformationService.php index 2c24d04..b3a9bf1 100644 --- a/app/Services/ParkingInformationService.php +++ b/app/Services/ParkingInformationService.php @@ -149,4 +149,26 @@ class ParkingInformationService extends BaseService } } + public function clearModel(): bool + { + try { + DB::beginTransaction(); + + $data = ParkingInformation::query()->get()->toArray(); + + $this->logService->logDeletedData( + (new ParkingInformation()), + 'parking_information.clear', + $data + ); + + ParkingInformation::query()->delete(); + + DB::commit(); + return true; + } catch (Exception $e) { + DB::rollBack(); + throw $e; + } + } } diff --git a/resources/lang/zh-CN/log.php b/resources/lang/zh-CN/log.php index d6dad09..096f5e5 100644 --- a/resources/lang/zh-CN/log.php +++ b/resources/lang/zh-CN/log.php @@ -57,6 +57,7 @@ return [ ], 'parking_information' => [ 'create' => '创建车位资讯', - 'delete' => '更新车位资讯' + 'delete' => '更新车位资讯', + 'clear' => '清除车位资讯' ] ]; diff --git a/routes/admin/api.php b/routes/admin/api.php index 11689c5..8e56550 100644 --- a/routes/admin/api.php +++ b/routes/admin/api.php @@ -79,6 +79,7 @@ Route::group(['prefix' => 'admin'], function () { Route::get('/information/search', [ParkingInformationController::class, 'search']); Route::post('/information', [ParkingInformationController::class, 'store']); Route::delete('/information/{id}', [ParkingInformationController::class, 'destroy']); + Route::get('/information/clear', [ParkingInformationController::class, 'clear']); Route::get('/information/rule', [ParkingInformationController::class, 'rule']); // VIP名单