Authored by htoooth

add hotarea

... ... @@ -49,7 +49,22 @@ module.exports.showMain = (req, res, next) => {
};
/**
* 获取热区图
*/
module.exports.indexHotArea = (req, res, next) => {
let pid = req.params.productId || 0;
service.indexHotAreaAsync(pid).then(result => {
res.render('hotarea', {
hotArea: result,
layout:false
});
}).catch(next);
};
/**
* 获得评论列表
* json
*/
module.exports.indexComment = (req, res, next) => {
let pid = req.params.productId || 0;
... ... @@ -59,10 +74,11 @@ module.exports.indexComment = (req, res, next) => {
service.indexCommentAsync(pid, page, size).then(result => {
res.json(result)
}).catch(next);
}
};
/**
* 获得咨询列表
* json
*/
module.exports.indexConsult = (req, res, next) => {
// TODO: uid
... ... @@ -78,6 +94,7 @@ module.exports.indexConsult = (req, res, next) => {
/**
* 新建咨询
* json
*/
module.exports.createConsult = (req, res, next) => {
... ... @@ -115,3 +132,5 @@ module.exports.createConsult = (req, res, next) => {
}
};
... ...
/**
* Created by TaoHuang on 2016/6/13.
*/
const library = '../../../library';
const API = require(`${library}/api`).API;
const sign = require(`${library}/sign`);
const Promise = require('bluebird');
const api = new API();
/**
* 获取商品的热区
*/
module.exports.indexAsync = (pid) => {
return api.get('', api.apiSign({
method: 'web.productCollocation.list',
product_id: pid
})).catch(console.log);
};
... ...
... ... @@ -19,6 +19,7 @@ const helpers = require(`${library}/helpers`);
const detailAPI = require('./detail-main-api');
const commentAPI = require('./detail-comment-api');
const consultAPI = require('./detail-consult-api');
const hotAreaAPI = require('./detail-hotarea-api');
const brandAPI = require('./brand-api');
const favoriteAPI = require('./favorite-api');
const shopAPI = require('./shop-api');
... ... @@ -76,9 +77,6 @@ function getMultiDataByResourceName(resourceName) {
/**
* 获取商品的喜欢
* @param uid
* @param pid
* @param bid
*/
const getProductFavoriteData = (uid, pid, bid) => {
return co(function*() {
... ... @@ -233,7 +231,6 @@ const getActivityDataByProductBaseInfo = (data) => {
/**
* 获取商品咨询和评论数据
* @param data
* @returns {{}}
*/
const getConsultCommentDataByProductInfo = (data) => {
... ... @@ -262,7 +259,6 @@ const getConsultCommentDataByProductInfo = (data) => {
/**
* 获取品牌数据
* @param data
*/
const getBrandDataByProductBaseInfo = (data) => {
... ... @@ -325,8 +321,6 @@ const getBrandDataByProductBaseInfo = (data) => {
/**
* 获得sku商品数据
* @param data
* @returns {{defaultImage: number, skuGoods: number, totalStorageNum: number}}
*/
const getSkuDataByProductBaseInfo = (data) => {
let totalStorageNum = 0;
... ... @@ -517,7 +511,6 @@ const getFashionTopGoodsStatus = (uid, showStatus, isBeginSale) => {
/**
* 获取分类导航列表
* @returns {Promise.<{}>}
*/
// controller item.php 32;
function getSortNavAsync(smallSortId, gender) {
... ... @@ -1339,9 +1332,6 @@ const getSizeInfoAsync = (productSkn, maxSortId)=> {
/**
* 获取评论
* @param pid
* @param page
* @param size
*/
module.exports.indexCommentAsync = (pid, page, size) => {
return co(function *() {
... ... @@ -1403,14 +1393,14 @@ module.exports.indexConsultAsync = (uid, pid, page, size) => {
/**
* 添加咨询
* @param uid
* @param pid
* @param content
*/
module.exports.createConsultAsync = (uid, pid, content) => {
return consultAPI.createAsync(uid, pid, content);
}
/**
* 获取某一个商品详情主页面
*/
module.exports.showMainAsync = (data) => {
return co(function * () {
... ... @@ -1442,3 +1432,62 @@ module.exports.showMainAsync = (data) => {
return result;
})();
};
/**
* 获取某一个商品的热区数据
*/
module.exports.indexHotAreaAsync = (pid) => {
return co(function *() {
let data = yield hotAreaAPI.indexAsync(pid);
if (data.code && data.code === 200 && data.data) {
return data.data.reduce((result, area) => {
let item = {};
if (area.imageUrl) {
item.img = helpers.getForceSourceUrl(area.imageUrl);
}
item.list = area.infos.reduce((acc, cur, index) => {
if (!cur.product || !cur.product.goodsList) {
return acc;
}
let point = {
label: index + 1,
top: cur.top,
left: cur.left,
height: cur.height,
width: cur.width
};
let goods = _.head(cur.product.goodsList);
// 封面图
point.img = helpers.getForceSourceUrl(goods.colorImage, 60, 60);
// 商品相关信息
point.product = {
salePrice: cur.product.productPriceBo.formatSalesPrice,
marketPrice: cur.product.productPriceBo.formatMarketPrice,
productName: cur.product.productName,
href: helpers.getUrlBySkc(_.head(goods.goodsImagesList).productId,
_.head(goods.goodsImagesList).goodsId,
cur.product.cnAlphabet)
};
acc.push(point);
}, []);
if (_.isEmpty(item)) {
return result;
} else {
result.push(item);
return result;
}
}, []);
}
return [];
})();
}
... ...
... ... @@ -41,5 +41,8 @@ router.get('/detail/comment', detail.indexComment);
router.get('/detail/consult', detail.indexConsult);
router.post('/detail/consult', detail.createConsult);
// 商品热图
router.get('/detail/hotarea',detail.indexHotArea);
module.exports = router;
... ...
{{#hotArea}}
<div class="hot-point-wrap">
<img src="{{img}}" id="img" />
{{#list}}
<div class="hot-point" style="width:{{width}}px;height:{{height}}px;top:{{top}}px;left:{{left}}px;">
<span class="pointer">{{label}}</span>
<div class="hp-good">
<a href="">
<img class="pic" src="{{img}}">
</a>
{{#product}}
<div class="info">
<strong>{{productName}}</strong>
<br>
<del>原价:{{marketPrice}}</del>
<br>现价:{{salePrice}}
<a class="check-btn" href="{{href}}">查看</a>
</div>
{{/product}}
</div>
</div>
{{/list}}
</div>
{{/hotArea}}
... ...
... ... @@ -158,3 +158,18 @@ exports.dateDiffFormat = (format, diff, type) => {
exports.getForceSourceUrl = (imageUrl) => {
return _.head(imageUrl.split('?'));
};
/**
* 根据skc获取商品链接
* @param pid
* @param goods_id
* @param cn_alphabet
*/
exports.getUrlBySkc = (pid, goods_id, cn_alphabet) => {
if (!cn_alphabet) {
cn_alphabet = 'goods';
}
return 'http://item.yohobuy.com/product/pro_' + pid + '_' + goods_id + '/' + cn_alphabet + '.html';
};
... ...