rkljw 1 day ago
parent
commit
1d1dbd023d
2 changed files with 83 additions and 1 deletions
  1. 65 0
      app/JsonRpc/FormService.php
  2. 18 1
      app/JsonRpc/FormServiceInterface.php

+ 65 - 0
app/JsonRpc/FormService.php

@@ -347,4 +347,69 @@ class FormService implements FormServiceInterface
             return Result::error('查询失败:' . $e->getMessage());
         }
     }
+    /**
+     * 删除自定义表里面的某一条数据
+     */
+    public function delGlobalTableData(array $data): array
+    {
+        try {
+            //查询global库的表GlobalTable模型中id为$data['id']的数据
+            $globalTable = GlobalTable::where('id',$data['table_id'])->first();
+            if(empty($globalTable)){
+                return Result::error('表单不存在');
+            }
+            // 构建查询
+            $query = Db::connection('global')->table($globalTable->table);
+            $query->where('id',$data['id']);
+            $query->delete();
+            return Result::success('删除成功');
+        }catch (\Throwable $e){
+            return Result::error('删除失败:' . $e->getMessage());
+        }
+    }
+    /**
+     * 修改自定义表里面的某一条数据
+     */
+    public function updateGlobalTableData(array $data): array
+    {
+        try {
+            //查询global库的表GlobalTable模型中id为$data['id']的数据
+            $globalTable = GlobalTable::where('id',$data['table_id'])->first();
+            if(empty($globalTable)){
+                return Result::error('表单不存在');
+            }
+            unset($data['table_id']);
+            // 构建查询
+            $query = Db::connection('global')->table($globalTable->table);
+            $query->where('id',$data['id']);
+            $query->update($data);
+            return Result::success('修改成功');
+        }catch (\Throwable $e){
+            return Result::error('修改失败:' . $e->getMessage());
+        }
+    }
+    /**
+     * 查看自定义表里面的某条数据
+     */
+    public function getGlobalTableDataById(array $data): array
+    {
+        try {
+            //查询
+            $globalTable = GlobalTable::where('id',$data['table_id'])->first();
+            if(empty($globalTable)){
+                return Result::error('表单不存在');
+            }
+            $query =  Db::connection('global')->table($globalTable->table);
+            $query->where('id',$data['id']);
+            $dataInfo = $query->first();
+            $globalTableField = GlobalTableField::where(['table_id'=>$data['table_id']])->get();
+            $return = [
+                'data'=>$dataInfo,
+                'tableFields'=>$globalTableField->toArray(),
+            ];
+            return Result::success($return);
+        }catch (\Throwable $e){
+            return Result::error('查询失败:' . $e->getMessage());
+        }
+    }
 }

+ 18 - 1
app/JsonRpc/FormServiceInterface.php

@@ -64,7 +64,24 @@ interface FormServiceInterface
      *  @return array
     */
     public function getGlobalTableFieldTypeList(array $data):array;
-   
+    /**
+     * 删除自定义表单的数据
+     * @param array $data
+     *  @return array
+    */
+    public function delGlobalTableData(array $data):array;
+    /**
+     * 获取自定义表里面的数据
+     */
+    public function getGlobalTableDataById(array $data):array;
+
+    /**
+     * @param array $data
+     * @return array
+     */
+    public function updateGlobalTableData(array $data):array;
+
+
 
 
 }