search.js
2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
'use strict';
const _ = require('lodash');
const prettyFilter = require(`${global.utils}/beautify/filters`);
const processProductList = require(`${global.utils}/beautify/product`);
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
products(params) {
let method = 'app.search.li';
if (params.hasOwnProperty('priceRange')) {
params.price = params.priceRange;
delete params.priceRange;
}
if (params.filter_poolId) {
params.productPool = params.filter_poolId;
delete params.filter_poolId;
method = 'app.search.pool';
}
const data = _.merge({
method
}, params);
return this.get({
data: data,
param: {
cache: true,
code: 200
}
}).then(result => {
result = result || {};
if (result.data) {
// java端不愿意将boys改为wen,所以没办法,只能在这边改了。
if (result.data.filter) {
const gender = result.data.filter.gender || {};
for (let k in gender) {
if (k.indexOf('1') > -1) {
gender[k] = 'MEN';
} else if (k.indexOf('2') > -1) {
gender[k] = 'WOMEN';
}
}
}
prettyFilter(result.data.filter);
result.data.product_list = processProductList(result.data.product_list, {
gender: params.gender
});
}
return result;
});
}
/**
* [根据商品SKN获取商品的简要信息]
* @param {[array]} sknString [skns]
* @return {[type]}
*/
productInfoBySkns(sknString) {
let limit = sknString && sknString.split(',').length;
// 调用搜索接口
let param = {
method: 'app.search.recomandLi',
query: sknString,
order: 's_t_desc',
limit: limit || 1
};
return this.get({
data: param,
param: {
cache: true
}
}).then(result => {
result = result || {};
if (result.data) {
result.data.product_list = processProductList(result.data.product_list);
}
return _.get(result, 'data.product_list', []);
});
}
};