修复随机查询

This commit is contained in:
mkm 2023-11-13 18:08:56 +08:00
parent de6480d3d9
commit 6c37022bfc
2 changed files with 18 additions and 18 deletions

View File

@ -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']);

View File

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