sale.js
4.29 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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/**
* 频道页面 model
* @author: wsl<shuiling.wang@yoho.cn>
* @date: 2016/05/17
*/
'use strict';
const library = '../../../library';
const utils = '../../../utils';
const API = require(`${library}/api`).API;
const ServiceAPI = require(`${library}/api`).ServiceAPI;
const sign = require(`${library}/sign`);
const logger = require(`${library}/logger`);
const helpers = require(`${library}/helpers`);
const camelCase = require(`${library}/camel-case`);
const resourcesProcess = require(`${utils}/resources-process`);
const _ = require('lodash');
const api = new API();
const serviceAPI = new ServiceAPI();
const anHour = 3600000;
const aDay = anHour * 24;
/**
* 折扣专场列表数据处理
*/
const processSpecial = (list) => {
const formatData = [];
list = list || [];
list = camelCase(list);
_.forEach(list, (data) => {
data.specialUrl = `/product/specialDetail?id=${data.id}`;
if (data.leftTime < anHour) {
data.warnColor = true;
data.leftTime = '低于1小时';
} else {
if (data.leftTime > aDay) {
data.leftTime = helpers.dateDiffFormat('剩{d}天{h}小时', data.leftTime, 'ms');
} else {
data.leftTime = helpers.dateDiffFormat('剩{h}小时', data.leftTime, 'ms');
}
}
formatData.push(data);
});
return formatData;
};
/**
* 商品搜索数据处理
*/
const processSearch = (list) => {
// const formartData = [];
// let goods = {};
list = list || [];
// _.forEach(camelCase(list.data.product_list), (data) => {
// });
};
/**
* 获取商品数据
*/
exports.getSearchData = (params) => {
return api.get('', sign.apiSign(Object.assign({
method: 'app.search.sales'
}, params))).then((result) => {
if (result && result.code === 200) {
return processSearch(result);
} else {
logger.error('SALE 商品搜索返回 code 不是 200');
return [];
}
});
};
exports.getSaleResources = () => {
return serviceAPI.get('operations/api/v5/resource/get', sign.apiSign({
content_code: '7c2b77093421efa8ae9302c91460db73'
})).then((result) => {
if (result && result.code === 200) {
return resourcesProcess(result.data);
} else {
logger.error('SALE 页面资源位返回 code 不是 200');
return [];
}
});
};
/**
* 获取折扣专场专题列表数据
* @param {[object]} params
* @return {[object]}
*/
exports.getSpecialData = (params) => {
const specialData = {};
return api.get('', sign.apiSign(Object.assign({
method: 'app.activity.get',
sort: 2,
plateform: 2
}, params))).then((result) => {
if (result && result.code === 200) {
specialData.data = processSpecial(result.data);
return specialData;
} else {
return Promise.reject('error');
}
});
};
/**
* 获取折扣专场专题详情数据
* @param {[object]} params
* @return {[object]}
*/
exports.getSpecialDetailData = (params) => {
return api.get('', sign.apiSign(Object.assign({
method: 'app.activity.get',
sort: 2,
plateform: 2
}, params))).then((result) => {
if (result && result.code === 200) {
return camelCase(result.data);
} else {
return Promise.reject('error');
}
});
};
/**
* 获取断码区数据
* @param {[object]} params
* @return {[object]}
*/
exports.getBreakCodeData = (params) => {
return api.get('', sign.apiSign(Object.assign({
method: 'app.activity.get',
sort: 2,
plateform: 2
}, params))).then((result) => {
if (result && result.code === 200) {
return camelCase(result.data);
} else {
return Promise.reject('error');
}
});
};
/**
* 获取会员享数据
* @param {[object]} params
* @return {[object]}
*/
exports.getVipData = (params) => {
return api.get('', sign.apiSign(Object.assign({
method: 'app.activity.get',
sort: 2,
plateform: 2
}, params))).then((result) => {
if (result && result.code === 200) {
return camelCase(result.data);
} else {
return Promise.reject('error');
}
});
};