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
{
/**
* @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()
);
}
}

39
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
]
];

Loading…
Cancel
Save