|
@@ -6,6 +6,17 @@ |
|
@@ -6,6 +6,17 @@ |
6
|
const _ = require('lodash');
|
6
|
const _ = require('lodash');
|
7
|
const helpers = global.yoho.helpers;
|
7
|
const helpers = global.yoho.helpers;
|
8
|
const productNameProcess = require('./product-name-process');
|
8
|
const productNameProcess = require('./product-name-process');
|
|
|
9
|
+const productPrcs = require('./product-process');
|
|
|
10
|
+
|
|
|
11
|
+/**
|
|
|
12
|
+ * 将商品转化成以 product_skn 为键名的对象
|
|
|
13
|
+ * @param {*} goodsArray
|
|
|
14
|
+ */
|
|
|
15
|
+const _goodsArrayToObj = (goodsArray) => {
|
|
|
16
|
+ return _.keyBy(goodsArray, value => {
|
|
|
17
|
+ return value.product_skn;
|
|
|
18
|
+ });
|
|
|
19
|
+};
|
9
|
|
20
|
|
10
|
/**
|
21
|
/**
|
11
|
* [将首字符为//的url转换为http://]
|
22
|
* [将首字符为//的url转换为http://]
|
|
@@ -344,6 +355,7 @@ const formatProduct = (productData, showTags, showNew, showSale, width, height, |
|
@@ -344,6 +355,7 @@ const formatProduct = (productData, showTags, showNew, showSale, width, height, |
344
|
|
355
|
|
345
|
const processArticleDetail = (articleContent, isApp, gender, isWeixin, isqq, isWeibo) => {
|
356
|
const processArticleDetail = (articleContent, isApp, gender, isWeixin, isqq, isWeibo) => {
|
346
|
let finalDetail = [];
|
357
|
let finalDetail = [];
|
|
|
358
|
+ let allgoods = '';
|
347
|
|
359
|
|
348
|
_.forEach(articleContent, (value, index) => {
|
360
|
_.forEach(articleContent, (value, index) => {
|
349
|
|
361
|
|
|
@@ -413,6 +425,10 @@ const processArticleDetail = (articleContent, isApp, gender, isWeixin, isqq, isW |
|
@@ -413,6 +425,10 @@ const processArticleDetail = (articleContent, isApp, gender, isWeixin, isqq, isW |
413
|
let relatedReco = [];
|
425
|
let relatedReco = [];
|
414
|
let moreThanOne = _.get(value, 'goods.data', []).length > 1;
|
426
|
let moreThanOne = _.get(value, 'goods.data', []).length > 1;
|
415
|
|
427
|
|
|
|
428
|
+ _.forEach(_.get(value, 'goods.data', []), item => {
|
|
|
429
|
+ allgoods += item.id + ',';
|
|
|
430
|
+ });
|
|
|
431
|
+
|
416
|
if (moreThanOne) {
|
432
|
if (moreThanOne) {
|
417
|
relatedReco = _.get(value, 'goods.data', []);
|
433
|
relatedReco = _.get(value, 'goods.data', []);
|
418
|
} else {
|
434
|
} else {
|
|
@@ -431,6 +447,10 @@ const processArticleDetail = (articleContent, isApp, gender, isWeixin, isqq, isW |
|
@@ -431,6 +447,10 @@ const processArticleDetail = (articleContent, isApp, gender, isWeixin, isqq, isW |
431
|
_.forEach(_.get(value, 'goodsGroup.data', []), item => {
|
447
|
_.forEach(_.get(value, 'goodsGroup.data', []), item => {
|
432
|
let cover = _.get(item, 'cover', '');
|
448
|
let cover = _.get(item, 'cover', '');
|
433
|
|
449
|
|
|
|
450
|
+ _.forEach(_.get(item, 'list', []), item2 => {
|
|
|
451
|
+ allgoods += item2.id + ',';
|
|
|
452
|
+ });
|
|
|
453
|
+
|
434
|
collocation.push({
|
454
|
collocation.push({
|
435
|
thumb: cover ?
|
455
|
thumb: cover ?
|
436
|
helpers.image(cover.cover, 235, 314) : '',
|
456
|
helpers.image(cover.cover, 235, 314) : '',
|
|
@@ -453,8 +473,31 @@ const processArticleDetail = (articleContent, isApp, gender, isWeixin, isqq, isW |
|
@@ -453,8 +473,31 @@ const processArticleDetail = (articleContent, isApp, gender, isWeixin, isqq, isW |
453
|
|
473
|
|
454
|
});
|
474
|
});
|
455
|
|
475
|
|
456
|
- console.log(JSON.stringify(finalDetail, 2, 2));
|
|
|
457
|
- console.log('-------------------------------------------------------------------------');
|
476
|
+ return {
|
|
|
477
|
+ finalDetail: finalDetail,
|
|
|
478
|
+ allgoods: allgoods
|
|
|
479
|
+ };
|
|
|
480
|
+};
|
|
|
481
|
+
|
|
|
482
|
+const pushGoodsInfo = (finalDetail, goodsList) => {
|
|
|
483
|
+ let goodsObj = _goodsArrayToObj(productPrcs.processProductList(goodsList));
|
|
|
484
|
+
|
|
|
485
|
+ // console.log(goodsList);
|
|
|
486
|
+ _.forEach(finalDetail, (value, key) => {
|
|
|
487
|
+ // if (value.relatedReco) {
|
|
|
488
|
+ // console.log(value.relatedReco);
|
|
|
489
|
+ // }
|
|
|
490
|
+
|
|
|
491
|
+ if (value.collocation) {
|
|
|
492
|
+ _.forEach(value.collocation, (item, subKey) => {
|
|
|
493
|
+ _.forEach(item.goods, (thItem, thKey) => {
|
|
|
494
|
+ finalDetail[key].collocation[subKey].goods[thKey] = goodsObj[thItem.id];
|
|
|
495
|
+ });
|
|
|
496
|
+ });
|
|
|
497
|
+ }
|
|
|
498
|
+ });
|
|
|
499
|
+
|
|
|
500
|
+ // console.log(JSON.stringify(finalDetail, 2, 2));
|
458
|
return finalDetail;
|
501
|
return finalDetail;
|
459
|
};
|
502
|
};
|
460
|
|
503
|
|
|
@@ -464,5 +507,6 @@ module.exports = { |
|
@@ -464,5 +507,6 @@ module.exports = { |
464
|
getFilterUrl,
|
507
|
getFilterUrl,
|
465
|
formatProduct,
|
508
|
formatProduct,
|
466
|
getProductIcon,
|
509
|
getProductIcon,
|
467
|
- processArticleDetail
|
510
|
+ processArticleDetail,
|
|
|
511
|
+ pushGoodsInfo
|
468
|
}; |
512
|
}; |