...
|
...
|
@@ -13,6 +13,7 @@ const logger = require(`${library}/logger`); |
|
|
const helpers = require(`${library}/helpers`);
|
|
|
const camelCase = require(`${library}/camel-case`);
|
|
|
const resourcesProcess = require(`${utils}/resources-process`);
|
|
|
const productProcess = require(`${utils}/product-process`);
|
|
|
const _ = require('lodash');
|
|
|
const api = new API();
|
|
|
const serviceAPI = new ServiceAPI();
|
...
|
...
|
@@ -34,8 +35,9 @@ const timeFormat = { |
|
|
const typeCont = {
|
|
|
price: ['s_p_desc', 's_p_asc'],
|
|
|
discount: ['p_d_desc', 'p_d_asc'],
|
|
|
sales: ['s_n_desc', 's_n_asc'],
|
|
|
newest: ['s_t_desc', 's_t_asc']
|
|
|
sale: ['s_n_desc', 's_n_asc'],
|
|
|
newest: ['s_t_desc', 's_t_asc'],
|
|
|
stock: ['s_s_desc', 's_s_asc']
|
|
|
};
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -129,141 +131,6 @@ const special = (params) => { |
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 根据性别来决定 默认图片获取字段 如果是 2、3
|
|
|
*
|
|
|
* 则优先从cover2 --》 cover1 -- 》 images_url
|
|
|
* 否则优先从cover1 --》 cover2 -- 》 images_url
|
|
|
*
|
|
|
*/
|
|
|
const procProductImg = (product, gender) => {
|
|
|
if (gender === '2,3') {
|
|
|
return product.cover2 || product.cover1 || product.imagesUrl || '';
|
|
|
}
|
|
|
|
|
|
return product.cover1 || product.cover2 || product.imagesUrl || '';
|
|
|
};
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 商品搜索商品数据处理
|
|
|
*/
|
|
|
const processProductList = (list, options) => {
|
|
|
const pruductList = [];
|
|
|
|
|
|
options = Object.assign({
|
|
|
showTags: true,
|
|
|
showNew: true,
|
|
|
showSale: true,
|
|
|
width: 290,
|
|
|
height: 388,
|
|
|
isApp: false,
|
|
|
showPoint: true,
|
|
|
gender: '2,3'
|
|
|
}, options);
|
|
|
list = camelCase(list);
|
|
|
|
|
|
_.forEach(list, (product) => {
|
|
|
// 商品信息有问题,则不显示
|
|
|
if (!product.productId || !product.goodsList.length) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
// 市场价和售价一样,则不显示市场价
|
|
|
if (product.marketPrice === product.salesPrice) {
|
|
|
product.marketPrice = false;
|
|
|
}
|
|
|
|
|
|
// 判别默认的商品是否将默认的图片URL赋值到skn
|
|
|
let flag = false;
|
|
|
|
|
|
// 如果设置了默认图片,就取默认的图片
|
|
|
_.forEach(product.goodsList, (goods) => {
|
|
|
if (flag) {
|
|
|
return;
|
|
|
}
|
|
|
if (goods.isDefault === 'Y') {
|
|
|
product.defaultImages = procProductImg(goods);
|
|
|
flag = true;
|
|
|
}
|
|
|
});
|
|
|
|
|
|
// 如果还未赋值,则取第一个skc产品的默认图片
|
|
|
if (!flag) {
|
|
|
product.defaultImages = procProductImg(product.goodsList[0]);
|
|
|
}
|
|
|
|
|
|
// product = Object.assign(product, {
|
|
|
// id: product.productSkn,
|
|
|
// thumb: product.defaultImages
|
|
|
// });
|
|
|
|
|
|
if (options.showPoint) {
|
|
|
product.price += '.00';
|
|
|
product.salePrice += '.00';
|
|
|
}
|
|
|
|
|
|
product.isSoonSoldOut = product.isSoonSoldOut === 'Y';
|
|
|
product.url = helpers.urlFormat(`/product/pro_${product.productId}_${product.goodsList[0].goodsId}/${product.cnAlphabet}.html`); // eslint-disable-line
|
|
|
|
|
|
// APP访问需要加附加的参数
|
|
|
// 备注:如果以后APP的接口太多,可以把这边参数提取出来,变成一个公共的方法来生成,便于以后管理维护
|
|
|
if (options.isApp) {
|
|
|
product.url += `?openby:yohobuy={"action":"go.productDetail","params":{"product_skn":'${product.productId}'}}`; // eslint-disable-line
|
|
|
}
|
|
|
|
|
|
if (options.showTags) {
|
|
|
product.tags = {};
|
|
|
|
|
|
product.tags.isNew = options.showNew && product.isNew === 'Y'; // 新品
|
|
|
product.tags.isDiscount = options.showSale && product.isDiscount === 'Y'; // 在售
|
|
|
product.tags.isLimited = product.isLimited === 'Y'; // 限量
|
|
|
product.tags.isYohood = product.isYohood === 'Y'; // YOHOOD
|
|
|
product.tags.midYear = product.midYear === 'Y'; // 年中
|
|
|
product.tags.yearEnd = product.yearEnd === 'Y'; // 年末
|
|
|
product.tags.isAdvance = product.isAdvance === 'Y'; // 再到着
|
|
|
|
|
|
// 打折与即将售完组合显示打折
|
|
|
if (product.isSoonSoldOut && product.tags.isDiscount) {
|
|
|
product.tags.isNew = false;
|
|
|
} else if (product.tags.isDiscount &&
|
|
|
(product.tags.isNew || product.tags.isLimited || product.tags.isYohood || product.tags.isAdvance)) {
|
|
|
// 打折与其它组合则隐藏打折
|
|
|
product.tags.isDiscount = false;
|
|
|
} else if (product.tags.isYohood && product.tags.isNew) {
|
|
|
// YOHOOD和新品组合显示YOHOOD
|
|
|
product.tags.isNew = false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
pruductList.push(product);
|
|
|
});
|
|
|
return pruductList;
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 处理筛选数据
|
|
|
* @param list
|
|
|
* @param string | options
|
|
|
* @return array 处理之后的筛选数据
|
|
|
*/
|
|
|
const processFilter = (list, options) => {
|
|
|
const filters = {
|
|
|
classify: {}
|
|
|
};
|
|
|
|
|
|
options = Object.assign({
|
|
|
gender: '1,2,3', // 默认选择的性别,默认1,2,3表示所有
|
|
|
exclude: null // 需要排除的字段
|
|
|
}, options);
|
|
|
list = camelCase(list);
|
|
|
|
|
|
_.forEach(list, (item, key) => {
|
|
|
console.log(key);
|
|
|
});
|
|
|
return filters;
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 断码区分类数据处理
|
|
|
*/
|
|
|
const processBreakingSort = (list) => {
|
...
|
...
|
@@ -293,12 +160,13 @@ const processBreakingSort = (list) => { |
|
|
*/
|
|
|
const searchSales = (params) => {
|
|
|
params = Object.assign({
|
|
|
limit: '20'
|
|
|
limit: '50'
|
|
|
}, params);
|
|
|
|
|
|
if (typeCont[params.type]) {
|
|
|
params.order = typeCont[params.type][params.order];
|
|
|
}
|
|
|
|
|
|
return api.get('', sign.apiSign(Object.assign({
|
|
|
method: 'app.search.sales'
|
|
|
}, params)), true);
|
...
|
...
|
@@ -310,7 +178,10 @@ const searchSales = (params) => { |
|
|
exports.getFilterData = (params) => {
|
|
|
return searchSales(params).then((result) => {
|
|
|
if (result && result.code === 200) {
|
|
|
return processFilter(result.data.filter || []);
|
|
|
return productProcess.processFilter(result.data.filter || [], {
|
|
|
hideSize: params.saleType === '1',
|
|
|
hideSort: params.saleType === '1'
|
|
|
});
|
|
|
} else {
|
|
|
logger.error('SALE 商品搜索返回 code 不是 200');
|
|
|
return [];
|
...
|
...
|
@@ -318,18 +189,41 @@ exports.getFilterData = (params) => { |
|
|
});
|
|
|
};
|
|
|
|
|
|
const getUserProfile = (uid) => {
|
|
|
if (!uid) {
|
|
|
return Promise.resolve({
|
|
|
code: 200,
|
|
|
data: {}
|
|
|
});
|
|
|
}
|
|
|
return api.get('', sign.apiSign({
|
|
|
method: 'app.passport.profile',
|
|
|
uid: uid
|
|
|
}), true);
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 获取商品数据
|
|
|
*/
|
|
|
exports.getSearchData = (params) => {
|
|
|
return searchSales(params).then((result) => {
|
|
|
if (result && result.code === 200) {
|
|
|
return processProductList(result.data.product_list || []);
|
|
|
} else {
|
|
|
logger.error('SALE 商品搜索返回 code 不是 200');
|
|
|
return {};
|
|
|
}
|
|
|
});
|
|
|
exports.getSearchData = (params, uid) => {
|
|
|
return Promise.all([
|
|
|
searchSales(params).then((result) => {
|
|
|
if (result && result.code === 200) {
|
|
|
return productProcess.processProductList(result.data.product_list || []);
|
|
|
} else {
|
|
|
logger.error('SALE 商品搜索返回 code 不是 200');
|
|
|
return [];
|
|
|
}
|
|
|
}),
|
|
|
getUserProfile(uid).then((result) => {
|
|
|
if (result && result.code === 200) {
|
|
|
return result.data.vip_info ? camelCase(result.data.vip_info) : {};
|
|
|
} else {
|
|
|
logger.error('获取用户信息返回 code 不是 200');
|
|
|
return {};
|
|
|
}
|
|
|
})
|
|
|
]);
|
|
|
};
|
|
|
|
|
|
/**
|
...
|
...
|
|