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.

85 lines
2.6 KiB

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