SearchHistoryService.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. namespace App\Services\Info;
  3. use App\Contracts\Repositories\Info\SearchHistoryRepository;
  4. use App\Repositories\Criteria\Info\SearchHistoryCriteria;
  5. use App\Repositories\Eloquent\Info\SearchHistoryRepositoryEloquent;
  6. use App\Repositories\Presenters\Info\SearchHistoryPresenter;
  7. use Illuminate\Http\Request;
  8. class SearchHistoryService
  9. {
  10. /**
  11. * @var SearchHistoryRepositoryEloquent
  12. */
  13. private $searchHistoryRepository;
  14. /**
  15. * SearchHistoryService constructor.
  16. *
  17. * @param SearchHistoryRepositoryEloquent $searchHistoryRepositoryEloquent
  18. */
  19. public function __construct(SearchHistoryRepositoryEloquent $searchHistoryRepositoryEloquent)
  20. {
  21. $this->searchHistoryRepository = $searchHistoryRepositoryEloquent;
  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->searchHistoryRepository->pushCriteria(new SearchHistoryCriteria($request));
  32. $this->searchHistoryRepository->setPresenter(SearchHistoryPresenter::class);
  33. return $this->searchHistoryRepository->searchSearchHistorysByPage();
  34. }
  35. /**
  36. * @param $id
  37. *
  38. * @return \Illuminate\Database\Eloquent\Model
  39. */
  40. public function handleProfile($id)
  41. {
  42. $this->searchHistoryRepository->setPresenter(SearchHistoryPresenter::class);
  43. return $this->searchHistoryRepository->searchSearchHistoryBy($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. $searchHistory = $this->searchHistoryRepository->create($data);
  54. return $searchHistory;
  55. }
  56. /**
  57. * @param array $data
  58. *
  59. * @return mixed
  60. * @throws \Prettus\Validator\Exceptions\ValidatorException
  61. */
  62. public function handleUpdate($data)
  63. {
  64. $searchHistory = $this->searchHistoryRepository->update($data, $data['id']);
  65. return $searchHistory;
  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->searchHistoryRepository->delete($id);
  76. }
  77. /**
  78. * 搜索历史
  79. * @param $type
  80. * @return mixed
  81. */
  82. public function handleHistory($type)
  83. {
  84. return $this->searchHistoryRepository->where('guard', 'admins')->where('type', $type)->where('user_id', login_admin_id())->orderByDesc('id')->limit(5)->select(['keyword', 'id'])->get();
  85. }
  86. }