ExtensionModuleController.php
12.6 KB
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
<?php
/**
* @remark :
* @name :ExtensionModuleController.php
* @author :lyh
* @method :post
* @time :2024/8/7 16:15
*/
namespace App\Http\Controllers\Bside\ExtensionModule;
use App\Enums\Common\Code;
use App\Http\Controllers\Bside\BaseController;
use App\Http\Logic\Bside\ExtensionModule\ExtensionModuleFieldLogic;
use App\Models\ExtentModule\ExtensionModule;
use App\Models\ExtentModule\ExtensionModuleField;
use App\Models\ExtentModule\ExtensionModuleValue;
use Illuminate\Support\Facades\DB;
class ExtensionModuleController extends BaseController
{
/**
* @remark :获取扩展数据模块
* @name :getModuleList
* @author :lyh
* @method :post
* @time :2024/8/7 16:16
*/
public function getModuleList(){
$moduleModel = new ExtensionModule();
$this->map['status'] = 0;
$list = $moduleModel->list($this->map);
$this->response('success',Code::SUCCESS,$list);
}
/**
* @remark :获取数据类型
* @name :getDataType
* @author :lyh
* @method :post
* @time :2024/8/7 17:31
*/
public function getDataType(){
$data = [
'1'=>'文本框',
'2'=>'多文本输入框',
'3'=>'图片框',
'4'=>'文件框',
'5'=>'下拉框',
'6'=>'自动生成订单框',
'7'=>'创建时间'
];
$this->response('success',Code::SUCCESS,$data);
}
/**
* @remark :获取当前模块字段
* @name :getModuleFiledInfo
* @author :lyh
* @method :post
* @time :2024/8/7 16:20
*/
public function getModuleFiledInfo(){
$this->request->validate([
'module_id'=>'required',
],[
'module_id.required' => '模块id不能为空',
]);
$moduleFieldModel = new ExtensionModuleField();
$list = $moduleFieldModel->list(['module_id'=>$this->param['module_id']],'sort',['*'],'desc');
$moduleValueModel = new ExtensionModuleValue();
foreach ($list as $k => $v){
$v['is_use'] = 0;
//查看当前字段是否已使用
$info = $moduleValueModel->read(['field_id'=>$v['id']],['id']);
if($info !== false){
$v['is_use'] = 1;
}
$list[$k] = $v;
if(!empty($v['data'])){
$v['data'] = json_decode($v['data'],true);
}
}
$this->response('success',Code::SUCCESS,$list);
}
/**
* @remark :添加字段
* @name :saveModuleField
* @author :lyh
* @method :post
* @time :2024/8/7 16:27
*/
public function saveModuleField(ExtensionModuleFieldLogic $logic){
$this->request->validate([
'module_id'=>'required',
'field_name'=>'required',
'data_type'=>'required',
'is_required'=>'required',
],[
'module_id.required' => '模块id不能为空',
'field_name.required' => '字段名称不能为空',
'data_type.required' => '数据类型不能为空',
'is_required.required' => '是否必填不能为空',
]);
$data = $logic->saveModuleField();
$this->response('success',Code::SUCCESS,$data);
}
/**
* @remark :删除字段
* @name :delModuleField
* @author :lyh
* @method :post
* @time :2024/8/7 17:10
*/
public function delModuleField(ExtensionModuleFieldLogic $logic){
$this->request->validate([
'field_id'=>'required',
],[
'field_id.required' => '字段id不能为空',
]);
$logic->delModuleField();
$this->response('success');
}
/**
* @remark :获取当前模块的所有数据
* @name :getModuleValueList
* @author :lyh
* @method :post
* @time :2024/8/7 17:37
*/
public function getModuleValueList(){
$this->request->validate([
'module_id'=>'required',
],[
'module_id.required' => '模块id不能为空',
]);
$searchParam = [
'module_id'=>$this->param['module_id'],
];
$data = [];
$moduleValueModel = new ExtensionModuleValue();
if(isset($this->param['field_id']) && ($this->param['field_id'] != 0) && isset($this->param['value'])){
$uuidArr = $moduleValueModel->formatQuery(['field_id'=>$this->param['field_id'],'value'=>$this->param['value'],'module_id'=>$this->param['module_id']])->distinct()->pluck('uuid')->toArray();
if(!empty($uuidArr)){
$searchParam['uuid'] = ['in',$uuidArr];
}
}
if(isset($this->param['start_time']) && !empty($this->param['start_time']) && isset($this->param['end_time']) && !empty($this->param['end_time'])){
$searchParam['created_at'] = ['between',[$this->param['start_time'],$this->param['end_time']]];
}
$lists = $moduleValueModel->list($searchParam);
if(!empty($lists)){
foreach ($lists as $k => $v){
$data[$v['uuid']][$v['field_id']] = $v['value'];
$data[$v['uuid']]['created_at'] = $v['created_at'];
}
}
$resultData = [];
foreach ($data as $k => $v){
$v['uuid'] = $k;
$resultData[] = $v;
}
$this->response('success',Code::SUCCESS,$resultData);
}
/**
* @remark :保存数据
* @name :saveModuleValue
* @author :lyh
* @method :post
* @time :2024/8/7 17:59
*/
public function editModuleValue(){
$this->request->validate([
'module_id'=>'required',
],[
'module_id.required' => '模块id不能为空',
]);
$data = $this->param['data'];
$moduleValueModel = new ExtensionModuleValue();
foreach ($data as $k => $v){
$info = $moduleValueModel->read(['uuid'=>$this->param['uuid'],'field_id'=>$v['field_id'],'module_id'=>$this->param['module_id']]);
if($info === false){
$data = [
'uuid'=>$this->param['uuid'],
'module_id'=>$this->param['module_id'],
'field_id'=>$v['field_id'],
'value'=>$v['value']
];
$moduleValueModel->addReturnId($data);
}else{
if($this->user['project_id'] == 2205 && $this->param['module_id'] == 1){
@file_put_contents(storage_path('logs/lyh_error.log'), var_export($v, true) . PHP_EOL, FILE_APPEND);
if($v['field_id'] == 12 && (!empty($v['value']) && !empty($info['value']))){//下拉框数据
$filedModel = new ExtensionModuleField();
$fileInfo = $filedModel->read(['id'=>12]);//获取当前下拉框的数据
$statusData = json_decode($fileInfo['data'],true);
$status_data = [];
$number = 1;
foreach ($statusData as $v){
$status_data[$v] = $number;
$number++;
}
@file_put_contents(storage_path('logs/lyh_error.log'), var_export($status_data, true) . PHP_EOL, FILE_APPEND);
@file_put_contents(storage_path('logs/lyh_error.log'), var_export($info['value'], true) . PHP_EOL, FILE_APPEND);
@file_put_contents(storage_path('logs/lyh_error.log'), var_export($v['value'], true) . PHP_EOL, FILE_APPEND);
if($status_data[$info['value']] > $status_data[$v['value']]){
$this->fail('流程控制只能往下选择');
}
}
}
$moduleValueModel->edit(['value'=>$v['value'] ?? ''],['id'=>$info['id']]);
}
}
$this->response('success',Code::SUCCESS,['uuid'=>$this->param['uuid']]);
}
/**
* @remark :新增數據
* @name :addModuleValue
* @author :lyh
* @method :post
* @time :2024/8/8 10:00
*/
public function addModuleValue(){
$this->request->validate([
'module_id'=>'required',
],[
'module_id.required' => '模块id不能为空',
]);
$moduleValueModel = new ExtensionModuleValue();
$info = $moduleValueModel->where('module_id',$this->param['module_id'])->orderBy('uuid','desc')->first();
if(empty($info)){
$uuid = 1;
}else{
$info = $info->toArray();
$uuid = $info['uuid'] + 1;
}
$data = $this->param['data'];
$moduleValueModel = new ExtensionModuleValue();
foreach ($data as $k => $v){
$data = [
'uuid'=>$uuid,
'module_id'=>$this->param['module_id'],
'field_id'=>$v['field_id'],
'value'=>$v['value']
];
$moduleValueModel->addReturnId($data);
}
$this->response('success',Code::SUCCESS,['uuid'=>$uuid]);
}
/**
* @remark :生成唯一的字符串
* @name :sendUniqueStr
* @author :lyh
* @method :post
* @time :2024/8/20 10:31
*/
public function sendUniqueStr(){
$this->request->validate([
'id'=>'required',
],[
'id.required' => '字段id不能为空',
]);
$uniqueString = '';
//查看当前字段id的data
$moduleFieldModel = new ExtensionModuleField();
$info = $moduleFieldModel->read(['id'=>$this->param['id']]);
if(empty($info['data'])){
$uniqueString = md5(time() . rand(1000, 9999));
}else{
$data = json_decode($info['data']);
foreach ($data as $v){
foreach ($v as $k => $sonV){
if($k == 1){
$uniqueString .= $sonV;
}elseif ($k == 2){
$uniqueString .= date('YmdHis');
}elseif ($k == 3){
$uniqueString .= uniqid();
}else{
$randomString = md5(uniqid(mt_rand(), true));
$uniqueString .= substr($randomString, 0, (int)$sonV);
}
}
}
}
$this->response('success',Code::SUCCESS,['str'=>$uniqueString]);
}
/**
* @remark :获取类型
* @name :getFieldType
* @author :lyh
* @method :post
* @time :2024/8/22 11:22
*/
public function getFieldType(){
$data = [
1=>'文本框',
2=>'多文本框',
3=>'图片框',
4=>'文件框',
5=>'下拉框',
6=>'自动订单'
];
$this->response('success',Code::SUCCESS,$data);
}
/**
* @remark :设置排序
* @name :setSort
* @author :lyh
* @method :post
* @time :2024/8/22 17:27
*/
public function setSort(){
$moduleFieldModel = new ExtensionModuleField();
$num = 100;
foreach ($this->param['id'] as $id){
$moduleFieldModel->edit(['sort'=>$num],['id'=>$id]);
$num--;
}
$this->response('success');
}
/**
* @remark :设置搜索参数
* @name :setSearchParam
* @author :lyh
* @method :post
* @time :2024/8/23 16:24
*/
public function setSearchParam(){
$this->request->validate([
'module_id'=>'required',
'id'=>'required|array'
],[
'module_id.required' => '模块id不能为空',
'id.required'=>'id不能为空',
'id.array'=>'id是一个数组'
]);
$moduleFieldModel = new ExtensionModuleField();
$moduleFieldModel->edit(['is_search'=>0],['module_id'=>$this->param['module_id']]);
$moduleFieldModel->edit(['is_search'=>1],['id'=>['in',$this->param['id']]]);
$this->response('success');
}
/**
* @remark :删除数据
* @name :delExtensionValue
* @author :lyh
* @method :post
* @time :2024/8/26 14:25
*/
public function delExtensionValue(){
$this->request->validate([
'module_id'=>'required',
'uuid'=>'required',
],[
'module_id.required' => '模块id不能为空',
'uuid.required' => '字段id不能为空',
]);
$moduleValueModel = new ExtensionModuleValue();
$moduleValueModel->del(['module_id'=>$this->param['module_id'],'uuid'=>$this->param['uuid']]);
$this->response('success');
}
}