84 lines
		
	
	
		
			3.0 KiB
		
	
	
	
		
			PHP
		
	
	
			
		
		
	
	
			84 lines
		
	
	
		
			3.0 KiB
		
	
	
	
		
			PHP
		
	
	
<?php
 | 
						|
namespace app\controller;
 | 
						|
 | 
						|
use app\model\{Category, Block, Article, History, Model};
 | 
						|
 | 
						|
class Page extends Base
 | 
						|
{
 | 
						|
    // 默认单页页面
 | 
						|
    public function index($categoryId)
 | 
						|
    {
 | 
						|
        $category = Category::getById($categoryId);
 | 
						|
        if ($category) {
 | 
						|
            $description = $category['description'] ? $category['description'] : $this->system['seo_description'];
 | 
						|
            $this->setSeo($category['title'], $this->system['seo_keywords'], $description);
 | 
						|
        } else {
 | 
						|
            return $this->error('页面错误');
 | 
						|
        }
 | 
						|
 | 
						|
        $this->data['categoryId'] = $categoryId;
 | 
						|
        $this->data['category'] = $category;
 | 
						|
        $this->data['blocks'] = Block::getByCategoryId($categoryId);
 | 
						|
        $this->templateDetailAssign($category);
 | 
						|
 | 
						|
        return $this->view($category['template_detail']);
 | 
						|
    }
 | 
						|
 | 
						|
    private function templateDetailAssign($category)
 | 
						|
    {
 | 
						|
        $template = $category['template_detail'] ?? '';
 | 
						|
        $TopCId = Category::firstGradeById($category['id']);
 | 
						|
        if($TopCId == $category['id']) {
 | 
						|
            $topCategory = $category;
 | 
						|
        } else {
 | 
						|
            $topCategory = Category::getById($TopCId);
 | 
						|
        }
 | 
						|
        $childCategory = Category::getChildrenByParentId($category['id']);
 | 
						|
 | 
						|
        $this->data['topCategory'] = $topCategory;
 | 
						|
        $this->data['childCategory'] = $childCategory;
 | 
						|
        switch ($template) {
 | 
						|
            case 'about' :
 | 
						|
                $this->assignAbout($topCategory, $category, $childCategory);
 | 
						|
                break;
 | 
						|
            default :
 | 
						|
        }
 | 
						|
    }
 | 
						|
 | 
						|
    // 走进超宇
 | 
						|
    private function assignAbout($topCategory, $category, $childCategory)
 | 
						|
    {
 | 
						|
        if(empty($childCategory)) {
 | 
						|
            $childCategory = Category::getChildrenByParentId($topCategory['id']);
 | 
						|
        }
 | 
						|
        $honorTopCId = Category::$CIdList['honors_manage'] ?? 0;
 | 
						|
        $historyCId = Category::$CIdList['history_manage'] ?? 0;
 | 
						|
        $historyCate = Category::getById($historyCId);
 | 
						|
        $honors = [];
 | 
						|
        $blockCateIds = [];
 | 
						|
        $blocks = [];
 | 
						|
        if($honorTopCId) {
 | 
						|
            $honors = Category::getChildrenByParentId($honorTopCId);
 | 
						|
            foreach ($honors as &$honor) {
 | 
						|
                $honor['items'] = Article::getListByCategoryIds([$honor['id']], 20);
 | 
						|
            }
 | 
						|
            unset($honor);
 | 
						|
        }
 | 
						|
        foreach ($childCategory as $cate) {
 | 
						|
            if($cate['model_id'] == Model::PAGE) {
 | 
						|
                $blockCateIds[] = $cate['id'];
 | 
						|
            }
 | 
						|
        }
 | 
						|
        $blockList = Block::getByCategoryIds($blockCateIds);
 | 
						|
        $aboutChildrenFlip = array_flip(Category::$CIdList['about_children']);
 | 
						|
        foreach ($childCategory as $cate) {
 | 
						|
            $blocks[$aboutChildrenFlip[$cate['id']]] = $blockList[$cate['id']] ?? [];
 | 
						|
        }
 | 
						|
 | 
						|
        $this->data['blocks'] = $blocks;
 | 
						|
        $this->data['honors'] = $honors;
 | 
						|
        $this->data['historyList'] = History::getByCategoryId($historyCId, true, $historyCate['number'] ?? -1);
 | 
						|
        //dump($this->data['honors']);
 | 
						|
        //dump($this->data['historyList']);
 | 
						|
    }
 | 
						|
} |