|
@@ -13,6 +13,7 @@ const logger = require(`${library}/logger`); |
|
@@ -13,6 +13,7 @@ const logger = require(`${library}/logger`); |
13
|
const helpers = require(`${library}/helpers`);
|
13
|
const helpers = require(`${library}/helpers`);
|
14
|
const camelCase = require(`${library}/camel-case`);
|
14
|
const camelCase = require(`${library}/camel-case`);
|
15
|
const resourcesProcess = require(`${utils}/resources-process`);
|
15
|
const resourcesProcess = require(`${utils}/resources-process`);
|
|
|
16
|
+const productProcess = require(`${utils}/product-process`);
|
16
|
const _ = require('lodash');
|
17
|
const _ = require('lodash');
|
17
|
const api = new API();
|
18
|
const api = new API();
|
18
|
const serviceAPI = new ServiceAPI();
|
19
|
const serviceAPI = new ServiceAPI();
|
|
@@ -130,248 +131,6 @@ const special = (params) => { |
|
@@ -130,248 +131,6 @@ const special = (params) => { |
130
|
};
|
131
|
};
|
131
|
|
132
|
|
132
|
/**
|
133
|
/**
|
133
|
- * 根据性别来决定 默认图片获取字段 如果是 2、3
|
|
|
134
|
- *
|
|
|
135
|
- * 则优先从cover2 --》 cover1 -- 》 images_url
|
|
|
136
|
- * 否则优先从cover1 --》 cover2 -- 》 images_url
|
|
|
137
|
- *
|
|
|
138
|
- */
|
|
|
139
|
-const procProductImg = (product, gender) => {
|
|
|
140
|
- if (gender === '2,3') {
|
|
|
141
|
- return product.cover2 || product.cover1 || product.imagesUrl || '';
|
|
|
142
|
- }
|
|
|
143
|
-
|
|
|
144
|
- return product.cover1 || product.cover2 || product.imagesUrl || '';
|
|
|
145
|
-};
|
|
|
146
|
-
|
|
|
147
|
-
|
|
|
148
|
-/**
|
|
|
149
|
- * 商品搜索商品数据处理
|
|
|
150
|
- */
|
|
|
151
|
-const processProductList = (list, options) => {
|
|
|
152
|
- const pruductList = [];
|
|
|
153
|
-
|
|
|
154
|
- options = Object.assign({
|
|
|
155
|
- showTags: true,
|
|
|
156
|
- showNew: true,
|
|
|
157
|
- showSale: true,
|
|
|
158
|
- width: 290,
|
|
|
159
|
- height: 388,
|
|
|
160
|
- isApp: false,
|
|
|
161
|
- showPoint: true,
|
|
|
162
|
- gender: '2,3'
|
|
|
163
|
- }, options);
|
|
|
164
|
- list = camelCase(list);
|
|
|
165
|
-
|
|
|
166
|
- _.forEach(list, (product) => {
|
|
|
167
|
- // 商品信息有问题,则不显示
|
|
|
168
|
- if (!product.productId || !product.goodsList.length) {
|
|
|
169
|
- return;
|
|
|
170
|
- }
|
|
|
171
|
-
|
|
|
172
|
- // 市场价和售价一样,则不显示市场价
|
|
|
173
|
- if (product.marketPrice === product.salesPrice) {
|
|
|
174
|
- product.marketPrice = false;
|
|
|
175
|
- }
|
|
|
176
|
-
|
|
|
177
|
- // 判别默认的商品是否将默认的图片URL赋值到skn
|
|
|
178
|
- let flag = false;
|
|
|
179
|
-
|
|
|
180
|
- // 如果设置了默认图片,就取默认的图片
|
|
|
181
|
- _.forEach(product.goodsList, (goods) => {
|
|
|
182
|
- if (flag) {
|
|
|
183
|
- return;
|
|
|
184
|
- }
|
|
|
185
|
- if (goods.isDefault === 'Y') {
|
|
|
186
|
- product.defaultImages = procProductImg(goods);
|
|
|
187
|
- flag = true;
|
|
|
188
|
- }
|
|
|
189
|
- });
|
|
|
190
|
-
|
|
|
191
|
- // 如果还未赋值,则取第一个skc产品的默认图片
|
|
|
192
|
- if (!flag) {
|
|
|
193
|
- product.defaultImages = procProductImg(product.goodsList[0]);
|
|
|
194
|
- }
|
|
|
195
|
-
|
|
|
196
|
- // product = Object.assign(product, {
|
|
|
197
|
- // id: product.productSkn,
|
|
|
198
|
- // thumb: product.defaultImages
|
|
|
199
|
- // });
|
|
|
200
|
-
|
|
|
201
|
- if (options.showPoint) {
|
|
|
202
|
- product.price += '.00';
|
|
|
203
|
- product.salePrice += '.00';
|
|
|
204
|
- }
|
|
|
205
|
-
|
|
|
206
|
- product.isSoonSoldOut = product.isSoonSoldOut === 'Y';
|
|
|
207
|
- product.url = helpers.urlFormat(`/product/pro_${product.productId}_${product.goodsList[0].goodsId}/${product.cnAlphabet}.html`); // eslint-disable-line
|
|
|
208
|
-
|
|
|
209
|
- // APP访问需要加附加的参数
|
|
|
210
|
- // 备注:如果以后APP的接口太多,可以把这边参数提取出来,变成一个公共的方法来生成,便于以后管理维护
|
|
|
211
|
- if (options.isApp) {
|
|
|
212
|
- product.url += `?openby:yohobuy={"action":"go.productDetail","params":{"product_skn":'${product.productId}'}}`; // eslint-disable-line
|
|
|
213
|
- }
|
|
|
214
|
-
|
|
|
215
|
- if (options.showTags) {
|
|
|
216
|
- product.tags = {};
|
|
|
217
|
-
|
|
|
218
|
- product.tags.isNew = options.showNew && product.isNew === 'Y'; // 新品
|
|
|
219
|
- product.tags.isDiscount = options.showSale && product.isDiscount === 'Y'; // 在售
|
|
|
220
|
- product.tags.isLimited = product.isLimited === 'Y'; // 限量
|
|
|
221
|
- product.tags.isYohood = product.isYohood === 'Y'; // YOHOOD
|
|
|
222
|
- product.tags.midYear = product.midYear === 'Y'; // 年中
|
|
|
223
|
- product.tags.yearEnd = product.yearEnd === 'Y'; // 年末
|
|
|
224
|
- product.tags.isAdvance = product.isAdvance === 'Y'; // 再到着
|
|
|
225
|
-
|
|
|
226
|
- // 打折与即将售完组合显示打折
|
|
|
227
|
- if (product.isSoonSoldOut && product.tags.isDiscount) {
|
|
|
228
|
- product.tags.isNew = false;
|
|
|
229
|
- } else if (product.tags.isDiscount &&
|
|
|
230
|
- (product.tags.isNew || product.tags.isLimited || product.tags.isYohood || product.tags.isAdvance)) {
|
|
|
231
|
- // 打折与其它组合则隐藏打折
|
|
|
232
|
- product.tags.isDiscount = false;
|
|
|
233
|
- } else if (product.tags.isYohood && product.tags.isNew) {
|
|
|
234
|
- // YOHOOD和新品组合显示YOHOOD
|
|
|
235
|
- product.tags.isNew = false;
|
|
|
236
|
- }
|
|
|
237
|
- }
|
|
|
238
|
-
|
|
|
239
|
- pruductList.push(product);
|
|
|
240
|
- });
|
|
|
241
|
- return pruductList;
|
|
|
242
|
-};
|
|
|
243
|
-
|
|
|
244
|
-/**
|
|
|
245
|
- * 处理筛选数据
|
|
|
246
|
- * @param list
|
|
|
247
|
- * @param string | options
|
|
|
248
|
- * @return array 处理之后的筛选数据
|
|
|
249
|
- */
|
|
|
250
|
-const processFilter = (list, options) => {
|
|
|
251
|
- const filters = {
|
|
|
252
|
- classify: []
|
|
|
253
|
- };
|
|
|
254
|
-
|
|
|
255
|
- const filtersType = {
|
|
|
256
|
- brand: {
|
|
|
257
|
- name: '所有品牌',
|
|
|
258
|
- title: '品牌',
|
|
|
259
|
- dataId: 'id',
|
|
|
260
|
- subsName: 'brandName',
|
|
|
261
|
- firstSub: 0,
|
|
|
262
|
- dataType: 'brand'
|
|
|
263
|
- },
|
|
|
264
|
- color: {
|
|
|
265
|
- name: '所有颜色',
|
|
|
266
|
- title: '颜色',
|
|
|
267
|
- dataId: 'colorId',
|
|
|
268
|
- subsName: 'colorName',
|
|
|
269
|
- firstSub: 0,
|
|
|
270
|
- dataType: 'color'
|
|
|
271
|
- },
|
|
|
272
|
- discount: {
|
|
|
273
|
- name: '所有商品',
|
|
|
274
|
- title: '折扣',
|
|
|
275
|
- dataId: 'key',
|
|
|
276
|
- subsName: 'name',
|
|
|
277
|
- firstSub: '0.1,0.9',
|
|
|
278
|
- dataType: 'discount'
|
|
|
279
|
- },
|
|
|
280
|
- gender: {
|
|
|
281
|
- name: '所有性别',
|
|
|
282
|
- title: '性别',
|
|
|
283
|
- dataId: 'key',
|
|
|
284
|
- subsName: 'flag',
|
|
|
285
|
- firstSub: '1,2,3',
|
|
|
286
|
- dataType: 'gender'
|
|
|
287
|
- },
|
|
|
288
|
- groupSort: {
|
|
|
289
|
- name: '所有品类',
|
|
|
290
|
- title: '品类',
|
|
|
291
|
- dataId: 'relationParameter',
|
|
|
292
|
- subsName: 'categoryName',
|
|
|
293
|
- firstSub: 0,
|
|
|
294
|
- dataType: 'sort'
|
|
|
295
|
- },
|
|
|
296
|
- priceRange: {
|
|
|
297
|
- name: '所有价格',
|
|
|
298
|
- title: '价格',
|
|
|
299
|
- dataId: 'key',
|
|
|
300
|
- subsName: 'flag',
|
|
|
301
|
- firstSub: 0,
|
|
|
302
|
- dataType: 'price'
|
|
|
303
|
- },
|
|
|
304
|
- size: {
|
|
|
305
|
- name: '所有尺码',
|
|
|
306
|
- title: '尺码',
|
|
|
307
|
- dataId: 'sizeId',
|
|
|
308
|
- subsName: 'sizeName',
|
|
|
309
|
- firstSub: 0,
|
|
|
310
|
- dataType: 'size'
|
|
|
311
|
- }
|
|
|
312
|
- };
|
|
|
313
|
-
|
|
|
314
|
- options = Object.assign({
|
|
|
315
|
- gender: '1,2,3', // 默认选择的性别,默认1,2,3表示所有
|
|
|
316
|
- exclude: null // 需要排除的字段
|
|
|
317
|
- }, options);
|
|
|
318
|
- list = camelCase(list);
|
|
|
319
|
-
|
|
|
320
|
- _.forEach(list, (item, key) => {
|
|
|
321
|
- let classify = {
|
|
|
322
|
- subs: []
|
|
|
323
|
- };
|
|
|
324
|
-
|
|
|
325
|
- if (key === 'group_sort') {
|
|
|
326
|
- return;
|
|
|
327
|
- }
|
|
|
328
|
-
|
|
|
329
|
- console.log(options, key);
|
|
|
330
|
-
|
|
|
331
|
- if ((options.hideSize && key === 'size') || (options.hideSort && key === 'groupSort')) {
|
|
|
332
|
- return;
|
|
|
333
|
- }
|
|
|
334
|
-
|
|
|
335
|
- classify.dataType = filtersType[key].dataType;
|
|
|
336
|
- classify.name = filtersType[key].name;
|
|
|
337
|
- classify.title = filtersType[key].title;
|
|
|
338
|
-
|
|
|
339
|
- classify.subs.push({
|
|
|
340
|
- chosed: true,
|
|
|
341
|
- dataId: filtersType[key].firstSub,
|
|
|
342
|
- name: filtersType[key].name
|
|
|
343
|
- });
|
|
|
344
|
-
|
|
|
345
|
- _.forEach(item, (sub, index) => {
|
|
|
346
|
- let subs = {};
|
|
|
347
|
-
|
|
|
348
|
- if (filtersType[key].dataId === 'key') {
|
|
|
349
|
- subs.dataId = index;
|
|
|
350
|
- } else if (filtersType[key].dataId === 'relationParameter') {
|
|
|
351
|
- subs.dataId = sub.relationParameter['sort']; // eslint-disable-line
|
|
|
352
|
- } else {
|
|
|
353
|
- subs.dataId = sub[filtersType[key].dataId];
|
|
|
354
|
- }
|
|
|
355
|
-
|
|
|
356
|
- if (filtersType[key].subsName === 'flag') {
|
|
|
357
|
- subs.name = sub;
|
|
|
358
|
- } else {
|
|
|
359
|
- subs.name = sub[filtersType[key].subsName];
|
|
|
360
|
-
|
|
|
361
|
- if (key === 'discount') {
|
|
|
362
|
- subs.name = subs.name + '折商品';
|
|
|
363
|
- }
|
|
|
364
|
- }
|
|
|
365
|
- classify.subs.push(subs);
|
|
|
366
|
- });
|
|
|
367
|
-
|
|
|
368
|
- filters.classify.push(classify);
|
|
|
369
|
- });
|
|
|
370
|
-
|
|
|
371
|
- return filters;
|
|
|
372
|
-};
|
|
|
373
|
-
|
|
|
374
|
-/**
|
|
|
375
|
* 断码区分类数据处理
|
134
|
* 断码区分类数据处理
|
376
|
*/
|
135
|
*/
|
377
|
const processBreakingSort = (list) => {
|
136
|
const processBreakingSort = (list) => {
|
|
@@ -419,8 +178,7 @@ const searchSales = (params) => { |
|
@@ -419,8 +178,7 @@ const searchSales = (params) => { |
419
|
exports.getFilterData = (params) => {
|
178
|
exports.getFilterData = (params) => {
|
420
|
return searchSales(params).then((result) => {
|
179
|
return searchSales(params).then((result) => {
|
421
|
if (result && result.code === 200) {
|
180
|
if (result && result.code === 200) {
|
422
|
- console.log(params);
|
|
|
423
|
- return processFilter(result.data.filter || [], {
|
181
|
+ return productProcess.processFilter(result.data.filter || [], {
|
424
|
hideSize: params.saleType === '1',
|
182
|
hideSize: params.saleType === '1',
|
425
|
hideSort: params.saleType === '1'
|
183
|
hideSort: params.saleType === '1'
|
426
|
});
|
184
|
});
|
|
@@ -437,7 +195,7 @@ exports.getFilterData = (params) => { |
|
@@ -437,7 +195,7 @@ exports.getFilterData = (params) => { |
437
|
exports.getSearchData = (params) => {
|
195
|
exports.getSearchData = (params) => {
|
438
|
return searchSales(params).then((result) => {
|
196
|
return searchSales(params).then((result) => {
|
439
|
if (result && result.code === 200) {
|
197
|
if (result && result.code === 200) {
|
440
|
- return processProductList(result.data.product_list || []);
|
198
|
+ return productProcess.processProductList(result.data.product_list || []);
|
441
|
} else {
|
199
|
} else {
|
442
|
logger.error('SALE 商品搜索返回 code 不是 200');
|
200
|
logger.error('SALE 商品搜索返回 code 不是 200');
|
443
|
return {};
|
201
|
return {};
|