family.js
3.31 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
'use strict';
const _ = require('lodash');
const moment = require('moment');
const api = global.yoho.API;
class familyModel extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
/**
* 个人详情数据
*/
_userData(uid) {
if (uid) {
return api.get('', {
method: 'app.passport.profile',
uid: uid
}, {
code: 200
});
} else {
return Promise.resolve({});
}
}
/**
* 潮流口令
*/
_getCode(uid) {
if (uid) {
return api.get('', {
method: 'app.invitecode.my',
uid: uid
}, {
code: 200
});
} else {
return Promise.resolve({});
}
}
familyIndex(uid) {
return Promise.all([
this._userData(uid),
this._getCode(uid)
]).then((result) => {
let familyIndexData = {};
if (result[0] && result[0].data) {
familyIndexData = _.assign(familyIndexData, {
head_ico: result[0].data.head_ico,
nickname: result[0].data.nickname,
gender: result[0].data.gender,
birthday: moment(result[0].data.birthday).format('MM-DD')
});
}
if (result[1] && result[1].data) {
familyIndexData = _.assign(familyIndexData, result[1].data);
}
return familyIndexData;
});
}
formatDay(day) {
return moment(day).format('YYYY-MM-DD');
}
getCoinData(params) {
let options = {
data: {
method: 'app.yohocoin.lists',
uid: params.uid,
source: params.source || -1,
queryType: params.queryType || 0,
beginTime: params.beginTime ? this.formatDay(parseInt(params.beginTime, 10)) : '',
endTime: params.endTime ? this.formatDay(parseInt(params.endTime, 10)) : '',
page: params.page || 1,
limit: params.limit || 10
},
param: {
code: 200
}
};
return this.get(options).then(result => {
let resu = {
coinList: []
};
let _this = this;
if (_.get(result, 'data.coinlist')) {
_.forEach(result.data.coinlist, function(val) {
Object.assign(val, {
typeName: _this.checkType(val.iconType),
minus: parseInt(val.num, 10) < 0
});
});
resu.coinList = result.data.coinlist;
}
return resu;
});
}
checkType(params) {
switch (params) {
case 1:
return 'yohobuy';
case 2:
return 'mars';
case 3:
return 'yohonow';
case 4:
return 'store';
case 5:
return 'green';
case 6:
return 'coffee';
case 7:
return 'little';
default:
return 'yohobuy';
}
}
}
module.exports = familyModel;