瀏覽代碼

自定义表单

rkljw 1 天之前
父節點
當前提交
9e908fac0a
共有 2 個文件被更改,包括 49 次插入9 次删除
  1. 43 8
      app/JsonRpc/FormService.php
  2. 6 1
      app/JsonRpc/FormServiceInterface.php

+ 43 - 8
app/JsonRpc/FormService.php

@@ -8,7 +8,7 @@ use App\Model\GlobalTable;
 use Hyperf\DbConnection\Db;
 use App\Model\GlobalTableField;
 use App\Model\GlobalTableFieldType;
-
+use App\Model\GlobalTableFieldValue;
 #[RpcService(name: "FormService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
 class FormService implements FormServiceInterface
 {
@@ -263,14 +263,49 @@ class FormService implements FormServiceInterface
     /**
      * 获取自定义生成表里面的数据
      */
-    public function getCustomTableData(array $data): array
+    public function getGlobalTableData(array $data): array
     {
-        $globalTable = GlobalTable::where('id',$data['table_id'])->first();
-        if(empty($globalTable)){
-            return Result::error('表单不存在');
+        var_dump($data);
+        try {
+            //查询global库的表GlobalTableField模型中table_id为$data['table_id']的数据条件为admin_display=1的数据
+            $globalTableField = GlobalTableField::where(['table_id'=>$data['id'],'admin_display'=>1])->pluck("field_name")->toArray();
+            var_dump($globalTableField);
+            //查询global库的表GlobalTable模型中id为$data['table_id']的数据
+            $globalTable = GlobalTable::where('id',$data['id'])->first(); 
+            if(empty($globalTable)){
+                return Result::error('表单不存在');
+            }
+
+            // 构建查询
+            $query = Db::connection('global')->table($globalTable->table);
+            
+            // 添加title模糊搜索
+            if (!empty($data['title'])) {
+                $query->where('title', 'like', '%' . $data['title'] . '%');
+            }
+
+            // 分页参数
+            $page = (int)($data['page'] ?? 1);
+            $pageSize = (int)($data['pageSize'] ?? 10);
+            
+            // 先获取总数
+            $total = $query->count();
+            
+            // 获取分页数据
+            $list = $query->select($globalTableField)
+                         ->orderBy('id', 'desc')
+                         ->offset(($page - 1) * $pageSize)
+                         ->limit($pageSize)
+                         ->get();
+
+            return Result::success([
+                'list' => $list,
+                'total' => $total,
+                'page' => $page,
+                'pageSize' => $pageSize
+            ]);
+        } catch (\Throwable $e) {
+            return Result::error('查询失败:' . $e->getMessage());
         }
-        //根据返回的table名称,查询这个表的数据
-        $data = Db::connection('global')->table($globalTable->table)->get();
-        return Result::success($data);
     }
 }

+ 6 - 1
app/JsonRpc/FormServiceInterface.php

@@ -54,7 +54,12 @@ interface FormServiceInterface
      *  @return array                   
      * */
     public function delGlobalTableField(array $data):array;
-    
+    /**
+     * @param array $data
+     *  @return array
+    */
+    public function getGlobalTableData(array $data):array;
+   
 
 
 }