<?php
declare(strict_types=1);

namespace app\index\controller;

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

/**
 * 专题 - 电力品线控制器
 */
class TopicPowerProdline extends Common
{
    /**
     * 专题 - 电力品线首页
     */
    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_691e729f2428d',
                'BANNER_691e732e4ad69',
                'BANNER_691e752d2bbe2',
                'BANNER_691e75561c4d3',
                'BANNER_691e75ec9391c',
                'BANNER_691e7616545bf',
                'BANNER_691e763fc08f4',
                'BANNER_691e765a27eba',
                'BANNER_691e76b6af393',
            ])
            ->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;
            }
            // 焦点轮播图
            $focus_image = data_get($banners_map, 'BANNER_691e729f2428d')?->items->toArray();
            if (!empty($focus_image)) $data['focus_image'] = $focus_image;

            // 分类
            $category = data_get($banners_map, 'BANNER_691e732e4ad69')?->items->toArray();
            if (!empty($category)) $data['category'] = $category;

            // 为什么选择奥睿科相关数据
            $why_choose = data_get($banners_map, 'BANNER_691e752d2bbe2')?->items->toArray();
            if (!empty($why_choose)) $data['why_choose'] = $why_choose;

            // 差旅充
            $travel_charger = data_get($banners_map, 'BANNER_691e75561c4d3')?->items->toArray();
            if (!empty($travel_charger)) $data['travel_charger'] = $travel_charger;

            // 家居充
            $home_charger = data_get($banners_map, 'BANNER_691e75ec9391c')?->items->toArray();
            if (!empty($home_charger)) $data['home_charger'] = $home_charger;

            // 桌面充
            $desktop_charger = data_get($banners_map, 'BANNER_691e7616545bf')?->items->toArray();
            if (!empty($desktop_charger)) $data['desktop_charger'] = $desktop_charger;

            // 墙充
            $wall_charger = data_get($banners_map, 'BANNER_691e763fc08f4')?->items->toArray();
            if (!empty($wall_charger)) $data['wall_charger'] = $wall_charger;

            // 转换器
            $converter = data_get($banners_map, 'BANNER_691e765a27eba')?->items->toArray();
            if (!empty($converter)) $data['converter'] = $converter;

            // 底部介绍
            $footer_info = data_get($banners_map, 'BANNER_691e76b6af393')?->items->toArray();
            if (!empty($footer_info)) $data['footer_info'] = $footer_info;
        }
        View::assign('data', $data);

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