BusinessCategoryService.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. namespace App\Services\Dwbs;
  3. use App\Contracts\Repositories\Dwbs\BusinessCategoryRepository;
  4. use App\Repositories\Criteria\Dwbs\BusinessCategoryCriteria;
  5. use App\Repositories\Eloquent\Dwbs\BusinessCategoryRepositoryEloquent;
  6. use App\Repositories\Presenters\Dwbs\BusinessCategoryPresenter;
  7. use Illuminate\Http\Request;
  8. class BusinessCategoryService
  9. {
  10. /**
  11. * @var BusinessCategoryRepositoryEloquent
  12. */
  13. private $repository;
  14. /**
  15. * BusinessCategoryService constructor.
  16. *
  17. * @param BusinessCategoryRepositoryEloquent $businessCategoryRepositoryEloquent
  18. */
  19. public function __construct(BusinessCategoryRepositoryEloquent $repository)
  20. {
  21. $this->repository = $repository;
  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->repository->pushCriteria(new BusinessCategoryCriteria($request));
  32. $this->repository->setPresenter(BusinessCategoryPresenter::class);
  33. return $this->repository->searchListsPage();
  34. }
  35. /**
  36. * @param $id
  37. *
  38. * @return \Illuminate\Database\Eloquent\Model
  39. */
  40. public function handleProfile($id)
  41. {
  42. $this->repository->setPresenter(BusinessCategoryPresenter::class);
  43. return $this->repository->searchBy($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. $businessCategory = $this->repository->create($data);
  54. return $businessCategory;
  55. }
  56. /**
  57. * @param array $data
  58. *
  59. * @return mixed
  60. * @throws \Prettus\Validator\Exceptions\ValidatorException
  61. */
  62. public function handleUpdate($data)
  63. {
  64. $businessCategory = $this->repository->update($data,$data['id']);
  65. return $businessCategory;
  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->repository->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->repository->pushCriteria(new BusinessCategoryCriteria($request));
  86. return $this->repository->all(['id', 'name']);
  87. }
  88. /**
  89. * 批量删除
  90. * @param $ids
  91. * @return mixed
  92. */
  93. public function handleBatchDelete($ids)
  94. {
  95. return $this->repository->whereIn('id', $ids)->delete();
  96. }
  97. /**
  98. * @param Request $request
  99. *
  100. * @return mixed
  101. * @throws \Prettus\Repository\Exceptions\RepositoryException
  102. */
  103. public function handleAll(Request $request)
  104. {
  105. $this->repository->pushCriteria(new BusinessCategoryCriteria($request));
  106. $this->repository->setPresenter(BusinessCategoryPresenter::class);
  107. return $this->repository->get();
  108. }
  109. /**
  110. * @param Request $request
  111. *
  112. * @return mixed
  113. * @throws \Prettus\Repository\Exceptions\RepositoryException
  114. */
  115. public function handleIds(Request $request)
  116. {
  117. $this->repository->pushCriteria(new BusinessCategoryCriteria($request));
  118. return $this->repository->pluck('id');
  119. }
  120. }