86 lines
		
	
	
		
			3.4 KiB
		
	
	
	
		
			PHP
		
	
	
		
			Executable File
		
	
			
		
		
	
	
			86 lines
		
	
	
		
			3.4 KiB
		
	
	
	
		
			PHP
		
	
	
		
			Executable File
		
	
<?php
 | 
						|
 | 
						|
namespace app\controller;
 | 
						|
 | 
						|
use app\model\{Article as MArticle,
 | 
						|
    Category,
 | 
						|
    Model
 | 
						|
};
 | 
						|
use page\DxtcPageA;
 | 
						|
use think\Paginator;
 | 
						|
 | 
						|
class News extends Base
 | 
						|
{
 | 
						|
    public function index()
 | 
						|
    {
 | 
						|
        $keyword = input('keyword/s', '');
 | 
						|
        $categoryId = input("category_id", 0);
 | 
						|
        if (!empty($categoryId)) {
 | 
						|
            $category = Category::where('id', $categoryId)->find();
 | 
						|
 | 
						|
            $childrenCategory = Category::where('parent_id', $categoryId)->order('sort', 'asc')->select();
 | 
						|
            // 若访问的是二级列表 如总的层级 新闻动态-省市县行业政策-集团要问 访问的是省市县行业政策这一层级则直接获取下面的分类第一个
 | 
						|
            if (!$childrenCategory->isEmpty()) {
 | 
						|
                $category = $childrenCategory[0];
 | 
						|
            }
 | 
						|
 | 
						|
            $parentCategory = Category::where('id', $category['parent_id'])->find();
 | 
						|
        } else {
 | 
						|
            $parentCategory = Category::where('parent_id', Category::CATEGORY_NEWS)->order('sort asc')->find();
 | 
						|
            $category = Category::where('parent_id', $parentCategory['id'])->order('sort asc')->find();
 | 
						|
        }
 | 
						|
 | 
						|
        $categoryId = $category['id'];
 | 
						|
 | 
						|
        $categoryChildren = Category::where('parent_id', $parentCategory['id'])->order('sort asc')->field('id,title')->select();
 | 
						|
 | 
						|
        $description = $category['seo_description'] ?: $this->system['seo_description'];
 | 
						|
        $keywords = $category['seo_keywords'] ?: $this->system['seo_keywords'];
 | 
						|
        $title = $category['seo_title'] ?: $category['title'] . ' | ' . $this->system['seo_title'];
 | 
						|
        $this->setSeo($title, $keywords, $description);
 | 
						|
        $listSort = ['a.top' => 'desc', 'a.sort' => 'desc'];
 | 
						|
 | 
						|
        // 自定义分页驱动
 | 
						|
        app('think\App')->bind(Paginator::class, DxtcPageA::class);
 | 
						|
 | 
						|
        $items = MArticle::getList($categoryId, 6, $keyword, [], 1, $listSort, false);
 | 
						|
 | 
						|
        $this->data['items'] = MArticle::parseList($items);
 | 
						|
        $this->data['category'] = $category;
 | 
						|
        $this->data['parentCategory'] = $parentCategory;
 | 
						|
        $this->data['categoryChildren'] = $categoryChildren;
 | 
						|
        $this->data['categoryId'] = $categoryId;
 | 
						|
        $this->data['bodyClass'] = 'main';
 | 
						|
 | 
						|
        return $this->view($category['template_list'] ?? '');
 | 
						|
    }
 | 
						|
 | 
						|
    //详情
 | 
						|
    public function detail($id = 0)
 | 
						|
    {
 | 
						|
        if ($id <= 0) {
 | 
						|
            return $this->error('错误页面');
 | 
						|
        }
 | 
						|
        $article = MArticle::getById($id);
 | 
						|
        if (empty($article)) {
 | 
						|
            return $this->error('无此文章');
 | 
						|
        }
 | 
						|
 | 
						|
        $category = Category::where('id', $article['category_id'])->find();
 | 
						|
        $parentCategory = Category::where('id', $category['parent_id'])->find();
 | 
						|
 | 
						|
        $categoryChildren = Category::where('parent_id', $parentCategory['id'])->order('sort asc')->field('id,title')->select();
 | 
						|
 | 
						|
        $description = $article['seo_description'] ?: $this->system['seo_description'];
 | 
						|
        $keywords = $article['seo_keywords'] ?: $this->system['seo_keywords'];
 | 
						|
        $title = $article['seo_title'] ?: $article['title'] . ' | ' . $this->system['seo_title'];
 | 
						|
 | 
						|
        $this->setSeo($title, $keywords, $description);
 | 
						|
        $this->data['item'] = MArticle::parseInfo($article);
 | 
						|
        $this->data['category'] = $category;
 | 
						|
        $this->data['parentCategory'] = $parentCategory;
 | 
						|
        $this->data['categoryChildren'] = $categoryChildren;
 | 
						|
        $this->data['categoryId'] = $category['id'];
 | 
						|
        return $this->view();
 | 
						|
    }
 | 
						|
} |