<?php

use App\Base\Base;
use App\Services\shop\ShopService;
use App\Exception\custom\ShopException;
class ShopController extends Base
{
    
    /**
     * 创建店铺
     *
     */
    public function add_shopAction()
    {
    	$params = $this->params;
        $shop = ShopService::addShop($params);
        if (!empty($shop)) {
        	$this->success();
        }else{
            throw new ShopException(['cus'=>5]);
        }
    }
    
    /**
     * 门店列表
     *
     */
    public function get_shop_listAction()
    {
        $params = $this->params;
        $subShopList = ShopService::getShopList($params);
        $this->success(['result' => $subShopList]);
    }

    /**
     * 店铺编辑接口
     *
     */
    public function update_shopAction()
    {
        $params = $this->params;
        $where['sub_shop_id'] = !empty($params['sub_shop_id']) ? $params['sub_shop_id'] : '';
        $subShopList = ShopService::updateShop($params,$where);
        $this->success();
    }

    /**
     * 获取数据
     *
     */
    public function get_shop_infoAction()
    {
        $params = $this->params;
        if (!empty($params['sub_shop_id'])) {
           $param['sub_shop_id'] = !empty($params['sub_shop_id']) ? $params['sub_shop_id'] : '';
        }

        if (!empty($params['shop_id'])) {
           $param['shop_id'] = !empty($params['shop_id']) ? $params['shop_id'] : '';
        }

        if (empty($params)) {
            $this->success(['result' => []]);
        }
        
        $subShopList = ShopService::getShopInfo($param);
        $this->success(['result' => $subShopList]);
    }

    /**
     * 后台门店列表
     *
     */
    public function shop_listAction()
    {
        $params = $this->params;
        $subShopList = ShopService::opShopList($params);
        $this->success($subShopList);
    }

 


}