|
@@ -174,15 +174,16 @@ class Merchant extends BaseController
|
|
174
|
$hasKeyword = !empty($params['keyword'] ?? '') || !empty($this->request->param('keyword', ''));
|
174
|
$hasKeyword = !empty($params['keyword'] ?? '') || !empty($this->request->param('keyword', ''));
|
|
175
|
if (!is_null($this->userInfo) && !empty($result['list']) && !$hasKeyword) {
|
175
|
if (!is_null($this->userInfo) && !empty($result['list']) && !$hasKeyword) {
|
|
176
|
try {
|
176
|
try {
|
|
177
|
- // 1. 获取用户最近的搜索关键词(去重)
|
|
|
|
|
|
177
|
+ // 1. 获取用户最近的搜索关键词(SQL 层去重)
|
|
178
|
$searchKeywords = Db::name('user_visit')
|
178
|
$searchKeywords = Db::name('user_visit')
|
|
179
|
->where('uid', $this->userInfo['uid'])
|
179
|
->where('uid', $this->userInfo['uid'])
|
|
180
|
->where('type', 'searchProduct')
|
180
|
->where('type', 'searchProduct')
|
|
181
|
->where('content', '<>', '')
|
181
|
->where('content', '<>', '')
|
|
|
|
182
|
+ ->group('content')
|
|
182
|
->order('create_time', 'DESC')
|
183
|
->order('create_time', 'DESC')
|
|
183
|
->limit(5)
|
184
|
->limit(5)
|
|
184
|
->column('content');
|
185
|
->column('content');
|
|
185
|
- $searchKeywords = array_unique(array_filter($searchKeywords));
|
|
|
|
|
|
186
|
+ $searchKeywords = array_filter($searchKeywords);
|
|
186
|
|
187
|
|
|
187
|
if (!empty($searchKeywords)) {
|
188
|
if (!empty($searchKeywords)) {
|
|
188
|
// 2. 查询所有匹配的商品ID(不 limit,形成推荐池),排除已在当前列表中的
|
189
|
// 2. 查询所有匹配的商品ID(不 limit,形成推荐池),排除已在当前列表中的
|