BTemplateLogic.php
7.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
<?php
namespace App\Http\Logic\Bside\BTemplate;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\Blog\BlogCategory;
use App\Models\News\NewsCategory;
use App\Models\Product\Category;
use App\Models\Product\Product;
use App\Models\Template\ModuleSetting;
use App\Models\Template\Template;
use App\Models\Template\BSetting;
use App\Models\Template\BTemplate;
/**
* @remark :b端模块
* @name :BTemplateLogic
* @author :lyh
* @time :2023/6/28 17:00
*/
class BTemplateLogic extends BaseLogic
{
public function __construct()
{
parent::__construct();
$this->model = new BTemplate();
$this->param = $this->requestAll;
}
/**
* @remark :获取所有公共模板
* @name :publicTemplateLists
* @author :lyh
* @method :post
* @time :2023/6/29 9:34
*/
public function publicTemplateLists($map,$page,$row,$order = 'created_at',$filed = ['id','name','image','url','created_at','status','deleted_status']){
$templateModel = new Template();
$map['deleted_status'] = 0;
$map['status'] = 0;
$lists = $templateModel->lists($map,$page,$row,$order,$filed);
return $this->success($lists);
}
/**
* @remark :获取当前选择使用的模板
* @name :getModuleTemplate
* @author :lyh
* @method :post
* @time :2023/6/29 9:44
*/
public function getTemplate(){
$bSettingModel = new BSetting();
$info = $bSettingModel->read(['project_id'=>$this->user['project_id']]);
$TemplateInfo = [];
if($info !== false){
//查看当前模板是否已编辑保存web_template
$TemplateInfo = $this->model->read([
'template_id'=>$info['template_id'],
'source'=>!isset($this->param['source']) ? 1 : $this->param['source'],
'project_id'=>$this->user['project_id'],
'source_id'=>!isset($this->param['source_id']) ? 0 : $this->param['source_id'],
]);
if($TemplateInfo === false){
//获取模板详情
$ATemplateModel = new Template();
$TemplateInfo = $ATemplateModel->read(['id'=>$info['template_id']]);
}
}
return $this->success($TemplateInfo);
}
/**
* @remark :设置模板
* @name :setTemplate
* @author :lyh
* @method :post
* @time :2023/6/29 9:47
*/
public function setTemplate(){
$bSettingModel = new BSetting();
$info = $bSettingModel->read(['project_id'=>$this->user['project_id']]);
if($info === false){
$param = [
'project_id'=>$this->user['project_id'],
'template_id'=>$this->param['template_id'],
];
$rs = $bSettingModel->add($param);
}else{
$rs = $bSettingModel->edit(['template_id'=>$this->param['template_id']],['project_id'=>$this->user['project_id']]);
}
if($rs === false){
$this->fail('error');
}
return $this->success();
}
/**
* @remark :保存修改后的模版
* @name :templateSave
* @author :lyh
* @method :post
* @time :2023/6/29 11:05
*/
public function templateSave(){
//查询当前模版是否已保存
$info = $this->model->read(
[
'project_id'=>$this->user['project_id'],
'source'=>$this->param['source'] ?? 1,
'source_id'=>$this->param['source_id'] ?? 0,
'template_id'=>$this->param['template_id'],
]
);
if($info === false){
//字符串截取
$this->StringProcessing();
$this->param['project_id'] = $this->user['project_id'];
//获取模板详情
$ATemplateModel = new Template();
$TemplateInfo = $ATemplateModel->read(['id'=>$this->param['template_id']]);
//同步数据
$this->param['name'] = $TemplateInfo['name'];
$this->param['image'] = $TemplateInfo['image'];
$rs = $this->model->add($this->param);
}else{
$this->StringProcessing();
$rs = $this->model->edit($this->param,['id'=>$info['id']]);
}
if($rs === false){
$this->fail('error');
}
return $this->success();
}
/**
* @remark :字符串处理
* @name :StringProcessing
* @author :lyh
* @method :post
* @time :2023/6/29 15:35
*/
public function StringProcessing(){
//字符串截取
$this->param['head_html'] = characterTruncation($this->param['html'],'/<header\b[^>]*>(.*?)<\/header>/s');
$this->param['footer_html'] = characterTruncation($this->param['html'],'/<footer\b[^>]*>(.*?)<\/footer>/s');
$this->param['head_css'] = characterTruncation($this->param['html'],'/<style id="vvvebjs-header">(.*?)<\/style>/s');
$this->param['footer_css'] = characterTruncation($this->param['html'],'/<style id="vvvebjs-footer">(.*?)<\/style>/s');
}
/**
* @remark :获取类型
* @name :getModuleType
* @author :lyh
* @method :any
* @time :2023/7/17 16:03
*/
public function getModuleType(): array
{
//定义数据结构
$data = [
"products"=>[
"category"=>[
[
"id"=>"hot",
"title"=>"热销产品",
],
[
"id"=>"recommend",
"title"=>"推荐产品",
],
],
"imageType"=>[
[
"id"=>1,
"title"=>"产品图片",
],[
"id"=>2,
"title"=>"产品分类图片",
],[
"id"=>3,
"title"=>"产品图标",
]
],
],
"news"=>[
"category"=>[
[
"id"=>"new",
"name"=>"最新",
],
],
],
"blogs"=>[
"category"=>[
[
"id"=>"new",
"name"=>"最新",
],
],
],
"productCategory"=>[
"category"=>[
[
"id"=>1,
"title"=>"分类1",
],
[
"id"=>2,
"title"=>"分类2",
],
[
"id"=>3,
"title"=>"分类3",
],
],
]
];
//产品,新闻,博客,一级分类数据
$productCategory = Category::where("pid",0)->get();
$newCategory = NewsCategory::where("pid",0)->get();
$blogCategory = BlogCategory::where("pid",0)->get();
if (!empty($productCategory)){
foreach ($productCategory as $item){
$data["products"]["category"][] =$item;
}
}
if (!empty($newCategory)){
foreach ($newCategory as $item){
$data["news"]["category"][] =$item;
}
}
if (!empty($blogCategory)){
foreach ($blogCategory as $item){
$data["blogs"]["category"][] =$item;
}
}
//返回
return $this->success($data);
}
}