作者 lyh

gx

@@ -7,6 +7,7 @@ use App\Http\Controllers\Bside\BaseController; @@ -7,6 +7,7 @@ use App\Http\Controllers\Bside\BaseController;
7 use App\Http\Logic\Bside\News\NewsCategoryLogic; 7 use App\Http\Logic\Bside\News\NewsCategoryLogic;
8 use App\Http\Logic\Bside\News\NewsLogic; 8 use App\Http\Logic\Bside\News\NewsLogic;
9 use App\Http\Requests\Bside\News\NewsRequest; 9 use App\Http\Requests\Bside\News\NewsRequest;
  10 +use App\Models\Com\AssociationCate;
10 use App\Models\News\News as NewsModel; 11 use App\Models\News\News as NewsModel;
11 use App\Models\News\NewsCategory; 12 use App\Models\News\NewsCategory;
12 use App\Models\RouteMap\RouteMap; 13 use App\Models\RouteMap\RouteMap;
@@ -18,23 +19,23 @@ use App\Models\User\User; @@ -18,23 +19,23 @@ use App\Models\User\User;
18 */ 19 */
19 class NewsController extends BaseController 20 class NewsController extends BaseController
20 { 21 {
21 - public $updateModelView = 'news';  
22 /** 22 /**
23 - * @name :获取新闻列表  
24 - * @author :liyuhang  
25 - * @method 23 + * @remark :博客列表
  24 + * @name :lists
  25 + * @author :lyh
  26 + * @method :post
  27 + * @time :2023/9/14 10:45
26 */ 28 */
27 - public function lists(NewsModel $news,NewsCategoryLogic $newsCategoryLogic){ 29 + public function lists(NewsModel $newsModel){
28 $this->map = $this->searchParam(); 30 $this->map = $this->searchParam();
29 - $lists = $news->lists($this->map,$this->page,$this->row,$this->order = 'sort',  
30 - ['id','category_id','operator_id','status','created_at','updated_at','image','name','sort','url']); 31 + $filed = ['id','operator_id','status','created_at','label_id','image','updated_at','name','sort','url'];
  32 + $lists = $newsModel->lists($this->map,$this->page,$this->row,$this->order = 'sort', $filed);
31 if(!empty($lists) && !empty($lists['list'])){ 33 if(!empty($lists) && !empty($lists['list'])){
32 - //获取当前项目的所有分类  
33 - $data = $this->getCategoryList(); 34 + //获取当前数据的分类
34 $user = new User(); 35 $user = new User();
35 foreach ($lists['list'] as $k => $v){ 36 foreach ($lists['list'] as $k => $v){
36 - $v['category_name'] = $this->categoryName($v['category_id'],$data);  
37 - $v['url'] = $this->user['domain'] . $v['url']; 37 + $v['category_name'] = $this->getCateName($v['id']);
  38 + $v['url'] = $this->user['domain'] .$v['url'];
38 $v['image_link'] = getImageUrl($v['image']); 39 $v['image_link'] = getImageUrl($v['image']);
39 $v['operator_name'] = $user->getName($v['operator_id']); 40 $v['operator_name'] = $user->getName($v['operator_id']);
40 $lists['list'][$k] = $v; 41 $lists['list'][$k] = $v;
@@ -53,49 +54,57 @@ class NewsController extends BaseController @@ -53,49 +54,57 @@ class NewsController extends BaseController
53 public function searchParam(){ 54 public function searchParam(){
54 $this->map['project_id'] = $this->user['project_id']; 55 $this->map['project_id'] = $this->user['project_id'];
55 if(isset($this->map['category_id']) && !empty($this->map['category_id'])){ 56 if(isset($this->map['category_id']) && !empty($this->map['category_id'])){
56 - $this->map['category_id'] = ['like','%,'.$this->map['category_id'].',%']; 57 + //获取当前分类下的所有子集
  58 + $str = $this->getAllSub($this->map['category_id'],$str);
  59 + //根据分类获取所有子集
  60 + $assCateModel = new AssociationCate();
  61 + $type_id = $assCateModel->formatQuery(['category_id'=>['in',$str],'type'=>$assCateModel::BLOG_CATE])->pluck('type_id')->toArray();
  62 + $this->map['id'] = ['in',$type_id];
  63 + unset($this->map['category_id']);
57 } 64 }
58 return $this->map; 65 return $this->map;
59 } 66 }
60 67
61 /** 68 /**
62 - * @remark :获取所有分类  
63 - * @name :getCategoryList 69 + * @remark :获取当前id下的所有子集
  70 + * @name :getAllSub
64 * @author :lyh 71 * @author :lyh
65 * @method :post 72 * @method :post
66 - * @time :2023/9/14 13:56 73 + * @time :2023/10/18 15:10
67 */ 74 */
68 - public function getCategoryList(){  
69 - $categoryModel = new NewsCategory();  
70 - $data = [];  
71 - $cateList = $categoryModel->list(['project_id'=>$this->user['project_id']],['id','name']);  
72 - if(!empty($cateList)){  
73 - foreach ($cateList as $value){  
74 - $data[$value['id']] = $value['name']; 75 + public function getAllSub($id,&$str = []){
  76 + $cateModel = new NewsCategory();
  77 + $str[] = $id;
  78 + $list = $cateModel->list(['pid'=>$id,'status'=>0],['id','pid']);
  79 + if(!empty($list)){
  80 + foreach ($list as $v){
  81 + $str[] = $v['id'];
  82 + $this->getAllSub($v['id'],$str);
75 } 83 }
76 } 84 }
77 - return $data; 85 + return $str;
78 } 86 }
79 87
80 /** 88 /**
81 - * @remark :获取分类名称  
82 - * @name :categoryName 89 + * @remark :获取分类名
  90 + * @name :getCateName
83 * @author :lyh 91 * @author :lyh
84 * @method :post 92 * @method :post
85 - * @time :2023/9/14 13:58 93 + * @time :2023/10/18 16:43
86 */ 94 */
87 - public function categoryName($category_id,$data){  
88 - $category_name = '';  
89 - if(!empty($category_id) && !empty($data)){  
90 - $arr = explode(',',trim($category_id,','));  
91 - foreach ($arr as $v){  
92 - if(isset($data[$v])){  
93 - $category_name .= $data[$v].',';  
94 - } 95 + public function getCateName($id){
  96 + //根据分类获取所有子集
  97 + $str = '';
  98 + if(!empty($id)){
  99 + $assCateModel = new AssociationCate();
  100 + $category_id = $assCateModel->formatQuery(['type_id'=>$id,'type'=>$assCateModel::BLOG_CATE])->pluck('category_id')->toArray();
  101 + if(!empty($category_id)){
  102 + $categoryModel = new NewsCategory();
  103 + $category_name_arr = $categoryModel->formatQuery(['id'=>['in',$category_id]])->pluck('name')->toArray();
  104 + $str = implode(',',$category_name_arr);
95 } 105 }
96 - $category_name = trim($category_name,',');  
97 } 106 }
98 - return $category_name; 107 + return $str;
99 } 108 }
100 109
101 /** 110 /**
@@ -112,12 +121,14 @@ class NewsController extends BaseController @@ -112,12 +121,14 @@ class NewsController extends BaseController
112 121
113 122
114 /** 123 /**
115 - * @name :添加新闻时获取分类列表  
116 - * @author :liyuhang  
117 - * @method 124 + * @remark :添加博客时获取分类列表
  125 + * @name :get_category_list
  126 + * @author :lyh
  127 + * @method :post
  128 + * @time :2023/10/18 16:51
118 */ 129 */
119 - public function get_category_list(NewsLogic $newsLogic){  
120 - $list = $newsLogic->news_get_category_list(); 130 + public function getCategoryList(NewsLogic $newsLogic){
  131 + $list = $newsLogic->getCategoryList();
121 $this->response('success',Code::SUCCESS,$list); 132 $this->response('success',Code::SUCCESS,$list);
122 } 133 }
123 /** 134 /**
@@ -132,7 +143,6 @@ class NewsController extends BaseController @@ -132,7 +143,6 @@ class NewsController extends BaseController
132 'id.required' => 'ID不能为空', 143 'id.required' => 'ID不能为空',
133 ]); 144 ]);
134 $info = $newsLogic->newsInfo(); 145 $info = $newsLogic->newsInfo();
135 -  
136 $this->response('success',Code::SUCCESS,$info); 146 $this->response('success',Code::SUCCESS,$info);
137 } 147 }
138 148
@@ -57,12 +57,16 @@ class BlogLogic extends BaseLogic @@ -57,12 +57,16 @@ class BlogLogic extends BaseLogic
57 DB::beginTransaction(); 57 DB::beginTransaction();
58 try { 58 try {
59 $category = $this->param['category_id']; 59 $category = $this->param['category_id'];
60 - $this->param = $this->paramProcessing($this->param); 60 + unset($this->param['category_id']);
61 if(isset($this->param['id']) && !empty($this->param['id'])){ 61 if(isset($this->param['id']) && !empty($this->param['id'])){
  62 + $this->param['operator_id'] = $this->user['id'];
62 //是否更新路由 63 //是否更新路由
63 $id = $this->editNewsRoute($this->param['id'],$this->param['url']); 64 $id = $this->editNewsRoute($this->param['id'],$this->param['url']);
64 $this->model->edit($this->param,['id'=>$this->param['id']]); 65 $this->model->edit($this->param,['id'=>$this->param['id']]);
65 }else{ 66 }else{
  67 + $this->param['create_id'] = $this->user['id'];
  68 + $this->param['operator_id'] = $this->user['id'];
  69 + $this->param['project_id'] = $this->user['project_id'];
66 $id = $this->model->addReturnId($this->param); 70 $id = $this->model->addReturnId($this->param);
67 } 71 }
68 $route = RouteMap::setRoute($this->param['url'], RouteMap::SOURCE_BLOG, $id, $this->user['project_id']); 72 $route = RouteMap::setRoute($this->param['url'], RouteMap::SOURCE_BLOG, $id, $this->user['project_id']);
@@ -184,9 +188,11 @@ class BlogLogic extends BaseLogic @@ -184,9 +188,11 @@ class BlogLogic extends BaseLogic
184 public function blogDel(){ 188 public function blogDel(){
185 DB::beginTransaction(); 189 DB::beginTransaction();
186 try { 190 try {
  191 + $assCate = new AssociationCate();
187 foreach ($this->param['id'] as $id){ 192 foreach ($this->param['id'] as $id){
188 $this->delRoute($id); 193 $this->delRoute($id);
189 $this->model->del(['id'=>$id]); 194 $this->model->del(['id'=>$id]);
  195 + $assCate->del(['type_id'=>$id]);
190 } 196 }
191 DB::commit(); 197 DB::commit();
192 }catch (Exception $e){ 198 }catch (Exception $e){
@@ -217,24 +223,6 @@ class BlogLogic extends BaseLogic @@ -217,24 +223,6 @@ class BlogLogic extends BaseLogic
217 } 223 }
218 224
219 /** 225 /**
220 - * @name :(参数处理)paramProcessing  
221 - * @author :lyh  
222 - * @method :post  
223 - * @time :2023/6/13 11:30  
224 - */  
225 - public function paramProcessing($param){  
226 - if(isset($this->param['id'])){  
227 - $param['operator_id'] = $this->user['id'];  
228 - }else{  
229 - $param['create_id'] = $this->user['id'];  
230 - $param['operator_id'] = $this->user['id'];  
231 - $param['project_id'] = $this->user['project_id'];  
232 - }  
233 - unset($this->param['category_id']);  
234 - return $this->success($param);  
235 - }  
236 -  
237 - /**  
238 * @remark :根据状态获取数量 226 * @remark :根据状态获取数量
239 * @name :getStatusNumber 227 * @name :getStatusNumber
240 * @author :lyh 228 * @author :lyh
@@ -5,6 +5,7 @@ namespace App\Http\Logic\Bside\News; @@ -5,6 +5,7 @@ namespace App\Http\Logic\Bside\News;
5 use App\Enums\Common\Code; 5 use App\Enums\Common\Code;
6 use App\Helper\Common; 6 use App\Helper\Common;
7 use App\Http\Logic\Bside\BaseLogic; 7 use App\Http\Logic\Bside\BaseLogic;
  8 +use App\Models\Com\AssociationCate;
8 use App\Models\News\News; 9 use App\Models\News\News;
9 use App\Models\News\NewsCategory as NewsCategoryModel; 10 use App\Models\News\NewsCategory as NewsCategoryModel;
10 use App\Models\RouteMap\RouteMap; 11 use App\Models\RouteMap\RouteMap;
@@ -29,7 +30,7 @@ class NewsLogic extends BaseLogic @@ -29,7 +30,7 @@ class NewsLogic extends BaseLogic
29 * @author :liyuhang 30 * @author :liyuhang
30 * @method 31 * @method
31 */ 32 */
32 - public function news_get_category_list() 33 + public function getCategoryList()
33 { 34 {
34 $this->map['status'] = 0; 35 $this->map['status'] = 0;
35 $this->map['project_id'] = $this->user['project_id']; 36 $this->map['project_id'] = $this->user['project_id'];
@@ -147,9 +148,13 @@ class NewsLogic extends BaseLogic @@ -147,9 +148,13 @@ class NewsLogic extends BaseLogic
147 public function newsInfo() 148 public function newsInfo()
148 { 149 {
149 $info = $this->model->read($this->param); 150 $info = $this->model->read($this->param);
  151 + if($info === false){
  152 + $this->fail('error');
  153 + }
  154 + //获取所有分类
  155 + $assCateModel = new AssociationCate();
  156 + $info['category_id'] = $assCateModel->where(['type_id'=>$info['id']])->pluck('category_id')->toArray();
150 $info['image_link'] = getImageUrl($info['image']); 157 $info['image_link'] = getImageUrl($info['image']);
151 - $newsCategoryLogic = new NewsCategoryLogic();  
152 - $info = $newsCategoryLogic->get_category_name($info);  
153 return $this->success($info); 158 return $this->success($info);
154 } 159 }
155 160
@@ -59,7 +59,7 @@ Route::middleware(['bloginauth'])->group(function () { @@ -59,7 +59,7 @@ Route::middleware(['bloginauth'])->group(function () {
59 Route::any('/category/categoryTopList', [\App\Http\Controllers\Bside\News\NewsCategoryController::class, 'categoryTopList'])->name('news_category_categoryTopList'); 59 Route::any('/category/categoryTopList', [\App\Http\Controllers\Bside\News\NewsCategoryController::class, 'categoryTopList'])->name('news_category_categoryTopList');
60 //新闻 60 //新闻
61 Route::any('/', [\App\Http\Controllers\Bside\News\NewsController::class, 'lists'])->name('news_category_lists'); 61 Route::any('/', [\App\Http\Controllers\Bside\News\NewsController::class, 'lists'])->name('news_category_lists');
62 - Route::any('/get_category_list', [\App\Http\Controllers\Bside\News\NewsController::class, 'get_category_list'])->name('news_get_category_list'); 62 + Route::any('/get_category_list', [\App\Http\Controllers\Bside\News\NewsController::class, 'getCategoryList'])->name('news_get_category_list');
63 Route::any('/add', [\App\Http\Controllers\Bside\News\NewsController::class, 'save'])->name('news_add'); 63 Route::any('/add', [\App\Http\Controllers\Bside\News\NewsController::class, 'save'])->name('news_add');
64 Route::any('/edit_seo', [\App\Http\Controllers\Bside\News\NewsController::class, 'edit_seo'])->name('news_edit_seo'); 64 Route::any('/edit_seo', [\App\Http\Controllers\Bside\News\NewsController::class, 'edit_seo'])->name('news_edit_seo');
65 Route::any('/info', [\App\Http\Controllers\Bside\News\NewsController::class, 'info'])->name('news_info'); 65 Route::any('/info', [\App\Http\Controllers\Bside\News\NewsController::class, 'info'])->name('news_info');