106 lines
3.2 KiB
PHP
106 lines
3.2 KiB
PHP
<?php
|
|
|
|
namespace app\controller\manager;
|
|
|
|
use app\model\{Desk as MDesk, Hall, System, Log};
|
|
use app\validate\Desk as VDesk;
|
|
use think\exception\ValidateException;
|
|
|
|
/**
|
|
* 坐桌子管理
|
|
*/
|
|
class Desk extends Base
|
|
{
|
|
|
|
//列表
|
|
public function index()
|
|
{
|
|
$hallId = input('hall_id/d', 0);
|
|
$hall = Hall::getById($hallId);
|
|
if (empty($hall)) {
|
|
return $this->error("大厅不存在");
|
|
}
|
|
$keyword = input('param.keyword');
|
|
$list = MDesk::getList(20, $keyword);
|
|
$this->data['hall'] = $hall;
|
|
$this->data['hall_id'] = $hallId;
|
|
$this->data['list'] = $list;
|
|
$this->data['keyword'] = $keyword;
|
|
return $this->view();
|
|
}
|
|
|
|
//删除
|
|
public function del()
|
|
{
|
|
if ($this->request->isPost()) {
|
|
$id = input('post.id/d');
|
|
if (is_numeric($id) && $id > 0) {
|
|
$item = MDesk::getById($id);
|
|
if (!empty($item)) {
|
|
MDesk::destroy($id);
|
|
return $this->json();
|
|
}
|
|
return $this->json(3, '待删除信息不存在');
|
|
}
|
|
return $this->json(2, '参数错误,请核对之后再操作!');
|
|
}
|
|
return $this->json(1, '非法请求!');
|
|
}
|
|
|
|
|
|
//编辑
|
|
public function edit()
|
|
{
|
|
if ($this->request->isPost()) {
|
|
$item = input('post.item/a');
|
|
$id = input('post.id/d');
|
|
$desk = MDesk::getById($id);
|
|
if (empty($desk)) {
|
|
return $this->json(1, '该信息不存在!');
|
|
}
|
|
$repeat = MDesk::editRepeat($desk['id'], $desk['hall_id'], $item['number']);
|
|
if (!empty($repeat)) {
|
|
return $this->json(1, '桌号不可重复!');
|
|
}
|
|
try {
|
|
validate(VDesk::class)->check($item);
|
|
MDesk::updateById($id, $item);
|
|
return $this->json();
|
|
} catch (ValidateException $e) {
|
|
return $this->json(2, $e->getError());
|
|
}
|
|
} else {
|
|
$id = input('param.id');
|
|
$desk = MDesk::getById($id);
|
|
$this->data['desk_type'] = MDesk::$desk_type;
|
|
$this->data['item'] = $desk;
|
|
return $this->view();
|
|
}
|
|
}
|
|
|
|
//添加
|
|
public function add()
|
|
{
|
|
if ($this->request->isPost()) {
|
|
$item = input('post.item/a');
|
|
$repeat = MDesk::addRepeat($item['hall_id'], $item['number']);
|
|
if (!empty($repeat)) {
|
|
return $this->json(1, '桌号不可重复!');
|
|
}
|
|
try {
|
|
validate(VDesk::class)->check($item);
|
|
MDesk::create($item);
|
|
return $this->json();
|
|
} catch (ValidateException $e) {
|
|
return $this->json(2, $e->getError());
|
|
}
|
|
} else {
|
|
$this->data['hall_id'] = input('hall_id/d', 0);
|
|
$this->data['desk_type'] = MDesk::$desk_type;
|
|
$this->data['default_type'] = MDesk::$default_type;
|
|
return $this->view();
|
|
}
|
|
}
|
|
|
|
}
|