CompanyService.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. namespace App\Services\Base;
  3. use App\Repositories\Criteria\Base\CompanyCriteria;
  4. use App\Repositories\Eloquent\Base\CompanyRepositoryEloquent;
  5. use App\Repositories\Presenters\Base\CompanyPresenter;
  6. use Illuminate\Http\Request;
  7. class CompanyService
  8. {
  9. /**
  10. * @var CompanyRepositoryEloquent
  11. */
  12. private $companyRepository;
  13. /**
  14. * CompanyService constructor.
  15. *
  16. * @param CompanyRepositoryEloquent $companyRepositoryEloquent
  17. */
  18. public function __construct(CompanyRepositoryEloquent $companyRepositoryEloquent)
  19. {
  20. $this->companyRepository = $companyRepositoryEloquent;
  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->companyRepository->pushCriteria(new CompanyCriteria($request));
  31. $this->companyRepository->setPresenter(CompanyPresenter::class);
  32. return $this->companyRepository->searchCompanysByPage();
  33. }
  34. /**
  35. * @param $id
  36. *
  37. * @return \Illuminate\Database\Eloquent\Model
  38. */
  39. public function handleProfile($id)
  40. {
  41. $this->companyRepository->setPresenter(CompanyPresenter::class);
  42. return $this->companyRepository->searchCompanyBy($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. $company = $this->companyRepository->create($data);
  53. return $company;
  54. }
  55. /**
  56. * @param array $data
  57. *
  58. * @return mixed
  59. * @throws \Prettus\Validator\Exceptions\ValidatorException
  60. */
  61. public function handleUpdate($data)
  62. {
  63. $company = $this->companyRepository->update($data, $data['id']);
  64. return $company;
  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->companyRepository->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->companyRepository->pushCriteria(new CompanyCriteria($request));
  85. return $this->companyRepository->all([
  86. 'id',
  87. 'name',
  88. 'sort',
  89. ]);
  90. }
  91. }