material.js
2.12 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
'use strict';
const platformApi = new global.yoho.ApiBase(global.yoho.config.domains.platformApi, {
name: 'imCs',
cache: global.yoho.cache,
useCache: false
});
const _ = require('lodash');
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) {
return platformApi.get('/platform/product/material/getRecommendProductList', {
page: params.page || 1
}).then(result => {
if (result && result.code === 200) {
let resu = {
goods: []
};
if (result && result.data && result.data.product_list) {
let build = [];
_.forEach(result.data.product_list, (val) => {
let url = `//m.yohobuy.com/product/${val.productSkn}.html`;
let imgUrl = val.picImgUrl;
if (imgUrl.split('?')[0]) {
imgUrl = imgUrl.split('?')[0] + '?imageView2/0/w/323/h/431';
}
if (params.unionType) {
url = `//m.yohobuy.com/product/${val.productSkn}.html?union_type=${params.unionType}`;
}
if (params.isApp) {
url = `http:${url}?openby:yohobuy={"action":"go.productDetail","params":{"product_skn":"${val.productSkn}"}}`; // eslint-disable-line
}
build.push({
product_name: val.productName,
default_images: imgUrl,
url: url
});
});
resu.goods = build;
}
return resu;
}
});
}
}
module.exports = materialModel;