<?php

namespace app\admin\controller\sys_manage;

use app\admin\validate\sys_manage\AdvValidate;
use app\controller\Curd;
use app\model\Adv;
use support\Request;
use support\Response;

class BannerController extends Curd
{
    public function __construct()
    {
        $this->model = new Adv();
        $this->validate = true;
        $this->validateClass = new AdvValidate();
    }

    /** 列表
     * @Desc
     * @Author Gorden
     * @Date 2024/3/5 10:00
     *
     * @param Request $request
     * @return Response
     * @throws \support\exception\BusinessException
     */
    public function select(Request $request): Response
    {
        [$where, $format, $limit, $field, $order] = $this->selectInput($request);
        $where['adv_category'] = 'banner';
        $order = $request->get('order', 'desc');
        $field = $field ?? 'adv_addtimes';
        $query = $this->doSelect($where, $field, $order);
        return $this->doFormat($query, $format, $limit);
    }

    /**
     * @Desc 插入数据处理
     * @Author Gorden
     * @Date 2024/3/27 10:24
     *
     * @param Request $request
     * @return array
     * @throws \support\exception\BusinessException
     */
    protected function insertInput(Request $request): array
    {
        $data = $this->inputFilter($request->post());
        $data['adv_category'] = 'banner';

        return $data;
    }
}