guang-new.js
3.28 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
98
99
100
101
'use strict';
const _ = require('lodash');
const helpers = global.yoho.helpers;
class newGuang extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
_indexRes(params) {
let options = {
url: '/operations/api/v5/resource/get',
data: {
content_code: '5523199f921ee2297b509397a224d9e8',
gender: params.gender
},
api: global.yoho.ServiceAPI
};
return this.get(options).then(result => {
return result;
});
}
list(params) {
let options = {
url: '/guang/api/v1/article/getHomePageList',
data: {
page: params.page || 1,
limit: params.limit || 10
},
api: global.yoho.ServiceAPI
};
return this.get(options).then(result => {
let resu = {
list: []
};
if (_.get(result, 'data.guangList')) {
resu.list = result.data.guangList;
_.forEach(resu.list, (val) => {
val.play = val.hasVideoFlag === 1;
});
}
return resu;
});
}
index(params) {
return Promise.all([
this._indexRes(params)
]).then((result) => {
let resu = {
floorRes: {},
gender: encodeURIComponent(params.gender)
};
if (_.get(result, '[0].data')) {
_.forEach(result[0].data, (val) => {
if (val.template_name === 'focus' && _.get(val, 'data')) {
resu.floorRes.focus = _.get(val, 'data');
_.forEach(val.data, (d) => {
d.src = helpers.image(d.src, 750, 480);
});
}
if (val.template_name === '3:4ImageListFloor' && _.get(val, 'data.list')) {
resu.floorRes.type = _.get(val, 'data.list');
_.forEach(val.data.list, (d) => {
d.src = helpers.image(d.src, 200, 640);
});
}
if (val.template_name === 'GuangRqFloor' && _.get(val, 'data.list')) {
resu.floorRes.renQi = _.get(val, 'data.list');
_.forEach(val.data.list, (d) => {
d.src = helpers.image(d.src, 690, 430);
});
}
if (val.template_name === 'GuangDpFloor' && _.get(val, 'data.list')) {
resu.floorRes.daPei = _.get(val, 'data.list');
_.forEach(val.data.list, (d) => {
d.src = helpers.image(d.src, 590, 370);
});
}
if (val.template_name === 'GuangHhFloor' && _.get(val, 'data.list')) {
resu.floorRes.haoHuo = _.get(val, 'data.list');
_.forEach(val.data.list, (d) => {
d.src = helpers.image(d.src, 360, 224);
});
}
});
}
return resu;
});
}
}
module.exports = newGuang;