ATemplateLogic.php
5.9 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
<?php
namespace App\Http\Logic\Aside\Template;
use App\Http\Logic\Aside\BaseLogic;
use App\Models\Service\Service as ServiceSettingModel;
use App\Models\Template\Template;
use App\Models\Template\BSetting;
use Illuminate\Support\Facades\DB;
use mysql_xdevapi\Exception;
class ATemplateLogic extends BaseLogic
{
public function __construct()
{
parent::__construct();
$this->model = new Template();
$this->param = $this->requestAll;
}
/**
* @remark :公共模块模板
* @name :aTemplateList
* @author :lyh
* @method :post
* @time :2023/6/28 17:03
*/
public function aTemplateList($map,$page,$row,$order = ['created_at'],$filed = ['id','name','url','status','deleted_status','sort','image']){
$map['deleted_status'] = 0;
$map['status'] = 0;
$lists = $this->model->lists($map,$page,$row,$order,$filed);
return $this->success($lists);
}
/**
* @remark :添加或编辑模块
* @name :aTemplateSave
* @author :lyh
* @method :post
* @time :2023/6/28 17:13
*/
public function aTemplateSave(){
//字符串截取
$this->StringProcessing();
if(isset($this->param['id'])){
$rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
}else{
$rs = $this->model->add($this->param);
}
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['main_html'] = characterTruncation($this->param['html'],'/<main\b[^>]*>(.*?)<\/main>/s');
$this->param['footer_html'] = characterTruncation($this->param['html'],'/<footer\b[^>]*>(.*?)<\/footer>/s');
$this->param['head_css'] = characterTruncation($this->param['html'],'/<style id="globalsojs-header">(.*?)<\/style>/s');
$this->param['main_css'] = characterTruncation($this->param['html'],'/<style id="globalsojs-styles">(.*?)<\/style>/s');
$this->param['footer_css'] = characterTruncation($this->param['html'],'/<style id="globalsojs-footer">(.*?)<\/style>/s');
}
/**
* @remark :修改模块状态
* @name :aTemplateStatus
* @author :lyh
* @method :post
* @time :2023/6/28 17:15
*/
public function aTemplateStatus(){
$rs = $this->model->edit(['status'=>$this->param['status']],['id'=>$this->param['id']]);
if($rs === false){
$this->fail('error');
}
return $this->success();
}
/**
* @remark :逻辑删除模板数据
* @name :aTemplateDel
* @author :lyh
* @method :post
* @time :2023/6/28 17:17
*/
public function aTemplateDel(){
//查看当前模板是否有模板在使用
$BSettingModel = new BSetting();
$info = $BSettingModel->read(['template_id'=>$this->param['id']]);
if($info !== false){
$this->fail('当前模板有项目在使用,不允许删除');
}
$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 :获取数据详情
* @name :aTemplateRead
* @author :lyh
* @method :post
* @time :2023/7/3 9:22
*/
public function aTemplateRead(){
$info = $this->model->read($this->param);
if($info === false){
$this->fail('当前数据不存在或已被删除');
}
if(!empty($info['image'])){
$info['image_link'] = getImageUrl($info['image']);
}
return $this->success($info);
}
/**
* @remark :设置主题公共head
* @name :setHeadInfo
* @author :lyh
* @method :post
* @time :2023/7/10 15:32
*/
public function setHeadFooterSave(){
$serviceSettingModel = new ServiceSettingModel();
DB::beginTransaction();
try {
$serviceSettingModel->del(['type'=>2]);
$data = [
['type'=>2,'key'=>'head','values'=>$this->param['head'],'created_at'=>date('Y-m-d H:i:s'),'updated_at'=>date('Y-m-d H:i:s')],
['type'=>2,'key'=>'footer','values'=>$this->param['footer'],'created_at'=>date('Y-m-d H:i:s'),'updated_at'=>date('Y-m-d H:i:s')]
];
$serviceSettingModel->insert($data);
DB::commit();
}catch (Exception $e){
DB::rollBack();
$this->fail('error');
}
}
/**
* @remark :获取主题公共head
* @name :getHeadInfo
* @author :lyh
* @method :post
* @time :2023/7/10 15:33
*/
public function getHeadFooterList(){
$serviceSettingModel = new ServiceSettingModel();
$list = $serviceSettingModel->list(['type'=>2],'created_at');
return $this->success($list);
}
/**
* @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->param['project_id']]);
if($info === false){
$param = [
'project_id'=>$this->param['project_id'],
'template_id'=>$this->param['template_id'],
];
$rs = $bSettingModel->add($param);
}else{
$rs = $bSettingModel->edit(['template_id'=>$this->param['template_id']],['id'=>$info['id']]);
}
if($rs === false){
$this->fail('error');
}
return $this->success();
}
}