Ken před 2 dny
rodič
revize
e36a487f62

+ 4 - 25
app/Http/Controllers/admin/Keyboard.php

@@ -5,6 +5,7 @@ namespace App\Http\Controllers\admin;
 
 use App\Constants\HttpStatus;
 use App\Http\Controllers\Controller;
+use App\Services\BaseService;
 use App\Services\KeyboardService;
 use Exception;
 
@@ -67,33 +68,11 @@ class Keyboard extends Controller
      * @apiParam {string} button 关键字
      * @apiParam {string} reply 回复内容
      * @apiParam {array} buttons 操作按钮组
-     * @apiExample {js} button 示例
-     * //button 的数据格式如下
-     * [
-     *   [      //第一行
-     *     {    //第一行按钮 的第一个按钮
-     *       "text": "百度",  //按钮文字
-     *       "url": "https://baidu.com"   //按钮跳转的链接
-     *     },
-     *     {    //第一行按钮 的第二个按钮
-     *       "text": "百度",
-     *       "url": "https://baidu.com"
-     *     }
-     *     //更多按钮...
-     *   ],
-     *   [    //第二行
-     *     {
-     *       "text": "百度",
-     *       "url": "https://baidu.com"
-     *     }
-     *   ]
-     *   //更多行...
-     * ]
      */
     public function store(): JsonResponse
     {
         try {
-            $id = request()->input('id', null);
+            $id = request()->input('id');
             $validator = [
                 'id' => ['required', 'integer'],
                 'reply' => 'required|string',
@@ -110,7 +89,7 @@ class Keyboard extends Controller
             }
             $params = request()->validate($validator);
             $ret = KeyboardService::submit($params);
-            if ($ret['code'] == KeyboardService::NOT) {
+            if ($ret['code'] == BaseService::NOT) {
                 throw new Exception($ret['msg'], HttpStatus::CUSTOM_ERROR);
             }
         } catch (ValidationException $e) {
@@ -137,13 +116,13 @@ class Keyboard extends Controller
      */
     public function destroy(): JsonResponse
     {
-        return $this->error(HttpStatus::CUSTOM_ERROR, '禁止删除');
         $id = request()->post('id');
         // 示例:通过 ID 删除回复
         $info = KeyboardService::findOne(['id' => $id]);
         if (!$info) {
             return $this->error(0, '数据不存在');
         }
+        if($info->group_id !=1)  return $this->error(0, '系统配置禁止删除');
         $info->delete();
         return $this->success([], '删除成功');
     }

+ 9 - 3
app/Services/KeyboardService.php

@@ -22,6 +22,8 @@ use Telegram\Bot\FileUpload\InputFile;
  */
 class KeyboardService extends BaseService
 {
+    public static string $MODEL = Keyboard::class;
+
     /**
      * @description: 模型
      * @return {string}
@@ -128,18 +130,22 @@ class KeyboardService extends BaseService
 
         // 2. 判断是否是更新
         if (!empty($params['id'])) {
-            // 更新
             $info = self::findOne(['id' => $params['id']]);
+
             if (!$info) {
                 $msg['msg'] = '数据不存在!';
             } else {
+                if ($info->group_id != 1) {
+                    unset($params['button']);
+                }
                 $result = $info->update($params);
                 $id = $params['id'];
             }
 
         } else {
             // 创建
-            $result = $info = self::model()::create($params);
+            $params['group_id'] = 1;
+            $result = $info = static::$MODEL::create($params);
             $id = $result->id;
         }
 
@@ -249,7 +255,7 @@ class KeyboardService extends BaseService
                 foreach ($keyboard as $item) {
                     $t = [];
                     foreach ($item as $item1) {
-                        if(static::isValidURL($item1['url'])){
+                        if (static::isValidURL($item1['url'])) {
                             $t[] = $item1;
                         }
                     }