From 04fa4a4ed03aac6facba3c0e1a3a6befe8260160 Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq.com> Date: Thu, 12 Mar 2026 11:50:28 +0800 Subject: [PATCH] =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E9=85=8D=E7=BD=AE=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E6=8E=A5=E5=8F=A3=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/Admin/ConfigController.php | 105 ++++++++---------- database/seeders/AdminConfigSeeder.php | 39 +++---- 2 files changed, 64 insertions(+), 80 deletions(-) diff --git a/app/Http/Controllers/Admin/ConfigController.php b/app/Http/Controllers/Admin/ConfigController.php index 4b4bebe..58bc80c 100644 --- a/app/Http/Controllers/Admin/ConfigController.php +++ b/app/Http/Controllers/Admin/ConfigController.php @@ -14,26 +14,16 @@ use Illuminate\Validation\ValidationException; class ConfigController extends BaseController { - /** - * @var ApiResponseService - */ - protected ApiResponseService $responseService; - /** * @var OperationLogService */ private OperationLogService $logService; - /** - * 构造函数 - * @param ApiResponseService $responseService - * @param OperationLogService $logService - */ public function __construct( ApiResponseService $responseService, OperationLogService $logService ) { - $this->responseService = $responseService; + parent::__construct($responseService); $this->logService = $logService; } @@ -41,9 +31,18 @@ class ConfigController extends BaseController public function index(): JsonResponse { try { - $columns = ['id', 'title', 'name', 'content']; - $data = AdminConfigs::query()->select($columns)->get()->toArray(); - $this->translationContent($data); + $AdminConfigs = AdminConfigs::query()->where( + 'name', + '=', + 'parking_lot' + )->get(['id', 'content'])->toArray(); + $data = $AdminConfigs[0] ?? []; + if (!$data) { + throw new Exception(''); + } + foreach ($data['content'] as &$val) { + $val['title'] = __('controller.config.' . $val['name']); + } return $this->responseService->success($data); } catch (Exception $e) { $m_prefix = __('exception.get_data_failed'); @@ -53,19 +52,13 @@ class ConfigController extends BaseController } } - protected function translationContent(array &$data) - { - foreach ($data as &$value) { - $value['title'] = __('controller.config.' . $value['name']); - if (empty($value['content'])) { - continue; - } - foreach ($value['content'] as &$val) { - $val['title'] = __('controller.config.' . $val['name']); - } - } - } - + /** + * @param Request $request + * @param string $id + * @return JsonResponse + * @throws CustomException + * @throws ValidationException + */ public function update(Request $request, string $id): JsonResponse { try { @@ -96,34 +89,32 @@ class ConfigController extends BaseController $content[$key] = $value; } - if ($oldValue['name'] == 'parking_lot') { - $rules = [ - 'parking_lot_id' => 'required', - 'parking_lot_sum' => 'required|numeric', - 'zombie_car_parking_duration' => 'required|numeric', - ]; - $messages = [ - 'parking_lot_id.required' => __( - 'validation.admin_config.parking_lot_id_empty' - ), - 'parking_lot_sum.required' => __( - 'validation.admin_config.parking_lot_sum_empty' - ), - 'parking_lot_sum.numeric' => __( - 'validation.admin_config.parking_lot_sum_num' - ), - 'zombie_car_parking_duration.required' => __( - 'validation.admin_config.zombie_car_empty' - ), - 'zombie_car_parking_duration.numeric' => __( - 'validation.admin_config.zombie_car_num' - ), - ]; - - $validator = Validator::make($validator_data, $rules, $messages); - if ($validator->fails()) { - throw new ValidationException($validator); - } + $rules = [ + 'parking_lot_id' => 'required', + 'parking_lot_sum' => 'required|numeric', + 'zombie_car_parking_duration' => 'required|numeric', + ]; + $messages = [ + 'parking_lot_id.required' => __( + 'validation.admin_config.parking_lot_id_empty' + ), + 'parking_lot_sum.required' => __( + 'validation.admin_config.parking_lot_sum_empty' + ), + 'parking_lot_sum.numeric' => __( + 'validation.admin_config.parking_lot_sum_num' + ), + 'zombie_car_parking_duration.required' => __( + 'validation.admin_config.zombie_car_empty' + ), + 'zombie_car_parking_duration.numeric' => __( + 'validation.admin_config.zombie_car_num' + ), + ]; + + $validator = Validator::make($validator_data, $rules, $messages); + if ($validator->fails()) { + throw new ValidationException($validator); } $model->update([ @@ -140,8 +131,8 @@ class ConfigController extends BaseController throw $e; } catch (Exception $e) { return $this->responseService->systemError( - __('exception.update_admin_config_failed') . ':' . $e->getMessage( - ) + __('exception.update_admin_config_failed') . ':' + . $e->getMessage() ); } } diff --git a/database/seeders/AdminConfigSeeder.php b/database/seeders/AdminConfigSeeder.php index 3cffddc..d3b38dc 100644 --- a/database/seeders/AdminConfigSeeder.php +++ b/database/seeders/AdminConfigSeeder.php @@ -22,59 +22,52 @@ class AdminConfigSeeder extends Seeder $created_at = date("Y-m-d H:i:s", time()); return [ [ - 'title' => '车场配置', - 'name' => 'parking_lot', - 'content' => json_encode([ + 'title' => '车场配置', + 'name' => 'parking_lot', + 'content' => json_encode([ [ - 'name' => 'parking_lot_id', + 'name' => 'parking_lot_id', 'value' => 666 ], [ - 'name' => 'parking_lot_sum', + 'name' => 'parking_lot_sum', 'value' => 1000 ], [ - 'name' => 'parking_lot_image_path', + 'name' => 'parking_lot_image_path', 'value' => '/home/wwwroot/test/saas-8' ], [ - 'name' => 'zombie_car_parking_duration', + 'name' => 'zombie_car_parking_duration', 'value' => 10 ], [ - 'name' => 'numberplate_fuzzy_search', + 'name' => 'numberplate_fuzzy_search', 'value' => 1 ], [ - 'name' => 'automatically_clear_photo_cycle', + 'name' => 'automatically_clear_photo_cycle', 'value' => 10 - ] - ]), - 'status' => 1, - 'created_at' => $created_at - ], - [ - 'title' => '第三方平台配置', - 'name' => 'third_party', - 'content' => json_encode([ + ], [ - 'name' => 'report_data_switch', + 'name' => 'report_data_switch', 'value' => 1 ], [ - 'name' => 'third_parking_lot_id', + 'name' => 'third_parking_lot_id', 'value' => 666 ], [ - 'name' => 'report_api_url', + 'name' => 'report_api_url', 'value' => 'https://xg-saas-8.icecloud-car.cc' ], [ - 'name' => 'report_cycle', + 'name' => 'report_cycle', 'value' => 60 ], + ]), - 'status' => 1, + 'status' => 1, 'created_at' => $created_at ] ];