|
...
|
...
|
@@ -5,6 +5,7 @@ namespace App\Http\Logic\Bside\Blog; |
|
|
|
use App\Http\Logic\Bside\BaseLogic;
|
|
|
|
use App\Models\Blog\Blog as BlogModel;
|
|
|
|
use App\Models\Blog\BlogCategory as BlogCategoryModel;
|
|
|
|
use App\Models\Com\AssociationCate;
|
|
|
|
use App\Models\RouteMap\RouteMap;
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
...
|
...
|
@@ -13,12 +14,71 @@ class BlogCategoryLogic extends BaseLogic |
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
|
|
|
|
$this->model = new BlogCategoryModel();
|
|
|
|
$this->param = $this->requestAll;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :添加/编辑时获取分类
|
|
|
|
* @name :categoryTopList
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/10/18 11:05
|
|
|
|
*/
|
|
|
|
public function getCateAllList(){
|
|
|
|
$this->param['project_id'] = $this->user['project_id'];
|
|
|
|
$this->param['status'] = 0;
|
|
|
|
if(isset($this->param['id']) && !empty($this->param['id'])){
|
|
|
|
//排序掉当前id下所有子集
|
|
|
|
$str = $this->getAllSub($this->param['id'],$str);
|
|
|
|
$this->param['id'] = ['!=',$str];
|
|
|
|
}
|
|
|
|
$list = $this->model->list($this->param);
|
|
|
|
if(!empty($list)){
|
|
|
|
foreach ($list as $k => $v){
|
|
|
|
$v['sub'] = _get_child($v['id'],$list);
|
|
|
|
$list[$k] = $v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$this->success($list);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :获取当前id下所有子集
|
|
|
|
* @name :getAllSub
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/10/18 15:10
|
|
|
|
*/
|
|
|
|
public function getAllSub($id,&$str = []){
|
|
|
|
$str[] = $id;
|
|
|
|
$list = $this->model->list(['pid'=>$id,'status'=>0],['id','pid']);
|
|
|
|
if(!empty($list)){
|
|
|
|
foreach ($list as $v){
|
|
|
|
$str[] = $v['id'];
|
|
|
|
$this->getAllSub($v['id'],$str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $this->success($str);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :获取数据详情
|
|
|
|
* @name :info
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/10/18 15:37
|
|
|
|
*/
|
|
|
|
public function info(){
|
|
|
|
$info = $this->model->read($this->param);
|
|
|
|
if($info === false){
|
|
|
|
$this->fail('当前数据不存在或者已被删除');
|
|
|
|
}
|
|
|
|
$info['url'] = $this->user['domain'] . $info['alias'];
|
|
|
|
return $this->success($info);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $v
|
|
|
|
* @name :获取分类名称
|
|
|
|
* @return void
|
|
...
|
...
|
@@ -46,38 +106,75 @@ class BlogCategoryLogic extends BaseLogic |
|
|
|
public function categorySave(){
|
|
|
|
//验证名称是否存在
|
|
|
|
$this->verifyParamName($this->param['name']);
|
|
|
|
DB::beginTransaction();
|
|
|
|
try {
|
|
|
|
if(isset($this->param['id']) && !empty($this->param['id'])){
|
|
|
|
//验证参数是否可编辑
|
|
|
|
$this->verifyParamEdit($this->param['id'],$this->param['pid']);
|
|
|
|
//查看路由是否更新
|
|
|
|
$id = $this->editCategoryRoute($this->param['id'],
|
|
|
|
isset($this->param['alias']) ?? RouteMap::setRoute(isset($this->param['alias']) ? $this->param['alias'] : $this->param['name'],
|
|
|
|
RouteMap::SOURCE_BLOG_CATE, $this->param['id'], $this->user['project_id']));
|
|
|
|
$this->param['operator_id'] = $this->user['id'];
|
|
|
|
$this->edit($this->param,['id'=>$this->param['id']]);
|
|
|
|
}else{
|
|
|
|
//拼接参数
|
|
|
|
$this->param = $this->addParamProcessing($this->param);
|
|
|
|
$id = $this->model->addReturnId($this->param);
|
|
|
|
//处理子集
|
|
|
|
$this->addProcessingSon($id);
|
|
|
|
}
|
|
|
|
$route = RouteMap::setRoute(isset($this->param['alias']) ? $this->param['alias'] : $this->param['name'],
|
|
|
|
RouteMap::SOURCE_BLOG_CATE, $id, $this->user['project_id']);
|
|
|
|
$this->edit(['alias'=>$route],['id'=>$id]);
|
|
|
|
DB::commit();
|
|
|
|
}catch (\Exception $e){
|
|
|
|
DB::rollBack();
|
|
|
|
$this->fail('系统错误,请联系管理');
|
|
|
|
if(isset($this->param['id']) && !empty($this->param['id'])){
|
|
|
|
$id = $this->cateEdit();
|
|
|
|
}else{
|
|
|
|
$id = $this->cateAdd();
|
|
|
|
}
|
|
|
|
//更新路由
|
|
|
|
$route = RouteMap::setRoute(isset($this->param['alias']) ? $this->param['alias'] : $this->param['name'],
|
|
|
|
RouteMap::SOURCE_BLOG_CATE, $id, $this->user['project_id']);
|
|
|
|
$this->model->edit(['alias'=>$route],['id'=>$id]);
|
|
|
|
//通知更新
|
|
|
|
$this->updateNotify(['project_id'=>$this->user['project_id'], 'type'=>RouteMap::SOURCE_BLOG_CATE, 'route'=>$route]);
|
|
|
|
return $this->success();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :添加数据
|
|
|
|
* @name :add
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/10/18 11:07
|
|
|
|
*/
|
|
|
|
public function cateAdd(){
|
|
|
|
//拼接参数
|
|
|
|
$this->param = $this->addParamProcessing($this->param);
|
|
|
|
try {
|
|
|
|
$id = $this->model->addReturnId($this->param);
|
|
|
|
//非顶级菜单处理子集
|
|
|
|
if($this->param['pid'] != 0){
|
|
|
|
//把所有上级博客移动到下级
|
|
|
|
$associationCateModel = new AssociationCate();
|
|
|
|
$associationCateModel->edit(['category_id'=>$id],['category_id'=>$this->param['pid'],$associationCateModel::BLOG_CATE]);
|
|
|
|
}
|
|
|
|
}catch (\Exception $e){
|
|
|
|
$this->fail('系统错误请联系管理员');
|
|
|
|
}
|
|
|
|
return $this->success($id);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :修改数据
|
|
|
|
* @name :edit
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/10/18 11:08
|
|
|
|
*/
|
|
|
|
public function cateEdit(){
|
|
|
|
$this->param['operator_id'] = $this->user['id'];
|
|
|
|
try {
|
|
|
|
$this->model->edit($this->param,['id'=>$this->param['id']]);
|
|
|
|
if($this->param['pid'] != 0){
|
|
|
|
//查看当前上级分类下是否有博客
|
|
|
|
$associationCateModel = new AssociationCate();
|
|
|
|
$num = $associationCateModel->where(['category_id'=>$this->param['pid'],'type'=>$associationCateModel::BLOG_CATE])->count();
|
|
|
|
if($num > 0){
|
|
|
|
//获取当前分类下的最后一级
|
|
|
|
$lastId = $this->getLastCateId($this->param['id']);
|
|
|
|
//更新所有博客到当前分类下
|
|
|
|
$associationCateModel->edit(['category_id'=>$lastId],['category_id'=>$this->param['pid'],'type'=>$associationCateModel::BLOG_CATE]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}catch (\Exception $e){
|
|
|
|
$this->fail('系统错误请联系管理员');
|
|
|
|
}
|
|
|
|
//查看路由是否更新
|
|
|
|
$id = $this->editCategoryRoute($this->param['id'],$this->param['alias']);
|
|
|
|
return $this->success($id);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :编辑路由时生成路由记录
|
|
|
|
* @name :editCategoryRoute
|
|
|
|
* @author :lyh
|
|
...
|
...
|
@@ -97,43 +194,20 @@ class BlogCategoryLogic extends BaseLogic |
|
|
|
return $this->success();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :查看参数是否可编辑
|
|
|
|
* @name :verifyParamEdit
|
|
|
|
* @remark :获取当前分类下最后一级分类的id
|
|
|
|
* @name :getLastCateId
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/7/31 16:31
|
|
|
|
* @time :2023/10/18 14:37
|
|
|
|
*/
|
|
|
|
public function verifyParamEdit($id,$pid){
|
|
|
|
$info = $this->model->read(['id'=>$id]);
|
|
|
|
if($info['id'] == $pid){
|
|
|
|
$this->fail('不能成为自己的上级');
|
|
|
|
}
|
|
|
|
if($info['pid'] != $pid){
|
|
|
|
$info = $this->model->read(['pid'=>$id]);
|
|
|
|
if($info !== false){
|
|
|
|
$this->fail('当前分类拥有子分类不允许修改父级');
|
|
|
|
}
|
|
|
|
//查询当前分类下是否有商品
|
|
|
|
$blogModel = new BlogModel();
|
|
|
|
$info = $blogModel->read(['id'=>['like','%,'.$id.',%']]);
|
|
|
|
if($info !== false){
|
|
|
|
$this->fail('当前分类下已存在博客,不允许修改上级');
|
|
|
|
}
|
|
|
|
public function getLastCateId($id){
|
|
|
|
$info = $this->model->read(['pid'=>$id],['id']);
|
|
|
|
if($info === false){
|
|
|
|
return $this->success($id);
|
|
|
|
}else{
|
|
|
|
$this->getLastCateId($info['id']);
|
|
|
|
}
|
|
|
|
return $this->success();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @name :详情
|
|
|
|
* @return array
|
|
|
|
* @author :liyuhang
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
public function info_blog_category(){
|
|
|
|
$info = $this->model->read($this->param);
|
|
|
|
return $this->success($info);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
...
|
...
|
@@ -142,7 +216,7 @@ class BlogCategoryLogic extends BaseLogic |
|
|
|
* @author :liyuhang
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
public function status_blog_category(){
|
|
|
|
public function cateStatus(){
|
|
|
|
$this->param['operator_id'] = $this->user['id'];
|
|
|
|
$rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
|
|
|
|
if($rs === false){
|
|
...
|
...
|
@@ -188,21 +262,6 @@ class BlogCategoryLogic extends BaseLogic |
|
|
|
return $this->success();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @name :(添加分类时获取1级分类)categoryTopList
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/6/13 9:09
|
|
|
|
*/
|
|
|
|
public function categoryTopList(){
|
|
|
|
$map = [
|
|
|
|
'project_id'=>$this->user['project_id'],
|
|
|
|
'pid'=>0,
|
|
|
|
'status'=>0,
|
|
|
|
];
|
|
|
|
$list = $this->model->list($map);
|
|
|
|
return $this->success($list);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @name :(参数处理)paramProcessing
|
|
...
|
...
|
@@ -240,37 +299,6 @@ class BlogCategoryLogic 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) {
|
|
|
|
//查看当前上一级分类下是否有新闻
|
|
|
|
$blogModel = new BlogModel();
|
|
|
|
$blog_count = $blogModel->where('category_id','like', '%,' . $this->param['pid'] . ',%')->count();
|
|
|
|
if ($blog_count > 0) {
|
|
|
|
$replacement = ','. $this->param['pid'] . ',' . $cate_id . ',';
|
|
|
|
$old = ',' . $this->param['pid'] . ',';
|
|
|
|
//更新所有商品到当前分类
|
|
|
|
$blogModel->where('category_id', 'like', '%' . $old . '%')
|
|
|
|
->update(['category_id' => DB::raw("REPLACE(category_id, '$old', '$replacement')")]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $this->success();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :删除路由
|
|
|
|
* @name :delRoute
|
|
|
|
* @author :lyh
|
...
|
...
|
|