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.

83 lines
2.4 KiB

5 years ago
  1. <?php
  2. namespace App\Controller\v3;
  3. use App\Constants\v3\ErrorCode;
  4. use App\Controller\BaseController;
  5. use App\Exception\ErrorCodeException;
  6. use App\Model\v3\Market;
  7. use App\Service\v3\Interfaces\LocationServiceInterface;
  8. use Hyperf\Di\Annotation\Inject;
  9. use Hyperf\Validation\Contract\ValidatorFactoryInterface;
  10. use Hyperf\Validation\ValidationException;
  11. /**
  12. * 定位相关
  13. * Class LocationController
  14. * @package App\Controller\v3
  15. */
  16. class LocationController extends BaseController
  17. {
  18. /**
  19. * @Inject
  20. * @var LocationServiceInterface
  21. */
  22. protected $locationService;
  23. /**
  24. * @Inject()
  25. * @var ValidatorFactoryInterface
  26. */
  27. protected $validationFactory;
  28. /**
  29. * 获取当前用户定位最近的市场
  30. * 1.用户上报经纬度数据
  31. * 2.如果经纬度不存在或无法获取到最近市场信息,则返回空数据
  32. * 3.根据经纬度查询获取市场数据,id、名称、省份、城市、行政区、地址、经纬度
  33. */
  34. public function getNearestMarket()
  35. {
  36. $lng = $this->request->input('lng',0);
  37. $lat = $this->request->input('lat',0);
  38. return $this->success(['market' => $this->locationService->getNearestMarket($lng,$lat)]);
  39. }
  40. public function getMarketListByLocation()
  41. {
  42. $lng = $this->request->input('lng',0);
  43. $lat = $this->request->input('lat',0);
  44. return $this->success($this->locationService->getMarketListByLocation($lng,$lat));
  45. }
  46. public function getMarketsInfo()
  47. {
  48. $ret = [];
  49. $ret['service_time']='8:30-20:00';
  50. $ret['markets_info']=$this->locationService->getMarketsInfo();
  51. return $this->success($ret);
  52. }
  53. public function addrSuggestion()
  54. {
  55. $validator = $this->validationFactory->make(
  56. $this->request->all(),
  57. ['keyword' => 'required|nonempty'],
  58. ['keyword.*' => '关键字不能为空或undefined等']
  59. );
  60. if ($validator->fails()){
  61. throw new ValidationException($validator);
  62. }
  63. $keyword = $this->request->input('keyword');
  64. $marketId = $this->request->input('market_id');
  65. $page = $this->request->input('page');
  66. $pageSize = $this->request->input('pagesize');
  67. $res = $this->locationService->placeSuggestion($keyword, $marketId, $page, $pageSize);
  68. return $this->success($res);
  69. }
  70. }