diff --git a/app/Controller/v3/SearchController.php b/app/Controller/v3/SearchController.php index 3477e75..79bcf99 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,26 @@ 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); + $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); + } } \ No newline at end of file diff --git a/app/Controller/v3/StoreController.php b/app/Controller/v3/StoreController.php index 7e21afd..2ba81d6 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,16 @@ 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)){ + $ids = $this->request->input('ids',''); + $ids = json_decode($ids,true); + $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,$ids,$page,$pagesize); return $this->success($res); } diff --git a/app/Model/v3/GoodsActivity.php b/app/Model/v3/GoodsActivity.php index c3097ea..5df8ea2 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 = [ @@ -87,9 +94,11 @@ 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['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; } diff --git a/app/Service/v3/Implementations/SearchService.php b/app/Service/v3/Implementations/SearchService.php index f10dcb5..e46b96c 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,24 @@ class SearchService implements SearchServiceInterface { // TODO: Implement undo() method. } + + 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']; + $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/Implementations/StoreService.php b/app/Service/v3/Implementations/StoreService.php index 2ef73e4..f871056 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)){ + $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')); + 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) @@ -87,7 +94,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(); diff --git a/app/Service/v3/Interfaces/SearchServiceInterface.php b/app/Service/v3/Interfaces/SearchServiceInterface.php index 0767938..33b75d0 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, $ids,$keywords ,$page=1, $pagesize=10); } \ No newline at end of file diff --git a/app/Service/v3/Interfaces/StoreServiceInterface.php b/app/Service/v3/Interfaces/StoreServiceInterface.php index e8c79cd..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 ,$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 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]]); // 微信支付回调