refactor: 修改文章及文章分类列表接口

This commit is contained in:
2025-01-13 17:07:27 +08:00
parent 4aebf5edf2
commit 7cdfa007c6
2 changed files with 26 additions and 13 deletions

View File

@@ -12,9 +12,9 @@ class Article
public function index() public function index()
{ {
$param = request()->param([ $param = request()->param([
'title' => '', 'title',
'category_id' => 0, 'category_id',
'created_at' => '', 'created_at',
'page/d' => 1, 'page/d' => 1,
'limit/d' => 10, 'limit/d' => 10,
]); ]);
@@ -33,11 +33,16 @@ class Article
'seo_keywords', 'seo_keywords',
'seo_desc' '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) { ->withSearch(['title', 'created_at'], (function() use($param) {
$condition = [ $condition = [];
'title' => $param['title'], if (isset($param['title'])) {
]; $condition['title'] = $param['title'];
}
if (isset($param['created_at'])) { if (isset($param['created_at'])) {
$condition = [ $condition = [
'created_at' => explode(',', $param['created_at']) 'created_at' => explode(',', $param['created_at'])
@@ -46,8 +51,10 @@ class Article
return $condition; return $condition;
})()) })())
->order('sort', 'desc') ->order('sort', 'desc')
->page($param['page'], $param['limit']) ->paginate([
->select(); 'page' => $param['page'],
'list_rows' => $param['limit'],
]);
return success('获取成功', $article); return success('获取成功', $article);
} }

View File

@@ -12,7 +12,7 @@ class ArticleCategory
public function index() public function index()
{ {
$param = request()->param([ $param = request()->param([
'name' => '', 'name',
'page/d' => 1, 'page/d' => 1,
'limit/d' => 10, 'limit/d' => 10,
]); ]);
@@ -24,10 +24,16 @@ class ArticleCategory
'seo_keywords', 'seo_keywords',
'seo_desc', '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') ->order('sort', 'asc')
->page($param['page'], $param['limit']) ->paginate([
->select(); 'page' => $param['page'],
'list_rows' => $param['limit']
]);
return success('获取成功', $category); return success('获取成功', $category);
} }