TeacherService.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. namespace App\Services\School;
  3. use App\Repositories\Criteria\School\TeacherCriteria;
  4. use App\Repositories\Eloquent\School\TeacherRepositoryEloquent;
  5. use App\Repositories\Presenters\School\TeacherPresenter;
  6. use Illuminate\Http\Request;
  7. class TeacherService
  8. {
  9. /**
  10. * @var TeacherRepositoryEloquent
  11. */
  12. private $teacherRepository;
  13. /**
  14. * TeacherService constructor.
  15. *
  16. * @param TeacherRepositoryEloquent $teacherRepositoryEloquent
  17. */
  18. public function __construct(TeacherRepositoryEloquent $teacherRepositoryEloquent)
  19. {
  20. $this->teacherRepository = $teacherRepositoryEloquent;
  21. }
  22. /**
  23. * @param Request $request
  24. *
  25. * @return mixed
  26. * @throws \Prettus\Repository\Exceptions\RepositoryException
  27. */
  28. public function handleList(Request $request)
  29. {
  30. $this->teacherRepository->pushCriteria(new TeacherCriteria($request));
  31. $this->teacherRepository->setPresenter(TeacherPresenter::class);
  32. return $this->teacherRepository->searchTeachersByPage();
  33. }
  34. /**
  35. * @param $id
  36. *
  37. * @return \Illuminate\Database\Eloquent\Model
  38. */
  39. public function handleProfile($id)
  40. {
  41. $this->teacherRepository->setPresenter(TeacherPresenter::class);
  42. return $this->teacherRepository->searchTeacherBy($id);
  43. }
  44. /**
  45. * @param array $data
  46. *
  47. * @return mixed
  48. * @throws \Prettus\Validator\Exceptions\ValidatorException
  49. */
  50. public function handleStore($data)
  51. {
  52. $teacher = $this->teacherRepository->create($data);
  53. return $teacher;
  54. }
  55. /**
  56. * @param array $data
  57. *
  58. * @return mixed
  59. * @throws \Prettus\Validator\Exceptions\ValidatorException
  60. */
  61. public function handleUpdate($data)
  62. {
  63. $teacher = $this->teacherRepository->update($data, $data['id']);
  64. return $teacher;
  65. }
  66. /**
  67. * @param Request $request
  68. *
  69. * @return mixed
  70. * @throws \Prettus\Validator\Exceptions\ValidatorException
  71. */
  72. public function handleDelete($id)
  73. {
  74. return $this->teacherRepository->delete($id);
  75. }
  76. /**
  77. * @param Request $request
  78. *
  79. * @return mixed
  80. * @throws \Prettus\Repository\Exceptions\RepositoryException
  81. */
  82. public function handleAll(Request $request)
  83. {
  84. $this->teacherRepository->pushCriteria(new TeacherCriteria($request));
  85. $this->teacherRepository->setPresenter(TeacherPresenter::class);
  86. return $this->teacherRepository->get();
  87. }
  88. /**
  89. * @param Request $request
  90. *
  91. * @return mixed
  92. * @throws \Prettus\Repository\Exceptions\RepositoryException
  93. */
  94. public function handleIds(Request $request)
  95. {
  96. $this->teacherRepository->pushCriteria(new TeacherCriteria($request));
  97. return $this->teacherRepository->pluck('id');
  98. }
  99. /**
  100. * 选项
  101. * @param Request $request
  102. * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator|\Illuminate\Support\Collection|mixed
  103. * @throws \Prettus\Repository\Exceptions\RepositoryException
  104. */
  105. public function handleSelectOptions(Request $request)
  106. {
  107. $this->teacherRepository->pushCriteria(new TeacherCriteria($request));
  108. return $this->teacherRepository->all(['id', 'name', 'account']);
  109. }
  110. /**
  111. * 批量删除
  112. * @param $ids
  113. * @return mixed
  114. */
  115. public function handleBatchDelete($ids)
  116. {
  117. return $this->teacherRepository->whereIn('id', $ids)->delete();
  118. }
  119. }