1 line
2.2 KiB
PHP
1 line
2.2 KiB
PHP
<?php
|
|
namespace app\store\controller\food\shop;
|
|
use app\store\controller\food\Controller;
|
|
use app\store\model\food\Qrcode as QrcodeModel;
|
|
use app\store\model\food\Shop as ShopModel;
|
|
use app\store\model\food\Table as TableModel;
|
|
use think\facade\View;
|
|
/**
|
|
* 二维码控制器
|
|
*/
|
|
class Qrcode extends Controller
|
|
{
|
|
/**
|
|
* 列表
|
|
*/
|
|
public function index()
|
|
{
|
|
$model = new QrcodeModel;
|
|
$list = $model->getList();
|
|
return View::fetch('index', compact('list'));
|
|
}
|
|
|
|
/**
|
|
* 添加
|
|
*/
|
|
public function add()
|
|
{
|
|
if ($this->request->isPost()) {
|
|
$model = new QrcodeModel;
|
|
if ($model->add($this->postData('data'))) {
|
|
return $this->renderSuccess('添加成功', url('food.shop.qrcode/index'));
|
|
}
|
|
$error = $model->getError() ?: '添加失败';
|
|
return $this->renderError($error);
|
|
}
|
|
return redirect(url('food.shop.qrcode/index'));
|
|
}
|
|
/**
|
|
* 编辑
|
|
*/
|
|
public function edit($id)
|
|
{
|
|
// 详情
|
|
$model = QrcodeModel::detail($id);
|
|
if (!$this->request->isAjax()) {
|
|
$shopModel = new ShopModel;
|
|
$shop = $shopModel->getList(false);//获取门店列表
|
|
$table = [];
|
|
//获取门店餐桌列表
|
|
for($n=0;$n<sizeof($shop);$n++){
|
|
$tableModel = new TableModel;
|
|
$table[$shop[$n]['shop_id']] = $tableModel->getList($shop[$n]['shop_id']);
|
|
}
|
|
return View::fetch('edit', compact('model','shop','table'));
|
|
}
|
|
// 更新记录
|
|
if ($model->edit($this->postData('data'))) {
|
|
return $this->renderSuccess('操作成功', url('food.shop.qrcode/index'));
|
|
}
|
|
$error = $model->getError() ?: '操作失败';
|
|
return $this->renderError($error);
|
|
}
|
|
/**
|
|
* 删除
|
|
*/
|
|
public function delete($id)
|
|
{
|
|
$model = QrcodeModel::get($id);
|
|
if($model->remove()) {
|
|
return $this->renderSuccess('删除成功');
|
|
}
|
|
$error = $model->getError() ?: '删除失败';
|
|
return $this->renderError($error);
|
|
}
|
|
} |