...
|
...
|
@@ -11,11 +11,31 @@ const _ = require('lodash'); |
|
|
const helpers = global.yoho.helpers;
|
|
|
|
|
|
/**
|
|
|
* 获取用户数据信息
|
|
|
* @param {[string]} uid
|
|
|
* @return {[array]}
|
|
|
*/
|
|
|
const _getUserProfile = (uid) => {
|
|
|
if (!uid) {
|
|
|
return Promise.resolve({
|
|
|
code: 200,
|
|
|
data: {}
|
|
|
});
|
|
|
}
|
|
|
return api.get('', {
|
|
|
method: 'app.passport.profile',
|
|
|
uid: uid
|
|
|
}, {
|
|
|
cache: true
|
|
|
});
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 处理品牌关联店铺信息
|
|
|
* @param {array}
|
|
|
* @return {array}
|
|
|
*/
|
|
|
const getShopsInfo = (data) => {
|
|
|
const _processShopsInfo = (data) => {
|
|
|
let enterStore = [];
|
|
|
|
|
|
_.forEach(data, function(value) {
|
...
|
...
|
@@ -44,7 +64,7 @@ const getShopsInfo = (data) => { |
|
|
* @param {Boolean} 限购商品是否已开售
|
|
|
* @return {array}
|
|
|
*/
|
|
|
const procShowStatus = (data, showStatus, isBeginSale) => {
|
|
|
const _procShowStatus = (data, showStatus, isBeginSale) => {
|
|
|
switch (showStatus) {
|
|
|
case 1: // 开售前/后,立即分享获得限购码(用户未领取限购码)
|
|
|
// 显示获取限购码按钮
|
...
|
...
|
@@ -93,7 +113,7 @@ const procShowStatus = (data, showStatus, isBeginSale) => { |
|
|
* @param {string} skn 限购商品skn
|
|
|
* @return {string} 限购商品跳转url
|
|
|
*/
|
|
|
const getLimitCodeUrl = (productCode, skn, ua) => {
|
|
|
const _getLimitCodeUrl = (productCode, skn, ua) => {
|
|
|
let url = 'yohoapp://yoho.app/openwith?limit_product_code=' + productCode +
|
|
|
'&product_skn=' + skn;
|
|
|
|
...
|
...
|
@@ -114,7 +134,7 @@ const getLimitCodeUrl = (productCode, skn, ua) => { |
|
|
* @param origin Object 原始数据
|
|
|
* @return dest Object 格式化数据
|
|
|
*/
|
|
|
const detailDataPkg = (origin, uid, vipLevel, ua) => {
|
|
|
const _detailDataPkg = (origin, uid, vipLevel, ua) => {
|
|
|
let dest = {}, // 结果输出
|
|
|
thumbImageList = [],
|
|
|
colorGroup = {},
|
...
|
...
|
@@ -128,8 +148,8 @@ const detailDataPkg = (origin, uid, vipLevel, ua) => { |
|
|
|
|
|
dest.goodsName = origin.productName;
|
|
|
|
|
|
// 用户未登录时 待处理
|
|
|
if (uid === null || typeof uid === 'undefined') {
|
|
|
// 用户未登录时
|
|
|
if (!uid) {
|
|
|
let params = {};
|
|
|
|
|
|
params.refer = helpers.urlFormat('/product/show_' + origin.erpProductId + '.html');
|
...
|
...
|
@@ -217,7 +237,7 @@ const detailDataPkg = (origin, uid, vipLevel, ua) => { |
|
|
dest.periodOfMarket = `${origin.expectArrivalTime}月`;
|
|
|
}
|
|
|
|
|
|
// 促销信息
|
|
|
// 促销信息 TODO: 换新接口
|
|
|
if (origin.promotionBoList) {
|
|
|
let discountList = [];
|
|
|
|
...
|
...
|
@@ -257,10 +277,11 @@ const detailDataPkg = (origin, uid, vipLevel, ua) => { |
|
|
|
|
|
if (_.has(dest, 'feedbacks.consultsNum')) {
|
|
|
consultParams.total = dest.feedbacks.consultsNum;
|
|
|
dest.feedbacks.consultsUrl = helpers.urlFormat('/product/detail/consult', consultParams);
|
|
|
} else {
|
|
|
dest.feedbacks.consultsUrl = helpers.urlFormat('/product/detail/consultform', consultParams);
|
|
|
}
|
|
|
|
|
|
dest.feedbacks.consultsUrl = helpers.urlFormat('/product/detail/consultform', consultParams);
|
|
|
|
|
|
|
|
|
// 商品评价
|
|
|
dest.feedbacks.commentsNum = 0;
|
...
|
...
|
@@ -481,14 +502,14 @@ const detailDataPkg = (origin, uid, vipLevel, ua) => { |
|
|
}
|
|
|
|
|
|
// 处理限购商品有关的按钮状态
|
|
|
dest = procShowStatus(dest, showStatus, isBeginSale);
|
|
|
Object.assign;
|
|
|
dest = _procShowStatus(dest, showStatus, isBeginSale);
|
|
|
|
|
|
dest.cartInfo.limitProductCode = origin.limitProductCode;
|
|
|
dest.cartInfo.limitCodeUrl = getLimitCodeUrl(origin.limitProductCode, origin.erpProductId, ua);
|
|
|
dest.cartInfo.limitProductPay = helpers.urlFormat('/cart/index/orderEnsure'); // 待处理 相关处理逻辑还不存在
|
|
|
dest.cartInfo.limitCodeUrl = _getLimitCodeUrl(origin.limitProductCode, origin.erpProductId, ua);
|
|
|
dest.cartInfo.limitProductPay = helpers.urlFormat('/cart/index/orderEnsure');
|
|
|
} else {
|
|
|
dest.cartInfo.addToCartUrl = helpers.urlFormat('/product/buy_' + origin.id + '_' +
|
|
|
origin.goodsList.id + '.html'); // 待处理 相关处理逻辑还不存在
|
|
|
origin.goodsList.id + '.html');
|
|
|
}
|
|
|
} else if (notForSale) {
|
|
|
dest.cartInfo.notForSale = true;
|
...
|
...
|
@@ -497,7 +518,6 @@ const detailDataPkg = (origin, uid, vipLevel, ua) => { |
|
|
}
|
|
|
|
|
|
// 是否收藏
|
|
|
|
|
|
dest.isCollect = false;
|
|
|
if (origin.isCollect !== null && typeof origin.isCollect !== 'undefined' && origin.isCollect === 'Y') {
|
|
|
dest.isCollect = true;
|
...
|
...
|
@@ -510,7 +530,37 @@ const detailDataPkg = (origin, uid, vipLevel, ua) => { |
|
|
return dest;
|
|
|
};
|
|
|
|
|
|
module.exports = (data) => {
|
|
|
let _getShopsInfo = (brandId) => {
|
|
|
return api.get('', {
|
|
|
method: 'app.shop.queryShopsByBrandId',
|
|
|
brand_id: _.toString(brandId)
|
|
|
}, {
|
|
|
cache: true
|
|
|
}).then(shops => {
|
|
|
if (shops.code === 200) {
|
|
|
return _processShopsInfo(shops.data);
|
|
|
}
|
|
|
|
|
|
return [];
|
|
|
});
|
|
|
};
|
|
|
|
|
|
let _getPromotionInfo = (skn) => {
|
|
|
return api.get('', {
|
|
|
method: 'app.product.promotion',
|
|
|
product_skn: _.toString(skn)
|
|
|
}, {
|
|
|
cache: true
|
|
|
}).then((result) => {
|
|
|
if (result.code === 200) {
|
|
|
return result.data;
|
|
|
}
|
|
|
|
|
|
return {};
|
|
|
});
|
|
|
};
|
|
|
|
|
|
let getProductData = (data) => {
|
|
|
let finalResult;
|
|
|
let params = {
|
|
|
productId: _.toString(data.id),
|
...
|
...
|
@@ -521,18 +571,25 @@ module.exports = (data) => { |
|
|
params.uid = data.uid;
|
|
|
}
|
|
|
|
|
|
return api.get('', params).then(result => {
|
|
|
finalResult = detailDataPkg(result, data.uid, data.vipLevel, data.ua);
|
|
|
return _getUserProfile(params.uid).then((user) => {
|
|
|
data.vipLevel = (user.data && user.data.vip_info && user.data.vip_info.cur_level) || '0';
|
|
|
|
|
|
return api.get('', {
|
|
|
method: 'app.shop.queryShopsByBrandId',
|
|
|
brand_id: _.toString(result.brandId)
|
|
|
}).then(shops => {
|
|
|
if (shops.code === 200) {
|
|
|
finalResult.enterStore = getShopsInfo(shops.data);
|
|
|
}
|
|
|
return api.get('', params, {
|
|
|
cache: true
|
|
|
}).then(result => {
|
|
|
return Promise.all([_getShopsInfo(result.brandId), _getPromotionInfo(result.erpProductId)]).then((info) => {
|
|
|
result.promotionBoList = info[1];
|
|
|
|
|
|
finalResult = _detailDataPkg(result, data.uid, data.vipLevel, data.ua);
|
|
|
finalResult.enterStore = info[0];
|
|
|
|
|
|
return finalResult;
|
|
|
});
|
|
|
|
|
|
return finalResult;
|
|
|
});
|
|
|
});
|
|
|
};
|
|
|
|
|
|
module.exports = {
|
|
|
getProductData
|
|
|
}; |
...
|
...
|
|