作者 lyh

gx

... ... @@ -7,6 +7,7 @@ use App\Http\Controllers\Bside\BaseController;
use App\Http\Logic\Bside\News\NewsCategoryLogic;
use App\Http\Logic\Bside\News\NewsLogic;
use App\Http\Requests\Bside\News\NewsRequest;
use App\Models\Com\AssociationCate;
use App\Models\News\News as NewsModel;
use App\Models\News\NewsCategory;
use App\Models\RouteMap\RouteMap;
... ... @@ -18,23 +19,23 @@ use App\Models\User\User;
*/
class NewsController extends BaseController
{
public $updateModelView = 'news';
/**
* @name :获取新闻列表
* @author :liyuhang
* @method
* @remark :博客列表
* @name :lists
* @author :lyh
* @method :post
* @time :2023/9/14 10:45
*/
public function lists(NewsModel $news,NewsCategoryLogic $newsCategoryLogic){
public function lists(NewsModel $newsModel){
$this->map = $this->searchParam();
$lists = $news->lists($this->map,$this->page,$this->row,$this->order = 'sort',
['id','category_id','operator_id','status','created_at','updated_at','image','name','sort','url']);
$filed = ['id','operator_id','status','created_at','label_id','image','updated_at','name','sort','url'];
$lists = $newsModel->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['url'] = $this->user['domain'] . $v['url'];
$v['category_name'] = $this->getCateName($v['id']);
$v['url'] = $this->user['domain'] .$v['url'];
$v['image_link'] = getImageUrl($v['image']);
$v['operator_name'] = $user->getName($v['operator_id']);
$lists['list'][$k] = $v;
... ... @@ -53,49 +54,57 @@ class NewsController 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 NewsCategory();
$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 NewsCategory();
$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 NewsCategory();
$category_name_arr = $categoryModel->formatQuery(['id'=>['in',$category_id]])->pluck('name')->toArray();
$str = implode(',',$category_name_arr);
}
$category_name = trim($category_name,',');
}
return $category_name;
return $str;
}
/**
... ... @@ -112,12 +121,14 @@ class NewsController extends BaseController
/**
* @name :添加新闻时获取分类列表
* @author :liyuhang
* @method
* @remark :添加博客时获取分类列表
* @name :get_category_list
* @author :lyh
* @method :post
* @time :2023/10/18 16:51
*/
public function get_category_list(NewsLogic $newsLogic){
$list = $newsLogic->news_get_category_list();
public function getCategoryList(NewsLogic $newsLogic){
$list = $newsLogic->getCategoryList();
$this->response('success',Code::SUCCESS,$list);
}
/**
... ... @@ -132,7 +143,6 @@ class NewsController extends BaseController
'id.required' => 'ID不能为空',
]);
$info = $newsLogic->newsInfo();
$this->response('success',Code::SUCCESS,$info);
}
... ...
... ... @@ -57,12 +57,16 @@ class BlogLogic extends BaseLogic
DB::beginTransaction();
try {
$category = $this->param['category_id'];
$this->param = $this->paramProcessing($this->param);
unset($this->param['category_id']);
if(isset($this->param['id']) && !empty($this->param['id'])){
$this->param['operator_id'] = $this->user['id'];
//是否更新路由
$id = $this->editNewsRoute($this->param['id'],$this->param['url']);
$this->model->edit($this->param,['id'=>$this->param['id']]);
}else{
$this->param['create_id'] = $this->user['id'];
$this->param['operator_id'] = $this->user['id'];
$this->param['project_id'] = $this->user['project_id'];
$id = $this->model->addReturnId($this->param);
}
$route = RouteMap::setRoute($this->param['url'], RouteMap::SOURCE_BLOG, $id, $this->user['project_id']);
... ... @@ -184,9 +188,11 @@ class BlogLogic extends BaseLogic
public function blogDel(){
DB::beginTransaction();
try {
$assCate = new AssociationCate();
foreach ($this->param['id'] as $id){
$this->delRoute($id);
$this->model->del(['id'=>$id]);
$assCate->del(['type_id'=>$id]);
}
DB::commit();
}catch (Exception $e){
... ... @@ -217,24 +223,6 @@ class BlogLogic extends BaseLogic
}
/**
* @name :(参数处理)paramProcessing
* @author :lyh
* @method :post
* @time :2023/6/13 11:30
*/
public function paramProcessing($param){
if(isset($this->param['id'])){
$param['operator_id'] = $this->user['id'];
}else{
$param['create_id'] = $this->user['id'];
$param['operator_id'] = $this->user['id'];
$param['project_id'] = $this->user['project_id'];
}
unset($this->param['category_id']);
return $this->success($param);
}
/**
* @remark :根据状态获取数量
* @name :getStatusNumber
* @author :lyh
... ...
... ... @@ -5,6 +5,7 @@ namespace App\Http\Logic\Bside\News;
use App\Enums\Common\Code;
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 as NewsCategoryModel;
use App\Models\RouteMap\RouteMap;
... ... @@ -29,7 +30,7 @@ class NewsLogic extends BaseLogic
* @author :liyuhang
* @method
*/
public function news_get_category_list()
public function getCategoryList()
{
$this->map['status'] = 0;
$this->map['project_id'] = $this->user['project_id'];
... ... @@ -147,9 +148,13 @@ class NewsLogic extends BaseLogic
public function newsInfo()
{
$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']);
$newsCategoryLogic = new NewsCategoryLogic();
$info = $newsCategoryLogic->get_category_name($info);
return $this->success($info);
}
... ...
... ... @@ -59,7 +59,7 @@ Route::middleware(['bloginauth'])->group(function () {
Route::any('/category/categoryTopList', [\App\Http\Controllers\Bside\News\NewsCategoryController::class, 'categoryTopList'])->name('news_category_categoryTopList');
//新闻
Route::any('/', [\App\Http\Controllers\Bside\News\NewsController::class, 'lists'])->name('news_category_lists');
Route::any('/get_category_list', [\App\Http\Controllers\Bside\News\NewsController::class, 'get_category_list'])->name('news_get_category_list');
Route::any('/get_category_list', [\App\Http\Controllers\Bside\News\NewsController::class, 'getCategoryList'])->name('news_get_category_list');
Route::any('/add', [\App\Http\Controllers\Bside\News\NewsController::class, 'save'])->name('news_add');
Route::any('/edit_seo', [\App\Http\Controllers\Bside\News\NewsController::class, 'edit_seo'])->name('news_edit_seo');
Route::any('/info', [\App\Http\Controllers\Bside\News\NewsController::class, 'info'])->name('news_info');
... ...