From 6c37022bfc6f37eb6fd992ac415a52ec032da87a Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Mon, 13 Nov 2023 18:08:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=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 | 35 ++++++++++--------- app/controller/api/store/product/StoreSpu.php | 1 - 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/app/common/repositories/store/product/SpuRepository.php b/app/common/repositories/store/product/SpuRepository.php index 94af352a..f77195f7 100644 --- a/app/common/repositories/store/product/SpuRepository.php +++ b/app/common/repositories/store/product/SpuRepository.php @@ -183,7 +183,12 @@ class SpuRepository extends BaseRepository app()->make(UserVisitRepository::class)->searchProduct($this->userInfo ? $this->userInfo['uid'] : 0, $where['keyword'], (int)($where['mer_id'] ?? 0)); } } + $entryMerId = $where['entry_mer_id'] ?? ''; + unset($where['entry_mer_id']); + $query = $this->dao->search($where); + $count = $query->fetchSql(false)->count(); if ($rand) { + $query->whereRaw('spu_id >= ( SELECT floor( RAND() * ( SELECT MAX( spu_id ) FROM `eb_store_spu` ) ) )'); // $dataKey = sprintf(CloudProduct::CacheKey, $where['mer_rand_id']); // $RedisCacheService = app()->make(RedisCacheService::class); // $exists = $RedisCacheService->exists($dataKey); @@ -195,24 +200,20 @@ class SpuRepository extends BaseRepository // } // $where['product_id'] = $this->getSpuFromCache($where['mer_rand_id'], $page, $limit); // 查询 - $query = $this->dao->search($where); - $randPidList = $query->setOption('field', [])->field(['P.product_id'])->fetchSql(false)->page(1)->limit(500)->column('P.product_id'); - $randNum = count($randPidList); - // 最多10条随机数据 - if ($randNum > 10) { - array_rand($randPidList, 10); - } elseif ($randNum > 0) { - array_rand($randPidList, $randNum); - } else { - $randPidList = []; - } - $where['product_id'] = $randPidList; - unset($where['mer_rand_id'], $where['page']); + // $query = $this->dao->search($where); + // $randPidList = $query->setOption('field', [])->field(['P.product_id'])->fetchSql(false)->page(1)->limit(500)->column('P.product_id'); + // $randNum = count($randPidList); + // // 最多10条随机数据 + // if ($randNum > 10) { + // array_rand($randPidList, 10); + // } elseif ($randNum > 0) { + // array_rand($randPidList, $randNum); + // } else { + // $randPidList = []; + // } + // $where['product_id'] = $randPidList; + // unset($where['mer_rand_id'], $where['page']); } - $entryMerId = $where['entry_mer_id'] ?? ''; - unset($where['entry_mer_id']); - $query = $this->dao->search($where); - $count = $query->fetchSql(false)->count(); $query->with([ 'merchant' => function ($query) { $query->field($this->merchantFiled)->with(['type_names']); diff --git a/app/controller/api/store/product/StoreSpu.php b/app/controller/api/store/product/StoreSpu.php index 61eab1ed..758a33ed 100644 --- a/app/controller/api/store/product/StoreSpu.php +++ b/app/controller/api/store/product/StoreSpu.php @@ -161,7 +161,6 @@ class StoreSpu extends BaseController ->whereIn('type_id', implode(',', $typeIdArray)) ->column('mer_id'); $where['mer_array_id'] = $merIdArray; - $where['mer_rand_id'] = $id; $where['entry_mer_id'] = $id; $where['is_gift_bag'] = 0; $where['order'] = $where['order'] ? $where['order'] : 'sort';