...
|
...
|
@@ -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 _getShopsInfo = (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 = {},
|
...
|
...
|
@@ -481,10 +501,10 @@ 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.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 + '_' +
|
...
|
...
|
@@ -510,7 +530,7 @@ const detailDataPkg = (origin, uid, vipLevel, ua) => { |
|
|
return dest;
|
|
|
};
|
|
|
|
|
|
module.exports = (data) => {
|
|
|
let getProductData = (data) => {
|
|
|
let finalResult;
|
|
|
let params = {
|
|
|
productId: _.toString(data.id),
|
...
|
...
|
@@ -521,18 +541,30 @@ module.exports = (data) => { |
|
|
params.uid = data.uid;
|
|
|
}
|
|
|
|
|
|
return api.get('', params).then(result => {
|
|
|
finalResult = detailDataPkg(result, data.uid, data.vipLevel, data.ua);
|
|
|
|
|
|
return api.get('', {
|
|
|
method: 'app.shop.queryShopsByBrandId',
|
|
|
brand_id: _.toString(result.brandId)
|
|
|
}).then(shops => {
|
|
|
if (shops.code === 200) {
|
|
|
finalResult.enterStore = getShopsInfo(shops.data);
|
|
|
}
|
|
|
return _getUserProfile(params.uid).then((user) => {
|
|
|
data.vipLevel = (user.data && user.data.vip_info && user.data.vip_info.cur_level) || '0';
|
|
|
|
|
|
return api.get('', params, {
|
|
|
cache: true
|
|
|
}).then(result => {
|
|
|
finalResult = _detailDataPkg(result, data.uid, data.vipLevel, data.ua);
|
|
|
|
|
|
return api.get('', {
|
|
|
method: 'app.shop.queryShopsByBrandId',
|
|
|
brand_id: _.toString(result.brandId)
|
|
|
}, {
|
|
|
cache: true
|
|
|
}).then(shops => {
|
|
|
if (shops.code === 200) {
|
|
|
finalResult.enterStore = _getShopsInfo(shops.data);
|
|
|
}
|
|
|
|
|
|
return finalResult;
|
|
|
return finalResult;
|
|
|
});
|
|
|
});
|
|
|
});
|
|
|
};
|
|
|
|
|
|
module.exports = {
|
|
|
getProductData
|
|
|
}; |
...
|
...
|
|