This repository has been archived on 2024-07-11. You can view files and clone it, but cannot push or open issues or pull requests.
yoshop/source/application/store/controller/Shop.php
2020-04-25 22:20:29 +08:00

90 lines
2.1 KiB
PHP

<?php
namespace app\store\controller;
use app\store\model\store\Shop as ShopModel;
/**
* 门店管理
* Class Shop
* @package app\store\controller\store
*/
class Shop extends Controller
{
/**
* 门店列表
* @return mixed
* @throws \think\exception\DbException
*/
public function index()
{
$model = new ShopModel;
$list = $model->getList();
return $this->fetch('index', compact('list'));
}
/**
* 腾讯地图坐标选取器
* @return mixed
*/
public function getpoint()
{
$this->view->engine->layout(false);
return $this->fetch('getpoint');
}
/**
* 添加门店
* @return array|bool|mixed
* @throws \Exception
*/
public function add()
{
$model = new ShopModel;
if (!$this->request->isAjax()) {
return $this->fetch('add');
}
// 新增记录
if ($model->add($this->postData('shop'))) {
return $this->renderSuccess('添加成功', url('shop/index'));
}
return $this->renderError($model->getError() ?: '添加失败');
}
/**
* 编辑门店
* @param $shop_id
* @return array|bool|mixed
* @throws \think\exception\DbException
*/
public function edit($shop_id)
{
// 门店详情
$model = ShopModel::detail($shop_id);
if (!$this->request->isAjax()) {
return $this->fetch('edit', compact('model'));
}
// 新增记录
if ($model->edit($this->postData('shop'))) {
return $this->renderSuccess('更新成功', url('shop/index'));
}
return $this->renderError($model->getError() ?: '更新失败');
}
/**
* 删除门店
* @param $shop_id
* @return array
* @throws \think\exception\DbException
*/
public function delete($shop_id)
{
// 门店详情
$model = ShopModel::detail($shop_id);
if (!$model->setDelete()) {
return $this->renderError($model->getError() ?: '删除失败');
}
return $this->renderSuccess('删除成功');
}
}