Showing
2 changed files
with
20 additions
and
16 deletions
@@ -10,11 +10,13 @@ const redis = global.yoho.redis; | @@ -10,11 +10,13 @@ const redis = global.yoho.redis; | ||
10 | const cache = global.yoho.cache; | 10 | const cache = global.yoho.cache; |
11 | const logger = global.yoho.logger; | 11 | const logger = global.yoho.logger; |
12 | const uuid = require('uuid'); | 12 | const uuid = require('uuid'); |
13 | +const helpers = global.yoho.helpers; | ||
14 | +const _ = require('lodash'); | ||
13 | 15 | ||
14 | function _cacheGet(key) { | 16 | function _cacheGet(key) { |
15 | return cache.get(key).then((data) => { | 17 | return cache.get(key).then((data) => { |
16 | if (data) { | 18 | if (data) { |
17 | - return data; | 19 | + return JSON.parse(data); |
18 | } | 20 | } |
19 | 21 | ||
20 | return Promise.reject(); | 22 | return Promise.reject(); |
@@ -195,10 +197,25 @@ const getLikeAsync = (skn, limit) => { | @@ -195,10 +197,25 @@ const getLikeAsync = (skn, limit) => { | ||
195 | }, {cache: 86400}); | 197 | }, {cache: 86400}); |
196 | }; | 198 | }; |
197 | 199 | ||
200 | +// 返回6条推荐关键词页面 | ||
201 | +function getKeywordsInfo(keywords) { | ||
202 | + let res = []; | ||
203 | + | ||
204 | + _.forEach(_.slice(_.shuffle(keywords), 0, 12), val => { | ||
205 | + res.push({ | ||
206 | + url: helpers.urlFormat(`/chanpin/${val.id}.html`), | ||
207 | + keyword: val.keyword | ||
208 | + }); | ||
209 | + }); | ||
210 | + return res; | ||
211 | +} | ||
212 | + | ||
198 | // 根据small_sort从redis获取分类下的关键词 | 213 | // 根据small_sort从redis获取分类下的关键词 |
199 | function _getRecommendKeywords(smallSort) { | 214 | function _getRecommendKeywords(smallSort) { |
200 | return redis.all([['get', `global:yoho:seo:keywords:sortId:${smallSort}:page:1`]]).then(res => { | 215 | return redis.all([['get', `global:yoho:seo:keywords:sortId:${smallSort}:page:1`]]).then(res => { |
201 | return res[0]; | 216 | return res[0]; |
217 | + }).then(result => { | ||
218 | + return getKeywordsInfo(JSON.parse(result || '[]')); | ||
202 | }); | 219 | }); |
203 | } | 220 | } |
204 | 221 |
@@ -1010,19 +1010,6 @@ const _getIntroInfo = (productSkn, maxSortId, additionalData)=> { | @@ -1010,19 +1010,6 @@ const _getIntroInfo = (productSkn, maxSortId, additionalData)=> { | ||
1010 | return result; | 1010 | return result; |
1011 | }; | 1011 | }; |
1012 | 1012 | ||
1013 | -// 返回6条推荐关键词页面 | ||
1014 | -const getKeywordsInfo = (keywords) => { | ||
1015 | - let res = []; | ||
1016 | - | ||
1017 | - _.forEach(_.slice(_.shuffle(keywords), 0, 12), val => { | ||
1018 | - res.push({ | ||
1019 | - url: Helpers.urlFormat(`/chanpin/${val.id}.html`), | ||
1020 | - keyword: val.keyword | ||
1021 | - }); | ||
1022 | - }); | ||
1023 | - return res; | ||
1024 | -}; | ||
1025 | - | ||
1026 | /** | 1013 | /** |
1027 | * 获取seo信息 | 1014 | * 获取seo信息 |
1028 | * | 1015 | * |
@@ -1194,13 +1181,13 @@ const _detailDataPkg = (origin, uid, vipLevel, cookies) => { | @@ -1194,13 +1181,13 @@ const _detailDataPkg = (origin, uid, vipLevel, cookies) => { | ||
1194 | let coupon = requestData.coupon; | 1181 | let coupon = requestData.coupon; |
1195 | let limitedInfo = requestData.limited; | 1182 | let limitedInfo = requestData.limited; |
1196 | let bundle = requestData.bundle; | 1183 | let bundle = requestData.bundle; |
1197 | - let recommendKeywords = requestData.recommendKeywords ? JSON.parse(requestData.recommendKeywords) : []; | 1184 | + let recommendKeywords = requestData.recommendKeywords; |
1198 | 1185 | ||
1199 | // 处理相似商品 | 1186 | // 处理相似商品 |
1200 | result.alike = productProcess.processProductList(_.get(requestData, 'alike.data.product_list', '')); | 1187 | result.alike = productProcess.processProductList(_.get(requestData, 'alike.data.product_list', '')); |
1201 | 1188 | ||
1202 | // 推荐关键词页面 | 1189 | // 推荐关键词页面 |
1203 | - result.recommendKeywords = getKeywordsInfo(recommendKeywords); | 1190 | + result.recommendKeywords = recommendKeywords; |
1204 | 1191 | ||
1205 | // 处理店铺推荐 | 1192 | // 处理店铺推荐 |
1206 | result.shopRecommend = productProcess.processProductList( | 1193 | result.shopRecommend = productProcess.processProductList( |
-
Please register or login to post a comment