diff --git a/app/index/controller/Article.php b/app/index/controller/Article.php index 6d7d85b7..52cfadb4 100644 --- a/app/index/controller/Article.php +++ b/app/index/controller/Article.php @@ -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'); } } diff --git a/app/index/lang/en-us.php b/app/index/lang/en-us.php index 75fa39c3..81f3cb94 100644 --- a/app/index/lang/en-us.php +++ b/app/index/lang/en-us.php @@ -21,5 +21,15 @@ return [ 'faq' => 'FAQ', 'faq_short_desc' => 'What are you most concerned about', 'faq_desc' => 'Our customer support is available Manday to Friday 9am600pmAverage arswer time 24h', + ], + 'article' => [ + 'detail_share' => 'SHARE', + 'detail_leave_reply' => 'Leave a Reply', + 'detail_leave_reply_name' => 'Name', + 'detail_leave_reply_email' => 'Email', + 'detail_leave_reply_email_tip' => 'Your email address will not be pulished.', + 'detail_leave_reply_comment' => 'Comment', + 'detail_leave_reply_submit' => 'POST COMMENT', + 'detail_recommend' => 'Recommended for you', ] ]; \ No newline at end of file diff --git a/app/index/lang/zh-cn.php b/app/index/lang/zh-cn.php index 3ad53f3b..14e93584 100644 --- a/app/index/lang/zh-cn.php +++ b/app/index/lang/zh-cn.php @@ -21,5 +21,15 @@ return [ 'faq' => '常见问题', 'faq_short_desc' => '回答您最关心的问题', 'faq_desc' => '客服团队的工作时间:周一到周五,早9点到晚6点 平均应答时间:24小时内', + ], + 'article' => [ + 'detail_share' => '分享', + 'detail_leave_reply' => '留言', + 'detail_leave_reply_name' => '名称', + 'detail_leave_reply_email' => '电子邮箱', + 'detail_leave_reply_email_tip' => '您的电子邮件地址不会被公开', + 'detail_leave_reply_comment' => '留言', + 'detail_leave_reply_submit' => '提交留言', + 'detail_recommend' => '你可能还喜欢', ] ]; \ No newline at end of file diff --git a/app/index/model/ArticleModel.php b/app/index/model/ArticleModel.php index 8903d51f..03b173da 100644 --- a/app/index/model/ArticleModel.php +++ b/app/index/model/ArticleModel.php @@ -20,18 +20,25 @@ class ArticleModel extends ArticleBaseModel // 语言范围查询 public function scopeLanguage($query, $language) { - return $query->where('language_id', '=', $language); + $query->where('language_id', '=', $language); } // 首页推荐状态范围查询 public function scopeRecommend($query, bool $stat = true) { - return $query->where('recommend', '=', (int)$stat); + $query->where('recommend', '=', (int)$stat); } // 文章分类范围查询 public function scopeCategory($query, $category) { - return $query->where('category_id', '=', $category); + $query->where('category_id', '=', $category); + } + + // 文章标题搜索器 + public function searchTitleAttr($query, $value) + { + if (is_null($value)) return; + $query->where('title', 'like', "%$value%"); } } diff --git a/app/index/view/article/detail.html b/app/index/view/article/detail.html new file mode 100644 index 00000000..ce450117 --- /dev/null +++ b/app/index/view/article/detail.html @@ -0,0 +1,84 @@ +{extend name="public/base" /} +{block name="title"} + {notempty name="detail.seo_title"}
{$detail.desc}
+{:lang('article.detail_recommend')}
+![]()
{$vo.title}
+ +