VideoService.php 3.1 KB

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