...
|
...
|
@@ -6,8 +6,10 @@ |
|
|
|
|
|
'use strict';
|
|
|
|
|
|
const api = global.yoho.API;
|
|
|
const _ = require('lodash');
|
|
|
const comment = require('./consult-comment');
|
|
|
|
|
|
const api = global.yoho.API;
|
|
|
const helpers = global.yoho.helpers;
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -237,47 +239,19 @@ const _detailDataPkg = (origin, uid, vipLevel, ua) => { |
|
|
dest.periodOfMarket = `${origin.expectArrivalTime}月`;
|
|
|
}
|
|
|
|
|
|
// 促销信息 TODO: 换新接口
|
|
|
if (origin.promotionBoList) {
|
|
|
let discountList = [];
|
|
|
|
|
|
_.forEach(origin.promotionBoList, function(value) {
|
|
|
discountList.push({
|
|
|
text: `【${value.promotionType}】${value.promotionTitle}`
|
|
|
});
|
|
|
});
|
|
|
|
|
|
if (discountList.length) {
|
|
|
dest.goodsDiscount = {
|
|
|
list: discountList
|
|
|
};
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 商品咨询
|
|
|
dest.feedbacks = {
|
|
|
consults: [],
|
|
|
consultsNum: 0
|
|
|
};
|
|
|
|
|
|
if (origin.consultBoWrapper) {
|
|
|
dest.feedbacks.consultsNum = origin.consultBoWrapper.consultTotal;
|
|
|
_.forEach(origin.consultBoWrapper.consultBoList, function(value) {
|
|
|
dest.feedbacks.consults.push({
|
|
|
question: value.ask,
|
|
|
time: value.askTime,
|
|
|
answer: value.answer
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
|
|
|
let consultParams = {
|
|
|
product_id: origin.id
|
|
|
};
|
|
|
|
|
|
if (_.has(dest, 'feedbacks.consultsNum')) {
|
|
|
consultParams.total = dest.feedbacks.consultsNum;
|
|
|
dest.feedbacks.consultsUrl = helpers.urlFormat('/product/detail/consult', consultParams);
|
|
|
dest.feedbacks.consultsUrl = helpers.urlFormat('/product/detail/consults', consultParams);
|
|
|
} else {
|
|
|
dest.feedbacks.consultsUrl = helpers.urlFormat('/product/detail/consultform', consultParams);
|
|
|
}
|
...
|
...
|
@@ -320,13 +294,13 @@ const _detailDataPkg = (origin, uid, vipLevel, ua) => { |
|
|
if (origin.goodsList) {
|
|
|
let goodsGroup = [],
|
|
|
sizeName = '',
|
|
|
colorList = {},
|
|
|
colorList = [],
|
|
|
sizeList = {},
|
|
|
allSizeList = {},
|
|
|
colorStorageGroup = {},
|
|
|
colorStorageNum = 0;
|
|
|
|
|
|
_.forEach(origin.goodsList, function(value, key) {
|
|
|
_.forEach(origin.goodsList, function(value) {
|
|
|
if (value.status === 0) {
|
|
|
return;
|
|
|
}
|
...
|
...
|
@@ -367,7 +341,7 @@ const _detailDataPkg = (origin, uid, vipLevel, ua) => { |
|
|
};
|
|
|
|
|
|
allSizeList[sizeName] = (allSizeList[sizeName] === null ||
|
|
|
typeof allSizeList[sizeName] === 'undefined') ? build :
|
|
|
typeof allSizeList[sizeName] === 'undefined') ? build :
|
|
|
allSizeList[sizeName];
|
|
|
|
|
|
colorStorageNum += parseInt(size.goodsSizeStorageNum, 10);
|
...
|
...
|
@@ -375,13 +349,13 @@ const _detailDataPkg = (origin, uid, vipLevel, ua) => { |
|
|
});
|
|
|
|
|
|
// 颜色分组
|
|
|
colorList[key] = {
|
|
|
colorList.push({
|
|
|
id: value.colorId,
|
|
|
skcId: value.productSkc,
|
|
|
name: value.colorName,
|
|
|
goodsName: value.goodsName,
|
|
|
colorNum: colorStorageNum
|
|
|
};
|
|
|
});
|
|
|
}
|
|
|
|
|
|
// 缩略图
|
...
|
...
|
@@ -399,10 +373,12 @@ const _detailDataPkg = (origin, uid, vipLevel, ua) => { |
|
|
sizeGroup[0] = {
|
|
|
size: []
|
|
|
};
|
|
|
_.forEach(allSizeList, function(value) {
|
|
|
|
|
|
_.forEach(allSizeList, (value, key) => {
|
|
|
|
|
|
// 默认尺码
|
|
|
sizeGroup[0].size.push({
|
|
|
name: sizeName,
|
|
|
name: key,
|
|
|
sizeNum: _.toNumber(value.storage) > 0 ? true : false,
|
|
|
id: value.id
|
|
|
});
|
...
|
...
|
@@ -412,13 +388,16 @@ const _detailDataPkg = (origin, uid, vipLevel, ua) => { |
|
|
};
|
|
|
|
|
|
// 各个颜色的尺码, 每行显示一个尺码对应的颜色
|
|
|
_.forEach(colorList, function(colorArr) {
|
|
|
colorArr.colorNum = 0;
|
|
|
if (colorStorageGroup[colorArr.skcId] &&
|
|
|
colorStorageGroup[colorArr.skcId][sizeName]) {
|
|
|
colorArr.colorNum = colorStorageGroup[colorArr.skcId][sizeName];
|
|
|
_.forEach(colorList, (colorArr) => {
|
|
|
let tempColorArr = _.cloneDeep(colorArr);
|
|
|
|
|
|
if (colorStorageGroup[tempColorArr.skcId] &&
|
|
|
colorStorageGroup[tempColorArr.skcId][key]) {
|
|
|
tempColorArr.colorNum = colorStorageGroup[tempColorArr.skcId][key];
|
|
|
} else {
|
|
|
tempColorArr.colorNum = 0;
|
|
|
}
|
|
|
colorGroup[i].color.push(colorArr);
|
|
|
colorGroup[i].color.push(Object.assign({}, tempColorArr));
|
|
|
});
|
|
|
colorGroup[i].id = value.id;
|
|
|
|
...
|
...
|
@@ -443,6 +422,7 @@ const _detailDataPkg = (origin, uid, vipLevel, ua) => { |
|
|
++i;
|
|
|
});
|
|
|
|
|
|
|
|
|
// 商品图:多个
|
|
|
if (goodsGroup.length > 1) {
|
|
|
let bannerList = [];
|
...
|
...
|
@@ -492,7 +472,7 @@ const _detailDataPkg = (origin, uid, vipLevel, ua) => { |
|
|
if (origin.isLimitBuy === 'Y') {
|
|
|
// 是否开售
|
|
|
let isBeginSale = (origin.saleStatus !== null && typeof origin.saleStatus !== 'undefined' &&
|
|
|
origin.saleStatus === 1);
|
|
|
origin.saleStatus === 1);
|
|
|
|
|
|
// 限购商品有关的展示状态
|
|
|
let showStatus = 1;
|
...
|
...
|
@@ -560,13 +540,44 @@ let _getPromotionInfo = (skn) => { |
|
|
});
|
|
|
};
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 获取默认咨询列表
|
|
|
*/
|
|
|
const _getCommonConsult = () => {
|
|
|
let params = {
|
|
|
method: 'app.consult.common'
|
|
|
};
|
|
|
|
|
|
return api.get('', params, {
|
|
|
code: 200
|
|
|
}).then(result => {
|
|
|
let data = {};
|
|
|
|
|
|
if (result.data) {
|
|
|
data = result.data;
|
|
|
}
|
|
|
|
|
|
return data;
|
|
|
});
|
|
|
};
|
|
|
|
|
|
let getProductData = (data) => {
|
|
|
let finalResult;
|
|
|
let params = {
|
|
|
productId: _.toString(data.id),
|
|
|
method: 'h5.product.data'
|
|
|
};
|
|
|
|
|
|
if (data.id) { // 通过 productId 获取商品详情
|
|
|
Object.assign(params, {
|
|
|
productId: _.toString(data.id)
|
|
|
});
|
|
|
} else if (data.productSkn) { // 通过 productSkn 获取商品详情
|
|
|
Object.assign(params, {
|
|
|
product_skn: _.toString(data.productSkn)
|
|
|
});
|
|
|
}
|
|
|
|
|
|
if (!_.isEmpty(data.uid)) {
|
|
|
params.uid = data.uid;
|
|
|
}
|
...
|
...
|
@@ -577,12 +588,43 @@ let getProductData = (data) => { |
|
|
return api.get('', params, {
|
|
|
cache: true
|
|
|
}).then(result => {
|
|
|
return Promise.all([_getShopsInfo(result.brandId), _getPromotionInfo(result.erpProductId)]).then((info) => {
|
|
|
if (result.code === 500) {
|
|
|
return {};
|
|
|
}
|
|
|
return Promise.all([
|
|
|
_getShopsInfo(result.brandId),
|
|
|
_getPromotionInfo(result.erpProductId),
|
|
|
comment.getCommentInfo({
|
|
|
productId: result.id
|
|
|
}),
|
|
|
_getCommonConsult(),
|
|
|
comment.getConsults(result.id, 1, 2)
|
|
|
]).then((info) => {
|
|
|
result.promotionBoList = info[1];
|
|
|
|
|
|
finalResult = _detailDataPkg(result, data.uid, data.vipLevel, data.ua);
|
|
|
finalResult.enterStore = info[0];
|
|
|
|
|
|
Object.assign(finalResult.feedbacks, info[2]);
|
|
|
|
|
|
if (!info[4].total && !_.isEmpty(info[3]) && !_.get(info[2], 'feedbacks.consultsNum', 0)) {
|
|
|
Object.assign(finalResult.feedbacks, {
|
|
|
commonConsults: true,
|
|
|
consultsNum: true,
|
|
|
consults: _.take(info[3], 2)
|
|
|
});
|
|
|
}
|
|
|
|
|
|
if (info[4]) {
|
|
|
finalResult.feedbacks.consultsNum = parseInt(info[4].total, 10);
|
|
|
|
|
|
Object.assign(finalResult.feedbacks, {
|
|
|
commonConsults: false,
|
|
|
consultsNum: parseInt(info[4].total, 10),
|
|
|
consults: _.take(info[4].list, 2)
|
|
|
});
|
|
|
}
|
|
|
|
|
|
return finalResult;
|
|
|
});
|
|
|
|
...
|
...
|
|