Browse Source

搜索店铺列表 id

master
Lemon 5 years ago
parent
commit
1e36ee1bd6
  1. 4
      app/Controller/v3/SearchController.php
  2. 11
      app/Service/v3/Implementations/SearchService.php
  3. 2
      app/Service/v3/Interfaces/SearchServiceInterface.php

4
app/Controller/v3/SearchController.php

@ -93,6 +93,8 @@ class SearchController extends BaseController
$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)
@ -101,7 +103,7 @@ class SearchController extends BaseController
if(empty($employees)){
return $this->success(['personnel' => false]);
}
$res = $this->searchService->getStoresForPersonnel($employees->market_id,$keywords,$page,$pagesize);
$res = $this->searchService->getStoresForPersonnel($employees->market_id,$ids,$keywords,$page,$pagesize);
return $this->success($res);
}
}

11
app/Service/v3/Implementations/SearchService.php

@ -197,16 +197,23 @@ class SearchService implements SearchServiceInterface
// TODO: Implement undo() method.
}
public function getStoresForPersonnel($marketId, $keywords, $page = 1, $pagesize = 10)
public function getStoresForPersonnel($marketId, $ids,$keywords, $page = 1, $pagesize = 10)
{
$market = Market::query()->withoutGlobalScope('normal')->find($marketId);
$builder = Store::query()->where('market_id',$marketId);
if(!is_null($ids)){
$builder->whereNotIn('id',$ids);
}
if(!is_null($keywords)){
$builder->where('name','like','%'.$keywords.'%');
}
$paginate = $builder->orderBy('is_rest', 'asc')->paginate($pagesize);
$stores = $paginate->toArray();
$market->stores = $stores['data'];
return ['has_more_pages' => $paginate->hasMorePages(), 'market' => $market];
$newIds = array_values(array_column($stores['data'], 'id'));
if(!is_null($ids)){
$newIds = array_merge($newIds,$ids);
}
return ['has_more_pages' => $paginate->hasMorePages(), 'market' => $market,'ids' => $newIds];
}
}

2
app/Service/v3/Interfaces/SearchServiceInterface.php

@ -10,5 +10,5 @@ interface SearchServiceInterface
public function do();
public function check();
public function undo();
public function getStoresForPersonnel($marketId, $keywords ,$page=1, $pagesize=10);
public function getStoresForPersonnel($marketId, $ids,$keywords ,$page=1, $pagesize=10);
}
Loading…
Cancel
Save