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

use app\admin\controller\BaseController;
use app\admin\model\MerchantShop;
use app\admin\model\MerchantShopCategory;
use app\admin\server\medical\MedicalCarePostageServer;
use app\admin\server\medical\MedicalCareProductServer;
use app\admin\server\medical\ShopCategoryServer;
use app\admin\server\medical\ShopServer;
use app\admin\server\package\PackageGoodsServer;

class ShopCategory extends BaseController
{
    /**
     * Notes:店铺分类列表
     * @return \support\Response
     * User: QJF
     * Date: 2022/11/03
     */
    public function getShopCategoryList()
    {
        [$page, $limit] = $this->getPage();
        $keywords = $this->request->get('keywords');
        $result         = ShopCategoryServer::getShopList($page, $limit,$keywords);
        return json_success($result, '成功');
    }

    /**
     * Notes:根据店铺id查询分类列表
     * @return \support\Response
     * User: ZQ
     * Date: 2022/11/08
     */
    public function getCategoryList()
    {
        $category_shop_id = $this->request->get('category_shop_id','');
        $result         = ShopCategoryServer::getCategoryList($category_shop_id);
        return json_success($result, '成功');
    }

    /**
     * Notes:添加店铺分类
     * @return \support\Response
     * User: QJF
     * Date: 2022/11/03
     *
     */
    public function addShopCategory()
    {
        $param     = $this->request->post();
        $admin_id = $this->request->admin_id;
        $this->validateCheck('medical\ShopCategoryValidate',
            [
                'category_pid'          => $param['category_pid'],
                'category_shop_id'      => $param['category_shop_id'],
                'category_name'         => $param['category_name'],
                'category_sort'         => $param['category_sort'],
            ],
            'add');
        $result         = ShopCategoryServer::insertShopCategory($param,$admin_id);
        return json_success($result, '添加成功');
    }
    /**
     * Notes:修改店铺分类
     * @return \support\Response
     * User: QJF
     * Date: 2022/9/30
     */
    public function updateShopCategory()
    {
        $param      = $this->request->post();
        $admin_id = $this->request->admin_id;
        $this->validateCheck('medical\ShopCategoryValidate',
            [
                'category_id'          => $param['category_id'],
                'category_pid'          => $param['category_pid'],
                'category_shop_id'      => $param['category_shop_id'],
                'category_name'         => $param['category_name'],
                'category_sort'         => $param['category_sort'],
            ], 'update');
         $result         = ShopCategoryServer::updateShopCategory($param,$admin_id);
        return json_success($result, '修改成功');
    }

    /**
     * Notes:删除店铺分类
     * @return \support\Response
     * User: QJF
     * Date: 2022/9/23
     */
    public function delShopCategory()
    {
        $category_id = $this->request->get('category_id');
        $admin_id = $this->request->admin_id;
        $this->validateCheck('medical\ShopCategoryValidate', ['category_id' => $category_id], 'del');
        $result         = ShopCategoryServer::delShopCategory($category_id,$admin_id);
        if ($result){
            return json_success($result, '删除成功');
        }else{
            throw new \Exception('删除失败！');
        }

    }
    /**
     * Notes:查看模板详情
     * @return \support\Response
     * User: QJF
     * Date: 2022/9/28
     */
    public function infoShopCategory()
    {
        $category_id = $this->request->get('category_id');
        $this->validateCheck('medical\ShopCategoryValidate', ['category_id' => $category_id], 'info');
        $result         = ShopCategoryServer::shopCategoryInfo($category_id);
        if ($result){
            return json_success($result, '获取成功');
        }else{
            throw new \Exception('获取失败！');
        }

    }
    //产品上下架
    public function showShop(){

        $shop_id = $this->request->get('shop_id');
        $shop_status= $this->request->get('shop_status');
        $this->validateCheck('medical\ShopValidate', ['shop_id' => $shop_id], 'del');
        $result         = ShopServer::showShop($shop_id,$shop_status);
        if ($result){
            return json_success($result, '成功');
        }else{
            throw new \Exception('失败！');
        }
    }
}
