refactor: 修改文章及文章分类列表接口
This commit is contained in:
@@ -12,9 +12,9 @@ class Article
|
||||
public function index()
|
||||
{
|
||||
$param = request()->param([
|
||||
'title' => '',
|
||||
'category_id' => 0,
|
||||
'created_at' => '',
|
||||
'title',
|
||||
'category_id',
|
||||
'created_at',
|
||||
'page/d' => 1,
|
||||
'limit/d' => 10,
|
||||
]);
|
||||
@@ -33,11 +33,16 @@ class Article
|
||||
'seo_keywords',
|
||||
'seo_desc'
|
||||
])
|
||||
->category($param['category_id'])
|
||||
->where(function($query) use($param) {
|
||||
if (isset($param['category_id'])) {
|
||||
$query->category($param['category_id']);
|
||||
}
|
||||
})
|
||||
->withSearch(['title', 'created_at'], (function() use($param) {
|
||||
$condition = [
|
||||
'title' => $param['title'],
|
||||
];
|
||||
$condition = [];
|
||||
if (isset($param['title'])) {
|
||||
$condition['title'] = $param['title'];
|
||||
}
|
||||
if (isset($param['created_at'])) {
|
||||
$condition = [
|
||||
'created_at' => explode(',', $param['created_at'])
|
||||
@@ -46,8 +51,10 @@ class Article
|
||||
return $condition;
|
||||
})())
|
||||
->order('sort', 'desc')
|
||||
->page($param['page'], $param['limit'])
|
||||
->select();
|
||||
->paginate([
|
||||
'page' => $param['page'],
|
||||
'list_rows' => $param['limit'],
|
||||
]);
|
||||
|
||||
return success('获取成功', $article);
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ class ArticleCategory
|
||||
public function index()
|
||||
{
|
||||
$param = request()->param([
|
||||
'name' => '',
|
||||
'name',
|
||||
'page/d' => 1,
|
||||
'limit/d' => 10,
|
||||
]);
|
||||
@@ -24,10 +24,16 @@ class ArticleCategory
|
||||
'seo_keywords',
|
||||
'seo_desc',
|
||||
])
|
||||
->withSearch(['name'], ['name' => $param['name']])
|
||||
->where(function($query) use($param) {
|
||||
if (isset($param['name'])) {
|
||||
$query->withSearch(['name'], ['name' => $param['name']]);
|
||||
}
|
||||
})
|
||||
->order('sort', 'asc')
|
||||
->page($param['page'], $param['limit'])
|
||||
->select();
|
||||
->paginate([
|
||||
'page' => $param['page'],
|
||||
'list_rows' => $param['limit']
|
||||
]);
|
||||
|
||||
return success('获取成功', $category);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user