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';