|
|
const api = global.yoho.API;
|
|
|
|
|
|
let _getProduct = function(o) {
|
|
|
if (!o) {
|
|
|
return {};
|
|
|
}
|
|
|
return {
|
|
|
small_sort_id: o.small_sort_id,
|
|
|
middle_sort_id: o.middle_sort_id,
|
|
|
max_sort_id: o.max_sort_id,
|
|
|
brand_id: o.brand_id,
|
|
|
brand_domain: o.brand_domain,
|
|
|
brand_name: o.brand_name,
|
|
|
product_id: o.product_id,
|
|
|
product_name: o.product_name,
|
|
|
product_skn: o.product_skn,
|
|
|
market_price: o.market_price,
|
|
|
sales_price: o.sales_price,
|
|
|
cn_alphabet: o.cn_alphabet,
|
|
|
default_images: o.default_images,
|
|
|
goods_id: Array.isArray(o.goods_list) && o.goods_list.length ? o.goods_list[0].goods_id : ''
|
|
|
};
|
|
|
};
|
|
|
|
|
|
module.exports = {
|
|
|
productLst: function(params) {
|
|
|
productLst: function(params, enumParam) {
|
|
|
return api.get('', Object.assign({
|
|
|
method: 'app.search.newPromotion'
|
|
|
}, params)).then(res => {
|
|
|
var data = [],
|
|
|
var data = new Array(Number(params.limit)),
|
|
|
lst = (res.data && res.data.product_list) || [];
|
|
|
|
|
|
lst.forEach(function(o) {
|
|
|
data.push({
|
|
|
brand_domain: o.brand_domain,
|
|
|
brand_name: o.brand_name,
|
|
|
product_id: o.product_id,
|
|
|
product_name: o.product_name,
|
|
|
product_skn: o.product_skn,
|
|
|
market_price: o.market_price,
|
|
|
sales_price: o.sales_price,
|
|
|
cn_alphabet: o.cn_alphabet,
|
|
|
default_images: o.default_images,
|
|
|
goods_id: Array.isArray(o.goods_list) && o.goods_list.length ? o.goods_list[0].goods_id : ''
|
|
|
});
|
|
|
});
|
|
|
for (var i = 0; i < data.length; i++) {
|
|
|
var o = lst[i] || {};
|
|
|
|
|
|
if (params.specified_sort) {
|
|
|
// 枚举类型
|
|
|
if (enumParam.brands && Number(enumParam.brands[i]) === Number(o.brand_id)) {
|
|
|
data[i] = _getProduct(o);
|
|
|
} else if (enumParam.sorts && Number(enumParam.sorts[i]) === Number(o.small_sort_id)) {
|
|
|
data[i] = _getProduct(o);
|
|
|
} else if (enumParam.misorts && Number(enumParam.misorts[i]) === Number(o.middle_sort_id)) {
|
|
|
data[i] = _getProduct(o);
|
|
|
} else if (enumParam.msorts && Number(enumParam.msorts[i]) === Number(o.max_sort_id)) {
|
|
|
data[i] = _getProduct(o);
|
|
|
} else {
|
|
|
lst.splice(i, 0, {});
|
|
|
data[i] = {};
|
|
|
}
|
|
|
} else {
|
|
|
data[i] = _getProduct(o);
|
|
|
}
|
|
|
}
|
|
|
return data;
|
|
|
});
|
|
|
}
|
...
|
...
|
|