12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- <?php
- namespace App\Services\Info;
- use App\Contracts\Repositories\Info\SearchHistoryRepository;
- use App\Repositories\Criteria\Info\SearchHistoryCriteria;
- use App\Repositories\Eloquent\Info\SearchHistoryRepositoryEloquent;
- use App\Repositories\Presenters\Info\SearchHistoryPresenter;
- use Illuminate\Http\Request;
- class SearchHistoryService
- {
- /**
- * @var SearchHistoryRepositoryEloquent
- */
- private $searchHistoryRepository;
- /**
- * SearchHistoryService constructor.
- *
- * @param SearchHistoryRepositoryEloquent $searchHistoryRepositoryEloquent
- */
- public function __construct(SearchHistoryRepositoryEloquent $searchHistoryRepositoryEloquent)
- {
- $this->searchHistoryRepository = $searchHistoryRepositoryEloquent;
- }
- /**
- * @param Request $request
- *
- * @return mixed
- * @throws \Prettus\Repository\Exceptions\RepositoryException
- */
- public function handleList(Request $request)
- {
- $this->searchHistoryRepository->pushCriteria(new SearchHistoryCriteria($request));
- $this->searchHistoryRepository->setPresenter(SearchHistoryPresenter::class);
- return $this->searchHistoryRepository->searchSearchHistorysByPage();
- }
- /**
- * @param $id
- *
- * @return \Illuminate\Database\Eloquent\Model
- */
- public function handleProfile($id)
- {
- $this->searchHistoryRepository->setPresenter(SearchHistoryPresenter::class);
- return $this->searchHistoryRepository->searchSearchHistoryBy($id);
- }
- /**
- * @param array $data
- *
- * @return mixed
- * @throws \Prettus\Validator\Exceptions\ValidatorException
- */
- public function handleStore($data)
- {
- $searchHistory = $this->searchHistoryRepository->create($data);
- return $searchHistory;
- }
- /**
- * @param array $data
- *
- * @return mixed
- * @throws \Prettus\Validator\Exceptions\ValidatorException
- */
- public function handleUpdate($data)
- {
- $searchHistory = $this->searchHistoryRepository->update($data, $data['id']);
- return $searchHistory;
- }
- /**
- * @param Request $request
- *
- * @return mixed
- * @throws \Prettus\Validator\Exceptions\ValidatorException
- */
- public function handleDelete($id)
- {
- return $this->searchHistoryRepository->delete($id);
- }
- /**
- * 搜索历史
- * @param $type
- * @return mixed
- */
- public function handleHistory($type)
- {
- return $this->searchHistoryRepository->where('guard', 'admins')->where('type', $type)->where('user_id', login_admin_id())->orderByDesc('id')->limit(5)->select(['keyword', 'id'])->get();
- }
- }
|