BlogCategoryController.php
5.3 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<?php
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\Requests\Bside\Blog\BlogCategoryRequest;
use App\Models\Blog\Blog as BlogModel;
use App\Models\Blog\BlogCategory as BlogCategoryModel;
use App\Models\RouteMap\RouteMap;
use App\Models\Template\BTemplate;
class BlogCategoryController extends BaseController
{
/**
* @name :博客分类列表
* @author :liyuhang
* @method
*/
public function lists(BlogCategoryModel $blogCategoryModel){
//搜索条件
$this->map['project_id'] = $this->user['project_id'];
$filed = ['id','pid','name','num','alias','status','sort','remark','created_at','updated_at'];
$lists = $blogCategoryModel->list($this->map,$this->order = ['sort','id'],$filed);
$data = [];
if(!empty($lists)){
$blogModel = new BlogModel();
$template_id = $this->getTemplateId(BTemplate::SOURCE_BLOG,BTemplate::IS_LIST);
foreach ($lists as $k => $v){
$v['num'] = $blogModel->formatQuery(['category_id'=>['like','%,' . $v['id'] . ',%']])->count();
$v['url'] = $this->user['domain'] . getRouteMap(RouteMap::SOURCE_BLOG_CATE,$v['id'],$this->user['is_upgrade']);
$v['is_renovation'] = $this->getIsRenovation(BTemplate::SOURCE_BLOG,BTemplate::IS_LIST,$template_id,$v['id']);
$lists[$k] = $v;
}
if(!isset($this->map['name'])){
$data = $this->getListSon($lists);
}else{
$data = $lists;
}
}
$this->response('success',Code::SUCCESS,$data);
}
/**
* @remark :无分页子集处理
* @name :getListSon
* @author :lyh
* @method :post
* @time :2023/8/17 11:12
*/
public function getListSon($list){
$data = array();
foreach ($list as $v){
$v = (array)$v;
if ($v['pid'] == 0) {
$v['sub'] = _get_child($v['id'], $list);
$data[] = $v;
}
}
return $data;
}
/**
* @name :(添加/编辑时获取顶级分类)topList
* @author :lyh
* @method :post
* @time :2023/6/13 9:03
*/
public function categoryTopList(BlogCategoryLogic $blogCategoryLogic){
$list = $blogCategoryLogic->categoryTopList();
$this->response('success',Code::SUCCESS,$list);
}
/**
* @name :获取当前分类详情
* @author :liyuhang
* @method
*/
public function info(BlogCategoryLogic $blogCategoryLogic){
$this->request->validate([
'id'=>['required']
],[
'id.required' => 'ID不能为空'
]);
$info = $blogCategoryLogic->info_blog_category();
$this->response('success',Code::SUCCESS,$info);
}
/**
* @remark :保存数据
* @name :save
* @author :lyh
* @method :post
* @time :2023/9/7 14:04
*/
public function save(BlogCategoryRequest $request,BlogCategoryLogic $blogCategoryLogic){
$request->validated();
$data = $blogCategoryLogic->categorySave();
$this->response('success',Code::SUCCESS,$data);
}
/**
* @name :编辑状态/与排序
* @author :liyuhang
* @method
*/
public function status(BlogCategoryLogic $blogCategoryLogic){
$this->request->validate([
'id'=>['required'],
],[
'id.required' => 'ID不能为空',
]);
$blogCategoryLogic->status_blog_category();
$this->response('success');
}
/**
* @remark :排序
* @name :sort
* @author :lyh
* @method :post
* @time :2023/9/26 17:40
*/
public function sort(BlogCategoryLogic $blogCategoryLogic){
$this->request->validate([
'id'=>'required',
'sort'=>'required'
],[
'id.required' => '产品ID不能为空',
'sort.required'=>'排序字段不能为空'
]);
$blogCategoryLogic->setSort();
$this->response('success');
}
/**
* @name :删除分类
* @author :liyuhang
* @method
*/
public function del(BlogCategoryLogic $blogCategoryLogic){
$this->request->validate([
'id'=>['required','array'],
],[
'id.required' => 'ID不能为空',
'id.array' => 'ID为数组',
]);
$blogCategoryLogic->delBlogCategory();
$this->response('success');
}
/**
* @remark :批量排序
* @name :allSort
* @author :lyh
* @method :post
* @time :2024/1/11 9:46
*/
public function allSort(BlogCategoryLogic $blogCategoryLogic){
$blogCategoryLogic->setAllSort();
$this->response('success');
}
/**
* @remark :复制博客分类
* @name :copyCategory
* @author :lyh
* @method :post
* @time :2024/5/9 9:14
*/
public function copyCategory(BlogCategoryLogic $logic){
$this->request->validate([
'id'=>'required',
],[
'id.required' => 'id不能为空',
]);
$data = $logic->copyCategory();
$this->response('success',Code::SUCCESS,$data);
}
}