...
|
...
|
@@ -10,8 +10,6 @@ const camelCase = global.yoho.camelCase; |
|
|
const productProcess = require(`${utils}/product-process`);
|
|
|
const _ = require('lodash');
|
|
|
const api = global.yoho.API;
|
|
|
const serviceAPI = global.yoho.ServiceAPI;
|
|
|
const helpers = global.yoho.helpers;
|
|
|
|
|
|
/**
|
|
|
* 排序转换
|
...
|
...
|
@@ -26,14 +24,6 @@ const typeCont = { |
|
|
category: ['s_t_desc', 's_t_asc']
|
|
|
};
|
|
|
|
|
|
const channelType = {
|
|
|
boys: '1',
|
|
|
girls: '2',
|
|
|
kids: '3',
|
|
|
lifestyle: '4',
|
|
|
all: '1,2,3,4'
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 商品搜索接口请求
|
|
|
* @param {[object]} params
|
...
|
...
|
@@ -81,8 +71,8 @@ const _processBrandNames = (list) => { |
|
|
list = list || [];
|
|
|
list = camelCase(list);
|
|
|
|
|
|
_.forEach(list, function(item) {
|
|
|
_.forEach(item, function(obj) {
|
|
|
_.forEach(list, (item) => {
|
|
|
_.forEach(item, (obj) => {
|
|
|
formatData.push({
|
|
|
brandDomain: obj.brandDomain,
|
|
|
brandName: obj.brandName
|
...
|
...
|
@@ -94,9 +84,40 @@ const _processBrandNames = (list) => { |
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 品牌名称处理
|
|
|
* @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;
|
|
|
};
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 获取商品数据
|
|
|
*/
|
|
|
const getSearchData = (params, uid) => {
|
|
|
const getSearchData = (params) => {
|
|
|
return _searchSales(params).then((result) => {
|
|
|
if (result && result.code === 200) {
|
|
|
return productProcess.processProductList(result.data.product_list || []);
|
...
|
...
|
@@ -126,34 +147,34 @@ const getFilterData = (params) => { |
|
|
/**
|
|
|
* 获取所有的品牌名称
|
|
|
**/
|
|
|
const getAllBrandNames = (query) => {
|
|
|
const getAllBrandNames = () => {
|
|
|
return api.get('', {
|
|
|
method: 'app.brand.brandlist'
|
|
|
}, {
|
|
|
cache: true
|
|
|
}).then((result) => {
|
|
|
if (result && result.code === 200) {
|
|
|
let domain = null;
|
|
|
let brandNames = _processBrandNames(result.data.brands);
|
|
|
|
|
|
_.forEach(brandNames, function(obj) {
|
|
|
// 精确查品牌域名
|
|
|
if (query === obj.brandDomain) {
|
|
|
domain = query;
|
|
|
}
|
|
|
|
|
|
// 精确查品牌名称
|
|
|
if (query === obj.brandName) {
|
|
|
domain = query;
|
|
|
}
|
|
|
|
|
|
// 模糊查品牌域名
|
|
|
//if ()
|
|
|
});
|
|
|
return _processBrandNames(result.data.brands);
|
|
|
} else {
|
|
|
logger.error('品牌名称接口返回 code 不是 200');
|
|
|
return {};
|
|
|
}
|
|
|
});
|
|
|
};
|
|
|
|
|
|
return domain;
|
|
|
/**
|
|
|
* 获取所有的品类名称
|
|
|
**/
|
|
|
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('断码区分类接口返回 code 不是 200');
|
|
|
logger.error('品类名称接口返回 code 不是 200');
|
|
|
return {};
|
|
|
}
|
|
|
});
|
...
|
...
|
@@ -162,5 +183,6 @@ const getAllBrandNames = (query) => { |
|
|
module.exports = {
|
|
|
getSearchData,
|
|
|
getFilterData,
|
|
|
getAllBrandNames
|
|
|
getAllBrandNames,
|
|
|
getClassNames
|
|
|
}; |
...
|
...
|
|