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

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

class Category extends BaseController
{

    /**
     * Notes:获取分类列表
     * @return \support\Response
     * User: ZQ
     * Date: 2022/9/30
     */
    public function getCategoryList()
    {
        $keywords = $this->request->get('keywords','');
        $result         = CategoryServer::getCategoryList($keywords);
        return json_success($result, '成功');
    }

    /**
     * Notes:修改分类
     * @return \support\Response
     * User: ZQ
     * Date: 2022/9/30
     */
    public function updateCategory()
    {
        $category_id      = $this->request->post('category_id');
        $category_name    = $this->request->post('category_name','');
        $category_pid     = $this->request->post('category_pid','');
        $category_type    = $this->request->post('category_type','');
        $category_icon    = $this->request->post('category_icon','');
        $category_open_type   = $this->request->post('category_open_type','');
        $category_open_url  = $this->request->post('category_open_url','');
        $category_sort    = $this->request->post('category_sort','');
        $category_recommend = $this->request->post('category_recommend');
        $this->validateCheck('category\CategoryValidate', ['category_id'=>$category_id], 'update');
        $result         = CategoryServer::updateCategory($category_id, $category_name, $category_pid, $category_type, $category_icon, $category_open_type, $category_open_url, $category_sort, $category_recommend);
        return json_success($result, '修改成功');

    }

    /**
     * Notes:删除分类
     * @return \support\Response
     * User: ZQ
     * Date: 2022/9/14
     */
    public function delCategory()
    {
        $category_id = $this->request->get('category_id');
        $this->validateCheck('category\CategoryValidate', ['category_id' => $category_id], 'info');
        $result         = CategoryServer::delCategory($category_id);

        return json_success($result, '删除成功');

    }

    /**
     * Notes:添加分类
     * @return \support\Response
     * User: ZQ
     * Date: 2022/9/30
     */
    public function addCategory()
    {
        $category_name    = $this->request->post('category_name');
        $category_pid     = $this->request->post('category_pid');
        $category_type    = $this->request->post('category_type');
        $category_icon    = $this->request->post('category_icon','');
        $category_open_type   = $this->request->post('category_open_type','');
        $category_open_url  = $this->request->post('category_open_url','');
        $category_sort    = $this->request->post('category_sort','');
        $category_recommend = $this->request->post('category_recommend');
        $this->validateCheck('category\CategoryValidate', ['category_name' => $category_name, 'category_pid' => $category_pid, 'category_type' => $category_type, 'category_open_type' => $category_open_type, 'category_recommend' => $category_recommend], 'create');
        $result         = CategoryServer::insertCategory($category_name, $category_pid, $category_type, $category_icon, $category_open_type, $category_open_url, $category_sort, $category_recommend);
        return json_success($result, '添加成功');
    }

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

    /*
     * Notes:角色三级菜单
     * @return \support\Response
     * User: ZQ
     * Date: 2022/9/15
     */
    public function categoryLevel()
    {
        $result         = CategoryServer::categoryLevel();
        return json_success($result, '成功');
    }

    /*
   * Notes:角色二级菜单
   * @return \support\Response
   * User: ZQ
   * Date: 2022/9/15
   */
    public function secondLevel()
    {
        $result         = CategoryServer::secondLevel();
        return json_success($result, '成功');
    }

    /**
     * Notes:修改菜单推荐状态
     * @return \support\Response
     * User: ZQ
     * Date: 2022/9/14
     */
    public function updateStatus()
    {
        $category_id      = $this->request->get('category_id');
        $category_recommend = $this->request->get('category_recommend');
        $this->validateCheck('category\CategoryValidate', ['category_id'=>$category_id], 'update');
        $result         = CategoryServer::updateStatus($category_id, $category_recommend);
        return json_success($result, '修改成功');

    }

    /**
     * Notes:菜单列表
     * @return \support\Response
     * User: yym
     * Date: 2022/9/21
     */
    public function getHomeCategoryList()
    {
        $admin_info = $this->request->admin_info;
        return json_success(CategoryServer::getHomeCategoryList($admin_info->toArray()));
    }
    /**
     * Notes:递归查询所有分类
     * @return \support\Response
     * User: QJF
     * Date: 2022/11/3
     */
    public function getLower()
    {
        return json_success(CategoryServer::getLower());
    }
}
