<?php
declare (strict_types = 1);

namespace app\index\controller;

use app\index\model\SysBannerModel;
use think\facade\View;

/**
 * 专题 - SSD
 */
class TopicSsd extends Common
{
    /**
     * 专题 - SSD首页
     */
    public function index()
    {
        $banners = SysBannerModel::with([
                'items' => function ($query) {
                    $query->withoutField(['sort', 'created_at', 'updated_at', 'deleted_at'])
                        ->order(['sort' => 'asc', 'id' => 'desc'])
                        ->enabled(true);
                }
            ])
            ->atPlatform(request()->from)
            ->uniqueLabel([
                'BANNER_69faaf8582967', // 专题 - 闪存（SSD）首页 - 焦点图
                'BANNER_69fab1bed8f71', // 专题 - 闪存（SSD）首页 - 产品
            ])
            ->language($this->lang_id)
            ->enabled(true)
            ->order(['sort' => 'asc', 'id' => 'desc'])
            ->select();

        $data = [];
        if (!$banners->isEmpty()) {
            $banners_map = [];
            foreach ($banners as $banner) {
                $banners_map[$banner->unique_label] = $banner;
            }

            // 焦点图轮播图
            $data['top_focus_images'] = data_get($banners_map, 'BANNER_69faaf8582967')?->items->toArray();
            // 产品
            $data['products'] = data_get($banners_map, 'BANNER_69fab1bed8f71')?->items->toArray();
        }
        View::assign('data', $data);

        return View::fetch('index');
    }
}
