From dd2a4b8df3aa0c8c85cc01f34aa1b82e5f01de85 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Mon, 2 Nov 2020 16:15:02 +0800 Subject: [PATCH 01/10] =?UTF-8?q?=E5=95=86=E5=93=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/v3/Implementations/StoreService.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/Service/v3/Implementations/StoreService.php b/app/Service/v3/Implementations/StoreService.php index 2ef73e4..cb9092a 100644 --- a/app/Service/v3/Implementations/StoreService.php +++ b/app/Service/v3/Implementations/StoreService.php @@ -87,7 +87,12 @@ class StoreService implements StoreServiceInterface $paginate = $builder->groupBy(''.$storeTable.'.id')->orderByDesc($storeTable.'.sales')->paginate($pagesize); $stores = $paginate->map(function ($item, $key) { - $item->goods; + $item->goods = Goods::query() + ->where('store_id',$item->id) + ->where(function ($query){ + $query->where('inventory', '>', 0)->orWhere('is_infinite', '=', 1); + }) + ->limit(5)->get(); return $item; })->all(); From 030aa91c0a62743d25e1b5746ad9e669bd352c07 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Mon, 2 Nov 2020 17:36:00 +0800 Subject: [PATCH 02/10] =?UTF-8?q?=E7=89=B9=E4=BB=B7=E5=95=86=E5=93=81?= =?UTF-8?q?=E5=BA=93=E5=AD=98=E4=B8=8D=E8=B6=B3=E6=9D=A1=E4=BB=B6=E5=88=A4?= =?UTF-8?q?=E6=96=AD=20=E5=8A=A0=E4=B8=8Aredis=E5=8E=8B=E7=9A=84=E5=BA=93?= =?UTF-8?q?=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Model/v3/GoodsActivity.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/Model/v3/GoodsActivity.php b/app/Model/v3/GoodsActivity.php index c3097ea..7d3a950 100644 --- a/app/Model/v3/GoodsActivity.php +++ b/app/Model/v3/GoodsActivity.php @@ -87,9 +87,12 @@ class GoodsActivity extends Model { $msg = ''; + // 获取冻结的库存 + $inventoryFrozen = $this->goodsInventoryService->getSold(2, $this->attributes['id']); + if ($this->attributes['expire_time'] < time()) { $msg = '已结束'; - } elseif ($this->attributes['inventory'] <= 0 && $this->attributes['is_infinite'] != 1) { + } elseif ($this->attributes['inventory'] <= $inventoryFrozen && $this->attributes['is_infinite'] != 1) { $msg = '已抢光'; } return $msg; From bccf8b38205ed22ad940b1cbd9a33cb4428cb814 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Mon, 2 Nov 2020 17:38:23 +0800 Subject: [PATCH 03/10] =?UTF-8?q?=E7=89=B9=E4=BB=B7=E5=95=86=E5=93=81?= =?UTF-8?q?=E5=BA=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Model/v3/GoodsActivity.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/Model/v3/GoodsActivity.php b/app/Model/v3/GoodsActivity.php index 7d3a950..c2d004f 100644 --- a/app/Model/v3/GoodsActivity.php +++ b/app/Model/v3/GoodsActivity.php @@ -7,6 +7,7 @@ use App\Constants\v3\OssThumbnail; use App\Constants\v3\SsdbKeys; use App\Model\Model; use App\Service\v3\Interfaces\AttachmentServiceInterface; +use App\Service\v3\Interfaces\GoodsInventoryServiceInterface; use App\Service\v3\Interfaces\ShopCartServiceInterface; use App\TaskWorker\SSDBTask; use Hyperf\Database\Model\Builder; @@ -31,6 +32,12 @@ class GoodsActivity extends Model */ protected $attachmentService; + /** + * @Inject + * @var GoodsInventoryServiceInterface + */ + protected $goodsInventoryService; + protected $table = 'lanzu_goods_activity'; protected $casts = [ From a2e438afb99e5f354b3f9ea5a85dafed59ca3fcd Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Wed, 4 Nov 2020 16:58:14 +0800 Subject: [PATCH 04/10] =?UTF-8?q?=E5=86=BB=E7=BB=93=E5=BA=93=E5=AD=98?= =?UTF-8?q?=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Model/v3/GoodsActivity.php | 3 +-- app/Service/v3/Implementations/GoodsActivityService.php | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/Model/v3/GoodsActivity.php b/app/Model/v3/GoodsActivity.php index c2d004f..5df8ea2 100644 --- a/app/Model/v3/GoodsActivity.php +++ b/app/Model/v3/GoodsActivity.php @@ -96,10 +96,9 @@ class GoodsActivity extends Model // 获取冻结的库存 $inventoryFrozen = $this->goodsInventoryService->getSold(2, $this->attributes['id']); - if ($this->attributes['expire_time'] < time()) { $msg = '已结束'; - } elseif ($this->attributes['inventory'] <= $inventoryFrozen && $this->attributes['is_infinite'] != 1) { + } elseif (($this->attributes['inventory'] <= $inventoryFrozen || $this->attributes['inventory'] <= 0) && $this->attributes['is_infinite'] != 1) { $msg = '已抢光'; } return $msg; diff --git a/app/Service/v3/Implementations/GoodsActivityService.php b/app/Service/v3/Implementations/GoodsActivityService.php index a1d7ee0..a29b14e 100644 --- a/app/Service/v3/Implementations/GoodsActivityService.php +++ b/app/Service/v3/Implementations/GoodsActivityService.php @@ -67,7 +67,7 @@ class GoodsActivityService implements GoodsActivityServiceInterface } // 是否超过限购数量 - if ($goods->restrict_num != 0 && $goods->restrict_num < $num) { + if (($goods->restrict_num <= $inventoryFrozen || $goods->restrict_num <= 0) && $goods->restrict_num < $num) { return ErrorCode::GOODS_ACTIVITY_RESTRICT_LIMIT; } From 02322bb14a97fc0639a8fae721fe48a547477850 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Wed, 4 Nov 2020 17:40:05 +0800 Subject: [PATCH 05/10] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E5=BA=97=E9=93=BA=E6=8E=A5=E5=8F=A3=20=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E4=B8=93=E5=91=98=E6=94=B9=E7=94=A8=E5=91=98=E5=B7=A5=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/v3/SearchController.php | 21 +++++++++++++++++++ app/Controller/v3/StoreController.php | 10 ++++++--- .../v3/Implementations/SearchService.php | 14 +++++++++++++ .../v3/Interfaces/SearchServiceInterface.php | 1 + config/routes.php | 1 + 5 files changed, 44 insertions(+), 3 deletions(-) diff --git a/app/Controller/v3/SearchController.php b/app/Controller/v3/SearchController.php index 3477e75..2536726 100644 --- a/app/Controller/v3/SearchController.php +++ b/app/Controller/v3/SearchController.php @@ -3,6 +3,7 @@ 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; @@ -83,4 +84,24 @@ class SearchController extends BaseController $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); + $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,$keywords,$page,$pagesize); + return $this->success($res); + } } \ No newline at end of file diff --git a/app/Controller/v3/StoreController.php b/app/Controller/v3/StoreController.php index 7e21afd..4261a21 100644 --- a/app/Controller/v3/StoreController.php +++ b/app/Controller/v3/StoreController.php @@ -5,6 +5,7 @@ namespace App\Controller\v3; use App\Constants\v3\ErrorCode; use App\Exception\ErrorCodeException; use App\Controller\BaseController; +use App\Model\v3\Employees; use App\Model\v3\ServicePersonnel; use App\Request\v3\StoreIndexRequest; use App\Service\v3\Interfaces\CategoryServiceInterface; @@ -109,11 +110,14 @@ class StoreController extends BaseController $userId = $this->request->input('user_id'); $page = $this->request->input('page',1); $pagesize = $this->request->input('pagesize',10); - $personnel = ServicePersonnel::query()->where('user_id',$userId)->first(); - if(empty($personnel)){ + $employees = Employees::query() + ->where('user_id',$userId) + ->whereJsonContains('position', '30') + ->first(); + if(empty($employees)){ return $this->success(['personnel' => false]); } - $res = $this->storeService->getList($personnel->market_id,$page,$pagesize); + $res = $this->storeService->getList($employees->market_id,$page,$pagesize); return $this->success($res); } diff --git a/app/Service/v3/Implementations/SearchService.php b/app/Service/v3/Implementations/SearchService.php index f10dcb5..3a2c5b2 100644 --- a/app/Service/v3/Implementations/SearchService.php +++ b/app/Service/v3/Implementations/SearchService.php @@ -8,6 +8,7 @@ use App\Constants\v3\Goods as GoodsConstants; use App\Model\v3\Category; use App\Model\v3\Goods; use App\Model\v3\GoodsCategory; +use App\Model\v3\Market; use App\Model\v3\Store; use App\Service\v3\Interfaces\SearchServiceInterface; use Hyperf\Paginator\Paginator; @@ -195,4 +196,17 @@ class SearchService implements SearchServiceInterface { // TODO: Implement undo() method. } + + public function getStoresForPersonnel($marketId, $keywords, $page = 1, $pagesize = 10) + { + $market = Market::query()->withoutGlobalScope('normal')->find($marketId); + $builder = Store::query()->where('market_id',$marketId); + 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]; + } } \ No newline at end of file diff --git a/app/Service/v3/Interfaces/SearchServiceInterface.php b/app/Service/v3/Interfaces/SearchServiceInterface.php index 0767938..b50dde9 100644 --- a/app/Service/v3/Interfaces/SearchServiceInterface.php +++ b/app/Service/v3/Interfaces/SearchServiceInterface.php @@ -10,4 +10,5 @@ interface SearchServiceInterface public function do(); public function check(); public function undo(); + public function getStoresForPersonnel($marketId, $keywords ,$page=1, $pagesize=10); } \ No newline at end of file diff --git a/config/routes.php b/config/routes.php index fbb8832..a82953c 100644 --- a/config/routes.php +++ b/config/routes.php @@ -176,6 +176,7 @@ Router::addGroup('/v3/', function () { Router::post('horseman/getOrderInfo', 'App\Controller\v3\HorsemanController@getOrderInfo'); Router::post('horseman/orderComplete', 'App\Controller\v3\HorsemanController@orderComplete'); Router::post('goods/bannerDelete', 'App\Controller\v3\GoodsController@bannerDelete'); + Router::post('search/storesForPersonnel', 'App\Controller\v3\SearchController@storesForPersonnel'); },['middleware' => [\App\Middleware\Auth\ApiMiddleware::class, \App\Middleware\Auth\UserMiddleware::class]]); // 微信支付回调 From a34c38907aa58cc39c02f70a53cddeed47acf90a Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Thu, 5 Nov 2020 15:53:28 +0800 Subject: [PATCH 06/10] =?UTF-8?q?=E5=BA=97=E9=93=BA=E6=8E=92=E5=BA=8F?= =?UTF-8?q?=E7=AD=9B=E9=80=89=E9=87=8D=E5=A4=8D=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/v3/StoreController.php | 3 ++- app/Service/v3/Implementations/StoreService.php | 15 +++++++++++---- .../v3/Interfaces/StoreServiceInterface.php | 2 +- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/app/Controller/v3/StoreController.php b/app/Controller/v3/StoreController.php index 4261a21..269c3b3 100644 --- a/app/Controller/v3/StoreController.php +++ b/app/Controller/v3/StoreController.php @@ -110,6 +110,7 @@ class StoreController 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',''); $employees = Employees::query() ->where('user_id',$userId) ->whereJsonContains('position', '30') @@ -117,7 +118,7 @@ class StoreController extends BaseController if(empty($employees)){ return $this->success(['personnel' => false]); } - $res = $this->storeService->getList($employees->market_id,$page,$pagesize); + $res = $this->storeService->getList($employees->market_id,$ids,$page,$pagesize); return $this->success($res); } diff --git a/app/Service/v3/Implementations/StoreService.php b/app/Service/v3/Implementations/StoreService.php index cb9092a..d4a214c 100644 --- a/app/Service/v3/Implementations/StoreService.php +++ b/app/Service/v3/Implementations/StoreService.php @@ -58,14 +58,21 @@ class StoreService implements StoreServiceInterface ->first(); } - public function getList($marketId, $page=1, $pagesize=10) + public function getList($marketId,$ids, $page=1, $pagesize=10) { $market = Market::query()->withoutGlobalScope('normal')->find($marketId); - $builder = Store::query(); - $paginate = $builder->where('market_id',$marketId)->orderBy('is_rest', 'asc')->paginate($pagesize); + $builder = Store::query()->where('market_id',$marketId); + if(!is_null($ids)){ + $ids = explode(',',$ids); + $builder->whereNotIn('id',$ids); + } + $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')); + $ids = array_merge($ids,$newIds); + $ids = implode(',',$ids); + return ['has_more_pages' => $paginate->hasMorePages(), 'market' => $market,'ids' => $ids]; } public function getListByMarketId($marketId, $page=1, $pagesize=10) diff --git a/app/Service/v3/Interfaces/StoreServiceInterface.php b/app/Service/v3/Interfaces/StoreServiceInterface.php index e8c79cd..35b7de5 100644 --- a/app/Service/v3/Interfaces/StoreServiceInterface.php +++ b/app/Service/v3/Interfaces/StoreServiceInterface.php @@ -8,7 +8,7 @@ interface StoreServiceInterface public function check($storeId); public function undo(); public function detail($storeId); - public function getList($marketId ,$page=1, $pagesize=10); + public function getList($marketId ,$ids,$page=1, $pagesize=10); public function getListByMarketId($marketId ,$page=1, $pagesize=10); public function updateIsRest($storeId); } \ No newline at end of file From 377883dfe88224ec61cbd7c104b4bf9180a7535a Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Thu, 5 Nov 2020 16:04:31 +0800 Subject: [PATCH 07/10] =?UTF-8?q?=E6=95=B0=E7=BB=84=E4=B8=BA=E7=A9=BA?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/v3/StoreController.php | 1 + app/Service/v3/Implementations/StoreService.php | 5 ++--- app/Service/v3/Interfaces/StoreServiceInterface.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/Controller/v3/StoreController.php b/app/Controller/v3/StoreController.php index 269c3b3..9afaf4a 100644 --- a/app/Controller/v3/StoreController.php +++ b/app/Controller/v3/StoreController.php @@ -111,6 +111,7 @@ class StoreController extends BaseController $page = $this->request->input('page',1); $pagesize = $this->request->input('pagesize',10); $ids = $this->request->input('ids',''); + $ids = explode(',',$ids); $employees = Employees::query() ->where('user_id',$userId) ->whereJsonContains('position', '30') diff --git a/app/Service/v3/Implementations/StoreService.php b/app/Service/v3/Implementations/StoreService.php index d4a214c..5707954 100644 --- a/app/Service/v3/Implementations/StoreService.php +++ b/app/Service/v3/Implementations/StoreService.php @@ -58,19 +58,18 @@ class StoreService implements StoreServiceInterface ->first(); } - public function getList($marketId,$ids, $page=1, $pagesize=10) + public function getList($marketId,$ids = [], $page=1, $pagesize=10) { $market = Market::query()->withoutGlobalScope('normal')->find($marketId); $builder = Store::query()->where('market_id',$marketId); if(!is_null($ids)){ - $ids = explode(',',$ids); $builder->whereNotIn('id',$ids); } $paginate = $builder->orderBy('is_rest', 'asc')->paginate($pagesize); $stores = $paginate->toArray(); $market->stores = $stores['data']; $newIds = array_values(array_column($stores['data'], 'id')); - $ids = array_merge($ids,$newIds); + $ids = array_merge($newIds,$ids); $ids = implode(',',$ids); return ['has_more_pages' => $paginate->hasMorePages(), 'market' => $market,'ids' => $ids]; } diff --git a/app/Service/v3/Interfaces/StoreServiceInterface.php b/app/Service/v3/Interfaces/StoreServiceInterface.php index 35b7de5..c9ed1ea 100644 --- a/app/Service/v3/Interfaces/StoreServiceInterface.php +++ b/app/Service/v3/Interfaces/StoreServiceInterface.php @@ -8,7 +8,7 @@ interface StoreServiceInterface public function check($storeId); public function undo(); public function detail($storeId); - public function getList($marketId ,$ids,$page=1, $pagesize=10); + public function getList($marketId ,$ids = [],$page=1, $pagesize=10); public function getListByMarketId($marketId ,$page=1, $pagesize=10); public function updateIsRest($storeId); } \ No newline at end of file From 27a19abb363d24711cc210ba532ba24026d20b60 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Thu, 5 Nov 2020 16:21:40 +0800 Subject: [PATCH 08/10] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/v3/StoreController.php | 2 +- app/Service/v3/Implementations/StoreService.php | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/app/Controller/v3/StoreController.php b/app/Controller/v3/StoreController.php index 9afaf4a..2ba81d6 100644 --- a/app/Controller/v3/StoreController.php +++ b/app/Controller/v3/StoreController.php @@ -111,7 +111,7 @@ class StoreController extends BaseController $page = $this->request->input('page',1); $pagesize = $this->request->input('pagesize',10); $ids = $this->request->input('ids',''); - $ids = explode(',',$ids); + $ids = json_decode($ids,true); $employees = Employees::query() ->where('user_id',$userId) ->whereJsonContains('position', '30') diff --git a/app/Service/v3/Implementations/StoreService.php b/app/Service/v3/Implementations/StoreService.php index 5707954..619582f 100644 --- a/app/Service/v3/Implementations/StoreService.php +++ b/app/Service/v3/Implementations/StoreService.php @@ -70,7 +70,6 @@ class StoreService implements StoreServiceInterface $market->stores = $stores['data']; $newIds = array_values(array_column($stores['data'], 'id')); $ids = array_merge($newIds,$ids); - $ids = implode(',',$ids); return ['has_more_pages' => $paginate->hasMorePages(), 'market' => $market,'ids' => $ids]; } From 002b2369fecefa383a2d9ff8e172a8db6a251a16 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Thu, 5 Nov 2020 16:48:02 +0800 Subject: [PATCH 09/10] =?UTF-8?q?=E5=BA=97=E9=93=BA=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/v3/Implementations/StoreService.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/Service/v3/Implementations/StoreService.php b/app/Service/v3/Implementations/StoreService.php index 619582f..f871056 100644 --- a/app/Service/v3/Implementations/StoreService.php +++ b/app/Service/v3/Implementations/StoreService.php @@ -69,8 +69,10 @@ class StoreService implements StoreServiceInterface $stores = $paginate->toArray(); $market->stores = $stores['data']; $newIds = array_values(array_column($stores['data'], 'id')); - $ids = array_merge($newIds,$ids); - return ['has_more_pages' => $paginate->hasMorePages(), 'market' => $market,'ids' => $ids]; + if(!is_null($ids)){ + $newIds = array_merge($newIds,$ids); + } + return ['has_more_pages' => $paginate->hasMorePages(), 'market' => $market,'ids' => $newIds]; } public function getListByMarketId($marketId, $page=1, $pagesize=10) From 1e36ee1bd639d2a250b8beed8cae3dab1b07db76 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Thu, 5 Nov 2020 17:24:46 +0800 Subject: [PATCH 10/10] =?UTF-8?q?=E6=90=9C=E7=B4=A2=E5=BA=97=E9=93=BA?= =?UTF-8?q?=E5=88=97=E8=A1=A8=20id?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/v3/SearchController.php | 4 +++- app/Service/v3/Implementations/SearchService.php | 11 +++++++++-- app/Service/v3/Interfaces/SearchServiceInterface.php | 2 +- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/app/Controller/v3/SearchController.php b/app/Controller/v3/SearchController.php index 2536726..79bcf99 100644 --- a/app/Controller/v3/SearchController.php +++ b/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); } } \ No newline at end of file diff --git a/app/Service/v3/Implementations/SearchService.php b/app/Service/v3/Implementations/SearchService.php index 3a2c5b2..e46b96c 100644 --- a/app/Service/v3/Implementations/SearchService.php +++ b/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]; } } \ No newline at end of file diff --git a/app/Service/v3/Interfaces/SearchServiceInterface.php b/app/Service/v3/Interfaces/SearchServiceInterface.php index b50dde9..33b75d0 100644 --- a/app/Service/v3/Interfaces/SearchServiceInterface.php +++ b/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); } \ No newline at end of file