<?php
declare (strict_types = 1);

namespace app\index\controller;

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

/**
 * 关于我们控制器
 */
class AboutUs extends Common
{
    /**
     * 品牌故事
     */
    public function story()
    {  
        // 获取品牌故事banner
        $banners = SysBannerItemModel::hasWhere('banner', [
                'language_id'  => $this->lang_id,
                'unique_label' => 'BANNER_67ff632a5f7aa'
            ])
            ->type('image')
            ->enabled(true)
            ->visible(['id', 'title', 'title_txt_color', 'image', 'desc', 'desc_txt_color', 'link'])
            ->order(['sort' => 'asc', 'id' => 'desc'])
            ->select();
        View::assign('banners', $banners);

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

    /**
     * 品牌里程
     */
    public function mileage()
    {
        $achievement = [];
        $events      = [];
        $development = [];

        // 获取品牌里程banner
        $banner = SysBannerModel::with(['items' => function($query) {
                $query->where('status', '=', 1)->order(['sort' => 'asc', 'id' => 'desc']);
            }])
            ->uniqueLabel([
                'BANNER_67ff786dc9c8d',
                'BANNER_67ff7ef1354cf',
                'BANNER_67ff7f37a0b67',
            ])
            ->language($this->lang_id)
            ->enabled(true)
            ->select();
        if (!$banner->isEmpty()) {
            $banner_map = [];
            foreach ($banner as $v) {
                $banner_map[$v->unique_label] = $v;
            }
            $achievement = data_get($banner_map, 'BANNER_67ff786dc9c8d')?->items->toArray();
            $events      = data_get($banner_map, 'BANNER_67ff7ef1354cf')?->items->toArray();
            $development = data_get($banner_map, 'BANNER_67ff7f37a0b67')?->items->toArray();
        }
        View::assign('achievement', $achievement);
        View::assign('events', $events);
        View::assign('development', $development);

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