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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
<?php
namespace addons\antis\model;
use think\Model;
use traits\model\SoftDelete;
/**
* 表单字段
*/
class FormField extends Model {
use SoftDelete;
const LEADS_TYPE = 'leads';
const CUSTOMER_TYPE = 'customer';
const CONTACTS_TYPE = 'contacts';
const CONTRACT_TYPE = 'contract';
const RECEIVABLES_TYPE = 'examine';
const BUSINESS_TYPE = 'business';
// 表名,不含前缀
protected $name = 'qingdong_form_field';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $deleteTime = 'deletetime';
public function getUpdatetimeAttr($value){
return date('Y-m-d H:i',$value);
}
/**
* 获取表单字段
*/
public static function getFields($type){
$fields=self::where(['types'=>$type,'field'=>['like',"main_%"],'list_show'=>1,'info_type'=>'main'])->select();
$js=[];
foreach ($fields as $v){
$d=[
'field' => $v['field'],
'title' => $v['name'],
'operate' => 'like',
'autocomplete' => false,
];
if($v['form_type'] == 'Cascader'){
$d['extend']='data-toggle="city-picker"';
}else if($v['form_type'] == 'uploadImage'){//图片
continue;
}else if($v['form_type'] == 'uploadFile'){//文件
continue;
}else if($v['form_type'] == 'DatePicker' ){//日期
$d['operate']='RANGE';
$d['addclass']='datetimerange';
$d['formatter']='Table.api.formatter.datetime';
$d['extend']='data-locale="{format:\"YYYY-MM-DD\"}"';
}else if($v['form_type'] == 'TimePicker' ){//时间
$d['operate']='RANGE';
$d['addclass']='datetimerange';
$d['formatter']='Table.api.formatter.datetime';
}else if($v['form_type'] == 'textarea'){//文本
$d['operate']=false;
}else if(in_array($v['form_type'],['select','checkbox','radio'])){//文件
$d['searchList']=json_encode(explode('|',$v['setting']),JSON_UNESCAPED_UNICODE);
}else if(in_array($v['form_type'],['Rate'])){//文件
$d['searchList']=json_encode([1=>1,2=>2,3=>3,4=>4,5=>5],JSON_UNESCAPED_UNICODE);
}
$js[] = $d;
}
return json_encode($js,JSON_UNESCAPED_UNICODE);
}
/**
* 验证表单字段
*/
public static function checkFields($types,$params,$id=null)
{
switch ($types){
case 'leads'://线索
$model=new Leads();
break;
case 'customer'://客户
$model=new Customer();
break;
case 'contract'://合同
$model=new Contract();
break;
case 'contacts'://联系人
$model=new Contacts();
break;
case 'receivabels'://回款
$model=new Receivables();
break;
}
$fields=self::where(['types'=>$types,'info_type'=>'main'])->select();
foreach ($fields as $v){
//必填
if($v['is_null'] == 1){
if (!isset($params[$v['field']]) || empty($params[$v['field']])) {
return $v['name'] . '不能为空!';
}
}
//唯一
if($v['is_unique'] == 1){
if (!isset($params[$v['field']]) || empty($params[$v['field']])) {
continue;
}
$where=[];
if(!empty($id)){
$where['id']=['neq',$id];
}
if(is_array($params[$v['field']])){
$params[$v['field']]=implode(',',$params[$v['field']]);
}
$where[$v['field']]=$params[$v['field']];
if($model->where($where)->count() > 0){
return $v['name'] ."【{$params[$v['field']]}】". '已存在!';
}
}
}
return true;
}
/**
* 获取搜索条件
*/
public static function updateWhereField($types,$params){
$fields=self::where(['types'=>$types,'info_type'=>'main'])->select();
$where=[];
foreach ($fields as $v){
if(!isset($params[$v['field']]) || $params[$v['field']] === ''){
continue;
}
if($v['form_type'] == 'uploadImage'){//图片
continue;
}else if($v['form_type'] == 'uploadFile'){//文件
continue;
}else if($v['form_type'] == 'DatePicker' ){//日期
$times=explode(',',$params[$v['field']]);
$where[$v['field']]=['between',$times ];
}else if($v['form_type'] == 'TimePicker' ){//时间
$times=explode(',',$params[$v['field']]);
$where[$v['field']]=['between',$times ];
}else if($v['form_type'] == 'textarea'){//文本
continue;
}else if(in_array($v['form_type'],['select','checkbox','radio'])){//
$where[$v['field']]=$params[$v['field']];
}else if(in_array($v['form_type'],['Rate'])){//星级
$where[$v['field']]=$params[$v['field']];
}else{
$where[$v['field']]=['like',"%{$params[$v['field']]}%" ];
}
}
return $where;
}
}
|