Browse Source

搜索市场

master
Lemon 5 years ago
parent
commit
9a2bbca592
  1. 19
      app/Controller/v3/SearchController.php
  2. 13
      app/Service/v3/Implementations/LocationService.php
  3. 1
      app/Service/v3/Interfaces/LocationServiceInterface.php
  4. 1
      config/routes.php

19
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]);
}
}

13
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)
{

1
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);
}

1
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]]);
// 需要登录的路由

Loading…
Cancel
Save