Ken 3 minggu lalu
induk
melakukan
e2933cadff
2 mengubah file dengan 38 tambahan dan 32 penghapusan
  1. 32 31
      app/Http/Controllers/admin/Config.php
  2. 6 1
      app/Services/ConfigService.php

+ 32 - 31
app/Http/Controllers/admin/Config.php

@@ -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([], '删除成功');
     }
 

+ 6 - 1
app/Services/ConfigService.php

@@ -46,7 +46,12 @@ class ConfigService extends BaseService
         }
 
         if (isset($search['group_id']) && !empty($search['group_id'])) {
-            $where[] = ['group_id', '=', $search['group_id']];
+            if (is_array($search['group_id'])) {
+                $where[] = ['group_id', 'in', $search['group_id']];
+            } else {
+                $where[] = ['group_id', '=', $search['group_id']];
+            }
+
         }
 
         if (isset($search['id']) && !empty($search['id'])) {