修复随机查询
This commit is contained in:
parent
de6480d3d9
commit
6c37022bfc
@ -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));
|
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) {
|
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']);
|
// $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);
|
||||||
@ -195,24 +200,20 @@ class SpuRepository extends BaseRepository
|
|||||||
// }
|
// }
|
||||||
// $where['product_id'] = $this->getSpuFromCache($where['mer_rand_id'], $page, $limit);
|
// $where['product_id'] = $this->getSpuFromCache($where['mer_rand_id'], $page, $limit);
|
||||||
// 查询
|
// 查询
|
||||||
$query = $this->dao->search($where);
|
// $query = $this->dao->search($where);
|
||||||
$randPidList = $query->setOption('field', [])->field(['P.product_id'])->fetchSql(false)->page(1)->limit(500)->column('P.product_id');
|
// $randPidList = $query->setOption('field', [])->field(['P.product_id'])->fetchSql(false)->page(1)->limit(500)->column('P.product_id');
|
||||||
$randNum = count($randPidList);
|
// $randNum = count($randPidList);
|
||||||
// 最多10条随机数据
|
// // 最多10条随机数据
|
||||||
if ($randNum > 10) {
|
// if ($randNum > 10) {
|
||||||
array_rand($randPidList, 10);
|
// array_rand($randPidList, 10);
|
||||||
} elseif ($randNum > 0) {
|
// } elseif ($randNum > 0) {
|
||||||
array_rand($randPidList, $randNum);
|
// array_rand($randPidList, $randNum);
|
||||||
} else {
|
// } else {
|
||||||
$randPidList = [];
|
// $randPidList = [];
|
||||||
}
|
// }
|
||||||
$where['product_id'] = $randPidList;
|
// $where['product_id'] = $randPidList;
|
||||||
unset($where['mer_rand_id'], $where['page']);
|
// 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([
|
$query->with([
|
||||||
'merchant' => function ($query) {
|
'merchant' => function ($query) {
|
||||||
$query->field($this->merchantFiled)->with(['type_names']);
|
$query->field($this->merchantFiled)->with(['type_names']);
|
||||||
|
@ -161,7 +161,6 @@ class StoreSpu extends BaseController
|
|||||||
->whereIn('type_id', implode(',', $typeIdArray))
|
->whereIn('type_id', implode(',', $typeIdArray))
|
||||||
->column('mer_id');
|
->column('mer_id');
|
||||||
$where['mer_array_id'] = $merIdArray;
|
$where['mer_array_id'] = $merIdArray;
|
||||||
$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