<?php
namespace app\controller;

use app\model\{Category, Block, Article, Slide};

class Index extends Base
{
    public function index()
    {
        $category = Category::getIndex();
        $categoryId = $category['id'] ?? 0;
        $this->data['categoryId'] = $categoryId;
        $this->setSeo($this->system['seo_title'], $this->system['seo_keywords'], $this->system['seo_description']);
        $blocks = Block::getByCategoryId($categoryId);
        $blocks = Block::analysisBlock($blocks);
        $this->data['blocks'] = $blocks;
        // 轮播图
        $this->data['slides'] = Slide::getList();
        // 网络营销栏目ID
        $this->data['marketingCId'] = Category::$CIdList['marketing'];
        // 关联产品中心
        $productsCId = Category::$CIdList['products'];
        $productChildren = Category::getChildrenByParentId($productsCId);
        $productsCIds[] = $productsCId;
        foreach ($productChildren as $cate) {
            $productsCIds[] = $cate['id'];
        }
        $this->data['products'] = [
            'category' => Category::getById($productsCId),
            'items' => Article::getListByCategoryIds($productsCIds, 4, '', [], 1, ['create_time'=>'desc'])
        ];
        // 关联新闻
        $this->data['newsCenter'] =  Category::getById(Category::$CIdList['news']);
        $newsCIdList = [Category::$CIdList['news_children']['enterprise'], Category::$CIdList['news_children']['industry']];
        $newsList = Category::getListByIds($newsCIdList);
        foreach ($newsList as &$cate) {
            $cate['items'] = Article::getLatestByCategory($cate['id'], 4, 1);
        }
        unset($cate);
        $this->data['newsList'] = $newsList;
        return $this->view();
    }
}