rkljw 2 dagen geleden
bovenliggende
commit
97507469dd
1 gewijzigde bestanden met toevoegingen van 21 en 7 verwijderingen
  1. 21 7
      app/JsonRpc/FormService.php

+ 21 - 7
app/JsonRpc/FormService.php

@@ -439,21 +439,35 @@ class FormService implements FormServiceInterface
     public function updateGlobalTableData(array $data): array
     {
         try {
-            //查询global库的表GlobalTable模型中id为$data['id']的数据
-            $globalTable = GlobalTable::where('id',$data['table_id'])->first();
-            if(empty($globalTable)){
+            $globalTable = GlobalTable::where('id', $data['table_id'])->first();
+            if (empty($globalTable)) {
                 return Result::error('表单不存在');
             }
+
             unset($data['table_id']);
-            // 构建查询
+
+            // 转换数组字段为字符串
+            $data = array_map(function ($value) {
+                if (is_array($value)) {
+                    // 如果是关联数组,转换为JSON字符串
+                    if (array_keys($value) !== range(0, count($value) - 1)) {
+                        return json_encode($value, JSON_UNESCAPED_UNICODE);
+                    }
+                    // 如果是索引数组,转换为逗号分隔字符串
+                    return implode(',', $value);
+                }
+                return $value;
+            }, $data);
+
             $query = Db::connection('global')->table($globalTable->table);
-            $query->where('id',$data['id']);
-            $query->update($data);
+            $query->where('id', $data['id'])->update($data);
+
             return Result::success('修改成功');
-        }catch (\Throwable $e){
+        } catch (\Throwable $e) {
             return Result::error('修改失败:' . $e->getMessage());
         }
     }
+
     /**
      * 查看自定义表里面的某条数据
      */