material.js
2.79 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
91
92
93
94
95
96
97
'use strict';
const _ = require('lodash');
const utils = '../../../utils';
const productProcess = require(`${utils}/product-process`);
const searchHandler = require('../../product/models/search-handler');
const platformApi = new global.yoho.ApiBase(global.yoho.config.domains.platformApi, {
name: 'imCs',
cache: global.yoho.cache,
useCache: false
});
const api = global.yoho.API;
const canLogin = (uid) => {
return platformApi.get('/platform/product/material/canlogin', {
uid: uid
}).then(result => {
return _.get(result, 'data.canLogin', 'N');
});
};
const newBrandList = (req) => {
let channel = req.query.yh_channel || 1;
return api.get('', { method: 'app.brand.newBrandList', yh_channel: channel });
};
const getCategory = () => {
return api.get('', {method: 'web.regular.groupsort'});
};
const getList = (params) => {
return platformApi.get('/platform/product/material/getList', params, {
code: 200
});
};
const getRecommendProductList = (params) => {
return platformApi.get('/platform/product/material/getRecommendProductList', params, {
code: 200
});
};
const getApiRecommendProductList = (params, unionType) => {
let qs = Object.assign({limit: 60}, params, {method: 'app.search.recommendProduct'}),
bqs = unionType ? {union_type: unionType} : {};
qs.size = qs.limit;
return Promise.all([
api.get('', qs, {code: 200}),
api.get('', {method: 'app.search.recommendProduct', size: 1}, {code: 200})
]).then(result => {
let resData = {};
let data = result[0].data;
if (data) {
data.paramBrand = _.split(qs.brand || '', ',');
resData = {
leftContent: searchHandler.handleSortData(_.get(result[1], 'data.filter.group_sort', []), bqs, params),
filters: searchHandler.handleFilterDataAll(data, params),
opts: searchHandler.handleOptsData(params, data.total, data.filter),
totalCount: data.total,
footPager: searchHandler.handlePagerData(data.total, params),
goods: _.map(productProcess.processProductList(data.product_list,
Object.assign({showDiscount: false}, params)), it => {
it.url += unionType ? `?union_type=${unionType}` : '';
return it;
})
};
_.set(resData, 'filters.brand.showAllBrands', true);
}
return resData;
});
};
const getRecommendlist = () => {
return platformApi.get('/platform/product/material/getRecommendlist', {
page: 1
}, {
code: 200
});
};
module.exports = {
canLogin,
newBrandList,
getCategory,
getList,
getRecommendlist,
getApiRecommendProductList,
getRecommendProductList
};