global.js
5.49 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/**
* 商品促销 model
* @author: yyq<yanqing.yang@yoho.cn>
* @date: 2017/4/6
*/
'use strict';
const _ = require('lodash');
const helpers = global.yoho.helpers;
const homeService = require('./home-service');
const globalApi = require('./global-api');
const headerModel = require('../../../doraemon/models/header');
const searchHandler = require('./search-handler');
const pager = require(`${global.utils}/pager`).setPager;
const productProcess = require(`${global.utils}/product-process`);
const getGlobalProductListData = (params, yoho) => {
return Promise.props({
header: headerModel.requestHeaderData(yoho.channel),
list: globalApi.getGlobalProductListAsync(Object.assign({
physical_channel: yoho.channelNum
}, params, {limit: params.limit ? params.limit - 1 : 59}))
}).then(result => {
let resData = {};
Object.assign(resData, result.header);
if (result.list.code === 200) {
let totalNum = _.get(result.list, 'data.total', 0);
// let filters = Object.assign(searchHandler.handleFilterDataAll(result[2].data, params),
// finalResult.list.leftContent.sort);
// filters.checkedConditions.conditions = _.concat(filters.checkedConditions.conditions,
// finalResult.list.leftContent.checked);
resData.list = {
// filters: filters,
// opts: searchHandler.handleOptsData(params, result[2].data.total, result[2].data.filter),
totalCount: totalNum,
footPager: pager(_.get(result.list, 'data.page_total', 0), params),
goods: productProcess.processProductList(_.get(result.list, 'data.product_list', []),
Object.assign({showDiscount: false, isGlobal: true}, params)),
hasNextPage: searchHandler.handleNextPage(params, totalNum),
latestWalk: 6 // 最近浏览记录
};
}
return resData;
});
};
const getGlobalProductDetailData = (skn, channelNum, channel) => {
return Promise.props({
header: headerModel.requestHeaderData(channel),
detail: globalApi.getGlobalProductDetailAsync(skn, channelNum),
html: globalApi.getGlobalProductHtmlAsync(skn, channelNum)
}).then(result => {
let resData = {};
let detailInfo, html = '';
if (+result.detail.code === 200) {
detailInfo = _.get(result, 'detail.data', {});
let brandInfo = detailInfo.brand_info || {};
resData.banner = {
bgColor: '#000',
homeUrl: helpers.urlFormat('/product/global/list', {brand: brandInfo.brand_id}),
brandName: brandInfo.brand_name,
logo: brandInfo.brand_ico
};
resData.pathNav = _.concat(
homeService.getHomeChannelNav(channel),
[
{name: '全球购', href: helpers.urlFormat('/product/global/list')},
{name: detailInfo.product_name || ''}
]
);
if (detailInfo.orign_price - detailInfo.final_price === 0) {
_.unset(detailInfo, 'formart_orign_price');
} else {
detailInfo.promotion = ((detailInfo.final_price / detailInfo.orign_price) * 10).toFixed(1);
// 只显示大于1折小于9折的折扣
if (detailInfo.promotion <= 1.0 || detailInfo.promotion >= 9.0) {
detailInfo.promotion = false;
}
}
if (detailInfo.market_price - detailInfo.sales_price === 0) {
_.unset(detailInfo, 'format_market_price');
}
if (!_.isEmpty(detailInfo.goods_list)) {
let colors = [];
_.forEach(detailInfo.goods_list, (value, index) => {
let size = [];
_.forEach(value.size_list || [], subVal => {
size.push({
sku: subVal.product_sku,
name: subVal.size_name,
soldOut: subVal.storage_number * 1 <= 0
});
});
if (_.isEmpty(value.images_list)) {
value.images_list = [{
image_url: value.color_image
}];
}
if (index === 0 && !detailInfo.mainThumb) {
value.focus = true;
detailInfo.mainThumb = _.get(value, 'images_list[0].image_url', value.color_image);
}
colors.push({
src: value.color_image,
name: value.color_name,
title: value.color_name,
imgList: value.images_list,
focus: value.focus,
size: size
});
});
detailInfo.colors = colors;
}
}
if (result.html) {
let regContent = /<body[^>]*>([\s\S]*)<\/body>/.exec(result.html);
html = regContent[1] || '';
html = html.replace(/<script.*?>.*?<\/script>/ig, '');
}
Object.assign(resData, result.header, {
goodsInfo: detailInfo,
detailHtml: html || ''
});
return resData;
});
};
module.exports = {
getGlobalProductListData,
getGlobalProductDetailData
};