更新随机查询

This commit is contained in:
yaooo 2023-09-27 15:51:55 +08:00
parent 5c470dba5d
commit 3afc4084b8
2 changed files with 23 additions and 12 deletions

View File

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

View File

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