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