From 9a2bbca592b4137531e1c051a587d5079d27f478 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Sat, 5 Sep 2020 16:47:38 +0800 Subject: [PATCH] =?UTF-8?q?=E6=90=9C=E7=B4=A2=E5=B8=82=E5=9C=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/v3/SearchController.php | 19 +++++++++++++++++++ .../v3/Implementations/LocationService.php | 13 +++++++++++++ .../Interfaces/LocationServiceInterface.php | 1 + config/routes.php | 1 + 4 files changed, 34 insertions(+) diff --git a/app/Controller/v3/SearchController.php b/app/Controller/v3/SearchController.php index 9d8581c..45d9552 100644 --- a/app/Controller/v3/SearchController.php +++ b/app/Controller/v3/SearchController.php @@ -5,6 +5,7 @@ namespace App\Controller\v3; use App\Controller\BaseController; use App\Request\v3\SearchGoodsRequest; use App\Request\v3\SearchStoreRequest; +use App\Service\v3\Interfaces\LocationServiceInterface; use App\Service\v3\Interfaces\SearchServiceInterface; use Hyperf\Di\Annotation\Inject; use Psr\Http\Message\ResponseInterface; @@ -17,6 +18,12 @@ class SearchController extends BaseController */ protected $searchService; + /** + * @Inject + * @var LocationServiceInterface + */ + protected $locationService; + /** * 获取搜索热词 * 1、参数type区分是商品还是商户 @@ -62,4 +69,16 @@ class SearchController extends BaseController return $this->success(['stores' => $data]); } + + /** + * 市场搜索 + * + */ + public function market() + { + $keywords = $this->request->input('keywords',''); + $cityId = $this->request->input('city_id',2163); + $data = $this->locationService->searchMarket($keywords,$cityId); + return $this->success(['markets' => $data]); + } } \ No newline at end of file diff --git a/app/Service/v3/Implementations/LocationService.php b/app/Service/v3/Implementations/LocationService.php index 9cfd504..c922c74 100644 --- a/app/Service/v3/Implementations/LocationService.php +++ b/app/Service/v3/Implementations/LocationService.php @@ -35,6 +35,19 @@ class LocationService implements LocationServiceInterface return $res; } + public function searchMarket($keywords,$cityId = 2163) + { + $res = Market::query()->where([ + ['name','like','%'.$keywords.'%'], + ['city_id','=',$cityId] + ]) + ->get(); + foreach ($res as &$v){ + $v->Distance = $this->getDistance($v->lng,$v->lat,108.370333,22.813527); + } + return $res; + } + function getDistance($lng1, $lat1, $lng2, $lat2, $unit = 2, $decimal = 2) { diff --git a/app/Service/v3/Interfaces/LocationServiceInterface.php b/app/Service/v3/Interfaces/LocationServiceInterface.php index 95eb3af..6bed48b 100644 --- a/app/Service/v3/Interfaces/LocationServiceInterface.php +++ b/app/Service/v3/Interfaces/LocationServiceInterface.php @@ -10,4 +10,5 @@ interface LocationServiceInterface public function check(); public function undo(); public function getMarketListByLocation($cityIds); + public function searchMarket($key,$cityId = 2163); } \ No newline at end of file diff --git a/config/routes.php b/config/routes.php index c853a65..aa393d1 100644 --- a/config/routes.php +++ b/config/routes.php @@ -90,6 +90,7 @@ Router::addGroup('/v3/', function () { Router::post('search/stores', 'App\Controller\v3\SearchController@stores'); Router::post('goodsRecommend/getByTab', 'App\Controller\v3\GoodsRecommendController@getByTab'); Router::post('store/index', 'App\Controller\v3\StoreController@index'); + Router::post('Search/market', 'App\Controller\v3\SearchController@market'); },['middleware' => [\App\Middleware\Auth\ApiMiddleware::class]]); // 需要登录的路由