2db47680
hexiaodong
chore: 初始提交 php 遗...
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
<?php
namespace addons\antis\model;
use think\Exception;
use think\Model;
use think\Session;
/**
* 配置模型
*/
class Field extends Model
{
// 表名,不含前缀
protected $name = 'qingdong_field';
// 自动写入时间戳字段
protected $autoWriteTimestamp = false;
// 定义时间戳字段名
protected $createTime = false;
protected $updateTime = false;
//获取字段
public static function getField($name,$type=null)
{
$where = [];
if($type){
$where['type'] = $type;
}
$data=self::where($where)->where(['name' => $name])->value('data');
if(empty($data)){
return [];
}
return json_decode($data,true);
}
//修改字段
public function fields()
{
return $this->hasOne(self::class, 'type', 'type')->field('type,data');
}
//设置form 表单选项
public function setFormField($type, $data)
{
$insertAll = [];
foreach ($data as $v) {
if ($v['component'] == 'select') {
$insertAll[] = [
'type' => $type,
'name' => $v['config']['label'],
'data' => json_encode($this->getDataFields($v['config']['content']), JSON_UNESCAPED_UNICODE)
];
}
}
$model = new self;
$model->where(['type' => $type])->delete();
if(empty($insertAll)){
return true;
}
if ($model->insertAll($insertAll) == false) {
throw new Exception('新增表单失败');
}
return true;
}
//循环获取data里面的字段
private function getDataFields($data, $fields = [])
{
foreach ($data as $v) {
$fields[] = $v['label'];
if (isset($v['children']) && $v['children']) {
$fields = self::getDataFields($data['children'], $fields);
}
}
return $fields;
}
}
|