getList($this->request->param()); return $this->renderSuccess(compact('list')); } /** * 获取所有记录 * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function all() { $model = new UnitModel; $list = $model->getAll(); return $this->renderSuccess(compact('list')); } /** * 获取详情记录 * @param int $id * @return array */ public function detail(int $id) { $detail = UnitModel::detail($id); return $this->renderSuccess(compact('detail')); } /** * 添加 * @return array */ public function add() { // 新增记录 $model = new UnitModel; if ($model->add($this->postForm())) { return $this->renderSuccess('添加成功'); } return $this->renderError($model->getError() ?: '添加失败'); } /** * 编辑 * @param int $id * @return array */ public function edit(int $id) { // 详情 $model = UnitModel::detail($id); // 更新记录 if ($model->edit($this->postForm())) { return $this->renderSuccess('更新成功'); } return $this->renderError($model->getError() ?: '更新失败'); } /** * 删除 * @param int $id * @return array */ public function delete(int $id) { // 详情 $model = UnitModel::detail($id); if (!$model->delete()) { return $this->renderError($model->getError() ?: '删除失败'); } return $this->renderSuccess('删除成功'); } }