|
@@ -28,17 +28,11 @@ class BlogCategoryLogic extends BaseLogic |
|
@@ -28,17 +28,11 @@ class BlogCategoryLogic extends BaseLogic |
|
28
|
public function categorySave(){
|
28
|
public function categorySave(){
|
|
29
|
//验证名称是否存在
|
29
|
//验证名称是否存在
|
|
30
|
$this->verifyParamName($this->param['name']);
|
30
|
$this->verifyParamName($this->param['name']);
|
|
31
|
- if(isset($this->param['id']) && !empty($this->param['id'])) {
|
|
|
|
32
|
- //验证参数是否可编辑
|
|
|
|
33
|
- $this->verifyParamEdit($this->param['id'], $this->param['pid']);
|
|
|
|
34
|
- }
|
|
|
|
35
|
DB::beginTransaction();
|
31
|
DB::beginTransaction();
|
|
36
|
try {
|
32
|
try {
|
|
37
|
if(isset($this->param['id']) && !empty($this->param['id'])){
|
33
|
if(isset($this->param['id']) && !empty($this->param['id'])){
|
|
38
|
//查看路由是否更新
|
34
|
//查看路由是否更新
|
|
39
|
- $id = $this->editCategoryRoute($this->param['id'],
|
|
|
|
40
|
- isset($this->param['alias']) ?? RouteMap::setRoute(isset($this->param['alias']) ? $this->param['alias'] : $this->param['name'],
|
|
|
|
41
|
- RouteMap::SOURCE_BLOG_CATE, $this->param['id'], $this->user['project_id']));
|
35
|
+ $id = $this->editCategoryRoute($this->param['id'], $this->param['alias']);
|
|
42
|
$this->param['operator_id'] = $this->user['id'];
|
36
|
$this->param['operator_id'] = $this->user['id'];
|
|
43
|
$this->edit($this->param,['id'=>$this->param['id']]);
|
37
|
$this->edit($this->param,['id'=>$this->param['id']]);
|
|
44
|
}else{
|
38
|
}else{
|
|
@@ -62,6 +56,46 @@ class BlogCategoryLogic extends BaseLogic |
|
@@ -62,6 +56,46 @@ class BlogCategoryLogic extends BaseLogic |
|
62
|
}
|
56
|
}
|
|
63
|
|
57
|
|
|
64
|
/**
|
58
|
/**
|
|
|
|
59
|
+ * @remark :编辑分类,处理博客数据
|
|
|
|
60
|
+ * @name :editCategory
|
|
|
|
61
|
+ * @author :lyh
|
|
|
|
62
|
+ * @method :post
|
|
|
|
63
|
+ * @time :2023/10/20 9:32
|
|
|
|
64
|
+ */
|
|
|
|
65
|
+ public function editHandleCategory($id,$pid){
|
|
|
|
66
|
+ $info = $this->model->read(['id'=>$id],['id','pid']);
|
|
|
|
67
|
+ if($info['pid'] != $pid){
|
|
|
|
68
|
+ //修改勒上级,先查看上级是否拥有博客
|
|
|
|
69
|
+ $blogModel = new BlogModel();
|
|
|
|
70
|
+ $blogList = $blogModel->list(['category_id'=>['like','%,'.$pid.',%']],['id']);
|
|
|
|
71
|
+ //随机获取最后一级id
|
|
|
|
72
|
+ $replacement = $this->getLastId($id);
|
|
|
|
73
|
+ if(!empty($blogList)){
|
|
|
|
74
|
+ //存在博客时,移动所有博客到当前分类最后一级
|
|
|
|
75
|
+ $blogModel->where('category_id', 'like', '%,' . $pid . ',%')
|
|
|
|
76
|
+ ->update(['category_id' => DB::raw("REPLACE(category_id, '$pid', '$replacement')")]);
|
|
|
|
77
|
+ }
|
|
|
|
78
|
+ }
|
|
|
|
79
|
+ return $this->success();
|
|
|
|
80
|
+ }
|
|
|
|
81
|
+
|
|
|
|
82
|
+ /**
|
|
|
|
83
|
+ * @remark :随机获取当前id下最后一级的id
|
|
|
|
84
|
+ * @name :getLastId
|
|
|
|
85
|
+ * @author :lyh
|
|
|
|
86
|
+ * @method :post
|
|
|
|
87
|
+ * @time :2023/10/20 9:45
|
|
|
|
88
|
+ */
|
|
|
|
89
|
+ public function getLastId($id){
|
|
|
|
90
|
+ $info = $this->model->read(['pid'=>$id],['id']);
|
|
|
|
91
|
+ if($info !== false){
|
|
|
|
92
|
+ $this->getLastId($id);
|
|
|
|
93
|
+ }else{
|
|
|
|
94
|
+ return $id;
|
|
|
|
95
|
+ }
|
|
|
|
96
|
+ }
|
|
|
|
97
|
+
|
|
|
|
98
|
+ /**
|
|
65
|
* @remark :编辑路由时生成路由记录
|
99
|
* @remark :编辑路由时生成路由记录
|
|
66
|
* @name :editCategoryRoute
|
100
|
* @name :editCategoryRoute
|
|
67
|
* @author :lyh
|
101
|
* @author :lyh
|
|
@@ -106,6 +140,7 @@ class BlogCategoryLogic extends BaseLogic |
|
@@ -106,6 +140,7 @@ class BlogCategoryLogic extends BaseLogic |
|
106
|
return $this->success();
|
140
|
return $this->success();
|
|
107
|
}
|
141
|
}
|
|
108
|
|
142
|
|
|
|
|
143
|
+
|
|
109
|
/**
|
144
|
/**
|
|
110
|
* @name :详情
|
145
|
* @name :详情
|
|
111
|
* @return array
|
146
|
* @return array
|
|
@@ -271,7 +306,7 @@ class BlogCategoryLogic extends BaseLogic |
|
@@ -271,7 +306,7 @@ class BlogCategoryLogic extends BaseLogic |
|
271
|
$blogModel = new BlogModel();
|
306
|
$blogModel = new BlogModel();
|
|
272
|
$blog_count = $blogModel->where('category_id','like', '%,' . $this->param['pid'] . ',%')->count();
|
307
|
$blog_count = $blogModel->where('category_id','like', '%,' . $this->param['pid'] . ',%')->count();
|
|
273
|
if ($blog_count > 0) {
|
308
|
if ($blog_count > 0) {
|
|
274
|
- $replacement = ','. $this->param['pid'] . ',' . $cate_id . ',';
|
309
|
+ $replacement = ',' . $cate_id . ',';
|
|
275
|
$old = ',' . $this->param['pid'] . ',';
|
310
|
$old = ',' . $this->param['pid'] . ',';
|
|
276
|
//更新所有商品到当前分类
|
311
|
//更新所有商品到当前分类
|
|
277
|
$blogModel->where('category_id', 'like', '%' . $old . '%')
|
312
|
$blogModel->where('category_id', 'like', '%' . $old . '%')
|