作者 lyh

gx

... ... @@ -61,17 +61,13 @@ class NewsCategoryLogic extends BaseLogic
public function newsCategorySave(){
//验证名称是否存在
$this->verifyParamName($this->param['name']);
//验证是否可编辑
if(isset($this->param['id']) && !empty($this->param['id'])) {
$this->verifyEditParam($this->param['id'], $this->param['pid']);
}
DB::beginTransaction();
try {
if(isset($this->param['id']) && !empty($this->param['id'])){
$this->param['operator_id'] = $this->user['id'];
//查看路由是否更新
$id = $this->editCategoryRoute($this->param['id'],$this->param['alias'] ?? RouteMap::setRoute(isset($this->param['alias']) ? $this->param['alias'] : $this->param['name'],
RouteMap::SOURCE_NEWS_CATE, $this->param['id'], $this->user['project_id']));
$id = $this->editCategoryRoute($this->param['id'],$this->param['alias']);
$this->editHandleCategory($this->param['id'],$this->param['pid']);
$this->edit($this->param,['id'=>$this->param['id']]);
}else{
$this->param = $this->addParamProcessing($this->param);
... ... @@ -91,6 +87,31 @@ class NewsCategoryLogic extends BaseLogic
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){
//修改勒上级,先查看上级是否拥有博客
$newsModel = new NewsModel();
$newsCount = $newsModel->formatQuery(['category_id'=>['like','%,'.$pid.',%']])->count();
//随机获取最后一级id
$replacement = $this->getLastId($id);
if($newsCount > 0){
//存在博客时,移动所有博客到当前分类最后一级
$newsCount->where('category_id', 'like', '%,' . $pid . ',%')->where('category_id', 'like', '%,' . $replacement . ',%')
->update(['category_id' => DB::raw("REPLACE(category_id, ',$pid,', ',')")]);
$newsCount->where('category_id', 'like', '%,' . $pid . ',%')
->update(['category_id' => DB::raw("REPLACE(category_id, ',$pid,', ',$replacement,')")]);
}
}
return $this->success();
}
/**
* @remark :编辑路由时生成路由记录
... ... @@ -272,7 +293,7 @@ class NewsCategoryLogic extends BaseLogic
$newsModel = new NewsModel();
$news_count = $newsModel->where('category_id','like', '%,' . $this->param['pid'] . ',%')->count();
if ($news_count > 0) {
$replacement = ','. $this->param['pid'] .','. $cate_id . ',';
$replacement = ',' . $cate_id . ',';
$old = ',' . $this->param['pid'] . ',';
//更新所有商品到当前分类
$newsModel->where('category_id', 'like', '%' . $old . '%')
... ...
... ... @@ -7,6 +7,7 @@ use App\Helper\Common;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\Com\AssociationCate;
use App\Models\News\News;
use App\Models\News\NewsCategory;
use App\Models\News\NewsCategory as NewsCategoryModel;
use App\Models\RouteMap\RouteMap;
use App\Services\CosService;
... ... @@ -148,13 +149,36 @@ class NewsLogic extends BaseLogic
public function newsInfo()
{
$info = $this->model->read($this->param);
if($info === false){
$this->fail('error');
}
$category = explode(',',trim($info['category_id'],','));
$str = [];
foreach ($category as $v){
$this->getAllFather($v,$str);
}
$info['category_id'] = array_unique($str);
$info['image_link'] = getImageUrl($info['image']);
$newsCategoryLogic = new NewsCategoryLogic();
$info = $newsCategoryLogic->get_category_name($info);
return $this->success($info);
}
/**
* @remark :获取分类的所有上级
* @name :getAllFather
* @author :lyh
* @method :post
* @time :2023/10/20 9:08
*/
public function getAllFather($id,&$str = []){
$cateModel = new NewsCategoryModel();
$info = $cateModel->read(['id'=>$id],['id','pid']);
if($info !== false){
$str[] = (int)$id;
$this->getAllFather($info['pid'],$str);
}
}
/**
* @name :逻辑删除
* @return void
* @author :liyuhang
... ... @@ -184,23 +208,42 @@ class NewsLogic extends BaseLogic
*/
public function paramProcessing($param)
{
if (isset($this->param['id'])) {
if(isset($this->param['id'])){
$param['operator_id'] = $this->user['id'];
if (isset($param['category_id']) && !empty($param['category_id'])) {
$param['category_id'] = ',' . trim($param['category_id'], ',') . ',';
if(isset($param['category_id']) && !empty($param['category_id'])){
$param['category_id'] = $this->getLastCategory($param['category_id']);
}
} else {
}else{
$param['create_id'] = $this->user['id'];
$param['operator_id'] = $this->user['id'];
$param['project_id'] = $this->user['project_id'];
if (isset($param['category_id']) && !empty($param['category_id'])) {
$param['category_id'] = ',' . $param['category_id'] . ',';
if(isset($param['category_id']) && !empty($param['category_id'])){
$param['category_id'] = $this->getLastCategory($param['category_id']);
}
}
return $this->success($param);
}
/**
* @remark :获取最后一级分类id
* @name :getLastCategory
* @author :lyh
* @method :post
* @time :2023/10/20 9:02
*/
public function getLastCategory($category){
$str = '';
$cateModel = new NewsCategoryModel();
foreach ($category as $v){
$info = $cateModel->read(['pid'=>$v]);
if($info === false){
$str .= $v.',';
}
}
return ','.$str;
}
/**
* @remark :根据状态获取数量
* @name :getStatusNumber
* @author :lyh
... ...