更新随机查询
This commit is contained in:
parent
5c470dba5d
commit
3afc4084b8
@ -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));
|
app()->make(UserVisitRepository::class)->searchProduct($this->userInfo ? $this->userInfo['uid'] : 0, $where['keyword'], (int)($where['mer_id'] ?? 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$rand = true;
|
||||||
if ($rand) {
|
if ($rand) {
|
||||||
$dataKey = sprintf(CloudProduct::CacheKey, $where['mer_id']);
|
// $dataKey = sprintf(CloudProduct::CacheKey, $where['mer_rand_id']);
|
||||||
$RedisCacheService = app()->make(RedisCacheService::class);
|
// $RedisCacheService = app()->make(RedisCacheService::class);
|
||||||
$exists = $RedisCacheService->exists($dataKey);
|
// $exists = $RedisCacheService->exists($dataKey);
|
||||||
if (!$exists) {
|
// if (!$exists) {
|
||||||
$productIds = Db::name('cloud_product')->where('mer_id', $where['mer_id'])->where('status', 1)->limit(100)->column('product_id');
|
// $productIds = Db::name('cloud_product')->where('mer_id', $where['mer_rand_id'])->where('status', 1)->limit(100)->column('product_id');
|
||||||
foreach ($productIds as $productId) {
|
// foreach ($productIds as $productId) {
|
||||||
$RedisCacheService->SADD($dataKey, $productId);
|
// $RedisCacheService->SADD($dataKey, $productId);
|
||||||
}
|
// }
|
||||||
//halt($productIds);
|
// }
|
||||||
|
// $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);
|
$where['product_id'] = $randPidList;
|
||||||
unset($where['mer_id'], $where['page']);
|
unset($where['mer_rand_id'], $where['page']);
|
||||||
$page = 1;
|
$page = 1;
|
||||||
}
|
}
|
||||||
$entryMerId = $where['entry_mer_id'] ?? '';
|
$entryMerId = $where['entry_mer_id'] ?? '';
|
||||||
|
@ -152,7 +152,7 @@ class StoreSpu extends BaseController
|
|||||||
->where('type_id', $typeTownSupplyChainId)
|
->where('type_id', $typeTownSupplyChainId)
|
||||||
->column('mer_id');
|
->column('mer_id');
|
||||||
$where['mer_array_id'] = $merIdArray;
|
$where['mer_array_id'] = $merIdArray;
|
||||||
// $where['mer_id'] = $mer_id;
|
$where['mer_rand_id'] = $id;
|
||||||
$where['entry_mer_id'] = $id;
|
$where['entry_mer_id'] = $id;
|
||||||
$where['is_gift_bag'] = 0;
|
$where['is_gift_bag'] = 0;
|
||||||
$where['order'] = $where['order'] ? $where['order'] : 'sort';
|
$where['order'] = $where['order'] ? $where['order'] : 'sort';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user