|
...
|
...
|
@@ -99,8 +99,6 @@ class CategoryLogic extends BaseLogic |
|
|
|
$info = $this->model->read(['id'=>$id]);
|
|
|
|
$info['url'] = $info['route'];
|
|
|
|
$info['image_link'] = getImageUrl($info['image']);
|
|
|
|
//获取当前分类子集
|
|
|
|
$info['sub'] = $this->model->read(['pid'=>$info['id']]);
|
|
|
|
return $this->success($info);
|
|
|
|
}
|
|
|
|
|
|
...
|
...
|
@@ -112,18 +110,18 @@ class CategoryLogic extends BaseLogic |
|
|
|
* @time :2023/8/21 17:14
|
|
|
|
*/
|
|
|
|
public function categorySave(){
|
|
|
|
if(isset($this->param['id']) && !empty($this->param['id'])) {
|
|
|
|
$this->handleEditParam($this->param);
|
|
|
|
}
|
|
|
|
DB::beginTransaction();
|
|
|
|
try {
|
|
|
|
if(isset($this->param['id']) && !empty($this->param['id'])){
|
|
|
|
//是否编辑路由
|
|
|
|
$id = $this->editCategoryRoute($this->param['id'],$this->param['route']);
|
|
|
|
$this->editHandleCategory($this->param['id'],$this->param['pid']);
|
|
|
|
$this->model->edit($this->param,['id'=>$this->param['id']]);
|
|
|
|
}else{
|
|
|
|
$this->param['project_id'] = $this->user['project_id'];
|
|
|
|
$id = $this->model->addReturnId($this->param);
|
|
|
|
//处理子集
|
|
|
|
$this->addProcessingSon($id);
|
|
|
|
}
|
|
|
|
//路由映射
|
|
|
|
$route = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_PRODUCT_CATE, $id, $this->user['project_id']);
|
|
...
|
...
|
@@ -142,6 +140,63 @@ class CategoryLogic extends BaseLogic |
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $cate_id
|
|
|
|
* @name :(处理子集)addProcessingSon
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/6/13 11:59
|
|
|
|
*/
|
|
|
|
public function addProcessingSon($cate_id){
|
|
|
|
if(!isset($this->param['pid'])){
|
|
|
|
$this->param['pid'] = 0;
|
|
|
|
}
|
|
|
|
//判断为子分类时
|
|
|
|
if($this->param['pid'] != 0){
|
|
|
|
//查看当前上级分类下是否有其他子分类
|
|
|
|
$cate_info = $this->model->read(['pid' => $this->param['pid'], 'id' => ['!=', $cate_id]]);
|
|
|
|
if ($cate_info === false) {
|
|
|
|
//查看当前上一级分类下是否有新闻
|
|
|
|
$productModel = new Product();
|
|
|
|
$blog_count = $productModel->where('category_id','like', '%,' . $this->param['pid'] . ',%')->count();
|
|
|
|
if ($blog_count > 0) {
|
|
|
|
$replacement = ',' . $cate_id . ',';
|
|
|
|
$old = ',' . $this->param['pid'] . ',';
|
|
|
|
//更新所有商品到当前分类
|
|
|
|
$productModel->where('category_id', 'like', '%' . $old . '%')
|
|
|
|
->update(['category_id' => DB::raw("REPLACE(category_id, '$old', '$replacement')")]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $this->success();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :编辑分类,处理博客数据
|
|
|
|
* @name :editCategory
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/10/20 9:32
|
|
|
|
*/
|
|
|
|
public function editHandleCategory($id,$pid){
|
|
|
|
$info = $this->model->read(['id'=>$id],['id','pid']);
|
|
|
|
if($info['pid'] != $pid){
|
|
|
|
//修改勒上级,先查看上级是否拥有博客
|
|
|
|
$productModel = new Product();
|
|
|
|
$blogCount = $productModel->formatQuery(['category_id'=>['like','%,'.$pid.',%']])->count();
|
|
|
|
if($blogCount > 0){
|
|
|
|
//随机获取最后一级id
|
|
|
|
$replacement = $this->getLastId($id);
|
|
|
|
//存在博客时,移动所有博客到当前分类最后一级
|
|
|
|
$productModel->where('category_id', 'like', '%,' . $pid . ',%')->where('category_id', 'like', '%,' . $replacement . ',%')
|
|
|
|
->update(['category_id' => DB::raw("REPLACE(category_id, ',$pid,', ',')")]);
|
|
|
|
$productModel->where('category_id', 'like', '%,' . $pid . ',%')
|
|
|
|
->update(['category_id' => DB::raw("REPLACE(category_id, ',$pid,', ',$replacement,')")]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $this->success();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :编辑路由时生成路由记录
|
|
|
|
* @name :editCategoryRoute
|
|
|
|
* @author :lyh
|
|
...
|
...
|
@@ -162,27 +217,6 @@ class CategoryLogic extends BaseLogic |
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :验证编辑时是否可修改pid
|
|
|
|
* @name :handleEditParam
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/8/21 17:43
|
|
|
|
*/
|
|
|
|
public function handleEditParam(&$param){
|
|
|
|
$category_ids = Category::getChildIdsArr($param['id'] ?? 0);
|
|
|
|
if(in_array($param['pid'], $category_ids)){
|
|
|
|
$this->fail('上级分类不能是本分类或子分类');
|
|
|
|
}
|
|
|
|
$productModel = new Product();
|
|
|
|
$rs = $productModel->read(['category_id'=>['like','%,'.$param['id'].',%']],['id']);
|
|
|
|
if($rs !== false){
|
|
|
|
$this->fail('当前分类拥有产品,不允许修改级别');
|
|
|
|
}
|
|
|
|
return $this->success();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :删除
|
|
|
|
* @name :delete
|
|
|
|
* @author :lyh
|
...
|
...
|
|