Authored by 张丽霞

拼接为你优选商品链接&商品分类tag

@@ -4,6 +4,8 @@ var API = require('../../../library/api').API; @@ -4,6 +4,8 @@ var API = require('../../../library/api').API;
4 var api = new API(); 4 var api = new API();
5 5
6 const camelCase = global.yoho.camelCase; 6 const camelCase = global.yoho.camelCase;
  7 +const helpers = global.yoho.helpers;
  8 +const _ = require('lodash');
7 9
8 /** 10 /**
9 * 分享页面基础参数 11 * 分享页面基础参数
@@ -16,8 +18,40 @@ const getPreferenceData = (data) => { @@ -16,8 +18,40 @@ const getPreferenceData = (data) => {
16 let list = data.data || {}; 18 let list = data.data || {};
17 19
18 list = camelCase(list); 20 list = camelCase(list);
  21 +
  22 + let distGoods = [];
  23 +
  24 + _.forEach(list.productList, function(value) {
  25 +
  26 + if (!value.productSkn || !value.goodsList || !value.goodsList.length) {
  27 + return;
  28 + }
  29 + value.goodsId = value.goodsList[0].goodsId;
  30 +
  31 + let goods = value;
  32 +
  33 + goods.url = helpers.urlFormat(`/product/pro_${value.productId}_${value.goodsId}/${value.cnAlphabet}.html`);
  34 + if (_.get(goods, 'tags[0]', null)) {
  35 + goods.tags = [];
  36 + if (goods.isNew === 'Y') {
  37 + goods.tags.push({isNew: true});
  38 + } else if (goods.isAdvance === 'Y') {
  39 + goods.tags.push({isAdvance: true});
  40 + } else if (goods.isDiscount === 'Y') {
  41 + goods.tags.push({isDiscount: true});
  42 + } else if (goods.isYohoood === 'Y') {
  43 + goods.tags.push({isYohoood: true});
  44 + } else if (goods.isLimited === 'Y') {
  45 + goods.tags.push({isLimited: true});
  46 + }
  47 + }
  48 + distGoods.push(goods);
  49 + });
  50 +
  51 +
  52 +
19 dest.code = list.code; 53 dest.code = list.code;
20 - dest.goods = list.productList; 54 + dest.goods = distGoods;
21 dest.rec_id = list.recId; 55 dest.rec_id = list.recId;
22 dest.message = list.message; 56 dest.message = list.message;
23 57
@@ -36,6 +70,7 @@ exports.getPreference = (data) => { @@ -36,6 +70,7 @@ exports.getPreference = (data) => {
36 infoData = Object.assign(defaultParam, data); // 处理完成后,发给后端 70 infoData = Object.assign(defaultParam, data); // 处理完成后,发给后端
37 71
38 return api.get('', infoData).then(result => { 72 return api.get('', infoData).then(result => {
  73 +
39 return getPreferenceData(result); 74 return getPreferenceData(result);
40 }); // 所有数据返回一个 Promise,方便 Promise.all 调用 75 }); // 所有数据返回一个 Promise,方便 Promise.all 调用
41 }; 76 };