Authored by htoooth

refactor hot area

... ... @@ -20,7 +20,7 @@ const detailHelper = require('../models/detail-helper');
module.exports.showMain = (req, res, next) => {
// TODO: vipLevel = 0; // 用户等级
let pid = 373057;
let pid = 217011;
let uid = req.user.uid || '';
... ...
/**
* Created by TaoHuang on 2016/6/14.
*/
'use strict';
const Promise = require('bluebird');
const co = Promise.coroutine;
const _ = require('lodash');
const library = '../../../library';
const helpers = require(`${library}/helpers`);
const api = require('./detail-hotarea-api');
/**
* 获取某一个商品的热区数据
*/
module.exports.indexAsync = (pid) => {
return co(function *() {
let data = yield api.indexAsync(pid);
if (!data.code && !(data.code === 200) && !data.data) {
return [];
}
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);
return acc;
}, []);
if (_.isEmpty(item)) {
return result;
} else {
result.push(item);
return result;
}
}, []);
})();
};
... ...
... ... @@ -17,10 +17,9 @@ 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 hotAreaService = require('./detail-hotarea-api');
const brandService = require('./brand-service');
const favoriteBrandService = require('./favorite-brand-service');
const favoriteProductService = require('./favorite-product-service');
... ... @@ -1440,63 +1439,4 @@ module.exports.showMainAsync = (data) => {
/**
* 获取某一个商品的热区数据
*/
module.exports.indexHotAreaAsync = (pid) => {
return co(function *() {
let data = yield hotAreaAPI.indexAsync(pid);
if (!data.code && !(data.code === 200) && !data.data) {
return [];
}
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);
return acc;
}, []);
if (_.isEmpty(item)) {
return result;
} else {
result.push(item);
return result;
}
}, []);
})();
};
module.exports.indexHotAreaAsync = hotAreaService.indexAsync;
... ...