departmentRepository = $departmentRepositoryEloquent; } /** * @param Request $request * * @return mixed * @throws \Prettus\Repository\Exceptions\RepositoryException */ public function handleList(Request $request) { $this->departmentRepository->pushCriteria(new DepartmentCriteria($request)); $this->departmentRepository->setPresenter(DepartmentPresenter::class); return $this->departmentRepository->searchDepartments(); } /** * @param $id * * @return \Illuminate\Database\Eloquent\Model */ public function handleProfile($id) { $this->departmentRepository->setPresenter(DepartmentPresenter::class); return $this->departmentRepository->searchDepartmentBy($id); } /** * @param array $data * * @return mixed * @throws \Prettus\Validator\Exceptions\ValidatorException */ public function handleStore($data) { $data['company_id'] = 0; if ($data['parent_id']) { $data['company_id'] = Department::byIdGetCompanyId($data['company_id']); } else { $admin = login_admin(); if ($admin && $admin['company_id']) $data['company_id'] = $admin['company_id']; } $department = $this->departmentRepository->create($data); return $department; } /** * @param array $data * * @return mixed * @throws \Prettus\Validator\Exceptions\ValidatorException */ public function handleUpdate($data) { $department = $this->departmentRepository->update($data, $data['id']); return $department; } /** * @param Request $request * * @return mixed * @throws \Prettus\Validator\Exceptions\ValidatorException */ public function handleDelete($id) { return $this->departmentRepository->delete($id); } /** * 选项数据 * @param Request $request * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator|\Illuminate\Support\Collection|mixed * @throws \Prettus\Repository\Exceptions\RepositoryException */ public function handleSelectOptions(Request $request) { $this->departmentRepository->pushCriteria(new DepartmentCriteria($request)); return $this->departmentRepository->all([ 'id', 'name', 'parent_id', 'sub_count', 'sort', ]); } }