From 3afc4084b81f8a0e1bbb0dcf18a7ec38b91e04bc Mon Sep 17 00:00:00 2001 From: yaooo <272523191@qq.com> Date: Wed, 27 Sep 2023 15:51:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E9=9A=8F=E6=9C=BA=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../store/product/SpuRepository.php | 33 ++++++++++++------- app/controller/api/store/product/StoreSpu.php | 2 +- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/app/common/repositories/store/product/SpuRepository.php b/app/common/repositories/store/product/SpuRepository.php index d3445bf7..f5da0559 100644 --- a/app/common/repositories/store/product/SpuRepository.php +++ b/app/common/repositories/store/product/SpuRepository.php @@ -178,19 +178,30 @@ class SpuRepository extends BaseRepository app()->make(UserVisitRepository::class)->searchProduct($this->userInfo ? $this->userInfo['uid'] : 0, $where['keyword'], (int)($where['mer_id'] ?? 0)); } } + $rand = true; if ($rand) { - $dataKey = sprintf(CloudProduct::CacheKey, $where['mer_id']); - $RedisCacheService = app()->make(RedisCacheService::class); - $exists = $RedisCacheService->exists($dataKey); - if (!$exists) { - $productIds = Db::name('cloud_product')->where('mer_id', $where['mer_id'])->where('status', 1)->limit(100)->column('product_id'); - foreach ($productIds as $productId) { - $RedisCacheService->SADD($dataKey, $productId); - } - //halt($productIds); + // $dataKey = sprintf(CloudProduct::CacheKey, $where['mer_rand_id']); + // $RedisCacheService = app()->make(RedisCacheService::class); + // $exists = $RedisCacheService->exists($dataKey); + // if (!$exists) { + // $productIds = Db::name('cloud_product')->where('mer_id', $where['mer_rand_id'])->where('status', 1)->limit(100)->column('product_id'); + // foreach ($productIds as $productId) { + // $RedisCacheService->SADD($dataKey, $productId); + // } + // } + // $where['product_id'] = $this->getSpuFromCache($where['mer_rand_id'], $page, $limit); + // 查询 + $query = $this->dao->search($where); + $randPidList = $query->setOption('field', [])->field(['P.product_id'])->page(1)->limit(500)->column('P.product_id'); + $randNum = count($randPidList); + // 最多10条随机数据 + if ($randNum > 10) { + array_rand($randPidList, 10); + } else { + array_rand($randPidList, $randNum); } - $where['product_id'] = $this->getSpuFromCache($where['mer_id'], $page, $limit); - unset($where['mer_id'], $where['page']); + $where['product_id'] = $randPidList; + unset($where['mer_rand_id'], $where['page']); $page = 1; } $entryMerId = $where['entry_mer_id'] ?? ''; diff --git a/app/controller/api/store/product/StoreSpu.php b/app/controller/api/store/product/StoreSpu.php index 83eda5f7..dafef786 100644 --- a/app/controller/api/store/product/StoreSpu.php +++ b/app/controller/api/store/product/StoreSpu.php @@ -152,7 +152,7 @@ class StoreSpu extends BaseController ->where('type_id', $typeTownSupplyChainId) ->column('mer_id'); $where['mer_array_id'] = $merIdArray; - // $where['mer_id'] = $mer_id; + $where['mer_rand_id'] = $id; $where['entry_mer_id'] = $id; $where['is_gift_bag'] = 0; $where['order'] = $where['order'] ? $where['order'] : 'sort';