作者 lyh

gx

... ... @@ -86,7 +86,7 @@ class CategoryController extends BaseController
}
/**
* @name :(添加/编辑时获取顶级分类)topList
* @name :(添加/编辑时获取分类)topList
* @author :lyh
* @method :post
* @time :2023/6/13 9:03
... ...
... ... @@ -115,16 +115,12 @@ class CategoryLogic extends BaseLogic
if(isset($this->param['id']) && !empty($this->param['id'])){
$this->param['route'] = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_PRODUCT_CATE, $this->param['id'], $this->user['project_id']);
$route = $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);
$route = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_PRODUCT_CATE, $id, $this->user['project_id']);
$this->edit(['route'=>$route],['id'=>$id]);
//处理子集
$this->addProcessingSon($id);
}
//清除缓存
Common::del_user_cache('product_category',$this->user['project_id']);
... ... @@ -139,90 +135,6 @@ 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')")]);
//同步更新关联表
$categoryRelatedModel = new CategoryRelated();
$categoryRelatedModel->edit(['category_id'=>$cate_id],['category_id'=>$this->param['pid']]);
}
}
}
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,')")]);
//同步更新关联表
$categoryRelatedModel = new CategoryRelated();
$cateRelateList = $categoryRelatedModel->list(['category_id'=>$pid]);
if(!empty($cateRelateList)){
foreach ($cateRelateList as $v){
$categoryRelatedModel->del(['category_id'=>$replacement,'product_id'=>$v['product_id']]);
}
}
$categoryRelatedModel->edit(['category_id'=>$replacement],['category_id'=>$pid]);
}
}
return $this->success();
}
/**
* @remark :随机获取当前id下最后一级的id
* @name :getLastId
* @author :lyh
* @method :post
* @time :2023/10/20 9:45
*/
public function getLastId($id){
$info = $this->model->read(['pid'=>$id],['id']);
if($info !== false){
return $this->getLastId($info['id']);
}else{
return $id;
}
}
/**
* @remark :删除
* @name :delete
* @author :lyh
... ... @@ -309,13 +221,10 @@ class CategoryLogic extends BaseLogic
$str = '';
if(isset($category) && !empty($category)){
foreach ($category as $v){
$info = $this->model->read(['pid'=>$v]);
if($info === false){
$str .= $v.',';
}
}
}
return ','.$str;
return !empty($str) ? ','.$str : '';
}
/**
... ...
... ... @@ -263,6 +263,7 @@ Route::middleware(['aloginauth'])->group(function () {
Route::prefix('create_keyword')->group(function () {
Route::any('/', [Aside\Optimize\CreateKeywordController::class, 'lists'])->name('admin.create_keywords_lists');//创建关键字获取语种+前后缀
Route::any('/save', [Aside\Optimize\CreateKeywordController::class, 'save'])->name('admin.create_keywords_save');//保存关键字获取语种+前后缀
Route::any('/createKeyword', [Aside\Optimize\CreateKeywordController::class, 'createKeyword'])->name('admin.create_keywords_createKeyword');//保存关键字获取语种+前后缀
});
... ...