作者 lyh

gx

... ... @@ -13,22 +13,21 @@ use App\Models\RouteMap\RouteMap;
class BlogCategoryController extends BaseController
{
/**
* @name :博客分类列表
* @author :liyuhang
* @method
* @remark :博客分类列表
* @name :lists
* @author :lyh
* @method :post
* @time :2023/10/18 11:06
*/
public function lists(BlogCategoryModel $blogCategoryModel){
//搜索条件
$this->map['project_id'] = $this->user['project_id'];
$lists = $blogCategoryModel->lists($this->map,$this->page,$this->row,$this->order,
['id','pid','name','num','alias','status','sort','remark','created_at','updated_at']);
$filed = ['id','pid','name','num','alias','status','sort','remark','created_at','updated_at'];
$lists = $blogCategoryModel->lists($this->map,$this->page,$this->row,$this->order,$filed);
if(!empty($lists['list'])){
$blogModel = new BlogModel();
foreach ($lists['list'] as $k => $v){
$v['num'] = $blogModel->formatQuery(['category_id'=>['like','%,' . $v['id'] . ',%']])->count();
$v['alias'] = RouteMap::getRoute(RouteMap::SOURCE_BLOG_CATE, $v['id'], $this->user['project_id']);
$v['num'] = 0;
$v['url'] = $this->user['domain'] . RouteMap::PATH_BLOG_CATE . '/' . $v['alias'];
$v['hasChildren'] = (($blogCategoryModel->read(['pid'=>$v['id']])) != false) ? true : false;
$lists['list'][$k] = $v;
}
}
... ... @@ -36,20 +35,23 @@ class BlogCategoryController extends BaseController
}
/**
* @name :(添加/编辑时获取顶级分类)topList
* @remark :添加/编辑时获取分类
* @name :categoryTopList
* @author :lyh
* @method :post
* @time :2023/6/13 9:03
* @time :2023/10/18 11:05
*/
public function categoryTopList(BlogCategoryLogic $blogCategoryLogic){
$list = $blogCategoryLogic->categoryTopList();
$list = $blogCategoryLogic->getCateAllList();
$this->response('success',Code::SUCCESS,$list);
}
/**
* @name :获取当前分类详情
* @author :liyuhang
* @method
* @remark :获取详情
* @name :info
* @author :lyh
* @method :post
* @time :2023/10/18 11:05
*/
public function info(BlogCategoryLogic $blogCategoryLogic){
$this->request->validate([
... ... @@ -57,8 +59,7 @@ class BlogCategoryController extends BaseController
],[
'id.required' => 'ID不能为空'
]);
$info = $blogCategoryLogic->info_blog_category();
$info['url'] = $this->user['domain'] . $info['alias'];
$info = $blogCategoryLogic->info();
$this->response('success',Code::SUCCESS,$info);
}
... ... @@ -77,9 +78,11 @@ class BlogCategoryController extends BaseController
/**
* @name :编辑状态/与排序
* @author :liyuhang
* @method
* @remark :修改状态
* @name :status
* @author :lyh
* @method :post
* @time :2023/10/18 15:55
*/
public function status(BlogCategoryLogic $blogCategoryLogic){
$this->request->validate([
... ... @@ -87,7 +90,7 @@ class BlogCategoryController extends BaseController
],[
'id.required' => 'ID不能为空',
]);
$blogCategoryLogic->status_blog_category();
$blogCategoryLogic->cateStatus();
$this->response('success');
}
... ...
... ... @@ -4,13 +4,10 @@ namespace App\Http\Controllers\Bside\Blog;
use App\Enums\Common\Code;
use App\Http\Controllers\Bside\BaseController;
use App\Http\Logic\Bside\Blog\BlogCategoryLogic;
use App\Http\Logic\Bside\Blog\BlogLabelLogic;
use App\Http\Logic\Bside\Blog\BlogLogic;
use App\Http\Requests\Bside\Blog\BlogRequest;
use App\Models\Blog\Blog as BlogModel;
use App\Models\Blog\BlogCategory;
use App\Models\RouteMap\RouteMap;
use App\Models\Com\AssociationCate;
use App\Models\User\User;
class BlogController extends BaseController
... ... @@ -23,15 +20,15 @@ class BlogController extends BaseController
* @method :post
* @time :2023/9/14 10:45
*/
public function lists(BlogModel $blogModel,BlogCategoryLogic $blogCategoryLogic,BlogLabelLogic $blogLabelLogic){
public function lists(BlogLogic $blogLogic){
$this->map = $this->searchParam();
$lists = $blogModel->lists($this->map,$this->page,$this->row,$this->order = 'sort', ['id','category_id','operator_id','status','created_at','label_id','image','updated_at','name','sort','url']);
$filed = ['id','operator_id','status','created_at','label_id','image','updated_at','name','sort','url'];
$lists = $blogLogic->lists($this->map,$this->page,$this->row,$this->order = 'sort', $filed);
if(!empty($lists) && !empty($lists['list'])){
//获取当前项目的所有分类
$data = $this->getCategoryList();
//获取当前数据的分类
$user = new User();
foreach ($lists['list'] as $k => $v){
$v['category_name'] = $this->categoryName($v['category_id'],$data);
$v['category_name'] = $this->getCateName($v['category_id']);
$v['url'] = $this->user['domain'] .$v['url'];
$v['image_link'] = getImageUrl($v['image']);
$v['operator_name'] = $user->getName($v['operator_id']);
... ... @@ -51,49 +48,57 @@ class BlogController extends BaseController
public function searchParam(){
$this->map['project_id'] = $this->user['project_id'];
if(isset($this->map['category_id']) && !empty($this->map['category_id'])){
$this->map['category_id'] = ['like','%,'.$this->map['category_id'].',%'];
//获取当前分类下的所有子集
$str = $this->getAllSub($this->map['category_id'],$str);
//根据分类获取所有子集
$assCateModel = new AssociationCate();
$type_id = $assCateModel->formatQuery(['category_id'=>['in',$str],'type'=>$assCateModel::BLOG_CATE])->pluck('type_id')->toArray();
$this->map['id'] = ['in',$type_id];
unset($this->map['category_id']);
}
return $this->map;
}
/**
* @remark :获取所有分类
* @name :getCategoryList
* @remark :获取当前id下的所有子集
* @name :getAllSub
* @author :lyh
* @method :post
* @time :2023/9/14 13:56
* @time :2023/10/18 15:10
*/
public function getCategoryList(){
$categoryModel = new BlogCategory();
$data = [];
$cateList = $categoryModel->list(['project_id'=>$this->user['project_id']],['id','name']);
if(!empty($cateList)){
foreach ($cateList as $value){
$data[$value['id']] = $value['name'];
public function getAllSub($id,&$str = []){
$cateModel = new BlogCategory();
$str[] = $id;
$list = $cateModel->list(['pid'=>$id,'status'=>0],['id','pid']);
if(!empty($list)){
foreach ($list as $v){
$str[] = $v['id'];
$this->getAllSub($v['id'],$str);
}
}
return $data;
return $str;
}
/**
* @remark :获取分类名称
* @name :categoryName
* @remark :获取分类名
* @name :getCateName
* @author :lyh
* @method :post
* @time :2023/9/14 13:58
* @time :2023/10/18 16:43
*/
public function categoryName($category_id,$data){
$category_name = '';
if(!empty($category_id) && !empty($data)){
$arr = explode(',',trim($category_id,','));
foreach ($arr as $v){
if(isset($data[$v])){
$category_name .= $data[$v].',';
}
public function getCateName($id){
//根据分类获取所有子集
$str = '';
if(!empty($id)){
$assCateModel = new AssociationCate();
$category_id = $assCateModel->formatQuery(['type_id'=>$id,'type'=>$assCateModel::BLOG_CATE])->pluck('category_id')->toArray();
if(!empty($category_id)){
$categoryModel = new BlogCategory();
$category_name_arr = $categoryModel->formatQuery(['category_id'=>['in',$category_id]])->pluck('name')->toArray();
}
$category_name = trim($category_name,',');
$str = explode(',',$category_name_arr);
}
return $category_name;
return $str;
}
/**
... ... @@ -109,20 +114,23 @@ class BlogController extends BaseController
}
/**
* @name :获取分页列表
* @throws \App\Exceptions\BsideGlobalException
* @author :liyuhang
* @method
* @remark :添加博客时获取分类列表
* @name :get_category_list
* @author :lyh
* @method :post
* @time :2023/10/18 16:51
*/
public function get_category_list(BlogLogic $blogLogic){
$list = $blogLogic->blog_get_category_list();
public function getCategoryList(BlogLogic $blogLogic){
$list = $blogLogic->getCategoryList();
$this->response('success',Code::SUCCESS,$list);
}
/**
* @name :获取当前博客详情
* @author :liyuhang
* @method
* @remark :获取详情
* @name :info
* @author :lyh
* @method :post
* @time :2023/10/18 16:58
*/
public function info(BlogLogic $blogLogic){
$this->request->validate([
... ...
... ... @@ -26,9 +26,7 @@ class NewsCategoryController extends BaseController
$newsModel = new NewsModel();
foreach ($lists['list'] as $k => $v){
$v['num'] = $newsModel->formatQuery(['category_id'=>['like','%,' . $v['id'] . ',%']])->count();
$v['alias'] = RouteMap::getRoute(RouteMap::SOURCE_NEWS_CATE, $v['id'], $this->user['project_id']);
$v['url'] = $this->user['domain'] . RouteMap::PATH_NEWS_CATE . '/' . $v['alias'];
$v['hasChildren'] = (($newsCategory->read(['pid'=>$v['id']])) != false) ? true : false;
$lists['list'][$k] = $v;
}
}
... ... @@ -36,13 +34,14 @@ class NewsCategoryController extends BaseController
}
/**
* @name :(添加/编辑时获取顶级分类)topList
* @remark :添加/编辑时获取分类
* @name :categoryTopList
* @author :lyh
* @method :post
* @time :2023/6/13 9:03
* @time :2023/10/18 11:05
*/
public function categoryTopList(NewsCategoryLogic $newsCategoryLogic){
$list = $newsCategoryLogic->categoryTopList();
$list = $newsCategoryLogic->getCateAllList();
$this->response('success',Code::SUCCESS,$list);
}
... ... @@ -57,8 +56,7 @@ class NewsCategoryController extends BaseController
],[
'id.required' => 'ID不能为空'
]);
$info = $newsCategoryLogic->info_news_category();
$info['url'] = $this->user['domain'] . $info['alias'];
$info = $newsCategoryLogic->cateInfo();
$this->response('success',Code::SUCCESS,$info);
}
... ... @@ -71,7 +69,7 @@ class NewsCategoryController extends BaseController
*/
public function save(NewsCategoryRequest $request,NewsCategoryLogic $newsCategoryLogic){
$request->validated();
$newsCategoryLogic->newsCategorySave();
$newsCategoryLogic->categorySave();
$this->response('success');
}
... ...
... ... @@ -94,9 +94,6 @@ class FileController
if ($type == 'multi') {
return $this->multi($files);
} else {
$size = $files->getSize();
$file_type = $files->getClientOriginalExtension();
$mime = $files->getMimeType();
return $this->single($files);
}
}
... ...
... ... @@ -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
... ...
... ... @@ -7,37 +7,33 @@ use App\Helper\Common;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\Blog\Blog;
use App\Models\Blog\BlogCategory as BlogCategoryModel;
use App\Models\Com\AssociationCate;
use App\Models\RouteMap\RouteMap;
use App\Services\CosService;
use Illuminate\Support\Facades\DB;
class BlogLogic extends BaseLogic
{
const STATUS_TWO = 2;
public function __construct()
{
parent::__construct();
$this->model = new Blog();
$this->param = $this->requestAll;
}
/**
* @name :获取分类列表
* @return array
* @throws \App\Exceptions\BsideGlobalException
* @author :liyuhang
* @method
* @remark :添加时获取分类数据
* @name :getCategoryList
* @author :lyh
* @method :post
* @time :2023/10/18 17:00
*/
public function blog_get_category_list(){
public function getCategoryList(){
$this->map['status'] = 0;
$this->map['project_id'] = $this->user['project_id'];
$blogCategoryModel = new BlogCategoryModel();
$cate_list = $blogCategoryModel->list($this->map,'sort');
if($cate_list === false){
$this->fail('error',Code::USER_ERROR);
}
$list = [];
foreach ($cate_list as $v){
$v = (array)$v;
... ... @@ -60,16 +56,18 @@ class BlogLogic extends BaseLogic
//拼接参数
DB::beginTransaction();
try {
$category = $this->param['category_id'];
$this->param = $this->paramProcessing($this->param);
if(isset($this->param['id']) && !empty($this->param['id'])){
//是否更新路由
$id = $this->editNewsRoute($this->param['id'],$this->param['url']);
$this->edit($this->param,['id'=>$this->param['id']]);
$this->model->edit($this->param,['id'=>$this->param['id']]);
}else{
$id = $this->model->addReturnId($this->param);
}
$route = RouteMap::setRoute($this->param['url'], RouteMap::SOURCE_BLOG, $id, $this->user['project_id']);
$this->edit(['url'=>$route],['id'=>$id]);
$this->model->edit(['url'=>$route],['id'=>$id]);
$this->saveAssociationCate($id,$category);
DB::commit();
}catch (\Exception $e){
DB::rollBack();
... ... @@ -81,6 +79,28 @@ class BlogLogic extends BaseLogic
}
/**
* @remark :保存分类数据
* @name :saveAssociationCate
* @author :lyh
* @method :post
* @time :2023/10/18 17:01
*/
public function saveAssociationCate($id,$category_arr){
//先删除产品与分类关联表
$assCateModel = new AssociationCate();
$assCateModel->del(['type_id'=>$id]);
$data = [];
foreach ($category_arr as $v){
$data[] = [
'type'=>$assCateModel::BLOG_CATE,
'type_id'=> $id,
'category_id'=>$v
];
}
return $assCateModel->insert($data);
}
/**
* @remark :查看是否编辑路由
* @name :editCategoryRoute
* @author :lyh
... ... @@ -123,23 +143,14 @@ class BlogLogic extends BaseLogic
* @method
*/
public function blogInfo(){
//读取缓存
$info = Common::get_user_cache($this->model->getTable(),$this->param['id']);
if(empty($info)){
$info = $this->model->read($this->param);
if($info === false){
$this->fail('error');
}
//获取分类名称
$blogCategoryLogic = new BlogCategoryLogic();
$info = $blogCategoryLogic->get_category_name($info);
//获取标签名称
$blogLabelLogic = new BlogLabelLogic();
$info = $blogLabelLogic->get_label_name($info);
$info['image_link'] = getImageUrl($info['image']);
//写入缓存
Common::set_user_cache($info,$this->model->getTable(),$this->param['id']);
$info = $this->model->read($this->param);
if($info === false){
$this->fail('error');
}
//获取所有分类
$assCateModel = new AssociationCate();
$info['category_id'] = $assCateModel->where(['type_id'=>$info['id']])->pluck('category_id')->toArray();
$info['image_link'] = getImageUrl($info['image']);
return $this->success($info);
}
... ... @@ -209,17 +220,12 @@ class BlogLogic extends BaseLogic
public function paramProcessing($param){
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'],',').',';
}
}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'].',';
}
}
unset($this->param['category_id']);
return $this->success($param);
}
... ...
... ... @@ -18,6 +18,50 @@ class NewsCategoryLogic extends BaseLogic
}
/**
* @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);
}
/**
* @param $v
* @name :获取分类名称
* @return void
... ... @@ -39,53 +83,97 @@ class NewsCategoryLogic extends BaseLogic
}
/**
* @name :详情
* @return array
* @throws \App\Exceptions\BsideGlobalException
* @author :liyuhang
* @method
* @remark :获取详情
* @name :cateInfo
* @author :lyh
* @method :post
* @time :2023/10/18 14:50
*/
public function info_news_category(){
public function cateInfo(){
$info = $this->model->read($this->param);
if($info === false){
$this->fail('当前数据不存在或者已被删除');
}
$info['url'] = $this->user['domain'] . $info['alias'];
return $this->success($info);
}
/**
* @remark :保存数据
* @name :newsCategorySave
* @name :categorySave
* @author :lyh
* @method :post
* @time :2023/9/7 14:53
* @time :2023/9/7 13:42
*/
public function newsCategorySave(){
public function categorySave(){
//验证名称是否存在
$this->verifyParamName($this->param['name']);
DB::beginTransaction();
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_NEWS_CATE, $id, $this->user['project_id']);
$this->model->edit(['alias'=>$route],['id'=>$id]);
//通知更新
$this->updateNotify(['project_id'=>$this->user['project_id'], 'type'=>RouteMap::SOURCE_NEWS_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 {
if(isset($this->param['id']) && !empty($this->param['id'])){
//验证是否可编辑
$this->verifyEditParam($this->param['id'],$this->param['pid']);
$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']));
$this->edit($this->param,['id'=>$this->param['id']]);
}else{
$this->param = $this->addParamProcessing($this->param);
$id = $this->model->addReturnId($this->param);
//当父级分类拥有产品时,处理子集
$this->addProcessingSon($id);
$id = $this->model->addReturnId($this->param);
//非顶级菜单处理子集
if($this->param['pid'] != 0){
//把所有上级博客移动到下级
$newsModel = new NewsModel();
$newsModel->edit(['category_id'=>$id],['category_id'=>$this->param['pid']]);
}
$route = RouteMap::setRoute(isset($this->param['alias']) ? $this->param['alias'] : $this->param['name'], RouteMap::SOURCE_NEWS_CATE, $id, $this->user['project_id']);
$this->model->edit(['alias'=>$route],['id'=>$id]);
DB::commit();
}catch (\Exception $e){
DB::rollBack();
$this->fail('error');
$this->fail('系统错误请联系管理员');
}
//更新通知记录表
$this->updateNotify(['project_id'=>$this->user['project_id'], 'type'=>RouteMap::SOURCE_NEWS_CATE, 'route'=>$route]);
return $this->success();
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){
//查看当前上级分类下是否有博客
$newsModel = new NewsModel();
$num = $newsModel->where(['category_id'=>$this->param['pid']])->count();
if($num > 0){
//获取当前分类下的最后一级
$lastId = $this->getLastCateId($this->param['id']);
//更新所有博客到当前分类下
$newsModel->edit(['category_id'=>$lastId],['category_id'=>$this->param['pid']]);
}
}
}catch (\Exception $e){
$this->fail('系统错误请联系管理员');
}
//查看路由是否更新
$id = $this->editCategoryRoute($this->param['id'],$this->param['alias']);
return $this->success($id);
}
... ... @@ -106,34 +194,23 @@ class NewsCategoryLogic extends BaseLogic
];
$this->setRouteDeleteSave($data);
}
return $id;
return $this->success($id);
}
/**
* @remark :验证是否可编辑
* @name :verifyEditParam
* @remark :获取当前分类下最后一级分类的id
* @name :getLastCateId
* @author :lyh
* @method :post
* @time :2023/7/31 15:41
* @time :2023/10/18 14:37
*/
public function verifyEditParam($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('当前分类拥有子分类不允许修改父级');
}
//查询当前分类下是否有商品
$newsModel = new NewsModel();
$info = $newsModel->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();
}
/**
... ... @@ -175,22 +252,6 @@ class NewsCategoryLogic extends BaseLogic
}
/**
* @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 :(验证名称是否存在)verifyParamName
* @author :lyh
* @method :post
... ... @@ -223,36 +284,6 @@ class NewsCategoryLogic extends BaseLogic
}
/**
* @name :(添加分类时处理子集分类)addProcessingSon
* @author :lyh
* @method :post
* @time :2023/6/13 11:34
*/
public function addProcessingSon($cate_id){
if(isset($this->param['pid']) && !empty($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) {
//查看当前上一级分类下是否有新闻
$newsModel = new NewsModel();
$news_count = $newsModel->where('category_id','like', '%,' . $this->param['pid'] . ',%')->count();
if ($news_count > 0) {
$replacement = ','. $this->param['pid'] .','. $cate_id . ',';
$old = ',' . $this->param['pid'] . ',';
//更新所有商品到当前分类
$newsModel->where('category_id', 'like', '%' . $old . '%')
->update(['category_id' => DB::raw("REPLACE(category_id, '$old', '$replacement')")]);
}
}
}
return $this->success();
}
/**
* @remark :删除路由
* @name :delRoute
* @author :lyh
... ...
... ... @@ -35,6 +35,7 @@ class ProjectCountryLogic extends BaseLogic
* @time :2023/4/28 17:42
*/
public function country_save(){
//处理数据
if(!isset($this->param['country_lists']) || empty($this->param['country_lists'])){
$this->param['country_lists'] = '';
}
... ...
<?php
/**
* @remark :
* @name :AssociationCate.php
* @author :lyh
* @method :post
* @time :2023/10/18 15:47
*/
namespace App\Models\Com;
use App\Models\Base;
/**
* @remark :分类关联表
* @name :AssociationCate
* @author :lyh
* @method :post
* @time :2023/10/18 15:48
*/
class AssociationCate extends Base
{
const BLOG_CATE = 1;//博客
const NEWS_CATE = 2;//博客
protected $table = 'gl_association_cate';
//连接数据库
protected $connection = 'custom_mysql';
}
... ...
... ... @@ -25,7 +25,7 @@ return [
//默认视频
'default_file' =>[
'size' => [
'max' => 1024*1024*20, // 20M
'max' => 1024*1024*50, // 50M
],
'path_b' => '/upload/p',
'path_a' => '/upload/m',
... ...
... ... @@ -74,7 +74,7 @@ Route::middleware(['bloginauth'])->group(function () {
Route::prefix('blog')->group(function () {
//博客
Route::any('/', [\App\Http\Controllers\Bside\Blog\BlogController::class, 'lists'])->name('blog_lists');
Route::any('/get_category_list', [\App\Http\Controllers\Bside\Blog\BlogController::class, 'get_category_list'])->name('blog_get_category_list');
Route::any('/get_category_list', [\App\Http\Controllers\Bside\Blog\BlogController::class, 'getCategoryList'])->name('blog_get_category_list');
Route::any('/add', [\App\Http\Controllers\Bside\Blog\BlogController::class, 'save'])->name('blog_add');
Route::any('/info', [\App\Http\Controllers\Bside\Blog\BlogController::class, 'info'])->name('blog_info');
Route::any('/edit', [\App\Http\Controllers\Bside\Blog\BlogController::class, 'save'])->name('blog_edit');
... ...