refactor: 文章详情页
This commit is contained in:
@@ -20,8 +20,9 @@ class Article extends Common
|
||||
$param = request()->param([
|
||||
'pid',
|
||||
'cid',
|
||||
'page/d' => 1,
|
||||
'size/d' => 12,
|
||||
'keywords' => null,
|
||||
'page/d' => 1,
|
||||
'size/d' => 12,
|
||||
]);
|
||||
|
||||
// 获取banner焦点图
|
||||
@@ -55,7 +56,10 @@ class Article extends Common
|
||||
'desc',
|
||||
'image'
|
||||
])
|
||||
->withSearch(['title'], ['title' => $param['keywords']??null])
|
||||
->category($param['cid']??$categorys[0]['id'])
|
||||
->where('release_time', '<=', date('Y-m-d H:i:s'))
|
||||
->order(['sort' => 'asc', 'release_time' => 'desc', 'id' => 'desc'])
|
||||
->paginate([
|
||||
'list_rows' => $param['size'],
|
||||
'page' => $param['page'],
|
||||
@@ -71,6 +75,29 @@ class Article extends Common
|
||||
*/
|
||||
public function detail()
|
||||
{
|
||||
$id = request()->param('id');
|
||||
$detail = ArticleModel::withoutField([
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'deleted_at'
|
||||
])
|
||||
->bypk($id)
|
||||
->find();
|
||||
View::assign('detail', $detail);
|
||||
|
||||
// 获取倒序或发布时间倒序3篇文章做为推荐文章
|
||||
$recommends = ArticleModel::field([
|
||||
'id',
|
||||
'title',
|
||||
'desc',
|
||||
'image'
|
||||
])
|
||||
->where('id', '<>', $id)
|
||||
->order(['release_time' => 'desc', 'id' => 'desc'])
|
||||
->limit(3)
|
||||
->select();
|
||||
View::assign('recommends', $recommends);
|
||||
|
||||
return View::fetch('detail');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user