|
@@ -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
|
|