diff --git a/app/common/repositories/store/product/SpuRepository.php b/app/common/repositories/store/product/SpuRepository.php index 19ec533b..c94bf4be 100644 --- a/app/common/repositories/store/product/SpuRepository.php +++ b/app/common/repositories/store/product/SpuRepository.php @@ -158,30 +158,32 @@ class SpuRepository extends BaseRepository return compact('count', 'list'); } - public function getApiCloudSearch($where, $page, $limit) + public function getApiCloudSearch($where, $page, $limit, $rand = true) { $where['spu_status'] = 1; $where['mer_status'] = 1; - $RedisCacheService = app()->make(RedisCacheService::class); - $exists=$RedisCacheService->exists('CloudMerchantSpu'.$where['mer_id']); - if ($exists){ - $Spu_arr=$RedisCacheService->SRANDMEMBER('CloudMerchantSpu'.$where['mer_id'], 10); - $where['product_id'] =$Spu_arr; - } else { - $where['product_id'] = Db::name('cloud_product')->where('mer_id', $where['mer_id'])->where('status', 1)->orderRand()->limit(10)->column('product_id'); + if ($rand) { + $RedisCacheService = app()->make(RedisCacheService::class); + $exists=$RedisCacheService->exists('CloudMerchantSpu'.$where['mer_id']); + if ($exists){ + $Spu_arr=$RedisCacheService->SRANDMEMBER('CloudMerchantSpu'.$where['mer_id'], 10); + $where['product_id'] =$Spu_arr; + } else { + //TODO 后期优化随机查询 + $where['product_id'] = Db::name('cloud_product')->where('mer_id', $where['mer_id'])->where('status', 1)->orderRand()->limit(10)->column('product_id'); + } + unset($where['mer_id']); } - unset($where['mer_id']); $query = $this->dao->search($where); - $count = 0; -// $Sql=$query->page($page, $limit)->setOption('field', [])->field($this->productFiled)->fetchSql(true); + $count = $query->count(); $query->with([ 'merchant' => function ($query) { $query->field($this->merchantFiled)->with(['type_name']); }, 'issetCoupon', ]); - $list = $query->setOption('field', [])->field($this->productFiled)->select(); + $list = $query->setOption('field', [])->field($this->productFiled)->page($page)->limit($limit)->select(); $append = ['stop_time','svip_price','show_svip_info','is_svip_price']; $list->append($append); diff --git a/app/controller/api/Common.php b/app/controller/api/Common.php index 02938c65..c404164f 100644 --- a/app/controller/api/Common.php +++ b/app/controller/api/Common.php @@ -496,7 +496,8 @@ class Common extends BaseController public function get_cloud_shop($street_code){ $find=DB::name('merchant')->alias('m')->where('m.type_id',11)->where('m.is_del',0)->where('m.status',1) ->join('merchant_address a','a.mer_id=m.mer_id and a.street_id='.$street_code) - ->field('m.mer_id')->find(); + ->join('merchant_category c','m.category_id=c.merchant_category_id') + ->field('m.mer_id,category_id,category_name')->select(); return app('json')->success($find??[]); } } diff --git a/app/controller/api/store/product/CloudWarehouse.php b/app/controller/api/store/product/CloudWarehouse.php new file mode 100644 index 00000000..605ecd6b --- /dev/null +++ b/app/controller/api/store/product/CloudWarehouse.php @@ -0,0 +1,66 @@ +repository = $repository; + $this->merchantDao = $merchantDao; + $this->spuRepository = $spuRepository; + } + + /** + * 指定类型的云仓商品列表 + * @return mixed + */ + public function index() + { + $params = $this->request->params(['category_id', 'street_code', 'order', ['product_type', 0]]); + $search = [ + 'street_id' => $params['street_code'], + 'type_id' => Merchant::TypeStore, + 'category_id' => $params['category_id'], + ]; + $merchantIds = $this->merchantDao->search($search)->column('mer_id'); + [$page, $limit] = $this->getPage(); + if (empty($merchantIds)) { + return app('json')->success(['count' => 0, 'list' => []]); + } + $where['mer_ids'] = $merchantIds; + $where['product_type'] = $params['product_type']; + $where['is_gift_bag'] = 0; + $where['order'] = $params['order'] ?: 'sort'; + $products = $this->spuRepository->getApiCloudSearch($where, $page, $limit, false); + return app('json')->success($products); + } + +} \ No newline at end of file diff --git a/route/api.php b/route/api.php index e71be2c7..3796ce86 100644 --- a/route/api.php +++ b/route/api.php @@ -532,6 +532,7 @@ Route::group('api/', function () { //test Route::any('store/test', 'api.Test/test'); Route::get('subscribe', 'api.Common/subscribe'); + Route::resource('store/product/cloudWarehouse', 'api.store.product.CloudWarehouse'); })->middleware(UserTokenMiddleware::class, false);