<?php

namespace plugin\admin\app\controller;

use support\Request;
use support\Response;
use plugin\admin\app\model\ArticleType;
use plugin\admin\app\controller\Crud;
use support\exception\BusinessException;

/**
 * 文章分类 
 */
class ArticleTypeController extends Crud
{
    /**
     * @var ArticleType
     */
    protected $model = null;

    /**
     * 构造函数
     * @return void
     */
    public function __construct()
    {
        $this->model = new ArticleType;
    }

    /**
     * 浏览
     * @return Response
     */
    public function index(): Response
    {
        return view('article-type/index');
    }

    /**
     * 插入
     * @param Request $request
     * @return Response
     * @throws BusinessException
     */
    public function insert(Request $request): Response
    {
        if ($request->method() === 'POST') {
            return parent::insert($request);
        }
        return view('article-type/insert');
    }

    /**
     * 更新
     * @param Request $request
     * @return Response
     * @throws BusinessException
     */
    public function update(Request $request): Response
    {
        if ($request->method() === 'POST') {
            return parent::update($request);
        }
        return view('article-type/update');
    }

    /** 文章分类
     * @param Request $request
     * @return Response
     */
    public function addselect(Request $request): Response
    {
        return json(['code' => 0, 'data' => ArticleType::query()->where('state',1)->selectRaw('id as value,name')->get(), 'msg' => 'ok']);
    }

}
