123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- <?php
- namespace App\Services\School;
- use App\Repositories\Criteria\School\StudentCriteria;
- use App\Repositories\Eloquent\School\StudentRepositoryEloquent;
- use App\Repositories\Presenters\School\StudentPresenter;
- use Illuminate\Http\Request;
- class StudentService
- {
- /**
- * @var StudentRepositoryEloquent
- */
- private $studentRepository;
- /**
- * StudentService constructor.
- *
- * @param StudentRepositoryEloquent $studentRepositoryEloquent
- */
- public function __construct(StudentRepositoryEloquent $studentRepositoryEloquent)
- {
- $this->studentRepository = $studentRepositoryEloquent;
- }
- /**
- * @param Request $request
- *
- * @return mixed
- * @throws \Prettus\Repository\Exceptions\RepositoryException
- */
- public function handleList(Request $request)
- {
- $this->studentRepository->pushCriteria(new StudentCriteria($request));
- $this->studentRepository->setPresenter(StudentPresenter::class);
- return $this->studentRepository->searchStudentsByPage();
- }
- /**
- * @param $id
- *
- * @return \Illuminate\Database\Eloquent\Model
- */
- public function handleProfile($id)
- {
- $this->studentRepository->setPresenter(StudentPresenter::class);
- return $this->studentRepository->searchStudentBy($id);
- }
- /**
- * @param array $data
- *
- * @return mixed
- * @throws \Prettus\Validator\Exceptions\ValidatorException
- */
- public function handleStore($data)
- {
- $student = $this->studentRepository->create($data);
- return $student;
- }
- /**
- * @param array $data
- *
- * @return mixed
- * @throws \Prettus\Validator\Exceptions\ValidatorException
- */
- public function handleUpdate($data)
- {
- $student = $this->studentRepository->update($data, $data['id']);
- return $student;
- }
- /**
- * @param Request $request
- *
- * @return mixed
- * @throws \Prettus\Validator\Exceptions\ValidatorException
- */
- public function handleDelete($id)
- {
- return $this->studentRepository->delete($id);
- }
- /**
- * @param Request $request
- *
- * @return mixed
- * @throws \Prettus\Repository\Exceptions\RepositoryException
- */
- public function handleAll(Request $request)
- {
- $this->studentRepository->pushCriteria(new StudentCriteria($request));
- $this->studentRepository->setPresenter(StudentPresenter::class);
- return $this->studentRepository->get();
- }
- /**
- * @param Request $request
- *
- * @return mixed
- * @throws \Prettus\Repository\Exceptions\RepositoryException
- */
- public function handleIds(Request $request)
- {
- $this->studentRepository->pushCriteria(new StudentCriteria($request));
- return $this->studentRepository->pluck('id');
- }
- /**
- * 选项
- * @param Request $request
- * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator|\Illuminate\Support\Collection|mixed
- * @throws \Prettus\Repository\Exceptions\RepositoryException
- */
- public function handleSelectOptions(Request $request)
- {
- $this->studentRepository->pushCriteria(new StudentCriteria($request));
- return $this->studentRepository->all(['id', 'name', 'account']);
- }
- /**
- * 批量删除
- * @param $ids
- * @return mixed
- */
- public function handleBatchDelete($ids)
- {
- return $this->studentRepository->whereIn('id', $ids)->delete();
- }
- }
|