myCurrency.js
2.26 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
'use strict';
const serviceAPI = global.yoho.ServiceAPI;
const api = global.yoho.API;
const _ = require('lodash');
const logger = global.yoho.logger;
class myCurrencyModel extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
_yohoCoin(uid) {
return api.get('', {
method: 'app.yoho.yohocoin',
uid: uid
}).then((result) => {
let data = [];
if (result && result.code === 200) {
data = result.data;
} else {
logger.error('youhocoin code no 200');
}
return data;
});
}
bannerData(contentCode) {
return serviceAPI.get('operations/api/v5/resource/get', {
content_code: contentCode
}, {
cache: true
}).then((result) => {
if (result && result.code === 200) {
return result.data;
} else {
logger.error('banner is not 200');
return {};
}
});
}
myCurrency(uid, contentCode) {
return Promise.all([
this._yohoCoin(uid),
this.bannerData(contentCode)
]).then((result) => {
return {
yohoCoin: result[0],
banner: result[1]
};
});
}
currencyDetail(uid, page, limit) {
return api.get('', {
method: 'app.yohocoin.lists',
uid: uid,
page: page,
limit: limit
}).then((result) => {
let data = [];
if (result && result.code === 200) {
data = _.get(result, 'data.coinlist', []);
_.forEach(data, (perCoin, key) => {
if (perCoin.num > 0) {
data[key].num = '+' + perCoin.num;
}
});
}
return data;
});
}
currencyDetailIndex(uid, page, limit) {
return Promise.all([
this.currencyDetail(uid, page, limit),
this._yohoCoin(uid)
]).then(result => {
return {
coinlist: result[0],
yohoCoin: result[1]
};
});
}
}
module.exports = myCurrencyModel;