<?php
declare (strict_types = 1);

namespace app\index\controller;

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

/**
 * 问答中心控制器
 */
class Faq extends Common
{
    /**
     * 问答列表
     */
    public function index()
    {
        $param = request()->param([
            'page/d' => 1,
            'size/d' => 12
        ]);

        // 获取banner焦点图
        $banner = SysBannerItemModel::hasWhere('banner', [
                'language_id'  => $this->lang_id,
                'unique_label' => 'BANNER_67fa37f30e151',
                'at_platform'  => request()->from
            ])
            ->type('image')
            ->enabled()
            ->visible(['id', 'title', 'image', 'link'])
            ->find();
        View::assign('banner', $banner);

        // 获取问答列表
        $faq = FaqModel::field([
                'id',
                'image',
                'question',
                'answer',
            ])
            ->language($this->lang_id)
            ->order(['sort' => 'asc', 'id' => 'desc'])
            ->paginate([
                'list_rows' => $param['size'],
                'page'      => $param['page'],
            ]);
        View::assign('faq', $faq);

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