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

use app\admin\controller\BaseController;
use app\admin\server\intelligence\CategoryServer;

class Category extends BaseController
{

    /**
     * Notes:获取智能产品分类列表
     * @return \support\Response
     * User: ZQ
     * Date: 2022/9/19
     */
    public function getCategoryList()
    {
        [$page, $limit] = $this->getPage();
        $keywords = $this->request->get('keywords');
        $result         = CategoryServer::getCategoryList($page, $limit, $keywords);
        return json_success($result, '成功');
    }

    /**
     * Notes:获取所有智能产品分类
     * @return \support\Response
     * User: ZQ
     * Date: 2022/9/19
     */
    public function getCategoryAll()
    {
        $type = $this->request->get('type');  //1:所有；2：1级
        $result         = CategoryServer::getCategoryAll($type);
        return json_success($result, '成功');
    }

    /**
     * Notes:修改智能产品分类
     * @return \support\Response
     * User: ZQ
     * Date: 2022/9/13
     */
    public function updateCategory()
    {
        $category_id      = $this->request->post('category_id');
        $category_name   = $this->request->post('category_name');
        $category_pid   = $this->request->post('category_pid');
        $this->validateCheck('intelligence\CategoryValidate', ['category_id' => $category_id], 'update');
        $result       = CategoryServer::updateCategory($category_id, $category_name, $category_pid);
        return json_success($result, '修改成功');

    }

    /**
     * Notes:删除智能产品分类
     * @return \support\Response
     * User: ZQ
     * Date: 2022/9/119
     */
    public function delCategory()
    {
        $category_id = $this->request->get('category_id');
        $this->validateCheck('intelligence\CategoryValidate', ['category_id' => $category_id], 'info');
        $result         = CategoryServer::delCategory($category_id);
        if ($result){
            return json_success($result, '删除成功');
        }else{
            throw new \Exception('删除失败！');
        }

    }

    /**
     * Notes:添加智能产品
     * @return \support\Response
     * User: ZQ
     * Date: 2022/9/19
     */
    public function addCategory()
    {
        $category_id = $this->request->post('category_id');
        $category_name         = $this->request->post('category_name');
        $category_pid      = $this->request->post('category_pid');
        $this->validateCheck('intelligence\CategoryValidate', ['category_id' => $category_id, 'category_name' => $category_name, 'category_pid' => $category_pid], 'create');
        $result               = CategoryServer::insertCategory($category_name, $category_pid);
        return json_success($result, '添加成功');
    }

    /**
     * Notes:查询智能产品分类详情
     * @return \support\Response
     * User: ZQ
     * Date: 2022/9/22
     */
    public function categoryInfo()
    {
        $category_id = $this->request->get('category_id');
        $this->validateCheck('intelligence\CategoryValidate', ['category_id' => $category_id], 'info');
        $result         = CategoryServer::categoryInfo($category_id);
        return json_success($result, '成功');
    }

}
