Browse Source

系统配置管理接口优化

master
wanghongjun 4 days ago
parent
commit
04fa4a4ed0
  1. 105
      app/Http/Controllers/Admin/ConfigController.php
  2. 39
      database/seeders/AdminConfigSeeder.php

105
app/Http/Controllers/Admin/ConfigController.php

@ -14,26 +14,16 @@ use Illuminate\Validation\ValidationException;
class ConfigController extends BaseController class ConfigController extends BaseController
{ {
/**
* @var ApiResponseService
*/
protected ApiResponseService $responseService;
/** /**
* @var OperationLogService * @var OperationLogService
*/ */
private OperationLogService $logService; private OperationLogService $logService;
/**
* 构造函数
* @param ApiResponseService $responseService
* @param OperationLogService $logService
*/
public function __construct( public function __construct(
ApiResponseService $responseService, ApiResponseService $responseService,
OperationLogService $logService OperationLogService $logService
) { ) {
$this->responseService = $responseService; parent::__construct($responseService);
$this->logService = $logService; $this->logService = $logService;
} }
@ -41,9 +31,18 @@ class ConfigController extends BaseController
public function index(): JsonResponse public function index(): JsonResponse
{ {
try { try {
$columns = ['id', 'title', 'name', 'content']; $AdminConfigs = AdminConfigs::query()->where(
$data = AdminConfigs::query()->select($columns)->get()->toArray(); 'name',
$this->translationContent($data); '=',
'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); return $this->responseService->success($data);
} catch (Exception $e) { } catch (Exception $e) {
$m_prefix = __('exception.get_data_failed'); $m_prefix = __('exception.get_data_failed');
@ -53,19 +52,13 @@ class ConfigController extends BaseController
} }
} }
protected function translationContent(array &$data) /**
{ * @param Request $request
foreach ($data as &$value) { * @param string $id
$value['title'] = __('controller.config.' . $value['name']); * @return JsonResponse
if (empty($value['content'])) { * @throws CustomException
continue; * @throws ValidationException
} */
foreach ($value['content'] as &$val) {
$val['title'] = __('controller.config.' . $val['name']);
}
}
}
public function update(Request $request, string $id): JsonResponse public function update(Request $request, string $id): JsonResponse
{ {
try { try {
@ -96,34 +89,32 @@ class ConfigController extends BaseController
$content[$key] = $value; $content[$key] = $value;
} }
if ($oldValue['name'] == 'parking_lot') { $rules = [
$rules = [ 'parking_lot_id' => 'required',
'parking_lot_id' => 'required', 'parking_lot_sum' => 'required|numeric',
'parking_lot_sum' => 'required|numeric', 'zombie_car_parking_duration' => 'required|numeric',
'zombie_car_parking_duration' => 'required|numeric', ];
]; $messages = [
$messages = [ 'parking_lot_id.required' => __(
'parking_lot_id.required' => __( 'validation.admin_config.parking_lot_id_empty'
'validation.admin_config.parking_lot_id_empty' ),
), 'parking_lot_sum.required' => __(
'parking_lot_sum.required' => __( 'validation.admin_config.parking_lot_sum_empty'
'validation.admin_config.parking_lot_sum_empty' ),
), 'parking_lot_sum.numeric' => __(
'parking_lot_sum.numeric' => __( 'validation.admin_config.parking_lot_sum_num'
'validation.admin_config.parking_lot_sum_num' ),
), 'zombie_car_parking_duration.required' => __(
'zombie_car_parking_duration.required' => __( 'validation.admin_config.zombie_car_empty'
'validation.admin_config.zombie_car_empty' ),
), 'zombie_car_parking_duration.numeric' => __(
'zombie_car_parking_duration.numeric' => __( 'validation.admin_config.zombie_car_num'
'validation.admin_config.zombie_car_num' ),
), ];
];
$validator = Validator::make($validator_data, $rules, $messages);
$validator = Validator::make($validator_data, $rules, $messages); if ($validator->fails()) {
if ($validator->fails()) { throw new ValidationException($validator);
throw new ValidationException($validator);
}
} }
$model->update([ $model->update([
@ -140,8 +131,8 @@ class ConfigController extends BaseController
throw $e; throw $e;
} catch (Exception $e) { } catch (Exception $e) {
return $this->responseService->systemError( return $this->responseService->systemError(
__('exception.update_admin_config_failed') . ':' . $e->getMessage( __('exception.update_admin_config_failed') . ':'
) . $e->getMessage()
); );
} }
} }

39
database/seeders/AdminConfigSeeder.php

@ -22,59 +22,52 @@ class AdminConfigSeeder extends Seeder
$created_at = date("Y-m-d H:i:s", time()); $created_at = date("Y-m-d H:i:s", time());
return [ return [
[ [
'title' => '车场配置', 'title' => '车场配置',
'name' => 'parking_lot', 'name' => 'parking_lot',
'content' => json_encode([ 'content' => json_encode([
[ [
'name' => 'parking_lot_id', 'name' => 'parking_lot_id',
'value' => 666 'value' => 666
], ],
[ [
'name' => 'parking_lot_sum', 'name' => 'parking_lot_sum',
'value' => 1000 'value' => 1000
], ],
[ [
'name' => 'parking_lot_image_path', 'name' => 'parking_lot_image_path',
'value' => '/home/wwwroot/test/saas-8' 'value' => '/home/wwwroot/test/saas-8'
], ],
[ [
'name' => 'zombie_car_parking_duration', 'name' => 'zombie_car_parking_duration',
'value' => 10 'value' => 10
], ],
[ [
'name' => 'numberplate_fuzzy_search', 'name' => 'numberplate_fuzzy_search',
'value' => 1 'value' => 1
], ],
[ [
'name' => 'automatically_clear_photo_cycle', 'name' => 'automatically_clear_photo_cycle',
'value' => 10 '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 'value' => 1
], ],
[ [
'name' => 'third_parking_lot_id', 'name' => 'third_parking_lot_id',
'value' => 666 'value' => 666
], ],
[ [
'name' => 'report_api_url', 'name' => 'report_api_url',
'value' => 'https://xg-saas-8.icecloud-car.cc' 'value' => 'https://xg-saas-8.icecloud-car.cc'
], ],
[ [
'name' => 'report_cycle', 'name' => 'report_cycle',
'value' => 60 'value' => 60
], ],
]), ]),
'status' => 1, 'status' => 1,
'created_at' => $created_at 'created_at' => $created_at
] ]
]; ];

Loading…
Cancel
Save