material-new.js
1.83 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
'use strict';
const platformApi = new global.yoho.ApiBase(global.yoho.config.domains.platformApi, {
name: 'imCs',
cache: global.yoho.cache,
useCache: false
});
const _ = require('lodash');
const utils = '../../../utils';
const productProcess = require(`${utils}/product-process`);
class materialModel extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
canLogin(params) {
return platformApi.get('/platform/product/material/canlogin', {
uid: params.uid
}).then(result => {
if (result && result.code === 200) {
return result.data.canLogin;
}
});
}
list(params) {
let options = {
data: {
method: 'app.search.recommendProduct',
type: 'default',
limit: 24
},
param: {
code: 200
}
};
return this.get(options).then(result => {
if (result && result.code === 200) {
let resu = {
goods: []
};
if (_.get(result, 'data.product_list', [])) {
let build = [];
build = productProcess.processProductList(result.data.product_list || [], {
isApp: params.isApp,
showSimilar: false
});
if (params.unionType) {
_.forEach(build, (val) => {
let newUrl = val.url;
val.url = newUrl.replace('.html', `.html?union_type=${params.unionType}`);
});
}
resu.goods = build;
}
return resu;
}
});
}
}
module.exports = materialModel;