Showing
4 changed files
with
89 additions
and
3 deletions
@@ -226,6 +226,22 @@ const createConsult = (req, res, next) => { | @@ -226,6 +226,22 @@ const createConsult = (req, res, next) => { | ||
226 | } | 226 | } |
227 | }; | 227 | }; |
228 | 228 | ||
229 | +const recommend = (req, res, next) => { | ||
230 | + let skn = req.query.skn || ''; | ||
231 | + let pageSize = req.query.size || 5; | ||
232 | + let pageNum = req.query.num || 1; | ||
233 | + | ||
234 | + if (!skn) { | ||
235 | + return res.json({ | ||
236 | + code: 400, | ||
237 | + message: '服务器错误' | ||
238 | + }); | ||
239 | + } | ||
240 | + | ||
241 | + service.recommendAsync(skn, pageNum, pageSize) | ||
242 | + .then(result => res.json(result)) | ||
243 | + .catch(next); | ||
244 | +}; | ||
229 | 245 | ||
230 | module.exports = { | 246 | module.exports = { |
231 | showMain, | 247 | showMain, |
@@ -234,7 +250,8 @@ module.exports = { | @@ -234,7 +250,8 @@ module.exports = { | ||
234 | indexConsult, | 250 | indexConsult, |
235 | createConsult, | 251 | createConsult, |
236 | productHeader: detailHeader, | 252 | productHeader: detailHeader, |
237 | - detailReturn | 253 | + detailReturn, |
254 | + recommend | ||
238 | }; | 255 | }; |
239 | 256 | ||
240 | 257 |
@@ -104,6 +104,20 @@ const getLimitedProductStatusAsync = (code, uid, skn) => { | @@ -104,6 +104,20 @@ const getLimitedProductStatusAsync = (code, uid, skn) => { | ||
104 | return api.get('', params, config.apiCache); | 104 | return api.get('', params, config.apiCache); |
105 | }; | 105 | }; |
106 | 106 | ||
107 | +/** | ||
108 | + * | ||
109 | + * @param skn product_skn | ||
110 | + * @param sid shop_id | ||
111 | + */ | ||
112 | +const getShopRecommendAsync = (skn, page, limit) => { | ||
113 | + return api.get('', { | ||
114 | + method: 'web.product.shopRecommend', | ||
115 | + product_skn: skn, | ||
116 | + page: page, | ||
117 | + limit: limit | ||
118 | + }); | ||
119 | +}; | ||
120 | + | ||
107 | module.exports = { | 121 | module.exports = { |
108 | getProductBannerAsync, | 122 | getProductBannerAsync, |
109 | sizeInfoAsync, | 123 | sizeInfoAsync, |
@@ -113,5 +127,6 @@ module.exports = { | @@ -113,5 +127,6 @@ module.exports = { | ||
113 | getProductAsync, | 127 | getProductAsync, |
114 | getPromotionAsync, | 128 | getPromotionAsync, |
115 | isSupportReturnedSale, | 129 | isSupportReturnedSale, |
116 | - getLimitedProductStatusAsync | 130 | + getLimitedProductStatusAsync, |
131 | + getShopRecommendAsync | ||
117 | }; | 132 | }; |
@@ -9,6 +9,7 @@ | @@ -9,6 +9,7 @@ | ||
9 | const Promise = require('bluebird'); | 9 | const Promise = require('bluebird'); |
10 | const co = Promise.coroutine; | 10 | const co = Promise.coroutine; |
11 | const _ = require('lodash'); | 11 | const _ = require('lodash'); |
12 | +const Fn = require('lodash/fp'); | ||
12 | const url = require('url'); | 13 | const url = require('url'); |
13 | const helpers = global.yoho.helpers; | 14 | const helpers = global.yoho.helpers; |
14 | 15 | ||
@@ -1404,6 +1405,57 @@ const showMainAsync = (data) => { | @@ -1404,6 +1405,57 @@ const showMainAsync = (data) => { | ||
1404 | })(); | 1405 | })(); |
1405 | }; | 1406 | }; |
1406 | 1407 | ||
1408 | + | ||
1409 | +const recommendAsync = (skn, page, limit) => { | ||
1410 | + return co(function * () { | ||
1411 | + let recommendData = productAPI.getShopRecommendAsync(skn, page, limit); | ||
1412 | + | ||
1413 | + if (_.get(recommendData, 'code', 400) !== 200) { | ||
1414 | + return { | ||
1415 | + code: 400, | ||
1416 | + message: '服务器错误!' | ||
1417 | + }; | ||
1418 | + } | ||
1419 | + | ||
1420 | + const formatPrice = p => `¥${p}`; | ||
1421 | + const productUrl = (pid, gid, cn) => helpers.urlFormat(`/product/pro_${pid}_${gid}/${cn}.html`, null, 'item'); | ||
1422 | + const productImageUrl = Fn.pipe(Fn.prop('default_images'), _.partial(helpers.image, _, 150, 200, 2, 70)); | ||
1423 | + | ||
1424 | + let products = _.get(recommendData, 'product_list', []).map(rp => { | ||
1425 | + let marketPrice = rp.sales_price; | ||
1426 | + let salePrice = rp.market_price; | ||
1427 | + | ||
1428 | + let defaultGoods = _.find(rp.goods_list, {is_default: 'Y'}); | ||
1429 | + | ||
1430 | + // 无默认商品取商品列表第一个 | ||
1431 | + if (!defaultGoods) { | ||
1432 | + defaultGoods = rp.goods_list[0]; | ||
1433 | + } | ||
1434 | + | ||
1435 | + return { | ||
1436 | + market_price: marketPrice === salePrice ? '' : formatPrice(helpers.round(marketPrice, 2)), | ||
1437 | + price: formatPrice(helpers.round(salePrice, 2)), | ||
1438 | + product_name: rp.product_name, | ||
1439 | + url: productUrl(rp.product_id, defaultGoods.goods_id, rp.cn_alphabet), | ||
1440 | + pic_url: productImageUrl(rp) | ||
1441 | + }; | ||
1442 | + }); | ||
1443 | + | ||
1444 | + return { | ||
1445 | + code: 200, | ||
1446 | + data: { | ||
1447 | + pager: { | ||
1448 | + total: _.get(recommendData, 'page_total', 0), | ||
1449 | + size: _.get(recommendData, 'page_size', 5), | ||
1450 | + num: _.get(recommendData, 'page', 1) | ||
1451 | + }, | ||
1452 | + products: products, | ||
1453 | + total: _.get(recommendData, 'total', 0) | ||
1454 | + } | ||
1455 | + }; | ||
1456 | + })(); | ||
1457 | +}; | ||
1458 | + | ||
1407 | module.exports = { | 1459 | module.exports = { |
1408 | getShareOrderListAsync: commentService.getShareOrderListAsync, // 获取评论列表 | 1460 | getShareOrderListAsync: commentService.getShareOrderListAsync, // 获取评论列表 |
1409 | indexConsultAsync: consultService.indexAsync, // 获取咨询列表 | 1461 | indexConsultAsync: consultService.indexAsync, // 获取咨询列表 |
@@ -1412,5 +1464,6 @@ module.exports = { | @@ -1412,5 +1464,6 @@ module.exports = { | ||
1412 | indexHotAreaAsync: hotAreaService.indexAsync, // 获取某一个商品的热区数据 | 1464 | indexHotAreaAsync: hotAreaService.indexAsync, // 获取某一个商品的热区数据 |
1413 | saveRecentGoodInCookies, // 保存最近的商品 | 1465 | saveRecentGoodInCookies, // 保存最近的商品 |
1414 | getDetailHeader, | 1466 | getDetailHeader, |
1415 | - saleReturn | 1467 | + saleReturn, |
1468 | + recommendAsync | ||
1416 | }; | 1469 | }; |
@@ -61,6 +61,7 @@ router.post('/index/favoriteBrand', favorite.changeFavoriteBrand);// 收è—å“ç‰ | @@ -61,6 +61,7 @@ router.post('/index/favoriteBrand', favorite.changeFavoriteBrand);// 收è—å“ç‰ | ||
61 | router.post('/item/togglecollect', favorite.collectProduct); // 收藏商品 | 61 | router.post('/item/togglecollect', favorite.collectProduct); // 收藏商品 |
62 | router.get('/detail/header', detail.productHeader); // 价格数据重新获取接口 | 62 | router.get('/detail/header', detail.productHeader); // 价格数据重新获取接口 |
63 | router.get('/detail/return', detail.detailReturn);// 特殊商品退换货 | 63 | router.get('/detail/return', detail.detailReturn);// 特殊商品退换货 |
64 | +router.get('/detail/recommend', detail.recommend);// 推荐商品 | ||
64 | router.get('/index/isfav', favorite.isFavoriteBrand);// 品牌收藏状态 | 65 | router.get('/index/isfav', favorite.isFavoriteBrand);// 品牌收藏状态 |
65 | 66 | ||
66 | // 搜索 | 67 | // 搜索 |
-
Please register or login to post a comment