request->input('limit', 10); $id = (int)$this->request->input('query_id'); $kitchenId = (int)$this->request->input('query_kitchen_id'); $list = $this->DepotModel ->where('is_del',DepotCode::IS_NO_DEL) ->when($id,function ($query) use ($id) { $query->where('id',$id); }) ->when($kitchenId,function ($query) use ($kitchenId) { $query->where('kitchen_id',$kitchenId); }) ->paginate($limit)->toArray(); return $this->return->success('success',$list); } /** * @return array */ public function add():array { $name = $this->request->input('name'); $kitchen_id = (int)$this->request->input('kitchen_id'); $info = $this->DepotModel->getInfoByName($name,$kitchen_id); if (!empty($info)) throw new ErrException('仓库已存在'); $depot = new Depot(); $depot->name = $name; $depot->city_id = $this->request->input('city_id'); $depot->kitchen_id = $kitchen_id; if (!$depot->save()) throw new ErrException('仓库添加失败'); return $this->return->success(); } /** * @return array */ public function edit(): array { $id = (int)$this->request->input('id'); $depotName = $this->request->input('name'); $kitchen_id = (int)$this->request->input('kitchen_id'); $info = $this->DepotModel->getInfoById($id); if (empty($info)) throw new ErrException('数据不存在'); $name = $this->DepotModel->getInfoByName($depotName,$kitchen_id); if (!empty($name)){ if ($name->id != $info->id && $info->kitchen_id == $kitchen_id) throw new ErrException('仓库已存在'); } $info->name = $depotName; if (!$info->save()) throw new ErrException('仓库修改失败'); return $this->return->success(); } /** * @return array */ public function delete(): array { $id = (int)$this->request->input('id'); $info = $this->DepotModel->getInfoById($id); if (empty($info)) throw new ErrException('仓库不存在'); $info->is_del = DepotCode::IS_DEL; if (!$info->save()) throw new ErrException('删除失败'); return $this->return->success(); } }