|
@@ -99,8 +99,6 @@ class CategoryLogic extends BaseLogic |
|
@@ -99,8 +99,6 @@ class CategoryLogic extends BaseLogic |
|
99
|
$info = $this->model->read(['id'=>$id]);
|
99
|
$info = $this->model->read(['id'=>$id]);
|
|
100
|
$info['url'] = $info['route'];
|
100
|
$info['url'] = $info['route'];
|
|
101
|
$info['image_link'] = getImageUrl($info['image']);
|
101
|
$info['image_link'] = getImageUrl($info['image']);
|
|
102
|
- //获取当前分类子集
|
|
|
|
103
|
- $info['sub'] = $this->model->read(['pid'=>$info['id']]);
|
|
|
|
104
|
return $this->success($info);
|
102
|
return $this->success($info);
|
|
105
|
}
|
103
|
}
|
|
106
|
|
104
|
|
|
@@ -112,18 +110,18 @@ class CategoryLogic extends BaseLogic |
|
@@ -112,18 +110,18 @@ class CategoryLogic extends BaseLogic |
|
112
|
* @time :2023/8/21 17:14
|
110
|
* @time :2023/8/21 17:14
|
|
113
|
*/
|
111
|
*/
|
|
114
|
public function categorySave(){
|
112
|
public function categorySave(){
|
|
115
|
- if(isset($this->param['id']) && !empty($this->param['id'])) {
|
|
|
|
116
|
- $this->handleEditParam($this->param);
|
|
|
|
117
|
- }
|
|
|
|
118
|
DB::beginTransaction();
|
113
|
DB::beginTransaction();
|
|
119
|
try {
|
114
|
try {
|
|
120
|
if(isset($this->param['id']) && !empty($this->param['id'])){
|
115
|
if(isset($this->param['id']) && !empty($this->param['id'])){
|
|
121
|
//是否编辑路由
|
116
|
//是否编辑路由
|
|
122
|
$id = $this->editCategoryRoute($this->param['id'],$this->param['route']);
|
117
|
$id = $this->editCategoryRoute($this->param['id'],$this->param['route']);
|
|
|
|
118
|
+ $this->editHandleCategory($this->param['id'],$this->param['pid']);
|
|
123
|
$this->model->edit($this->param,['id'=>$this->param['id']]);
|
119
|
$this->model->edit($this->param,['id'=>$this->param['id']]);
|
|
124
|
}else{
|
120
|
}else{
|
|
125
|
$this->param['project_id'] = $this->user['project_id'];
|
121
|
$this->param['project_id'] = $this->user['project_id'];
|
|
126
|
$id = $this->model->addReturnId($this->param);
|
122
|
$id = $this->model->addReturnId($this->param);
|
|
|
|
123
|
+ //处理子集
|
|
|
|
124
|
+ $this->addProcessingSon($id);
|
|
127
|
}
|
125
|
}
|
|
128
|
//路由映射
|
126
|
//路由映射
|
|
129
|
$route = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_PRODUCT_CATE, $id, $this->user['project_id']);
|
127
|
$route = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_PRODUCT_CATE, $id, $this->user['project_id']);
|
|
@@ -142,6 +140,63 @@ class CategoryLogic extends BaseLogic |
|
@@ -142,6 +140,63 @@ class CategoryLogic extends BaseLogic |
|
142
|
}
|
140
|
}
|
|
143
|
|
141
|
|
|
144
|
/**
|
142
|
/**
|
|
|
|
143
|
+ * @param $cate_id
|
|
|
|
144
|
+ * @name :(处理子集)addProcessingSon
|
|
|
|
145
|
+ * @author :lyh
|
|
|
|
146
|
+ * @method :post
|
|
|
|
147
|
+ * @time :2023/6/13 11:59
|
|
|
|
148
|
+ */
|
|
|
|
149
|
+ public function addProcessingSon($cate_id){
|
|
|
|
150
|
+ if(!isset($this->param['pid'])){
|
|
|
|
151
|
+ $this->param['pid'] = 0;
|
|
|
|
152
|
+ }
|
|
|
|
153
|
+ //判断为子分类时
|
|
|
|
154
|
+ if($this->param['pid'] != 0){
|
|
|
|
155
|
+ //查看当前上级分类下是否有其他子分类
|
|
|
|
156
|
+ $cate_info = $this->model->read(['pid' => $this->param['pid'], 'id' => ['!=', $cate_id]]);
|
|
|
|
157
|
+ if ($cate_info === false) {
|
|
|
|
158
|
+ //查看当前上一级分类下是否有新闻
|
|
|
|
159
|
+ $productModel = new Product();
|
|
|
|
160
|
+ $blog_count = $productModel->where('category_id','like', '%,' . $this->param['pid'] . ',%')->count();
|
|
|
|
161
|
+ if ($blog_count > 0) {
|
|
|
|
162
|
+ $replacement = ',' . $cate_id . ',';
|
|
|
|
163
|
+ $old = ',' . $this->param['pid'] . ',';
|
|
|
|
164
|
+ //更新所有商品到当前分类
|
|
|
|
165
|
+ $productModel->where('category_id', 'like', '%' . $old . '%')
|
|
|
|
166
|
+ ->update(['category_id' => DB::raw("REPLACE(category_id, '$old', '$replacement')")]);
|
|
|
|
167
|
+ }
|
|
|
|
168
|
+ }
|
|
|
|
169
|
+ }
|
|
|
|
170
|
+ return $this->success();
|
|
|
|
171
|
+ }
|
|
|
|
172
|
+
|
|
|
|
173
|
+ /**
|
|
|
|
174
|
+ * @remark :编辑分类,处理博客数据
|
|
|
|
175
|
+ * @name :editCategory
|
|
|
|
176
|
+ * @author :lyh
|
|
|
|
177
|
+ * @method :post
|
|
|
|
178
|
+ * @time :2023/10/20 9:32
|
|
|
|
179
|
+ */
|
|
|
|
180
|
+ public function editHandleCategory($id,$pid){
|
|
|
|
181
|
+ $info = $this->model->read(['id'=>$id],['id','pid']);
|
|
|
|
182
|
+ if($info['pid'] != $pid){
|
|
|
|
183
|
+ //修改勒上级,先查看上级是否拥有博客
|
|
|
|
184
|
+ $productModel = new Product();
|
|
|
|
185
|
+ $blogCount = $productModel->formatQuery(['category_id'=>['like','%,'.$pid.',%']])->count();
|
|
|
|
186
|
+ if($blogCount > 0){
|
|
|
|
187
|
+ //随机获取最后一级id
|
|
|
|
188
|
+ $replacement = $this->getLastId($id);
|
|
|
|
189
|
+ //存在博客时,移动所有博客到当前分类最后一级
|
|
|
|
190
|
+ $productModel->where('category_id', 'like', '%,' . $pid . ',%')->where('category_id', 'like', '%,' . $replacement . ',%')
|
|
|
|
191
|
+ ->update(['category_id' => DB::raw("REPLACE(category_id, ',$pid,', ',')")]);
|
|
|
|
192
|
+ $productModel->where('category_id', 'like', '%,' . $pid . ',%')
|
|
|
|
193
|
+ ->update(['category_id' => DB::raw("REPLACE(category_id, ',$pid,', ',$replacement,')")]);
|
|
|
|
194
|
+ }
|
|
|
|
195
|
+ }
|
|
|
|
196
|
+ return $this->success();
|
|
|
|
197
|
+ }
|
|
|
|
198
|
+
|
|
|
|
199
|
+ /**
|
|
145
|
* @remark :编辑路由时生成路由记录
|
200
|
* @remark :编辑路由时生成路由记录
|
|
146
|
* @name :editCategoryRoute
|
201
|
* @name :editCategoryRoute
|
|
147
|
* @author :lyh
|
202
|
* @author :lyh
|
|
@@ -162,27 +217,6 @@ class CategoryLogic extends BaseLogic |
|
@@ -162,27 +217,6 @@ class CategoryLogic extends BaseLogic |
|
162
|
}
|
217
|
}
|
|
163
|
|
218
|
|
|
164
|
/**
|
219
|
/**
|
|
165
|
- * @remark :验证编辑时是否可修改pid
|
|
|
|
166
|
- * @name :handleEditParam
|
|
|
|
167
|
- * @author :lyh
|
|
|
|
168
|
- * @method :post
|
|
|
|
169
|
- * @time :2023/8/21 17:43
|
|
|
|
170
|
- */
|
|
|
|
171
|
- public function handleEditParam(&$param){
|
|
|
|
172
|
- $category_ids = Category::getChildIdsArr($param['id'] ?? 0);
|
|
|
|
173
|
- if(in_array($param['pid'], $category_ids)){
|
|
|
|
174
|
- $this->fail('上级分类不能是本分类或子分类');
|
|
|
|
175
|
- }
|
|
|
|
176
|
- $productModel = new Product();
|
|
|
|
177
|
- $rs = $productModel->read(['category_id'=>['like','%,'.$param['id'].',%']],['id']);
|
|
|
|
178
|
- if($rs !== false){
|
|
|
|
179
|
- $this->fail('当前分类拥有产品,不允许修改级别');
|
|
|
|
180
|
- }
|
|
|
|
181
|
- return $this->success();
|
|
|
|
182
|
- }
|
|
|
|
183
|
-
|
|
|
|
184
|
-
|
|
|
|
185
|
- /**
|
|
|
|
186
|
* @remark :删除
|
220
|
* @remark :删除
|
|
187
|
* @name :delete
|
221
|
* @name :delete
|
|
188
|
* @author :lyh
|
222
|
* @author :lyh
|