Authored by htoooth

refactor

... ... @@ -86,7 +86,7 @@ const getPromotionAsync = (skn) => {
return api.get('', params);
};
const getLimitedProductStatus = (code, uid, skn) => {
const getLimitedProductStatusAsync = (code, uid, skn) => {
let params = {
method: 'app.limitProduct.productStatus',
limitProductCode: code
... ... @@ -112,5 +112,5 @@ module.exports = {
getProductAsync,
getPromotionAsync,
isSupportReturnedSale,
getLimitedProductStatus
getLimitedProductStatusAsync
};
... ...
... ... @@ -35,16 +35,11 @@ const EXHIBITION_TICKET = 51335912;
const _getProductAdditionInfoAsync = (data) => {
return co(function * () {
let productId = _.get(data, 'product_id', 0);
let productSkn = _.get(data, 'product_skn', 0);
let brandId = _.get(data, 'brand_info.brand_id', 0);
// 获取相关数据
let promiseData = {
productBanner: productAPI.getProductBannerAsync(productId),
sizeInfo: productAPI.sizeInfoAsync(productSkn),
productComfort: productAPI.getProductComfortAsync(productId),
productModelCard: productAPI.getProductModelCardAsync(productId),
productModelTry: productAPI.getProductModelTryAsync(productSkn),
bannerInfo: brandService.getBannerInfoAsync(brandId)
};
... ... @@ -54,6 +49,19 @@ const _getProductAdditionInfoAsync = (data) => {
})();
};
const _getProductIntroAsync = (productId, productSkn) => {
return co(function * () {
let result = yield Promise.props({
sizeInfo: productAPI.sizeInfoAsync(productSkn),
productComfort: productAPI.getProductComfortAsync(productId),
productModelCard: productAPI.getProductModelCardAsync(productId),
productModelTry: productAPI.getProductModelTryAsync(productSkn)
});
return result;
})();
};
/**
* 获取商品的喜欢
* pid : product id
... ... @@ -70,15 +78,26 @@ const _getProductFavoriteDataAsync = (uid, pid, bid) => {
return result;
}
if (pid) {
let productData = yield favoriteProductService.isFavoriteAsync(uid, pid);
let requestApi = {};
result.product = productData.code === 200 && productData.data ? true : false;
if (pid) {
requestApi.product = favoriteProductService.isFavoriteAsync(uid, pid);
}
if (bid) {
let brandData = yield favoriteBrandService.isFavoriteAsync(uid, bid);
requestApi.brand = favoriteBrandService.isFavoriteAsync(uid, bid);
}
let requestData = yield Promise.props(requestApi);
let productData = requestData.product;
let brandData = requestData.brand;
if (productData) {
result.product = productData.code === 200 && productData.data ? true : false;
}
if (brandData) {
result.brand = brandData.code && brandData.code === 200 ? true : false;
}
... ... @@ -940,7 +959,7 @@ const _getSizeAttrByMaxSortId = (maxSortId, sizeList) => {
* @param maxSortId
* @return object
*/
const _getSizeInfo = (productSkn, maxSortId, additionalData)=> {
const _getIntroInfo = (productSkn, maxSortId, additionalData)=> {
if (!productSkn) {
return {};
}
... ... @@ -1058,15 +1077,32 @@ const _detailDataPkg = (origin, uid, vipLevel) => {
result.goCartUrl = helpers.urlFormat('/shopping/cart');
let brandId = propOrigin('brand_info.brand_id', 0);
let requestData = yield Promise.all([
_getProductAdditionInfoAsync(origin), // 预处理所有的数据
_getProductFavoriteDataAsync(uid, result.productId, brandId), // 处理收藏喜欢数据
productAPI.getPromotionAsync(result.skn)
]);
let additionalData = requestData[0];
let favoriteData = requestData[1];
let promotionData = requestData[2];
let requestApi = {
addition: _getProductAdditionInfoAsync(origin), // 预处理所有的数据
fav: _getProductFavoriteDataAsync(uid, result.productId, brandId), // 处理收藏喜欢数据
promotion: productAPI.getPromotionAsync(result.skn) // 打折信息
};
if (propOrigin('isLimitBuy', false) && propOrigin('limitProductCode', '')) {
requestApi.limited = productAPI.getLimitedProductStatusAsync(
propOrigin('limitProductCode'),
uid,
result.skn
); // 限购商品的状态
}
if (propOrigin('brand_info', '')) {
requestApi.brand = brandService.getBrandByDomainAsync(propOrigin('brand_info.brand_domain'));
}
let requestData = yield Promise.props(requestApi);
let additionalData = requestData.addition;
let favoriteData = requestData.fav;
let promotionData = requestData.promotion;
let limitedInfo = requestData.limited;
let domainBrand = requestData.brand;
// 商品标签
result.tags = _getTagsDataByProductInfo(origin);
... ... @@ -1130,40 +1166,34 @@ const _detailDataPkg = (origin, uid, vipLevel) => {
result.isCollect = favoriteData.product;
// 限购商品
if (propOrigin('isLimitBuy', false) && propOrigin('limitProductCode', '')) {
const limitedInfo = yield productAPI.getLimitedProductStatus(
propOrigin('limitProductCode'),
uid,
result.skn
);
if (limitedInfo.code === 200 && _.get(limitedInfo, 'data.isLimitBuy', false) === true) {
// 是否开售
let isBeginSale = _.get(limitedInfo, 'data.saleStatus', 0) === 1;
if (limitedInfo && limitedInfo.code === 200 && _.get(limitedInfo, 'data.isLimitBuy', false) === true) {
// 是否开售
let isBeginSale = _.get(limitedInfo, 'data.saleStatus', 0) === 1;
// 限购商品有关的展示状态
let showStatus = _.get(limitedInfo, 'data.showStatus', 1);
// 限购商品有关的展示状态
let showStatus = _.get(limitedInfo, 'data.showStatus', 1);
let fashTopGoods = _getFashionTopGoodsStatus(uid, showStatus, isBeginSale);
let fashTopGoods = _getFashionTopGoodsStatus(uid, showStatus, isBeginSale);
result.fashionTopGoods = {
getLimitedCode: fashTopGoods.getLimitedCode, // 限购码状态
hadLimitedCode: fashTopGoods.hadLimitedCode, // 是否已经获取限购码
limitedCodeSoldOut: fashTopGoods.limitedCodeSoldOut, // 限购码是否已经抢光
getLimitedCodeDis: fashTopGoods.getLimitedCodeDis // 限购码是否失效
};
result.fashionTopGoods = {
getLimitedCode: fashTopGoods.getLimitedCode, // 限购码状态
hadLimitedCode: fashTopGoods.hadLimitedCode, // 是否已经获取限购码
limitedCodeSoldOut: fashTopGoods.limitedCodeSoldOut, // 限购码是否已经抢光
getLimitedCodeDis: fashTopGoods.getLimitedCodeDis // 限购码是否失效
};
if (fashTopGoods.soldOut) {
result.soldOut = fashTopGoods.soldOut;
totalStorageNum = 0; // 改总数为已售磬
} else {
result.openSoon = fashTopGoods.openSoon; // 即将开售
result.dis = fashTopGoods.dis; // 是否失效
result.buyNow = fashTopGoods.buyNow; // 是否立即购买
}
if (fashTopGoods.soldOut) {
result.soldOut = fashTopGoods.soldOut;
totalStorageNum = 0; // 改总数为已售磬
} else {
result.openSoon = fashTopGoods.openSoon; // 即将开售
result.dis = fashTopGoods.dis; // 是否失效
result.buyNow = fashTopGoods.buyNow; // 是否立即购买
}
}
// 商品购买状态
let soldOut = !!(propOrigin('status') === 0 || totalStorageNum === 0);
let notForSale = propOrigin('attribute') === 2; // 非卖品
let virtualGoods = propOrigin('attribute') === 3; // 虚拟商品
... ... @@ -1231,42 +1261,36 @@ const _detailDataPkg = (origin, uid, vipLevel) => {
statGoodsInfo.smallSortId = result.smallSortId;
statGoodsInfo.soldOut = soldOut ? 1 : 0;
// 品牌信息
let banner = {};
// 商品的品牌信息
let bandInfo = {};
if (propOrigin('brand_info', '')) {
result.brandImg = helpers.image(propOrigin('brand_info.brand_ico', ''), 47, 47);
result.brandName = propOrigin('brand_info.brand_name', '');
result.brandUrl = helpers.urlFormat('', null, propOrigin('brand_info.brand_domain'));
banner = _getBrandDataByProductBaseInfo(origin, additionalData);
banner.isCollect = favoriteData.brand;
let domainBrand = yield brandService.getBrandByDomainAsync(banner.brandDomain);
bandInfo = _getBrandDataByProductBaseInfo(origin, additionalData);
bandInfo.isCollect = favoriteData.brand;
if (domainBrand.type && domainBrand.shopId) {
let type = _.parseInt(domainBrand.type);
if (type === 1) {
// 多品店不显示
banner = {};
bandInfo = {};
} else if (type === 2) {
// 单品店显示新版的店铺banner
let basisData = yield shopService.basisTemplateAsync(domainBrand.shopId);
banner.bgImg = basisData.shopTopBanner.banner || banner.bgImg;
bandInfo.bgImg = basisData.shopTopBanner.banner || bandInfo.bgImg;
}
}
}
// 获取商品尺寸相关
let sizeInfo = _getSizeInfo(result.skn, result.maxSortId, additionalData);
return Object.assign({
return {
goodsInfo: result,
consultComment: true,
banner: _.isEmpty(banner) ? null : banner,
banner: _.isEmpty(bandInfo) ? null : bandInfo,
statGoodsInfo: statGoodsInfo
}, sizeInfo);
};
})();
};
... ... @@ -1295,10 +1319,9 @@ const getDetailHeader = (pid, uid, isStudent, vipLevel, dataMd5) => {
*/
const showMainAsync = (data) => {
return co(function * () {
let result = {};
let currentUserProductInfo = _.partial(_detailDataPkg, _, data.uid, data.vipLevel);
// 获取商品信息
// 获取并处理商品基本信息
let productInfo = yield productAPI.getProductAsync(data.pid, data.uid, data.isStudent, data.vipLevel)
.then(currentUserProductInfo);
... ... @@ -1309,41 +1332,57 @@ const showMainAsync = (data) => {
}
let requestData = yield Promise.all([
_getSortNavAsync(productInfo.goodsInfo.smallSortId, data.gender),
HeaderModel.requestHeaderData(data.channel),
productAPI.isSupportReturnedSale(productInfo.goodsInfo.skn)
_getSortNavAsync(productInfo.goodsInfo.smallSortId, data.gender), // 导航
HeaderModel.requestHeaderData(data.channel), // 头部数据
productAPI.isSupportReturnedSale(productInfo.goodsInfo.skn), // 退换货
_getProductIntroAsync(productInfo.goodsInfo.productId, productInfo.goodsInfo.skn) // 商品详细介绍
]);
// 分类导航 ,seo
let navs = requestData[0];
let seo = _getSeoByGoodsInfo(productInfo.goodsInfo, navs);
// 拼装数据
let result = {};
result.seo = seo;
// 商品数据详情
result.productDetailPage = true;
result.detail = productInfo;
// 最近浏览功能 ,限量商品不能使用这个功能
if (!_.has(productInfo, 'goodsInfo.fashionTopGoods')) {
data.saveInCookies(data.gid, _.get(productInfo, 'goodsInfo.skn', ''));
}
// 商品详细介绍
let intro = _getIntroInfo(productInfo.goodsInfo.skn, productInfo.goodsInfo.maxSortId, requestData[3]);
result.deatil = Object.assign(result.detail, intro);
// 咨询和评论
result.detail.consultComment = true;
// seo
result.seo = _getSeoByGoodsInfo(productInfo.goodsInfo, requestData[0]);
// 头部数据
result.headerData = requestData[1].headerData;
result.productDetailPage = true;
result.detail = productInfo;
result.statGoodsInfo = Object.assign({fullSortName: navs.map(x => x.name).join('-')},
// 商品页面统计
result.statGoodsInfo = Object.assign({fullSortName: requestData[0].map(x => x.name).join('-')},
productInfo.statGoodsInfo
);
// 是否支持退换货,true 支持,false 不支持
result.detail.supportSaleReturnedService =
_.get(requestData, `[2].data.${productInfo.goodsInfo.skn}`, 'N') === 'N';
_.get(requestData[2], `data.${productInfo.goodsInfo.skn}`, 'N') === 'N';
// 导航
// 面包屑导航
result.detail.pathNav = _.concat(
homeService.getHomeChannelNav(data.channel),
navs,
requestData[0],
[{name: productInfo.goodsInfo.name}]
);
// 最近浏览功能 ,限量商品不加入到最近浏览
if (!_.has(productInfo, 'goodsInfo.fashionTopGoods')) {
data.saveInCookies(data.gid, _.get(productInfo, 'goodsInfo.skn', ''));
}
// 只显示5个
result.detail.latestWalk = 5;
return result;
})();
};
... ...