detail-hotarea-service.js
2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/**
* Created by TaoHuang on 2016/6/14.
*/
'use strict';
const Promise = require('bluebird');
const co = Promise.coroutine;
const _ = require('lodash');
const helpers = global.yoho.helpers;
const api = require('./detail-hotarea-api');
/**
* 获取某一个商品的热区数据
*/
const indexAsync = pid => {
return co(function *() {
let data = yield api.indexAsync(pid);
if (!data || !data.code || data.code !== 200) {
return [];
}
return data.data.reduce((result, area) => {
if (!area.infos) {
return result;
}
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(
_.get(cur.product, 'productPriceBo.productSkn', ''))
};
acc.push(point);
return acc;
}, []);
if (_.isEmpty(item)) {
return result;
} else {
result.push(item);
return result;
}
}, []);
})();
};
module.exports = {
indexAsync
};