<?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 introduction()
    {
        $focus_image = [];
        $why         = [];
        $service     = [];
        $difference  = [];
        // 获取品牌介绍banner
        $banner = SysBannerModel::with(['items' => function($query) {
                $query->withoutField(['status', 'created_at', 'updated_at', 'deleted_at'])
                    ->where('status', '=', 1)
                    ->order(['sort' => 'asc', 'id' => 'desc']);
            }])
            ->atPlatform(request()->from)
            ->uniqueLabel([
                "BANNER_680744b1d0000",
                "BANNER_680744e7cacb3",
                "BANNER_680744fd0998d",
                "BANNER_68074513b5d20",
            ])
            ->language($this->lang_id)
            ->enabled(true)
            ->select();
        if (!$banner->isEmpty()) {
            $banner_map = [];
            foreach ($banner as $v) {
                $banner_map[$v->unique_label] = $v;
            }
            $focus_image = data_get($banner_map, 'BANNER_680744b1d0000')?->items->first()?->toArray();
            $why         = data_get($banner_map, 'BANNER_680744e7cacb3')?->items->toArray();
            $service     = data_get($banner_map, 'BANNER_680744fd0998d')?->items->chunk(4)?->toArray();
            $difference  = data_get($banner_map, 'BANNER_68074513b5d20')?->items->chunk(4)?->toArray();
        }
        View::assign('focus_image', $focus_image);
        View::assign('why', $why);
        View::assign('service', $service);
        View::assign('difference', $difference);

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

    /**
     * 品牌故事
     */
    public function story()
    {  
        // 获取品牌故事banner
        $banners = SysBannerItemModel::hasWhere('banner', [
                'language_id'  => $this->lang_id,
                'unique_label' => 'BANNER_67ff632a5f7aa',
                'at_platform'  => request()->from,
            ])
            ->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']);
            }])
            ->atPlatform(request()->from)
            ->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');
    }

    /**
     * 文化介绍
     */
    public function culture()
    {
        $focus_image = [];
        $culture     = [];
        // 获取文化介绍banner
        $banner = SysBannerModel::with(['items' => function($query) {
                $query->withoutField(['status', 'created_at', 'updated_at', 'deleted_at'])
                    ->where('status', '=', 1)
                    ->order(['sort' => 'asc', 'id' => 'desc']);
            }])
            ->atPlatform(request()->from)
            ->uniqueLabel([
                "BANNER_68075a636e648",
                "BANNER_68075bf4dd0f5",
            ])
            ->language($this->lang_id)
            ->enabled(true)
            ->select();
        if (!$banner->isEmpty()) {
            $banner_map = [];
            foreach ($banner as $v) {
                $banner_map[$v->unique_label] = $v;
            }
            $focus_image = data_get($banner_map, 'BANNER_68075a636e648')?->items->first()?->toArray();
            $culture     = data_get($banner_map, 'BANNER_68075bf4dd0f5')?->items->toArray();
        }
        View::assign('focus_image', $focus_image);
        View::assign('culture', $culture);

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

    /**
     * 售后政策
     */
    public function policy()
    {
        $policy = [];
        // 获取售后政策banner
        $banner = SysBannerModel::with(['items' => function($query) {
                $query->withoutField(['status', 'created_at', 'updated_at', 'deleted_at'])
                    ->where('status', '=', 1)
                    ->order(['sort' => 'asc', 'id' => 'desc']);
            }])
            ->atPlatform(request()->from)
            ->uniqueLabel([
                "BANNER_6806f5f19c3d6",
                "BANNER_6806f609b9fe9",
                "BANNER_6806f6315a699",
                "BANNER_6806f65c90eb6",
                "BANNER_6806f6736bb71",
                "BANNER_6806f684d4558",
                "BANNER_6806f69d81bd0",
            ])
            ->language($this->lang_id)
            ->enabled(true)
            ->select();
        if (!$banner->isEmpty()) {
            $banner_map = [];
            foreach ($banner as $v) {
                $banner_map[$v->unique_label] = $v;
            }
            $policy['focus_image'] = data_get($banner_map, 'BANNER_6806f5f19c3d6')?->items->first()?->toArray();
            $policy['banner_1']    = data_get($banner_map, 'BANNER_6806f609b9fe9')?->items->toArray();
            $policy['banner_2']    = data_get($banner_map, 'BANNER_6806f6315a699')?->items->toArray();
            $policy['banner_3']    = data_get($banner_map, 'BANNER_6806f65c90eb6')?->items->toArray();
            $policy['banner_4']    = data_get($banner_map, 'BANNER_6806f6736bb71')?->items->toArray();
            $policy['banner_5']    = data_get($banner_map, 'BANNER_6806f684d4558')?->items->toArray();
            $policy['banner_6']    = data_get($banner_map, 'BANNER_6806f69d81bd0')?->items->toArray();
        }
        View::assign('policy', $policy);

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