Authored by 沈志敏

增加参数

... ... @@ -2,28 +2,40 @@
const model = require('../models/individuation');
exports.productLst = function(req, res, next) {
let params = {
uid: req.query.uid,
udid: req.query.udid,
newPromotionId: req.query.pid
};
let keys = ['sort', 'misort', 'msort', 'gender', 'brand'],
enumParam = {},
params = {
uid: req.query.uid,
udid: req.query.udid,
promotion: req.query.pid,
specified_sort: req.query.enum,
p_d: req.query.pd,
limit: req.query.limit || 10
};
if (req.query.sort) {
params.sort = req.query.sort;
} else if (req.query.brand) {
params.brand = req.query.brand;
}
if (req.query.enum) {
params.specified_sort = req.query.enum;
}
if (req.query.pd) {
params.p_d = req.query.pd;
}
if (req.query.limit) {
params.limit = req.query.limit;
keys.forEach(function(k) {
if (req.query[k]) {
params[k] = req.query[k];
}
});
if (params.specified_sort) {
if (params.brand) {
enumParam.brands = params.brand.split(',');
params.limit = enumParam.brands.length;
} else if (params.sort) {
enumParam.sorts = params.sort.split(',');
params.limit = enumParam.sorts.length;
} else if (params.misort) {
enumParam.misorts = params.misort.split(',');
params.limit = enumParam.misorts.length;
} else if (params.msort) {
enumParam.msorts = params.msort.split(',');
params.limit = enumParam.msorts.length;
}
}
model.productLst(params).then((result) => {
model.productLst(params, enumParam).then((result) => {
res.jsonp(result);
}).catch(next);
};
\ No newline at end of file
... ...
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;
});
}
... ...