CustomTemplateLogic.php
5.4 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
namespace App\Http\Logic\Bside\BTemplate;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\RouteMap;
use App\Models\Service\Service as ServiceSettingModel;
use App\Models\Template\BCustomTemplate;
use App\Models\Template\BSetting;
use App\Models\Template\BTemplate;
use App\Models\Template\Template;
class CustomTemplateLogic extends BaseLogic
{
public function __construct()
{
parent::__construct();
$this->model = new BCustomTemplate();
$this->param = $this->requestAll;
}
/**
* @remark :获取自定义模块列表
* @name :lists
* @author :lyh
* @method :post
* @time :2023/6/29 15:46
*/
public function customTemplateLists($map,$page,$row,$order = 'created_at',$filed = ['*']){
$map['deleted_status'] = 0;
$lists = $this->model->lists($map,$page,$row,$order,$filed);
return $this->success($lists);
}
/**
* @remark :获取当前自定义界面详情
* @name :customTemplateInfo
* @author :lyh
* @method :post
* @time :2023/6/29 16:23
*/
public function customTemplateInfo(){
$info = $this->model->read(['id'=>$this->param['id']]);
$html = $this->getBodyHeaderFooter($info['html'],$info['html_style']);
$info['html'] = $this->getHeadFooter($html);
if($info === false){
$this->fail('error');
}
return $this->success($info);
}
/**
* @remark :保存自定义界面
* @name :customTemplateSave
* @author :lyh
* @method :post
* @time :2023/6/29 16:21
*/
public function customTemplateSave(){
if(isset($this->param['id']) && !empty($this->param['id'])){
if(isset($this->param['html']) && !empty($this->param['html'])){
$html = $this->param['html'];
$this->param['html'] = characterTruncation($html,'/<main>(.*?)<\/main>/s');
$this->param['html_style'] = characterTruncation($html,'/<style id="globalsojs-styles">(.*?)<\/style>/s');
}
$rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
}else{
$this->param['project_id'] = $this->user['project_id'];
$rs = $this->model->add($this->param);
}
if($rs === false){
$this->fail('error');
}
//TODO::通知网站更新
$data = [
'project_id'=>$this->user['project_id'],
'type'=>RouteMap::SOURCE_PAGE,
'route'=>$this->param['url'],
];
updateNotify($this->user['domain'],$data);
return $this->success();
}
/**
* @remark :删除自定义界面
* @name :customTemplateDel
* @author :lyh
* @method :post
* @time :2023/6/29 16:21
*/
public function customTemplateDel(){
$rs = $this->model->edit(['deleted_status'=>1,'deleted_at'=>date('Y-m-d H:i:s')],['id'=>$this->param['id']]);
if($rs === false){
$this->fail('error');
}
return $this->success();
}
/**
* @remark :获取body的详情
* @name :getBodyHeaderFooter
* @author :lyh
* @method :post
* @time :2023/7/21 18:08
*/
public function getBodyHeaderFooter($preg_html,$html_style){
//获取设置的默认模版
$bSettingModel = new BSetting();
$info = $bSettingModel->read(['project_id'=>$this->user['project_id']]);
//获取模板详情
$bTemplateModel = new BTemplate();
$TemplateInfo = $bTemplateModel->read([
'template_id'=>$info['template_id'],
'project_id'=>$this->user['project_id'],
'source'=>1//首页
]);
if(empty($preg_html)){
$preg_html = "<main></main>";
$html = preg_replace('/<style id="globalsojs-styles">(.*?)<\/style>/s', "<style id='globalsojs-styles'></style>", $TemplateInfo['html']);
}else{
$html = preg_replace('/<style id="globalsojs-styles">(.*?)<\/style>/s',$html_style , $TemplateInfo['html']);
}
//内容
$html = preg_replace('/<main\b[^>]*>(.*?)<\/main>/s', $preg_html, $html);
return $html;
}
/**
* @remark :拼接获取公共头部底部
* @name :getHeadFooter
* @author :lyh
* @method :post
* @time :2023/7/21 17:22
*/
public function getHeadFooter($html = ''){
//获取公共主题头部底部
$serviceSettingModel = new ServiceSettingModel();
$list = $serviceSettingModel->list(['type'=>2],'created_at');
//拼接html
foreach ($list as $v){
if($v['key'] == 'head'){
$html = $v['values'].$html;
}
if($v['key'] == 'footer'){
$html = $html.$v['values'];
}
}
return $html;
}
/**
* @remark :根据状态获取数量
* @name :getStatusNumber
* @author :lyh
* @method :post
* @time :2023/7/29 17:40
*/
public function getStatusNumber(){
//三种状态 0:草稿 1:发布 2:回收站
$data = ['dra'=>0,'pub'=>1,'del'=>2,'tal'=>3];
foreach ($data as $k => $v){
if($v == 3){
$data[$k] = $this->model->where(['deleted_status'=>0])->count();
}else{
$data[$k] = $this->model->where(['status'=>$v,'deleted_status'=>0])->count();
}
}
return $this->success($data);
}
}