Extension3915ModuleController.php
3.5 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
<?php
/**
* @remark :
* @name :Extension3915ModuleController.php
* @author :lyh
* @method :post
* @time :2025/11/20 11:42
*/
namespace App\Http\Controllers\Bside\ExtensionModule;
use App\Enums\Common\Code;
use App\Http\Controllers\Bside\BaseController;
use App\Models\ExtentModule\ExtensionModuleValue;
use Illuminate\Support\Facades\Cache;
class Extension3915ModuleController extends BaseController
{
/**
* @remark :获取列表数据
* @name :lists
* @author :lyh
* @method :post
* @time :2025/11/20 14:38
*/
public function lists(){
$this->request->validate([
'module_id'=>'required',
],[
'module_id.required' => '模块id不能为空',
]);
$searchParam = [
'module_id'=>$this->param['module_id'],
];
$resultData = Cache::get('extension_module_list_3915_'.$this->param['module_id']);
if(empty($resultData)){
$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;
}
Cache::add('extension_module_list_3915_'.$this->param['module_id'],$resultData);
}
$resultData = $this->formatPaginate($resultData,$this->row,$this->page);
//执行分页
$this->response('success',Code::SUCCESS,$resultData);
}
/**
* @remark :分页
* @name :simplePaginate
* @author :lyh
* @method :post
* @time :2025/11/20 14:50
*/
public function formatPaginate($data, $size = 20, $page = 1)
{
$collection = collect($data);
$total = $collection->count();
$totalPage = max(1, ceil($total / $size));
// 确保页码在有效范围内
$page = max(1, min($page, $totalPage));
$list = $collection->forPage($page, $size)->values()->toArray();
return [
'list' => $list,
'page' => (int)$page,
'size' => (string)$size,
'total' => $total,
'total_page' => $totalPage
];
}
/**
* @remark :导入数据
* @name :importData
* @author :lyh
* @method :post
* @time :2025/11/20 14:40
*/
public function importData()
{
$data = $this->param;
//todo::优先截断表
$resultData = [];
foreach ($data as $k => $v){
}
return $data;
}
}