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

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

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

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

    /**
     * Notes:根据分类查询店铺列表
     * @return \support\Response
     * User: ZQ
     * Date: 2022/11/8
     */
    public function getCategorysShop()
    {
        $result         = ShopServer::getCategorysShop();
        return json_success($result, '成功');
    }

    /**
     * Notes:健康模块店铺列表
     * @return \support\Response
     * User: QJF
     * Date: 2022/11/08
     */
    public function getHealthyShopList()
    {
        $result         = ShopServer::getHealthyShopList();
        return json_success($result, '成功');
    }
    /**
     * Notes:添加运费模板
     * @return \support\Response
     * User: QJF
     * Date: 2022/9/28
     *
     */
    public function addShop()
    {
        $param     = $this->request->post();
        $this->validateCheck('medical\ShopValidate',
            [
                'shop_sort'             => $param['shop_sort'],
                'shop_category_id'      => $param['shop_category_id'],
                'shop_name'             => $param['shop_name'],
                'shop_logo'             => $param['shop_logo'],
                'shop_label'            => $param['shop_label'],
                'shop_business_hours'   => $param['shop_business_hours'],
                'shop_type'             => $param['shop_type'],
                'shop_address'          => $param['shop_address'],
                'shop_is_auto'          => $param['shop_is_auto'],
                'shop_lat'              => $param['shop_lat'],
                'shop_lng'              => $param['shop_lng'],
                'shop_phone'            => $param['shop_phone'],
                'shop_real_name'        => $param['shop_real_name'],
            ],
            'add');
        $result         = ShopServer::insertShop($param);
        return json_success($result, '添加成功');
    }
    /**
     * Notes:修改店铺
     * @return \support\Response
     * User: QJF
     * Date: 2022/9/30
     */
    public function updateShop()
    {
        $param      = $this->request->post();
        $this->validateCheck('medical\ShopValidate',
            [
                'shop_sort'             => $param['shop_sort'],
                'shop_category_id'      => $param['shop_category_id'],
                'shop_id'               => $param['shop_id'],
                'shop_name'             => $param['shop_name'],
                'shop_logo'             => $param['shop_logo'],
                'shop_label'            => $param['shop_label'],
                'shop_business_hours'   => $param['shop_business_hours'],
                'shop_type'             => $param['shop_type'],
                'shop_address'          => $param['shop_address'],
                'shop_is_auto'          => $param['shop_is_auto'],
                'shop_lat'              => $param['shop_lat'],
                'shop_lng'              => $param['shop_lng'],
                'shop_phone'            => $param['shop_phone'],
                'shop_real_name'        => $param['shop_real_name'],
            ], 'update');
         $result         = ShopServer::updateShop($param);
        return json_success($result, '修改成功');
    }

    /**
     * Notes:删除权益包
     * @return \support\Response
     * User: QJF
     * Date: 2022/9/23
     */
    public function delShop()
    {
        $shop_id = $this->request->get('shop_id');
        $this->validateCheck('medical\ShopValidate', ['shop_id' => $shop_id], 'del');
        $result         = ShopServer::delShop($shop_id);
        if ($result){
            return json_success($result, '删除成功');
        }else{
            throw new \Exception('删除失败！');
        }

    }
    /**
     * Notes:查看模板详情
     * @return \support\Response
     * User: QJF
     * Date: 2022/9/28
     */
    public function infoShop()
    {
        $shop_id = $this->request->get('shop_id');
        $this->validateCheck('medical\ShopValidate', ['shop_id' => $shop_id], 'info');
        $result         = ShopServer::infoShop($shop_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('失败！');
        }
    }
}
