<?php
namespace app\admin\controller\index;

use app\admin\controller\BaseController;
use app\admin\server\index\ConfigServer;

class Config extends BaseController
{
    /**
     * Notes:获取设置分类列表
     * @return \support\Response
     * User: yym
     * Date: 2022/10/10
     */
    public function getClassify()
    {
        return json_success(ConfigServer::getClassify(), '获取成功');
    }

    /**
     * Notes:设置分类添加
     * @return \support\Response
     * User: yym
     * Date: 2022/10/10
     */
    public function insertClassify()
    {
        $classify_pid    = $this->request->post('classify_pid', 0);//父级ID
        $classify_name   = $this->request->post('classify_name');//分类名称
        $classify_key    = $this->request->post('classify_key');//分类键名
        $classify_info   = $this->request->post('classify_info', '');//配置分类说明
        $classify_sort   = $this->request->post('classify_sort', 0);//排序
        $classify_status = $this->request->post('classify_status', 1);//状态 0禁用 1启用
        $admin_id        = $this->request->admin_id;
        $this->validateCheck('index\ConfigValidate', ['classify_name' => $classify_name, 'classify_key' => $classify_key], 'add');
        ConfigServer::insertClassify($classify_pid, $classify_name, $classify_key, $classify_info, $classify_sort, $classify_status, $admin_id);
        return json_success([], '操作成功');
    }

    /**
     * Notes:系统设置分类编辑
     * @return \support\Response
     * @throws \Exception
     * User: yym
     * Date: 2022/10/10
     */
    public function updateClassify()
    {
        $classify_id     = $this->request->post('classify_id');//分类编号
        $classify_pid    = $this->request->post('classify_pid', 0);//父级ID
        $classify_name   = $this->request->post('classify_name');//分类名称
        $classify_key    = $this->request->post('classify_key');//分类键名
        $classify_info   = $this->request->post('classify_info', '');//配置分类说明
        $classify_sort   = $this->request->post('classify_sort', 0);//排序
        $classify_status = $this->request->post('classify_status', 1);//状态 0禁用 1启用
        $admin_id        = $this->request->admin_id;
        $this->validateCheck('index\ConfigValidate', ['classify_id' => $classify_id, 'classify_name' => $classify_name, 'classify_key' => $classify_key], 'up');
        ConfigServer::updateClassify($classify_id, $classify_pid, $classify_name, $classify_key, $classify_info, $classify_sort, $classify_status, $admin_id);
        return json_success([], '操作成功');
    }

    /**
     * Notes:配置分类删除或编辑状态
     * @return \support\Response
     * @throws \Exception
     * User: yym
     * Date: 2022/10/10
     */
    public function delUpClassify()
    {
        $type        = $this->request->post('type', 0);//类型 0删除   1修改状态
        $classify_id = $this->request->post('classify_id');//分类编号
        $status      = $this->request->post('status', 0);//状态 0禁用 1启用
        $admin_id    = $this->request->admin_id;
        $this->validateCheck('index\ConfigValidate', ['classify_id' => $classify_id], 'del_up');
        ConfigServer::delUpClassify($classify_id, $type, $status, $admin_id);
        return json_success([], '操作成功');
    }

    /**
     * Notes:获取单个配置信息
     * @return \support\Response
     * User: yym
     * Date: 2022/10/10
     */
    public function getClassifyInfo()
    {
        $classify_id = $this->request->get('classify_id');//分类编号
        $this->validateCheck('index\ConfigValidate', ['classify_id' => $classify_id], 'del_up');
        return json_success(ConfigServer::getClassifyInfo($classify_id), '获取成功');
    }
}
