123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- <?php
- namespace App\Http\Controllers\Admin\Info;
- use App\Http\Controllers\Controller;
- use App\Services\Info\SearchHistoryService;
- use Illuminate\Http\Request;
- /**
- * 搜索历史记录
- */
- class SearchHistoryController extends Controller
- {
- /**
- * @var SearchHistoryService
- */
- private $searchHistoryService;
- /**
- * SearchHistoryController constructor.
- *
- * @param SearchHistoryService $searchHistoryService
- */
- public function __construct(SearchHistoryService $searchHistoryService)
- {
- parent::__construct();
- $this->middleware('checkUserPermission');
- $this->searchHistoryService = $searchHistoryService;
- }
- /**
- * 新增
- * @must
- * @param Request $request
- *
- * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\Resources\Json\JsonResource
- * @throws \Prettus\Validator\Exceptions\ValidatorException
- */
- public function store(Request $request)
- {
- $data = $this->validateData($request, [
- 'keyword' => 'required|string',
- 'type' => 'required',
- ], [
- 'keyword' => '关键字',
- 'type' => '类型',
- ]);
- $data['guard'] = 'admins';
- $data['user_id'] = login_admin_id();
- $searchHistory = $this->searchHistoryService->handleStore($data);
- return $this->response->created($searchHistory, '创建成功');
- }
- /**
- * 搜索历史
- * @must
- * @param Request $request
- * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\Resources\Json\JsonResource
- * @throws \Illuminate\Validation\ValidationException
- */
- public function history(Request $request)
- {
- $data = $this->validateData($request, [
- 'type' => 'required',
- ], [
- 'type' => '类型',
- ]);
- $lists = $this->searchHistoryService->handleHistory($data['type']);
- return $this->response->success($lists);
- }
- /**
- * 删除
- * @must
- * @param Request $request
- */
- public function destroy(Request $request)
- {
- $this->validate($request, ['id' => 'required|integer']);
- $re = $this->searchHistoryService->handleDelete($request->get('id'));
- if ($re) {
- return $this->response->ok('删除成功');
- }
- return $this->response->fail('删除失败');
- }
- }
|