You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
2.0 KiB

5 years ago
5 years ago
5 years ago
5 years ago
  1. <?php
  2. namespace App\Controller\v3;
  3. use App\Controller\BaseController;
  4. use App\Request\v3\SearchGoodsRequest;
  5. use App\Request\v3\SearchStoreRequest;
  6. use App\Service\v3\Interfaces\SearchServiceInterface;
  7. use Hyperf\Di\Annotation\Inject;
  8. use Psr\Http\Message\ResponseInterface;
  9. class SearchController extends BaseController
  10. {
  11. /**
  12. * @Inject
  13. * @var SearchServiceInterface
  14. */
  15. protected $searchService;
  16. /**
  17. * 获取搜索热词
  18. * 1、参数type区分是商品还是商户
  19. * 2、不同type处理不同的service获取热词
  20. */
  21. public function hotKeywords()
  22. {
  23. $type = $this->request->input('type', 'goods');
  24. $keywords = $this->searchService->getHotKeywords($type);
  25. return $this->success(['keywords' => $keywords]);
  26. }
  27. /**
  28. * 商品搜索
  29. * 1、筛选条件:商品分类、商品关键词
  30. * 2、排序:综合排序、销量最多、价格高/
  31. * 3、返回数据格式,大购物车统计+商品数据含有id、封面图、名称、原价、现价、库存、月销、tag、规格、购物车相关、商户id、商户avatar、商户名
  32. * @param SearchGoodsRequest $request
  33. * @return ResponseInterface
  34. */
  35. public function goods(SearchGoodsRequest $request)
  36. {
  37. $params = $request->validated();
  38. $data = $this->searchService->doForGoods($params);
  39. return $this->success(['goods' => $data]);
  40. }
  41. /**
  42. * 商户搜索
  43. * 1、筛选条件:商户分类、商户关键词
  44. * 2、排序:综合排序、销量最多
  45. * 3、返回数据格式,大购物车统计+商品数据含有id、封面图、名称、原价、现价、库存、月销、tag、规格、购物车相关、商户id、商户avatar、商户名
  46. * @param SearchStoreRequest $request
  47. * @return ResponseInterface
  48. */
  49. public function stores(SearchStoreRequest $request)
  50. {
  51. $params = $request->validated();
  52. $data = $this->searchService->doForStores($params);
  53. return $this->success(['stores' => $data]);
  54. }
  55. }