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.

108 lines
3.4 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
5 years ago
  1. <?php
  2. namespace App\Controller\v3;
  3. use App\Controller\BaseController;
  4. use App\Model\v3\Employees;
  5. use App\Request\v3\SearchGoodsRequest;
  6. use App\Request\v3\SearchStoreRequest;
  7. use App\Service\v3\Interfaces\LocationServiceInterface;
  8. use App\Service\v3\Interfaces\SearchServiceInterface;
  9. use Hyperf\Di\Annotation\Inject;
  10. use Psr\Http\Message\ResponseInterface;
  11. class SearchController extends BaseController
  12. {
  13. /**
  14. * @Inject
  15. * @var SearchServiceInterface
  16. */
  17. protected $searchService;
  18. /**
  19. * @Inject
  20. * @var LocationServiceInterface
  21. */
  22. protected $locationService;
  23. /**
  24. * 获取搜索热词
  25. * 1、参数type区分是商品还是商户
  26. * 2、不同type处理不同的service获取热词
  27. */
  28. public function hotKeywords()
  29. {
  30. $type = $this->request->input('type', 'goods');
  31. $keywords = $this->searchService->getHotKeywords($type);
  32. return $this->success(['keywords' => $keywords]);
  33. }
  34. /**
  35. * 商品搜索
  36. * 1、筛选条件:商品分类、商品关键词
  37. * 2、排序:综合排序、销量最多、价格高/
  38. * 3、返回数据格式,大购物车统计+商品数据含有id、封面图、名称、原价、现价、库存、月销、tag、规格、购物车相关、商户id、商户avatar、商户名
  39. * @param SearchGoodsRequest $request
  40. * @return ResponseInterface
  41. */
  42. public function goods(SearchGoodsRequest $request)
  43. {
  44. $params = $this->request->all();
  45. $data = $this->searchService->doForGoods($params);
  46. return $this->success($data);
  47. }
  48. /**
  49. * 商户搜索
  50. * 1、筛选条件:商户分类、商户关键词
  51. * 2、排序:综合排序、销量最多
  52. * 3、返回数据格式,大购物车统计+商品数据含有id、封面图、名称、原价、现价、库存、月销、tag、规格、购物车相关、商户id、商户avatar、商户名
  53. * @param SearchStoreRequest $request
  54. * @return ResponseInterface
  55. */
  56. public function stores(SearchStoreRequest $request)
  57. {
  58. $params = $request->validated();
  59. $data = $this->searchService->doForStores($params);
  60. return $this->success($data);
  61. }
  62. /**
  63. * 市场搜索
  64. *
  65. */
  66. public function market()
  67. {
  68. $keywords = $this->request->input('keywords','');
  69. $cityId = $this->request->input('city_id',2163);
  70. $lng = $this->request->input('lng',0);
  71. $lat = $this->request->input('lat',0);
  72. $data = $this->locationService->searchMarket($keywords,$lng,$lat,$cityId);
  73. return $this->success(['markets' => $data]);
  74. }
  75. /**
  76. * 服务专员店铺搜索
  77. */
  78. public function storesForPersonnel()
  79. {
  80. $userId = $this->request->input('user_id');
  81. $page = $this->request->input('page',1);
  82. $pagesize = $this->request->input('pagesize',10);
  83. $ids = $this->request->input('ids','');
  84. $ids = json_decode($ids,true);
  85. $keywords = $this->request->input('keywords','');
  86. $employees = Employees::query()
  87. ->where('user_id',$userId)
  88. ->whereJsonContains('position', '30')
  89. ->first();
  90. if(empty($employees)){
  91. return $this->success(['personnel' => false]);
  92. }
  93. $res = $this->searchService->getStoresForPersonnel($employees->market_id,$ids,$keywords,$page,$pagesize);
  94. return $this->success($res);
  95. }
  96. }