...
|
...
|
@@ -6,10 +6,14 @@ |
|
|
|
|
|
'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;
|
|
|
|
|
|
const SINGLE_TICKETS_SKN = 512579596;// 展览票
|
|
|
|
|
|
/**
|
|
|
* 获取用户数据信息
|
|
|
* @param {[string]} uid
|
...
|
...
|
@@ -148,6 +152,9 @@ const _detailDataPkg = (origin, uid, vipLevel, ua) => { |
|
|
|
|
|
dest.goodsName = origin.productName;
|
|
|
|
|
|
// 是否是虚拟商品
|
|
|
dest.virtualGoods = origin.attribute * 1 === 3 ? true : false;
|
|
|
|
|
|
// 用户未登录时
|
|
|
if (!uid) {
|
|
|
let params = {};
|
...
|
...
|
@@ -237,47 +244,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 +299,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 +346,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 +354,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 +378,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 +393,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 +427,7 @@ const _detailDataPkg = (origin, uid, vipLevel, ua) => { |
|
|
++i;
|
|
|
});
|
|
|
|
|
|
|
|
|
// 商品图:多个
|
|
|
if (goodsGroup.length > 1) {
|
|
|
let bannerList = [];
|
...
|
...
|
@@ -492,7 +477,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;
|
...
|
...
|
@@ -527,6 +512,31 @@ const _detailDataPkg = (origin, uid, vipLevel, ua) => { |
|
|
dest.introUrl = '/product/detail/intro/' + origin.erpProductId;
|
|
|
dest.id = origin.id;
|
|
|
|
|
|
// 虚拟商品(门票)
|
|
|
if (origin.attribute * 1 === 3) {
|
|
|
dest.tickets = true;
|
|
|
dest.ticketsConfirm = helpers.urlFormat('/cart/index/ticketsConfirm');
|
|
|
|
|
|
// 展览票
|
|
|
if (origin.erpProductId * 1 === SINGLE_TICKETS_SKN) {
|
|
|
dest.single = true;
|
|
|
} else {
|
|
|
// 套票
|
|
|
dest.package = true;
|
|
|
}
|
|
|
|
|
|
// 购票限制
|
|
|
dest.cartInfo.limit = 4;
|
|
|
|
|
|
// 清空活动
|
|
|
dest.goodsDiscount = [];
|
|
|
|
|
|
// 来自登录页,自动弹出选择框
|
|
|
// if (isset($_GET['product_type']) && $_GET['product_type'] == 'ticket') {
|
|
|
// $result['showPannel'] = true;
|
|
|
// }
|
|
|
}
|
|
|
|
|
|
return dest;
|
|
|
};
|
|
|
|
...
|
...
|
@@ -560,13 +570,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 +618,42 @@ 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) {
|
|
|
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)
|
|
|
});
|
|
|
} else if (!_.isEmpty(info[3]) && !_.get(info[2], 'feedbacks.consultsNum', 0)) {
|
|
|
Object.assign(finalResult.feedbacks, {
|
|
|
commonConsults: true,
|
|
|
consultsNum: true,
|
|
|
consults: _.take(info[3], 2)
|
|
|
});
|
|
|
}
|
|
|
|
|
|
return finalResult;
|
|
|
});
|
|
|
|
...
|
...
|
|