NewsCategoryController.php
4.0 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
namespace App\Http\Controllers\Bside\News;
use App\Enums\Common\Code;
use App\Http\Controllers\Bside\BaseController;
use App\Http\Logic\Bside\News\NewsCategoryLogic;
use App\Http\Requests\Bside\News\NewsCategoryRequest;
use App\Models\News\News as NewsModel;
use App\Models\News\NewsCategory as NewsCategoryModel;
use App\Models\RouteMap\RouteMap;
class NewsCategoryController extends BaseController
{
/**
* @name :新闻分类列表
* @author :liyuhang
* @method
*/
public function lists(NewsCategoryModel $newsCategory){
//搜索条件
$this->map['project_id'] = $this->user['project_id'];
$lists = $newsCategory->lists($this->map,$this->page,$this->row,$this->order,
['id','pid','name','num','alias','status','sort','remark','created_at','updated_at']);
if(!empty($lists['list'])){
$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;
}
}
$this->response('success',Code::SUCCESS,$lists);
}
/**
* @name :(添加/编辑时获取顶级分类)topList
* @author :lyh
* @method :post
* @time :2023/6/13 9:03
*/
public function categoryTopList(NewsCategoryLogic $newsCategoryLogic){
$list = $newsCategoryLogic->categoryTopList();
$this->response('success',Code::SUCCESS,$list);
}
/**
* @name :获取当前分类详情
* @author :liyuhang
* @method
*/
public function info(NewsCategoryLogic $newsCategoryLogic){
$this->request->validate([
'id'=>['required']
],[
'id.required' => 'ID不能为空'
]);
$info = $newsCategoryLogic->info_news_category();
$info['alias'] = RouteMap::getRoute(RouteMap::SOURCE_NEWS_CATE, $info['id'], $this->user['project_id']);
$info['url'] = $this->user['domain'] . RouteMap::PATH_NEWS_CATE . '/' . $info['alias'];
$this->response('success',Code::SUCCESS,$info);
}
/**
* @name :添加分类
* @author :liyuhang
* @method
*/
public function add(NewsCategoryRequest $request,NewsCategoryLogic $newsCategoryLogic){
$request->validated();
//添加时,验证分类上级分类是否有,有则更新到当前分类中,没有时直接添加
$newsCategoryLogic->add_news_category();
$this->response('success');
}
/**
* @name :编辑分类
* @author :liyuhang
* @method
*/
public function edit(NewsCategoryRequest $request,NewsCategoryLogic $newsCategoryLogic){
$request->validate([
'id'=>['required']
],[
'id.required' => 'ID不能为空'
]);
$newsCategoryLogic->edit_news_category();
$this->response('success');
}
/**
* @name :编辑状态/排序
* @author :liyuhang
* @method
*/
public function status(NewsCategoryLogic $newsCategoryLogic){
$this->request->validate([
'id'=>['required'],
],[
'id.required' => 'ID不能为空',
]);
$newsCategoryLogic->status_news_category();
$this->response('success');
}
/**
* @name :删除分类
* @author :liyuhang
* @method
*/
public function del(NewsCategoryLogic $newsCategoryLogic){
$this->request->validate([
'id'=>['required','array'],
],[
'id.required' => 'ID不能为空',
'id.array' => 'ID为数组',
]);
$newsCategoryLogic->del_news_category();
$this->response('success');
}
}