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()
{
$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);
}