|
@@ -46,41 +46,15 @@ class BlogCategoryLogic extends BaseLogic |
|
@@ -46,41 +46,15 @@ class BlogCategoryLogic extends BaseLogic |
|
46
|
* @method
|
46
|
* @method
|
|
47
|
*/
|
47
|
*/
|
|
48
|
public function add_blog_category(){
|
48
|
public function add_blog_category(){
|
|
49
|
- $condition = [
|
|
|
|
50
|
- 'name'=>$this->param['name']
|
|
|
|
51
|
- ];
|
|
|
|
52
|
- $info = $this->model->read($condition);
|
|
|
|
53
|
- if($info !== false){
|
|
|
|
54
|
- $this->fail('当前分类名称已存在');
|
|
|
|
55
|
- }
|
|
|
|
56
|
- $this->param['project_id'] = $this->user['project_id'];
|
|
|
|
57
|
- $this->param['operator_id'] = $this->user['id'];
|
|
|
|
58
|
- $this->param['create_id'] = $this->user['id'];
|
|
|
|
59
|
- $this->param['created_at'] = date('Y-m-d H:i:s');
|
|
|
|
60
|
- $this->param['updated_at'] = date('Y-m-d H:i:s');
|
49
|
+ //验证名称是否存在
|
|
|
|
50
|
+ $this->verifyParamName();
|
|
|
|
51
|
+ //拼接参数
|
|
|
|
52
|
+ $this->param = $this->addParamProcessing($this->param);
|
|
61
|
DB::beginTransaction();
|
53
|
DB::beginTransaction();
|
|
62
|
try {
|
54
|
try {
|
|
63
|
$cate_id = $this->model->insertGetId($this->param);
|
55
|
$cate_id = $this->model->insertGetId($this->param);
|
|
64
|
- if(!isset($this->param['pid'])){
|
|
|
|
65
|
- $this->param['pid'] = 0;
|
|
|
|
66
|
- }
|
|
|
|
67
|
- //判断为子分类时
|
|
|
|
68
|
- if($this->param['pid'] != 0){
|
|
|
|
69
|
- //查看当前上级分类下是否有其他子分类
|
|
|
|
70
|
- $cate_info = $this->model->read(['pid' => $this->param['pid'], 'id' => ['!=', $cate_id]]);
|
|
|
|
71
|
- if ($cate_info === false) {
|
|
|
|
72
|
- //查看当前上一级分类下是否有新闻
|
|
|
|
73
|
- $blogModel = new BlogModel();
|
|
|
|
74
|
- $blog_count = $blogModel->where('category_id','like', '%,' . $this->param['pid'] . ',%')->count();
|
|
|
|
75
|
- if ($blog_count > 0) {
|
|
|
|
76
|
- $replacement = ','. $this->param['pid'] . ',' . $cate_id . ',';
|
|
|
|
77
|
- $old = ',' . $this->param['pid'] . ',';
|
|
|
|
78
|
- //更新所有商品到当前分类
|
|
|
|
79
|
- DB::table('gl_Blog')->where('category_id', 'like', '%' . $old . '%')
|
|
|
|
80
|
- ->update(['category_id' => DB::raw("REPLACE(category_id, '$old', '$replacement')")]);
|
|
|
|
81
|
- }
|
|
|
|
82
|
- }
|
|
|
|
83
|
- }
|
56
|
+ //处理子集
|
|
|
|
57
|
+ $this->addProcessingSon($cate_id);
|
|
84
|
RouteMap::setRoute($this->param['alias'] ?: $this->param['name'], RouteMap::SOURCE_BLOG_CATE, $cate_id, $this->user['project_id']);
|
58
|
RouteMap::setRoute($this->param['alias'] ?: $this->param['name'], RouteMap::SOURCE_BLOG_CATE, $cate_id, $this->user['project_id']);
|
|
85
|
DB::commit();
|
59
|
DB::commit();
|
|
86
|
}catch (\Exception $e){
|
60
|
}catch (\Exception $e){
|
|
@@ -97,15 +71,8 @@ class BlogCategoryLogic extends BaseLogic |
|
@@ -97,15 +71,8 @@ class BlogCategoryLogic extends BaseLogic |
|
97
|
* @method
|
71
|
* @method
|
|
98
|
*/
|
72
|
*/
|
|
99
|
public function edit_blog_category(){
|
73
|
public function edit_blog_category(){
|
|
100
|
- $condition = [
|
|
|
|
101
|
- 'id'=>['!=',$this->param['id']],
|
|
|
|
102
|
- 'name'=>$this->param['name']
|
|
|
|
103
|
- ];
|
|
|
|
104
|
- //查看当前分类名称是否存在
|
|
|
|
105
|
- $info = $this->model->read($condition);
|
|
|
|
106
|
- if($info !== false){
|
|
|
|
107
|
- $this->fail('当前分类名称已存在');
|
|
|
|
108
|
- }
|
74
|
+ //验证名称是否存在
|
|
|
|
75
|
+ $this->verifyParamName();
|
|
109
|
$info = $this->model->read(['id'=>$this->param['id']]);
|
76
|
$info = $this->model->read(['id'=>$this->param['id']]);
|
|
110
|
if($info['id'] == $this->param['pid']){
|
77
|
if($info['id'] == $this->param['pid']){
|
|
111
|
$this->fail('不能成为自己的上级');
|
78
|
$this->fail('不能成为自己的上级');
|
|
@@ -167,7 +134,7 @@ class BlogCategoryLogic extends BaseLogic |
|
@@ -167,7 +134,7 @@ class BlogCategoryLogic extends BaseLogic |
|
167
|
$blogModel = new BlogModel();
|
134
|
$blogModel = new BlogModel();
|
|
168
|
$rs = $blogModel->read(['category_id'=>$v],['id']);
|
135
|
$rs = $blogModel->read(['category_id'=>$v],['id']);
|
|
169
|
if($rs !== false){
|
136
|
if($rs !== false){
|
|
170
|
- $this->response('当前分类拥有博客');
|
137
|
+ $this->response('当前分类拥有博客,不允许删除');
|
|
171
|
}
|
138
|
}
|
|
172
|
RouteMap::delRoute(RouteMap::SOURCE_BLOG_CATE, $v, $this->user['project_id']);
|
139
|
RouteMap::delRoute(RouteMap::SOURCE_BLOG_CATE, $v, $this->user['project_id']);
|
|
173
|
}
|
140
|
}
|
|
@@ -191,4 +158,74 @@ class BlogCategoryLogic extends BaseLogic |
|
@@ -191,4 +158,74 @@ class BlogCategoryLogic extends BaseLogic |
|
191
|
$list = $this->model->list($map);
|
158
|
$list = $this->model->list($map);
|
|
192
|
return $this->success($list);
|
159
|
return $this->success($list);
|
|
193
|
}
|
160
|
}
|
|
|
|
161
|
+
|
|
|
|
162
|
+ /**
|
|
|
|
163
|
+ * @name :(参数处理)paramProcessing
|
|
|
|
164
|
+ * @author :lyh
|
|
|
|
165
|
+ * @method :post
|
|
|
|
166
|
+ * @time :2023/6/13 11:30
|
|
|
|
167
|
+ */
|
|
|
|
168
|
+ public function addParamProcessing($param){
|
|
|
|
169
|
+ $param['project_id'] = $this->user['project_id'];
|
|
|
|
170
|
+ $param['operator_id'] = $this->user['id'];
|
|
|
|
171
|
+ $param['create_id'] = $this->user['id'];
|
|
|
|
172
|
+ $param['created_at'] = date('Y-m-d H:i:s');
|
|
|
|
173
|
+ $param['updated_at'] = date('Y-m-d H:i:s');
|
|
|
|
174
|
+ return $this->success($param);
|
|
|
|
175
|
+ }
|
|
|
|
176
|
+
|
|
|
|
177
|
+ /**
|
|
|
|
178
|
+ * @name :(验证名称是否存在)verifyParamName
|
|
|
|
179
|
+ * @author :lyh
|
|
|
|
180
|
+ * @method :post
|
|
|
|
181
|
+ * @time :2023/6/13 11:41
|
|
|
|
182
|
+ */
|
|
|
|
183
|
+ public function verifyParamName(){
|
|
|
|
184
|
+ if(isset($this->param['id'])){
|
|
|
|
185
|
+ $condition = [
|
|
|
|
186
|
+ 'id'=>['!=',$this->param['id']],
|
|
|
|
187
|
+ 'name'=>$this->param['name'],
|
|
|
|
188
|
+ ];
|
|
|
|
189
|
+ }else{
|
|
|
|
190
|
+ $condition = [
|
|
|
|
191
|
+ 'name'=>$this->param['name']
|
|
|
|
192
|
+ ];
|
|
|
|
193
|
+ }
|
|
|
|
194
|
+ $info = $this->model->read($condition);
|
|
|
|
195
|
+ if($info !== false){
|
|
|
|
196
|
+ $this->fail('当前分类名称已存在');
|
|
|
|
197
|
+ }
|
|
|
|
198
|
+ return $this->success();
|
|
|
|
199
|
+ }
|
|
|
|
200
|
+
|
|
|
|
201
|
+ /**
|
|
|
|
202
|
+ * @param $cate_id
|
|
|
|
203
|
+ * @name :(处理子集)addProcessingSon
|
|
|
|
204
|
+ * @author :lyh
|
|
|
|
205
|
+ * @method :post
|
|
|
|
206
|
+ * @time :2023/6/13 11:59
|
|
|
|
207
|
+ */
|
|
|
|
208
|
+ public function addProcessingSon($cate_id){
|
|
|
|
209
|
+ if(!isset($this->param['pid'])){
|
|
|
|
210
|
+ $this->param['pid'] = 0;
|
|
|
|
211
|
+ }
|
|
|
|
212
|
+ //判断为子分类时
|
|
|
|
213
|
+ if($this->param['pid'] != 0){
|
|
|
|
214
|
+ //查看当前上级分类下是否有其他子分类
|
|
|
|
215
|
+ $cate_info = $this->model->read(['pid' => $this->param['pid'], 'id' => ['!=', $cate_id]]);
|
|
|
|
216
|
+ if ($cate_info === false) {
|
|
|
|
217
|
+ //查看当前上一级分类下是否有新闻
|
|
|
|
218
|
+ $blogModel = new BlogModel();
|
|
|
|
219
|
+ $blog_count = $blogModel->where('category_id','like', '%,' . $this->param['pid'] . ',%')->count();
|
|
|
|
220
|
+ if ($blog_count > 0) {
|
|
|
|
221
|
+ $replacement = ','. $this->param['pid'] . ',' . $cate_id . ',';
|
|
|
|
222
|
+ $old = ',' . $this->param['pid'] . ',';
|
|
|
|
223
|
+ //更新所有商品到当前分类
|
|
|
|
224
|
+ DB::table('gl_Blog')->where('category_id', 'like', '%' . $old . '%')
|
|
|
|
225
|
+ ->update(['category_id' => DB::raw("REPLACE(category_id, '$old', '$replacement')")]);
|
|
|
|
226
|
+ }
|
|
|
|
227
|
+ }
|
|
|
|
228
|
+ }
|
|
|
|
229
|
+ return $this->success();
|
|
|
|
230
|
+ }
|
|
194
|
} |
231
|
} |