adminSectionModel->get(['id','pid','name','status','remark']); if (empty($all)) return $this->return->success('success',['list' => []]); $data = $this->getDbList($all->toArray()); return $this->return->success('success',['list' => $data]); } /** * @return array * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface * @throws RedisException */ public function add(): array { $model = new AdminSection(); $pid = (int)$this->request->input('pid',0); if ($pid > 0) $pidInfo = $this->adminSectionModel->getInfoById($pid); $model->name = $this->request->input('name'); $model->pid = $pid; $model->city_id = !empty($pidInfo) ? $pidInfo->city_id : $this->request->input('city_id',0); $model->remark = $this->request->input('remark'); $model->status = $this->request->input('status',1); if (!$model->save()) throw new ErrException('添加失败'); $this->sectionCache->delList(); return $this->return->success(); } /** * @return array * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface * @throws RedisException */ public function edit(): array { $id = (int)$this->request->input('id'); $info = $this->adminSectionModel->getInfoById($id); if (empty($info)) throw new ErrException('数据不存在'); $info->name = $this->request->input('name'); $info->pid = $this->request->input('pid',0); $info->city_id = $this->request->input('city_id',0); $info->remark = $this->request->input('remark'); $info->status = $this->request->input('status',1); if (!$info->save()) throw new ErrException('修改失败'); $this->sectionCache->delList(); return $this->return->success(); } /** * @return array * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface * @throws RedisException */ public function del(): array { $id = (int)$this->request->input('id'); $info = $this->adminSectionModel->getInfoById($id); if (empty($info)) throw new ErrException('数据不存在'); $children = $this->adminSectionModel->getInfoByPid($info->id); if (empty($children)) throw new ErrException('请先删除下级数据'); $this->adminUserModel->where('section_id',$id)->update(['section_id'=>0]); $info->delete(); $this->sectionCache->delList(); return $this->return->success(); } /** * @return array */ public function info(): array { $id = (int)$this->request->input('id'); $info = $this->adminSectionModel->getInfoById($id); if (empty($info)) throw new ErrException('数据不存在'); return $this->return->success('success',$info->toArray()); } /** * @return array * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface * @throws RedisException */ public function allList(): array { return $this->return->success('success',['list' => $this->sectionCache->getList()]); } }