Authored by htoooth

new api

... ... @@ -53,17 +53,18 @@ const getProductModelTryAsync = skn => {
*/
const getProductAsync = (pid, uid, isStudents, vipLevel) => {
let params = {
method: 'h5.product.data',
productId: pid
method: 'app.product.data',
product_id: pid
};
if (uid) {
params.uid = uid;
}
if (isStudents) {
params.is_student = isStudents;
}
//if (isStudents) {
// params.is_student = isStudents;
//}
params.is_student = 1;
if (vipLevel) {
params.current_vip_level = vipLevel;
... ... @@ -71,14 +72,21 @@ const getProductAsync = (pid, uid, isStudents, vipLevel) => {
return api.get('', params);
};
const getPromotionAsync = (skn) => {
let params = {
method: 'app.product.promotion',
product_skn: skn
};
return api.get('', params);
};
module.exports = {
getProductBannerAsync,
sizeInfoAsync,
getProductComfortAsync,
getProductModelCardAsync,
getProductModelTryAsync,
getProductAsync
getProductAsync,
getPromotionAsync
};
... ...
... ... @@ -31,22 +31,22 @@ const BLANK_STR = ' ';
const cachedRequestData = {};
// 展览票
const EXHIBITION_TICKET = 51335912;
const EXHIBITION_TICKET = '51335912';
const _getProductAdditionInfoAsync = (data) => {
return co(function * () {
let productId = data.id || 0;
let skn = data.erpProductId;
let brandId = data.brand && data.brand.id ? data.brand.id : 0;
let productId = _.get(data, 'productId', 0);
let productSkn = _.get(data, 'productSkn', 0);
let brandId = _.get(data, 'brandInfo.brandId', 0);
let index = 0;
// 获取相关数据
let promiseData = [
productAPI.getProductBannerAsync(productId, 'web'),
productAPI.sizeInfoAsync(skn),
productAPI.sizeInfoAsync(productSkn),
productAPI.getProductComfortAsync(productId),
productAPI.getProductModelCardAsync(productId),
productAPI.getProductModelTryAsync(skn),
productAPI.getProductModelTryAsync(productSkn),
brandService.getBannerInfoAsync(brandId)
];
... ... @@ -107,7 +107,7 @@ const _getProductFavoriteDataAsync = (uid, pid, bid) => {
const _getTagsDataByProductInfo = (data) => {
let tags = {};
_.get(data, 'productTagBoList', []).forEach((value) => {
_.get(data, 'tags', []).forEach((value) => {
switch (value.tagLabel) {
case 'is_soon_sold_out': // 即将售磬
tags.isFew = true;
... ... @@ -144,7 +144,7 @@ const _getVipDataByProductBaseInfo = (data, vipLevel, uid) => {
vipLevel = vipLevel || 0;
uid = uid || 0;
if (_.isEmpty(_.get(data, 'productPriceBo.vipPrices', []))) {
if (_.isEmpty(_.get(data, 'vip', []))) {
return null;
}
... ... @@ -196,7 +196,7 @@ const _getActivityDataByProductBaseInfo = (data) => {
result.push(activityBanner);
}
_.get(data, 'promotionBoList', []).forEach(value => {
_.get(data, 'data', []).forEach(value => {
result.push({
type: value.promotionType.replace('¥', '¥'),
des: value.promotionTitle.replace('¥', '¥')
... ... @@ -241,11 +241,11 @@ const _getConsultCommentDataByProductInfo = (data) => {
* 获取品牌数据
*/
const _getBrandDataByProductBaseInfo = (data) => {
if (!data.brand) {
if (!data.brandInfo) {
return {};
}
let brandId = data.brand.id;
let brandId = data.brandInfo.id;
let bgImg = '';
let logo = '';
let bannerInfo = null;
... ... @@ -255,8 +255,8 @@ const _getBrandDataByProductBaseInfo = (data) => {
return {};
}
if (_.get(data, 'brand.brandIco')) {
logo = helpers.getForceSourceUrl(data.brand.brandIco);
if (_.get(data, 'brandInfo.brandIco')) {
logo = helpers.getForceSourceUrl(data.brandInfo.brandIco);
}
if (result.code && result.code === 200 && result.data) {
... ... @@ -273,8 +273,8 @@ const _getBrandDataByProductBaseInfo = (data) => {
let homeUrl = 'javascript:void(0)';
if (data.brand.brandDomain) {
homeUrl = helpers.urlFormat('', null, data.brand.brandDomain);
if (data.brandInfo.brandDomain) {
homeUrl = helpers.urlFormat('', null, data.brandInfo.brandDomain);
}
// 导航的品牌banner
... ... @@ -283,9 +283,9 @@ const _getBrandDataByProductBaseInfo = (data) => {
bgColor: bannerInfo && bannerInfo.colorValue ? bannerInfo.colorValue : '#000000',
bgImg: bgImg,
logo: logo,
alt: data.brand.brandName,
brandName: data.brand.brandName,
brandDomain: data.brand.brandDomain,
alt: data.brandInfo.brandName,
brandName: data.brandInfo.brandName,
brandDomain: data.brandInfo.brandDomain,
homeUrl: homeUrl
};
};
... ... @@ -299,86 +299,92 @@ const _getSkuDataByProductBaseInfo = (data) => {
let defaultImage = '';// 默认图
let chooseSkuFlag = false; // 选中状态
if (data.goodsList) {
skuGoods = _.get(data, 'goodsList', []).reduce((acc, cur, pos)=> {
if (!data.goodsList) {
return {
totalStorageNum,
skuGoods,
defaultImage
};
}
// 如果status为0,即skc下架时就跳过该商品$value['status'] === 0
let goodsGroup = {};
skuGoods = _.get(data, 'goodsList', []).reduce((acc, cur, pos)=> {
if (_.isEmpty(cur.colorImage)) {
return acc;
}
// 如果status为0,即skc下架时就跳过该商品$value['status'] === 0
let goodsGroup = {};
if (cur.goodsImagesList) {
// 商品列表
goodsGroup.productSkc = cur.productSkc;
goodsGroup.src = helpers.image(cur.colorImage, 40, 40);
goodsGroup.title = `${_.trim(data.productName)} ${cur.colorName}`;
goodsGroup.name = cur.colorName;
goodsGroup.focus = false;
goodsGroup.total = 0;
goodsGroup.thumbs = [];
goodsGroup.size = [];
}
if (_.isEmpty(cur.colorImage)) {
return acc;
}
_.get(cur, 'goodsImagesList', []).forEach(good => {
if (good.imageUrl) {
goodsGroup.thumbs.push({
url: '',
shower: helpers.image(good.imageUrl, 420, 560),
img: helpers.image(good.imageUrl, 75, 100)
});
}
});
if (cur.imagesList) {
// 商品列表
goodsGroup.productSkc = cur.productSkc;
goodsGroup.src = helpers.image(cur.colorImage, 40, 40);
goodsGroup.title = `${_.trim(data.productName)} ${cur.colorName}`;
goodsGroup.name = cur.colorName;
goodsGroup.focus = false;
goodsGroup.total = 0;
goodsGroup.thumbs = [];
goodsGroup.size = [];
}
// 缩略图空,不显示
if (_.isEmpty(goodsGroup.thumbs)) {
return acc;
_.get(cur, 'imagesList', []).forEach((good) => {
if (good.imageUrl) {
goodsGroup.thumbs.push({
url: '',
shower: helpers.image(good.imageUrl, 420, 560),
img: helpers.image(good.imageUrl, 75, 100)
});
}
});
// 默认第一张图片
if (pos === 0) {
defaultImage = helpers.image(cur.colorImage, 420, 560);
}
// 缩略图空,不显示
if (_.isEmpty(goodsGroup.thumbs)) {
return acc;
}
// 商品的尺码列表
_.get(cur, 'goodsSizeBoList', []).forEach((size) => {
if (data.attribute === 3) {
// 虚拟商品,门票默认最大为4,
size.goodsSizeStorageNum = size.goodsSizeStorageNum > 4 ? 4 : size.goodsSizeStorageNum;
}
// 默认第一张图片
if (pos === 0) {
defaultImage = helpers.image(cur.colorImage, 420, 560);
}
// 如果status为0,即skc下架时就跳过该商品
if (cur.status === 0) {
size.goodsSizeStorageNum = 0;
}
// 商品的尺码列表
_.get(cur, 'sizeList', []).forEach((size) => {
if (data.attribute === 3) {
// 虚拟商品,门票默认最大为4,
size.storageNumber = size.storageNumber > 4 ? 4 : size.storageNumber;
}
goodsGroup.size.push({
name: size.sizeName,
sku: size.goodsSizeSkuId,
num: parseInt(size.goodsSizeStorageNum),
goodsId: size.goodsId
});
// 如果status为0,即skc下架时就跳过该商品
if (cur.status === 0) {
size.storageNumber = 0;
}
// 单个sku商品的总数
goodsGroup.total += parseInt(size.goodsSizeStorageNum);
goodsGroup.size.push({
name: size.sizeName,
sku: size.productSku,
num: parseInt(size.storageNumber),
goodsId: size.sizeId
});
if (goodsGroup.total > 0 && !chooseSkuFlag) { // 默认选中该sku商品
goodsGroup.focus = true;
chooseSkuFlag = true;// 选中sku商品
}
// 单个sku商品的总数
goodsGroup.total += parseInt(size.storageNumber);
totalStorageNum += parseInt(size.goodsSizeStorageNum);
if (goodsGroup.total > 0 && !chooseSkuFlag) { // 默认选中该sku商品
goodsGroup.focus = true;
chooseSkuFlag = true;// 选中sku商品
}
});
totalStorageNum += parseInt(size.storageNumber);
acc.push(goodsGroup);
return acc;
}, []);
});
if (!_.isEmpty(skuGoods) && !chooseSkuFlag) { // 没有选中一个sku商品,默认选中第一个sku商品
_.head(skuGoods).focus = true;
}
acc.push(goodsGroup);
return acc;
}, []);
if (!_.isEmpty(skuGoods) && !chooseSkuFlag) { // 没有选中一个sku商品,默认选中第一个sku商品
_.head(skuGoods).focus = true;
}
return {
... ... @@ -538,6 +544,11 @@ const _detailDataPkg = (origin, uid, vipLevel) => {
return co(function*() {
let result = {}; // 结果输出
origin = global.yoho.camelCase(origin);
console.dir(origin);
let propOrigin = _.partial(_.get, origin);
// 商品名称
if (!origin.productName) {
return result;
... ... @@ -546,22 +557,19 @@ const _detailDataPkg = (origin, uid, vipLevel) => {
origin.uid = uid;
result.name = origin.productName;
result.skn = origin.erpProductId;
result.productId = origin.id;
result.maxSortId = origin.maxSortId;
result.smallSortId = origin.smallSortId;
result.promotionId = origin.isPromotion;
result.goCartUrl = helpers.urlFormat('/shopping/cart');
result.skn = origin.productSkn;
result.productId = origin.productId;
let brandId = 0;
result.maxSortId = propOrigin('maxSortId', '');
result.smallSortId = propOrigin('smallSortId', '');
if (origin.brand && origin.brand.id) {
brandId = origin.brand.id;
}
result.goCartUrl = helpers.urlFormat('/shopping/cart');
let brandId = propOrigin('brandInfo.brandId', 0);
let requestData = yield Promise.all([
_getProductAdditionInfoAsync(origin), // 预处理所有的数据
_getProductFavoriteDataAsync(uid, result.productId, brandId) // 处理收藏喜欢数据
_getProductFavoriteDataAsync(uid, result.productId, brandId), // 处理收藏喜欢数据
productAPI.getPromotionAsync(result.skn)
]);
let favoriteData = requestData[1];
... ... @@ -570,24 +578,21 @@ const _detailDataPkg = (origin, uid, vipLevel) => {
result.tags = _getTagsDataByProductInfo(origin);
// 商品促销短语
if (origin.salesPhrase) {
result.saleTip = origin.salesPhrase;
}
result.saleTip = propOrigin('formatSalesPhrase', '');
// 商品价格
if (origin.productPriceBo) {
result.marketPrice = origin.productPriceBo.formatMarketPrice;
result.hasOtherPrice = true;
result.salePrice = origin.productPriceBo.formatSalesPrice;
if (result.marketPrice === result.salePrice) {
delete result.salePrice;
result.hasOtherPrice = false;
}
result.marketPrice = propOrigin('formatMarketPrice');
result.salePrice = propOrigin('formatSalesPrice');
result.hasOtherPrice = true;
if (result.marketPrice === result.salePrice) {
delete result.salePrice;
result.hasOtherPrice = false;
}
if (origin.productPriceBo.studentPrice) {
if (propOrigin('studentPrice', '')) {
// 学生价
result.studentsPrice = '¥' + origin.productPriceBo.studentPrice.toFixed(2);
result.studentsPrice = propOrigin('studentPrice');
} else {
// VIP学生数据
result.vipPrice = _getVipDataByProductBaseInfo(origin, vipLevel, uid);
... ... @@ -595,7 +600,7 @@ const _detailDataPkg = (origin, uid, vipLevel) => {
// 促销活动banner,虚拟商品无促销
if (origin.attribute !== 3) {
result.activity = _getActivityDataByProductBaseInfo(origin);
result.activity = _getActivityDataByProductBaseInfo(requestData[2]);
}
const C_VALUE = {
... ... @@ -604,24 +609,20 @@ const _detailDataPkg = (origin, uid, vipLevel) => {
rest: '个 有货币'
};
do {
if (origin.productPriceBo.yohoCoinNum && origin.productPriceBo.yohoCoinNum !== 0) {
result.activity.push({
type: C_VALUE.type,
des: `${C_VALUE.des}${origin.productPriceBo.yohoCoinNum}${C_VALUE.rest}`
});
break;
}
if (origin.productPriceBo.studentCoinNum && origin.productPriceBo.studentCoinNum !== 0) {
result.activity.push({
type: C_VALUE.type,
des: `${C_VALUE.des}${origin.productPriceBo.studentCoinNum}${C_VALUE.rest}`
});
}
} while (false);
if (propOrigin('yohoCoinNum ', 0)) {
result.activity.push({
type: C_VALUE.type,
des: `${C_VALUE.des}${origin.productPriceBo.yohoCoinNum}${C_VALUE.rest}`
});
} else if (propOrigin('studentCoinNum', 0)) {
result.activity.push({
type: C_VALUE.type,
des: `${C_VALUE.des}${origin.productPriceBo.studentCoinNum}${C_VALUE.rest}`
});
}
// 上市期
// TODO:
if (origin.expectArrivalTime) {
result.arrivalDate = `${origin.expectArrivalTime}月`;
result.presalePrice = origin.productPriceBo.formatSalesPrice;
... ... @@ -635,10 +636,10 @@ const _detailDataPkg = (origin, uid, vipLevel) => {
// 品牌信息
let banner = {};
if (origin.brand) {
result.brandImg = helpers.image(origin.brand.brandIco, 47, 47);
result.brandName = origin.brand.brandName;
result.brandUrl = helpers.urlFormat('', null, origin.brand.brandDomain);
if (propOrigin('brandInfo', '')) {
result.brandImg = helpers.image(propOrigin('brandInfo.brandIco', ''), 47, 47);
result.brandName = propOrigin('brandInfo.brandName', '');
result.brandUrl = helpers.urlFormat('', null, propOrigin('brandInfo.brandDomain'));
banner = _getBrandDataByProductBaseInfo(origin);
banner.isCollect = favoriteData.brand;
}
... ... @@ -653,16 +654,12 @@ const _detailDataPkg = (origin, uid, vipLevel) => {
// 是否收藏
result.isCollect = favoriteData.product;
if (origin.isLimitBuy === 'Y') {
if (origin.isLimitBuy === true) {
// 是否开售
let isBeginSale = !!(origin.saleStatus && origin.saleStatus === 1);
// 限购商品有关的展示状态
let showStatus = 1;
if (origin.showStatus) {
showStatus = _.parseInt(origin.showStatus, 10);
}
let showStatus = propOrigin('showStatus', 1);
let fashTopGoods = _getFashionTopGoodsStatus(uid, showStatus, isBeginSale);
... ... @@ -694,7 +691,7 @@ const _detailDataPkg = (origin, uid, vipLevel) => {
result.isVirtualBtn = soldOut ? false : true;
// 是否展览票
result.isTicket = origin.erpProductId * 1 === EXHIBITION_TICKET;
result.isTicket = origin.productSkn === EXHIBITION_TICKET;
}
if (!soldOut && !notForSale && !virtualGoods) {
... ... @@ -738,16 +735,12 @@ const _detailDataPkg = (origin, uid, vipLevel) => {
let statGoodsInfo = {};
statGoodsInfo.uid = uid;
statGoodsInfo.skn = origin.erpProductId;
statGoodsInfo.skn = origin.productSkn;
statGoodsInfo.productId = origin.id;
statGoodsInfo.productName = result.name.replace('\'', '’');
statGoodsInfo.brandName = (result.brandName || '').replace('\'', '’');
statGoodsInfo.marketPrice = result.marketPrice.replace('¥', '');
if (result.salePrice) {
statGoodsInfo.salePrice = result.salePrice.replace('¥', '');
} else {
statGoodsInfo.salePrice = result.marketPrice.replace('¥', '');
}
statGoodsInfo.marketPrice = result.marketPrice;
statGoodsInfo.salePrice = result.salePrice ? result.salePrice : result.marketPrice;
if (banner.brandId) {
let domainBrand = yield brandService.getBrandByDomainAsync(banner.brandDomain);
... ... @@ -755,23 +748,23 @@ const _detailDataPkg = (origin, uid, vipLevel) => {
if (domainBrand.type && domainBrand.shopId) {
switch (parseInt(domainBrand.type, 10)) {
case 1:
{
{
// 多品店不显示
banner = [];
break;
}
banner = [];
break;
}
case 2:
{
{
// 单品店显示新版的店铺banner
let basisData = yield shopService.basisTemplateAsync(domainBrand.shopId);
let basisData = yield shopService.basisTemplateAsync(domainBrand.shopId);
banner.bgImg = basisData.shopTopBanner.banner || banner.bgImg;
break;
}
banner.bgImg = basisData.shopTopBanner.banner || banner.bgImg;
break;
}
default:
{
break;
}
{
break;
}
}
}
}
... ... @@ -896,8 +889,6 @@ const _sizeInfoBoSort = (sizeInfoBo) => {
return {};
}
// TODO: 这里的排序代码很乱
_.get(sizeInfoBo, 'sizeBoList', []).forEach((sizeBoList, sizek)=> {
let sortAttr = {};
... ... @@ -1338,7 +1329,8 @@ const showMainAsync = (data) => {
let currentUserProductInfo = _.partial(_detailDataPkg, _, data.uid, data.vipLevel);
// 获取商品信息
let productInfo = yield productAPI.getProductAsync(data.pid, data.uid, data.isStudent, data.vipLevel).then(currentUserProductInfo);
let productInfo = yield productAPI.getProductAsync(data.pid, data.uid, data.isStudent, data.vipLevel)
.then(res => currentUserProductInfo(res.data));
if (_.isEmpty(productInfo) || _.isEmpty(productInfo.goodsInfo)) {
return Promise.reject({
... ...