123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- <?php
- namespace App\Services\Base;
- use App\Contracts\Repositories\Base\DepartmentRepository;
- use App\Repositories\Criteria\Base\DepartmentCriteria;
- use App\Repositories\Eloquent\Base\DepartmentRepositoryEloquent;
- use App\Repositories\Presenters\Base\DepartmentPresenter;
- use Illuminate\Http\Request;
- class DepartmentService
- {
- /**
- * @var DepartmentRepositoryEloquent
- */
- private $departmentRepository;
- /**
- * DepartmentService constructor.
- *
- * @param DepartmentRepositoryEloquent $departmentRepositoryEloquent
- */
- public function __construct(DepartmentRepositoryEloquent $departmentRepositoryEloquent)
- {
- $this->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->searchDepartmentsByPage();
- }
- /**
- * @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)
- {
- $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 $ids
- * @return mixed
- */
- public function handleBatchDelete($ids)
- {
- return $this->departmentRepository->whereIn('id', $ids)->delete();
- }
- /**
- * 选项
- * @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']);
- }
- /**
- * @param Request $request
- *
- * @return mixed
- * @throws \Prettus\Repository\Exceptions\RepositoryException
- */
- public function handleAll(Request $request)
- {
- $this->departmentRepository->pushCriteria(new DepartmentCriteria($request));
- $this->departmentRepository->setPresenter(DepartmentPresenter::class);
- return $this->departmentRepository->get();
- }
- }
|