// +---------------------------------------------------------------------- namespace app\teahouse\controller; use app\teahouse\model\LockModel; use cmf\controller\AdminBaseController; class AdminLockController extends AdminBaseController { public function index() { $param = $this->request->param(); //搜索条件 $where = []; if (!empty($param['keyword'])) { $where[] = ['name', 'like', "%{$param['keyword']}%"]; } if (!empty($param['is_show'])) { $where[] = ['is_show', '=', $param['is_show']]; } $list = LockModel::where($where) ->append(['is_show_text']) ->paginate(10, false, ['query' => $param]); $this->assign('is_show', isset($param['is_show']) ? $param['is_show'] : 0); $this->assign('keyword', isset($param['keyword']) ? $param['keyword'] : ''); $this->assign('list', $list->items()); $this->assign('page', $list->render()); return $this->fetch(); } public function add() { return $this->fetch(); } public function addPost() { if ($this->request->isPost()) { $data = $this->request->post(); LockModel::create($data); $this->success('添加成功!', url('index')); } } public function edit() { $id = $this->request->param('id', 0, 'intval'); $info = LockModel::get($id); $this->assign('info', $info); return $this->fetch(); } public function editPost() { if ($this->request->isPost()) { $data = $this->request->post(); LockModel::update($data, ['id' => $data['id']]); $this->success('编辑成功!', url('index')); } } public function delete() { $id = $this->request->param('id', 0, 'intval'); LockModel::destroy($id); $this->success('删除成功'); } }