Authored by htoooth

add hotarea

@@ -49,7 +49,22 @@ module.exports.showMain = (req, res, next) => { @@ -49,7 +49,22 @@ module.exports.showMain = (req, res, next) => {
49 }; 49 };
50 50
51 /** 51 /**
  52 + * 获取热区图
  53 + */
  54 +module.exports.indexHotArea = (req, res, next) => {
  55 + let pid = req.params.productId || 0;
  56 +
  57 + service.indexHotAreaAsync(pid).then(result => {
  58 + res.render('hotarea', {
  59 + hotArea: result,
  60 + layout:false
  61 + });
  62 + }).catch(next);
  63 +};
  64 +
  65 +/**
52 * 获得评论列表 66 * 获得评论列表
  67 + * json
53 */ 68 */
54 module.exports.indexComment = (req, res, next) => { 69 module.exports.indexComment = (req, res, next) => {
55 let pid = req.params.productId || 0; 70 let pid = req.params.productId || 0;
@@ -59,10 +74,11 @@ module.exports.indexComment = (req, res, next) => { @@ -59,10 +74,11 @@ module.exports.indexComment = (req, res, next) => {
59 service.indexCommentAsync(pid, page, size).then(result => { 74 service.indexCommentAsync(pid, page, size).then(result => {
60 res.json(result) 75 res.json(result)
61 }).catch(next); 76 }).catch(next);
62 -} 77 +};
63 78
64 /** 79 /**
65 * 获得咨询列表 80 * 获得咨询列表
  81 + * json
66 */ 82 */
67 module.exports.indexConsult = (req, res, next) => { 83 module.exports.indexConsult = (req, res, next) => {
68 // TODO: uid 84 // TODO: uid
@@ -78,6 +94,7 @@ module.exports.indexConsult = (req, res, next) => { @@ -78,6 +94,7 @@ module.exports.indexConsult = (req, res, next) => {
78 94
79 /** 95 /**
80 * 新建咨询 96 * 新建咨询
  97 + * json
81 */ 98 */
82 module.exports.createConsult = (req, res, next) => { 99 module.exports.createConsult = (req, res, next) => {
83 100
@@ -115,3 +132,5 @@ module.exports.createConsult = (req, res, next) => { @@ -115,3 +132,5 @@ module.exports.createConsult = (req, res, next) => {
115 } 132 }
116 133
117 }; 134 };
  135 +
  136 +
1 /** 1 /**
2 * Created by TaoHuang on 2016/6/13. 2 * Created by TaoHuang on 2016/6/13.
3 */ 3 */
  4 +
  5 +const library = '../../../library';
  6 +const API = require(`${library}/api`).API;
  7 +const sign = require(`${library}/sign`);
  8 +const Promise = require('bluebird');
  9 +
  10 +const api = new API();
  11 +
  12 +/**
  13 + * 获取商品的热区
  14 + */
  15 +module.exports.indexAsync = (pid) => {
  16 + return api.get('', api.apiSign({
  17 + method: 'web.productCollocation.list',
  18 + product_id: pid
  19 + })).catch(console.log);
  20 +};
@@ -19,6 +19,7 @@ const helpers = require(`${library}/helpers`); @@ -19,6 +19,7 @@ const helpers = require(`${library}/helpers`);
19 const detailAPI = require('./detail-main-api'); 19 const detailAPI = require('./detail-main-api');
20 const commentAPI = require('./detail-comment-api'); 20 const commentAPI = require('./detail-comment-api');
21 const consultAPI = require('./detail-consult-api'); 21 const consultAPI = require('./detail-consult-api');
  22 +const hotAreaAPI = require('./detail-hotarea-api');
22 const brandAPI = require('./brand-api'); 23 const brandAPI = require('./brand-api');
23 const favoriteAPI = require('./favorite-api'); 24 const favoriteAPI = require('./favorite-api');
24 const shopAPI = require('./shop-api'); 25 const shopAPI = require('./shop-api');
@@ -76,9 +77,6 @@ function getMultiDataByResourceName(resourceName) { @@ -76,9 +77,6 @@ function getMultiDataByResourceName(resourceName) {
76 77
77 /** 78 /**
78 * 获取商品的喜欢 79 * 获取商品的喜欢
79 - * @param uid  
80 - * @param pid  
81 - * @param bid  
82 */ 80 */
83 const getProductFavoriteData = (uid, pid, bid) => { 81 const getProductFavoriteData = (uid, pid, bid) => {
84 return co(function*() { 82 return co(function*() {
@@ -233,7 +231,6 @@ const getActivityDataByProductBaseInfo = (data) => { @@ -233,7 +231,6 @@ const getActivityDataByProductBaseInfo = (data) => {
233 /** 231 /**
234 * 获取商品咨询和评论数据 232 * 获取商品咨询和评论数据
235 * @param data 233 * @param data
236 - * @returns {{}}  
237 */ 234 */
238 const getConsultCommentDataByProductInfo = (data) => { 235 const getConsultCommentDataByProductInfo = (data) => {
239 236
@@ -262,7 +259,6 @@ const getConsultCommentDataByProductInfo = (data) => { @@ -262,7 +259,6 @@ const getConsultCommentDataByProductInfo = (data) => {
262 259
263 /** 260 /**
264 * 获取品牌数据 261 * 获取品牌数据
265 - * @param data  
266 */ 262 */
267 const getBrandDataByProductBaseInfo = (data) => { 263 const getBrandDataByProductBaseInfo = (data) => {
268 264
@@ -325,8 +321,6 @@ const getBrandDataByProductBaseInfo = (data) => { @@ -325,8 +321,6 @@ const getBrandDataByProductBaseInfo = (data) => {
325 321
326 /** 322 /**
327 * 获得sku商品数据 323 * 获得sku商品数据
328 - * @param data  
329 - * @returns {{defaultImage: number, skuGoods: number, totalStorageNum: number}}  
330 */ 324 */
331 const getSkuDataByProductBaseInfo = (data) => { 325 const getSkuDataByProductBaseInfo = (data) => {
332 let totalStorageNum = 0; 326 let totalStorageNum = 0;
@@ -517,7 +511,6 @@ const getFashionTopGoodsStatus = (uid, showStatus, isBeginSale) => { @@ -517,7 +511,6 @@ const getFashionTopGoodsStatus = (uid, showStatus, isBeginSale) => {
517 511
518 /** 512 /**
519 * 获取分类导航列表 513 * 获取分类导航列表
520 - * @returns {Promise.<{}>}  
521 */ 514 */
522 // controller item.php 32; 515 // controller item.php 32;
523 function getSortNavAsync(smallSortId, gender) { 516 function getSortNavAsync(smallSortId, gender) {
@@ -1339,9 +1332,6 @@ const getSizeInfoAsync = (productSkn, maxSortId)=> { @@ -1339,9 +1332,6 @@ const getSizeInfoAsync = (productSkn, maxSortId)=> {
1339 1332
1340 /** 1333 /**
1341 * 获取评论 1334 * 获取评论
1342 - * @param pid  
1343 - * @param page  
1344 - * @param size  
1345 */ 1335 */
1346 module.exports.indexCommentAsync = (pid, page, size) => { 1336 module.exports.indexCommentAsync = (pid, page, size) => {
1347 return co(function *() { 1337 return co(function *() {
@@ -1403,14 +1393,14 @@ module.exports.indexConsultAsync = (uid, pid, page, size) => { @@ -1403,14 +1393,14 @@ module.exports.indexConsultAsync = (uid, pid, page, size) => {
1403 1393
1404 /** 1394 /**
1405 * 添加咨询 1395 * 添加咨询
1406 - * @param uid  
1407 - * @param pid  
1408 - * @param content  
1409 */ 1396 */
1410 module.exports.createConsultAsync = (uid, pid, content) => { 1397 module.exports.createConsultAsync = (uid, pid, content) => {
1411 return consultAPI.createAsync(uid, pid, content); 1398 return consultAPI.createAsync(uid, pid, content);
1412 } 1399 }
1413 1400
  1401 +/**
  1402 + * 获取某一个商品详情主页面
  1403 + */
1414 module.exports.showMainAsync = (data) => { 1404 module.exports.showMainAsync = (data) => {
1415 1405
1416 return co(function * () { 1406 return co(function * () {
@@ -1442,3 +1432,62 @@ module.exports.showMainAsync = (data) => { @@ -1442,3 +1432,62 @@ module.exports.showMainAsync = (data) => {
1442 return result; 1432 return result;
1443 })(); 1433 })();
1444 }; 1434 };
  1435 +
  1436 +/**
  1437 + * 获取某一个商品的热区数据
  1438 + */
  1439 +module.exports.indexHotAreaAsync = (pid) => {
  1440 + return co(function *() {
  1441 + let data = yield hotAreaAPI.indexAsync(pid);
  1442 +
  1443 + if (data.code && data.code === 200 && data.data) {
  1444 + return data.data.reduce((result, area) => {
  1445 + let item = {};
  1446 +
  1447 + if (area.imageUrl) {
  1448 + item.img = helpers.getForceSourceUrl(area.imageUrl);
  1449 + }
  1450 +
  1451 + item.list = area.infos.reduce((acc, cur, index) => {
  1452 + if (!cur.product || !cur.product.goodsList) {
  1453 + return acc;
  1454 + }
  1455 +
  1456 + let point = {
  1457 + label: index + 1,
  1458 + top: cur.top,
  1459 + left: cur.left,
  1460 + height: cur.height,
  1461 + width: cur.width
  1462 + };
  1463 +
  1464 + let goods = _.head(cur.product.goodsList);
  1465 +
  1466 + // 封面图
  1467 + point.img = helpers.getForceSourceUrl(goods.colorImage, 60, 60);
  1468 +
  1469 + // 商品相关信息
  1470 + point.product = {
  1471 + salePrice: cur.product.productPriceBo.formatSalesPrice,
  1472 + marketPrice: cur.product.productPriceBo.formatMarketPrice,
  1473 + productName: cur.product.productName,
  1474 + href: helpers.getUrlBySkc(_.head(goods.goodsImagesList).productId,
  1475 + _.head(goods.goodsImagesList).goodsId,
  1476 + cur.product.cnAlphabet)
  1477 + };
  1478 + acc.push(point);
  1479 + }, []);
  1480 +
  1481 + if (_.isEmpty(item)) {
  1482 + return result;
  1483 + } else {
  1484 + result.push(item);
  1485 + return result;
  1486 + }
  1487 +
  1488 + }, []);
  1489 + }
  1490 +
  1491 + return [];
  1492 + })();
  1493 +}
@@ -41,5 +41,8 @@ router.get('/detail/comment', detail.indexComment); @@ -41,5 +41,8 @@ router.get('/detail/comment', detail.indexComment);
41 router.get('/detail/consult', detail.indexConsult); 41 router.get('/detail/consult', detail.indexConsult);
42 router.post('/detail/consult', detail.createConsult); 42 router.post('/detail/consult', detail.createConsult);
43 43
  44 +// 商品热图
  45 +router.get('/detail/hotarea',detail.indexHotArea);
  46 +
44 47
45 module.exports = router; 48 module.exports = router;
  1 +{{#hotArea}}
  2 + <div class="hot-point-wrap">
  3 + <img src="{{img}}" id="img" />
  4 + {{#list}}
  5 + <div class="hot-point" style="width:{{width}}px;height:{{height}}px;top:{{top}}px;left:{{left}}px;">
  6 + <span class="pointer">{{label}}</span>
  7 + <div class="hp-good">
  8 + <a href="">
  9 + <img class="pic" src="{{img}}">
  10 + </a>
  11 + {{#product}}
  12 + <div class="info">
  13 + <strong>{{productName}}</strong>
  14 + <br>
  15 + <del>原价:{{marketPrice}}</del>
  16 + <br>现价:{{salePrice}}
  17 + <a class="check-btn" href="{{href}}">查看</a>
  18 + </div>
  19 + {{/product}}
  20 + </div>
  21 + </div>
  22 + {{/list}}
  23 + </div>
  24 +{{/hotArea}}
@@ -158,3 +158,18 @@ exports.dateDiffFormat = (format, diff, type) => { @@ -158,3 +158,18 @@ exports.dateDiffFormat = (format, diff, type) => {
158 exports.getForceSourceUrl = (imageUrl) => { 158 exports.getForceSourceUrl = (imageUrl) => {
159 return _.head(imageUrl.split('?')); 159 return _.head(imageUrl.split('?'));
160 }; 160 };
  161 +
  162 +/**
  163 + * 根据skc获取商品链接
  164 + * @param pid
  165 + * @param goods_id
  166 + * @param cn_alphabet
  167 + */
  168 +exports.getUrlBySkc = (pid, goods_id, cn_alphabet) => {
  169 +
  170 + if (!cn_alphabet) {
  171 + cn_alphabet = 'goods';
  172 + }
  173 +
  174 + return 'http://item.yohobuy.com/product/pro_' + pid + '_' + goods_id + '/' + cn_alphabet + '.html';
  175 +};