81 lines
2.6 KiB
PHP
81 lines
2.6 KiB
PHP
<?php
|
|
namespace app\controller;
|
|
|
|
use app\model\{Article as MArticle, Category};
|
|
|
|
class Article extends Base
|
|
{
|
|
//详情
|
|
public function detail($id=0)
|
|
{
|
|
if($id <= 0){
|
|
return $this->error('错误页面');
|
|
}
|
|
$article = MArticle::getById($id);
|
|
if(empty($article)){
|
|
return $this->error('无此文章');
|
|
}
|
|
MArticle::updateById($id, ['views' => $article['views'] + 1]);
|
|
$category = Category::getById($article['category_id']);
|
|
$prev = MArticle::getPrevArticleByIdAndCategoryId($id, $article['category_id']);
|
|
$next = MArticle::getNextArticleByIdAndCategoryId($id, $article['category_id']);
|
|
|
|
$keywords = $article['seo_keywords'] ? $article['seo_keywords'] : $this->system['seo_keywords'];
|
|
$description = $article['seo_description'] ? $article['seo_description'] : $this->system['seo_description'];
|
|
$this->setSeo($article['title'], $keywords, $description);
|
|
$this->data['article'] = $article;
|
|
$this->data['category'] = $category;
|
|
$this->data['categoryId'] = $category['id'];
|
|
$this->data['prev'] = $prev;
|
|
$this->data['next'] = $next;
|
|
return $this->view($category['template_detail'] ?? '');
|
|
}
|
|
//列表页
|
|
public function index()
|
|
{
|
|
$categoryId = input('param.category_id/d', 0);
|
|
if($categoryId <= 0){
|
|
return $this->error('错误页面');
|
|
}
|
|
$category = Category::getById($categoryId);
|
|
if(empty($category)){
|
|
return $this->error('错误页面');
|
|
}
|
|
$childCategory = Category::getChildrenByParentId($categoryId);
|
|
$description = $category['description'] ? $category['description'] : $this->system['seo_description'];
|
|
$this->setSeo($category['title'], $this->system['seo_keywords'], $description);
|
|
$this->data['items'] = MArticle::getListPageByCategory($categoryId, $category['number'] ? $category['number'] : 20);
|
|
$this->data['category'] = $category;
|
|
$this->data['categoryId'] = $categoryId;
|
|
return $this->view($category['template_list'] ?? '');
|
|
}
|
|
|
|
//新闻列表
|
|
public function news($categoryId)
|
|
{
|
|
dump('新闻资讯');
|
|
dump($categoryId);
|
|
|
|
}
|
|
|
|
//新闻详情
|
|
public function newsDetail($newsId)
|
|
{
|
|
dump('新闻资讯详情');
|
|
dump($newsId);
|
|
}
|
|
|
|
// 产品列表
|
|
public function product($categoryId)
|
|
{
|
|
dump('产品列表');
|
|
dump($categoryId);
|
|
}
|
|
|
|
// 产品列表
|
|
public function productDetail($productId)
|
|
{
|
|
dump('产品详情');
|
|
dump($productId);
|
|
}
|
|
} |