|
|
@@ -30,7 +30,7 @@ class Config extends Controller
|
|
|
'id' => ['nullable', 'string'],
|
|
|
]);
|
|
|
$search = request()->all();
|
|
|
- $search['group_id'] = 1;
|
|
|
+ $search['group_id'] = [1, 3];
|
|
|
$result = ConfigService::paginate($search);
|
|
|
} catch (ValidationException $e) {
|
|
|
return $this->error(HttpStatus::VALIDATION_FAILED, $e->validator->errors()->first());
|
|
|
@@ -46,36 +46,36 @@ class Config extends Controller
|
|
|
*/
|
|
|
public function store()
|
|
|
{
|
|
|
- // try {
|
|
|
- $params = request()->all();
|
|
|
-
|
|
|
- $id = request()->post('id', '');
|
|
|
- if ($id) {
|
|
|
- $validator = [
|
|
|
- 'id' => ['required', 'integer', 'min:1'],
|
|
|
- 'val' => ['required', 'string'],
|
|
|
- 'remark' => 'required|nullable|string',
|
|
|
- ];
|
|
|
- } else {
|
|
|
- $validator = [
|
|
|
- 'field' => 'required|string|max:50|alpha_dash|unique:config,field',
|
|
|
- 'val' => 'required|string',
|
|
|
- 'remark' => 'required|nullable|string',
|
|
|
- ];
|
|
|
- }
|
|
|
-//
|
|
|
+ try {
|
|
|
+ $id = request()->post('id', '');
|
|
|
+ if ($id) {
|
|
|
+ $validator = [
|
|
|
+ 'id' => ['required', 'integer', 'min:1'],
|
|
|
+ 'val' => ['required', 'string'],
|
|
|
+ 'remark' => 'required|nullable|string',
|
|
|
+ ];
|
|
|
+ } else {
|
|
|
+ $validator = [
|
|
|
+ 'field' => 'required|string|max:50|alpha_dash|unique:config,field',
|
|
|
+ 'val' => 'required|string',
|
|
|
+ 'remark' => 'required|nullable|string',
|
|
|
+ ];
|
|
|
+ }
|
|
|
|
|
|
|
|
|
- $params = request()->validate($validator);
|
|
|
- $ret = ConfigService::submit($params);
|
|
|
- if ($ret['code'] == ConfigService::NOT) {
|
|
|
- return $this->error($ret['code'], $ret['msg']);
|
|
|
+ $params = request()->validate($validator);
|
|
|
+ if (!isset($params['id'])) $params['group_id'] = 3;
|
|
|
+
|
|
|
+
|
|
|
+ $ret = ConfigService::submit($params);
|
|
|
+ if ($ret['code'] == ConfigService::NOT) {
|
|
|
+ throw new Exception(HttpStatus::CUSTOM_ERROR, $ret['code']);
|
|
|
+ }
|
|
|
+ } catch (ValidationException $e) {
|
|
|
+ return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
|
|
|
+ } catch (Exception $e) {
|
|
|
+ return $this->error(intval($e->getCode()));
|
|
|
}
|
|
|
- // } catch (ValidationException $e) {
|
|
|
- // return $this->error(HttpStatus::VALIDATION_FAILED, '', $e->errors());
|
|
|
- // } catch (Exception $e) {
|
|
|
- // return $this->error(intval($e->getCode()));
|
|
|
- // }
|
|
|
return $this->success([], $ret['msg']);
|
|
|
|
|
|
}
|
|
|
@@ -85,16 +85,17 @@ class Config extends Controller
|
|
|
*/
|
|
|
public function destroy()
|
|
|
{
|
|
|
- return $this->error(HttpStatus::CUSTOM_ERROR,'禁止删除');
|
|
|
+
|
|
|
$id = request()->post('id');
|
|
|
// 示例:通过 ID 删除
|
|
|
$info = ConfigService::findOne(['id' => $id]);
|
|
|
if (!$info) {
|
|
|
return $this->error(HttpStatus::CUSTOM_ERROR, '配置不存在');
|
|
|
}
|
|
|
-
|
|
|
+ if ($info->group_id !== 3) {
|
|
|
+ return $this->error(HttpStatus::CUSTOM_ERROR, '禁止删除');
|
|
|
+ }
|
|
|
$info->delete();
|
|
|
-
|
|
|
return $this->success([], '删除成功');
|
|
|
}
|
|
|
|