index.js
3.22 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
132
133
134
135
136
137
138
139
'use strict';
const api = global.yoho.API;
const serviceAPI = global.yoho.ServiceAPI;
const Promise = require('bluebird');
const _ = require('lodash');
const helpers = global.yoho.helpers;
/**
* 查询用户信息
*
* @param int uid 用户ID
* @return Object 个人详情数据
*/
const _getUserProfileData = (uid) => {
return api.get('', {
uid: uid,
method: 'app.passport.profile'
}).then(result => {
return result.data;
});
};
/**
* 个人中心页面收藏及订单等的数目数据
*
* @param int uid 用户ID
* @return Object 处理之后的数据
*/
const _getInfoNumData = (uid) => {
return api.all([api.get('', {
uid: uid,
method: 'app.home.getInfoNum' // 收藏及订单数目数据
}), api.get('', {
uid: uid,
method: 'app.address.gethidden' // 用户地址的数据
})]).then(data => {
let res = {
wait_pay_num: 0,
wait_cargo_num: 0,
send_cargo_num: 0,
refund_exchange_num: 0,
product_favorite_total: 0,
brand_favorite_total: 0,
yoho_coin_num: 0
};
if (data[0].data) {
for (let k in data[0].data) {
if (res[k] !== null) {
res[k] = data[0].data[k] ? data[0].data[k] : '';
if (k !== 'yoho_coin_num' && res[k] > 99) {
res[k] = '99+';
}
}
}
}
if (data[1].data) {
res = _.merge(res, {
address_num: data[1].data.length ? data[1].data.length : ''
});
}
return res;
});
};
/**
* 个人中心主页数据
*
* @param int uid 用户ID
* @return Object 处理之后的数据
*/
exports.getUserHomeData = (uid) => {
return Promise.all([_getUserProfileData(uid), _getInfoNumData(uid)]);
};
/**
* 帮助中心列表页
*
* @param data
*
*/
exports.getHelpInfo = (data) => {
var defaultParam = {
method: 'app.help.li'
},
infoData = Object.assign(defaultParam, data);
return api.get('', infoData).then(result => {
var helpData = result.data;
var formatData = [];
helpData = helpData || [];
_.forEach(helpData, (item) => {
formatData.push({
name: item.caption,
code: item.code,
url: helpers.urlFormat('/home/help-detail', {
code: item.code,
caption: item.caption,
})
});
});
return formatData;
});
};
/**
* 帮助中心详情页
*
* @param data
*/
exports.getHelpDetail = (data) => {
var defaultParam = {
method: 'app.help.detail',
return_type: 'html'
},
detailData = Object.assign(defaultParam, data);
return api.get('', detailData).then(result => {
return result;
});
};
/**
* 保存意见反馈数据
*
* @param data
*/
exports.saveFeedback = (data) => {
return serviceAPI.post('/suggest/api/v1/suggest/saveSuggest', data).then(result => {
return {
code: result.code,
message: result.message
};
// 参考接口数据
});
};