<?php
namespace app\controller\en;

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'];
        // 关联产品分类
		$productsCenterCId = Category::$CIdList['products'];
		$this->data['productsCenter'] = Category::getById($productsCenterCId);
		$this->data['products'] = Category::getChildrenByParentId($productsCenterCId);
        // 关联新闻
        $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();
    }
}