123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- <?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\Models\Base\Department;
- 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->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',
- ]);
- }
- }
|