...
|
...
|
@@ -5,21 +5,64 @@ |
|
|
*/
|
|
|
'use strict';
|
|
|
const utils = '../../../utils';
|
|
|
const logger = global.yoho.logger;
|
|
|
const productProcess = require(`${utils}/product-process`);
|
|
|
const searchProcess = require(`${utils}/search-process`);
|
|
|
const _ = require('lodash');
|
|
|
const logger = global.yoho.logger;
|
|
|
const api = global.yoho.API;
|
|
|
const camelCase = global.yoho.camelCase;
|
|
|
|
|
|
/**
|
|
|
* 排序转换
|
|
|
* 品牌名称处理
|
|
|
* @param {[object]} list
|
|
|
* @return {[object]}
|
|
|
*/
|
|
|
const typeCont = {
|
|
|
price: ['s_p_desc', 's_p_asc'],
|
|
|
discount: ['p_d_desc', 'p_d_asc'],
|
|
|
sale: ['s_n_desc', 's_n_asc'],
|
|
|
newest: ['s_t_desc', 's_t_asc'],
|
|
|
stock: ['s_s_desc', 's_s_asc'],
|
|
|
all: ['d_s_desc', 'd_s_asc'],
|
|
|
category: ['s_t_desc', 's_t_asc']
|
|
|
const _processBrandNames = (list) => {
|
|
|
const formatData = [];
|
|
|
|
|
|
list = list || [];
|
|
|
list = camelCase(list);
|
|
|
|
|
|
_.forEach(list, (item) => {
|
|
|
_.forEach(item, (obj) => {
|
|
|
formatData.push({
|
|
|
brandDomain: obj.brandDomain,
|
|
|
brandName: obj.brandName
|
|
|
});
|
|
|
});
|
|
|
});
|
|
|
|
|
|
return formatData;
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 品牌名称处理
|
|
|
* @param {[object]} list
|
|
|
* @return {[object]}
|
|
|
*/
|
|
|
const _processClassNames = (list) => {
|
|
|
const formatData = {
|
|
|
first: {},
|
|
|
second: {}
|
|
|
};
|
|
|
|
|
|
list = list || [];
|
|
|
list = camelCase(list);
|
|
|
|
|
|
_.forEach(list, (item) => {
|
|
|
_.forEach(item, (obj) => {
|
|
|
formatData.first[obj.categoryId] = obj.categoryName;
|
|
|
|
|
|
if (obj.sub) {
|
|
|
_.forEach(obj.sub, (sub) => {
|
|
|
formatData.second[sub.categoryId] = sub.categoryName;
|
|
|
});
|
|
|
}
|
|
|
|
|
|
});
|
|
|
});
|
|
|
|
|
|
return formatData;
|
|
|
};
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -37,9 +80,12 @@ const _searchGoods = (params) => { |
|
|
}
|
|
|
}
|
|
|
|
|
|
// params.yh_channel = channelType[params.yh_channel];
|
|
|
if (params.channel) {
|
|
|
params.yh_channel = searchProcess.getChannelType(params.channel);
|
|
|
delete params.channel;
|
|
|
}
|
|
|
|
|
|
params = Object.assign({
|
|
|
params = _.assign({
|
|
|
limit: '60',
|
|
|
status: 1,
|
|
|
sales: 'Y',
|
...
|
...
|
@@ -47,11 +93,11 @@ const _searchGoods = (params) => { |
|
|
attribute_not: 2
|
|
|
}, params);
|
|
|
|
|
|
if (typeCont[params.type]) {
|
|
|
params.order = typeCont[params.type][params.order];
|
|
|
if (params.order) {
|
|
|
params.order = searchProcess.getTypeCont(params.type || '', params.order);
|
|
|
}
|
|
|
|
|
|
return api.get('', Object.assign({
|
|
|
return api.get('', _.assign({
|
|
|
method: method
|
|
|
}, params), {
|
|
|
cache: true
|
...
|
...
|
@@ -88,7 +134,45 @@ const getFilterData = (params) => { |
|
|
});
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 获取所有的品类名称
|
|
|
**/
|
|
|
const getClassNames = () => {
|
|
|
return api.get('', {
|
|
|
method: 'app.sort.get'
|
|
|
}, {
|
|
|
cache: true
|
|
|
}).then((result) => {
|
|
|
if (result && result.code === 200) {
|
|
|
return _processClassNames(result.data);
|
|
|
} else {
|
|
|
logger.error('get category name api return code is not 200');
|
|
|
return {};
|
|
|
}
|
|
|
});
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 获取所有的品牌名称
|
|
|
**/
|
|
|
const getAllBrandNames = () => {
|
|
|
return api.get('', {
|
|
|
method: 'app.brand.brandlist'
|
|
|
}, {
|
|
|
cache: true
|
|
|
}).then((result) => {
|
|
|
if (result && result.code === 200) {
|
|
|
return _processBrandNames(result.data.brands);
|
|
|
} else {
|
|
|
logger.error('get brand all name data api return code is not 200');
|
|
|
return {};
|
|
|
}
|
|
|
});
|
|
|
};
|
|
|
|
|
|
module.exports = {
|
|
|
getSearchData,
|
|
|
getFilterData
|
|
|
getFilterData,
|
|
|
getAllBrandNames,
|
|
|
getClassNames
|
|
|
}; |
...
|
...
|
|