ShopGoodService.php 3.3 KB

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