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.
109 lines
3.4 KiB
109 lines
3.4 KiB
<?php
|
|
|
|
namespace App\Controller\v3;
|
|
|
|
use App\Controller\BaseController;
|
|
use App\Model\v3\Employees;
|
|
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;
|
|
|
|
class SearchController extends BaseController
|
|
{
|
|
/**
|
|
* @Inject
|
|
* @var SearchServiceInterface
|
|
*/
|
|
protected $searchService;
|
|
|
|
/**
|
|
* @Inject
|
|
* @var LocationServiceInterface
|
|
*/
|
|
protected $locationService;
|
|
|
|
/**
|
|
* 获取搜索热词
|
|
* 1、参数type区分是商品还是商户
|
|
* 2、不同type处理不同的service获取热词
|
|
*/
|
|
public function hotKeywords()
|
|
{
|
|
|
|
$type = $this->request->input('type', 'goods');
|
|
$keywords = $this->searchService->getHotKeywords($type);
|
|
|
|
return $this->success(['keywords' => $keywords]);
|
|
}
|
|
|
|
/**
|
|
* 商品搜索
|
|
* 1、筛选条件:商品分类、商品关键词
|
|
* 2、排序:综合排序、销量最多、价格高/低
|
|
* 3、返回数据格式,大购物车统计+商品数据含有id、封面图、名称、原价、现价、库存、月销、tag、规格、购物车相关、商户id、商户avatar、商户名
|
|
* @param SearchGoodsRequest $request
|
|
* @return ResponseInterface
|
|
*/
|
|
public function goods(SearchGoodsRequest $request)
|
|
{
|
|
$params = $this->request->all();
|
|
$data = $this->searchService->doForGoods($params);
|
|
|
|
return $this->success($data);
|
|
}
|
|
|
|
/**
|
|
* 商户搜索
|
|
* 1、筛选条件:商户分类、商户关键词
|
|
* 2、排序:综合排序、销量最多
|
|
* 3、返回数据格式,大购物车统计+商品数据含有id、封面图、名称、原价、现价、库存、月销、tag、规格、购物车相关、商户id、商户avatar、商户名
|
|
* @param SearchStoreRequest $request
|
|
* @return ResponseInterface
|
|
*/
|
|
public function stores(SearchStoreRequest $request)
|
|
{
|
|
$params = $request->validated();
|
|
$data = $this->searchService->doForStores($params);
|
|
|
|
return $this->success($data);
|
|
}
|
|
|
|
/**
|
|
* 市场搜索
|
|
*
|
|
*/
|
|
public function market()
|
|
{
|
|
$keywords = $this->request->input('keywords','');
|
|
$cityId = $this->request->input('city_id',2163);
|
|
$lng = $this->request->input('lng',0);
|
|
$lat = $this->request->input('lat',0);
|
|
$data = $this->locationService->searchMarket($keywords,$lng,$lat,$cityId);
|
|
return $this->success(['markets' => $data]);
|
|
}
|
|
|
|
/**
|
|
* 服务专员店铺搜索
|
|
*/
|
|
public function storesForPersonnel()
|
|
{
|
|
$userId = $this->request->input('user_id');
|
|
$page = $this->request->input('page',1);
|
|
$pagesize = $this->request->input('pagesize',10);
|
|
$ids = $this->request->input('ids','');
|
|
$ids = json_decode($ids,true);
|
|
$keywords = $this->request->input('keywords','');
|
|
$employees = Employees::query()
|
|
->where('user_id',$userId)
|
|
->whereJsonContains('position', '30')
|
|
->first();
|
|
if(empty($employees)){
|
|
return $this->success(['personnel' => false]);
|
|
}
|
|
$res = $this->searchService->getStoresForPersonnel($employees->market_id,$ids,$keywords,$page,$pagesize);
|
|
return $this->success($res);
|
|
}
|
|
}
|