|
@@ -34,8 +34,21 @@ class FormService implements FormServiceInterface
|
|
|
`title` varchar(255) DEFAULT NULL,
|
|
|
PRIMARY KEY (`id`)
|
|
|
)");
|
|
|
- //给GlobalTableField表初始化一条数据,表table_id为$id,field_name为title字符串,title为标题,field_type为varchar,length为255,is_required为1,is_unique为0,is_primary为0,is_index为0,is_foreign为0,is_auto_increment为1,is_default为0,default_value为'',description为'',website_id为$data['website_id']
|
|
|
+ //给GlobalTableField表初始化数据
|
|
|
GlobalTableField::on('global')->insert([
|
|
|
+ [
|
|
|
+ 'table_id' => $id,
|
|
|
+ 'field_name' => 'id',
|
|
|
+ 'title' => '编号',
|
|
|
+ 'field_type' => '1',
|
|
|
+ 'length' => 255,
|
|
|
+ 'sort' => 0,
|
|
|
+ 'is_check' => 1,
|
|
|
+ 'admin_display' => 1,
|
|
|
+ 'home_display' => 1,
|
|
|
+ 'disable_del' => 1,
|
|
|
+ ],
|
|
|
+ [
|
|
|
'table_id' => $id,
|
|
|
'field_name' => 'title',
|
|
|
'title' => '标题',
|
|
@@ -46,7 +59,9 @@ class FormService implements FormServiceInterface
|
|
|
'admin_display' => 1,
|
|
|
'home_display' => 1,
|
|
|
'disable_del' => 1,
|
|
|
- ]);
|
|
|
+ ]
|
|
|
+
|
|
|
+ ]);
|
|
|
|
|
|
return Result::success('添加成功');
|
|
|
}
|
|
@@ -265,12 +280,11 @@ class FormService implements FormServiceInterface
|
|
|
*/
|
|
|
public function getGlobalTableData(array $data): array
|
|
|
{
|
|
|
- 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']的数据
|
|
|
+ //查询global库的表GlobalTableField模型中table_id为$data['id']的数据条件为admin_display=1的数据
|
|
|
+ $globalTableFields = GlobalTableField::where(['table_id'=>$data['id'],'admin_display'=>1])->get();
|
|
|
+
|
|
|
+ //查询global库的表GlobalTable模型中id为$data['id']的数据
|
|
|
$globalTable = GlobalTable::where('id',$data['id'])->first();
|
|
|
if(empty($globalTable)){
|
|
|
return Result::error('表单不存在');
|
|
@@ -292,12 +306,24 @@ class FormService implements FormServiceInterface
|
|
|
$total = $query->count();
|
|
|
|
|
|
// 获取分页数据
|
|
|
- $list = $query->select($globalTableField)
|
|
|
+ $list = $query->select($globalTableFields->pluck('field_name')->toArray())
|
|
|
->orderBy('id', 'desc')
|
|
|
->offset(($page - 1) * $pageSize)
|
|
|
->limit($pageSize)
|
|
|
->get();
|
|
|
|
|
|
+ // 处理返回数据,将field_name替换为title
|
|
|
+ $list = $list->map(function($item) use ($globalTableFields) {
|
|
|
+ $newItem = new \stdClass();
|
|
|
+ foreach ($globalTableFields as $field) {
|
|
|
+ $fieldName = $field->field_name;
|
|
|
+ if (isset($item->$fieldName)) {
|
|
|
+ $newItem->{$field->title} = $item->$fieldName;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return $newItem;
|
|
|
+ });
|
|
|
+
|
|
|
return Result::success([
|
|
|
'list' => $list,
|
|
|
'total' => $total,
|