BProjectComConfigLogic.php
5.3 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
<?php
/**
* @remark :
* @name :BProjectComConfigLogic.php
* @author :lyh
* @method :post
* @time :2024/8/1 14:25
*/
namespace App\Http\Logic\Bside\BTemplate;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\CustomModule\CustomModule;
use App\Models\IsCom\ProjectComConfig;
use App\Models\Template\BTemplate;
/**
* @remark :独立头部——底部设置
* @name :BProjectComConfigLogic
* @author :lyh
* @method :post
* @time :2024/8/1 14:43
*/
class BProjectComConfigLogic extends BaseLogic
{
/**
* 初始化数据
*/
public function __construct()
{
parent::__construct();
$this->model = new ProjectComConfig();
$this->param = $this->requestAll;
}
const PUB_STATUS = 0;//公共
const PRO_STATUS = 1;//獨立
const IS_LIST = 1;
const IS_DETAIL = 0;
const IS_NO_CUSTOM = 0;
const IS_CUSTOM = 1;//扩展模块
/**
* @remark :获取初始数据
* @name :getIsComSetting
* @author :lyh
* @method :post
* @time :2024/8/1 15:02
*/
public function getIsComConfig(){
$data = [];
$data = $this->initParamData($data);
$data = $this->initPageParamData($data);
$data = $this->initCustomData($data);
return $this->success($data);
}
/**
* @remark :(独立头底)初始数据
* @name :initializedData
* @author :lyh
* @method :post
* @time :2024/8/1 11:52
*/
public function initParamData(&$data){
//默认模块
$initParam = $this->model->initParam;
foreach ($initParam as $pKey => $pValue){
$is_list = [self::IS_LIST,self::IS_DETAIL];
foreach ($is_list as $isValue){
//查询当前数据是否已保存
$info = $this->model->read(['source'=>$pValue,'is_list'=>$isValue,'is_custom'=>BTemplate::IS_NO_CUSTOM],['id','name','source','is_list','is_custom','header_status','footer_status']);
if($info !== false){
$data[] = $info;
}else{
$data[] = [
'name'=>$pKey.($isValue == 0 ? '详情' : '列表'),
'source'=>$pValue,
'is_list'=>$isValue,
'is_custom'=>self::IS_NO_CUSTOM,
'header_status'=>self::PUB_STATUS,
'footer_status'=>self::PUB_STATUS,
];
}
}
}
return $this->success($data);
}
/**
* @remark :单页面初始化
* @name :initPageParamData
* @author :lyh
* @method :post
* @time :2024/8/1 14:37
*/
public function initPageParamData(&$data){
$initPageParam = $this->model->initPageParam;
foreach($initPageParam as $key => $value){
$info = $this->model->read(['source'=>$value,'is_list'=>self::IS_DETAIL,'is_custom'=>BTemplate::IS_NO_CUSTOM],['id','name','source','is_list','is_custom','header_status','footer_status']);
if($info !== false){
$data[] = $info;
}else{
$data[] = [
'name'=>$key,
'source'=>$value,
'is_list'=>self::IS_DETAIL,
'is_custom'=>self::IS_NO_CUSTOM,
'header_status'=>self::PUB_STATUS,
'footer_status'=>self::PUB_STATUS,
];
}
}
return $this->success($data);
}
/**
* @remark :获取扩展模块初始数据
* @name :initCustomData
* @author :lyh
* @method :post
* @time :2024/8/1 14:42
*/
public function initCustomData(&$data){
$customModel = new CustomModule();
$customList = $customModel->list(['status'=>0]);
$is_list = [self::IS_LIST,self::IS_DETAIL];
foreach($customList as $value){
foreach ($is_list as $isValue){
$info = $this->model->read(['source'=>$value['id'],'is_list'=>$isValue,'is_custom'=>BTemplate::IS_CUSTOM],['id','name','source','is_list','is_custom','header_status','footer_status']);
if($info !== false){
$data[] = $info;
}else{
$data[] = [
'name'=>$value['name'].($isValue == self::IS_DETAIL ? '详情' : '列表'),
'source'=>$value['id'],
'is_list'=>$isValue,
'is_custom'=>self::IS_CUSTOM,
'header_status'=>self::PUB_STATUS,
'footer_status'=>self::PUB_STATUS,
];
}
}
}
return $this->success($data);
}
/**
* @remark :保存配置
* @name :saveComConfig
* @author :lyh
* @method :post
* @time :2024/8/1 15:41
*/
public function saveComConfig(){
$data = $this->param['data'];
foreach ($data as $k => $v){
if(isset($v['id']) && !empty($v['id'])){
$id = $v['id'];
unset($v['id']);
$this->model->edit($v,['id'=>$id]);
}else{
//查询当前数据是否存在
$this->model->add($v);
}
}
return $this->success();
}
}