index.js
4.09 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
'use strict';
const api = global.yoho.API;
const serviceAPI = global.yoho.ServiceAPI;
const singleAPI = global.yoho.SingleAPI;
const Promise = require('bluebird');
const helpers = global.yoho.helpers;
/**
* 查询用户信息
*
* @param int uid 用户ID
* @return Object 个人详情数据
*/
const _getUserProfileData = exports.getUserProfileData = (uid) => {
if (!uid) {
return Promise.resolve({});
}
return api.get('', {
uid: uid,
method: 'app.passport.profile'
}, {
code: 200
}).then(result => {
return result.data || {};
});
};
/**
* 个人中心页面收藏及订单等的数目数据
*
* @param int uid 用户ID
* @return Object 处理之后的数据
*/
const _getInfoNumData = (uid) => {
if (!uid) {
return Promise.resolve({});
}
return api.all([api.get('', {
uid: uid,
method: 'app.home.getInfoNum' // 收藏及订单数目数据
}, {
code: 200
}), api.get('', {
uid: uid,
method: 'app.address.gethidden' // 用户地址的数据
}, {
code: 200
}), singleAPI.get('brower', {
method: 'app.favorite.getFavoriteCount', // 获取用户收藏商品总数
uid: uid
}, {
code: 200
})]).then(data => {
const res = {
wait_pay_num: '',
wait_cargo_num: '',
send_cargo_num: '',
refund_exchange_num: '',
product_favorite_total: '',
brand_favorite_total: '',
yoho_coin_num: ''
};
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[2] && data[2].data && data[2].data.product_favorite_total > 0) {
res.product_favorite_total = data[2].data.product_favorite_total > 99 ? '99+' :
data[2].data.product_favorite_total;
}
return Object.assign(res, {
address_num: data[1].data && data[1].data.length ? data[1].data.length : ''
});
});
};
/**
* 个人中心主页数据
*
* @param int uid 用户ID
* @return Object 处理之后的数据
*/
exports.getUserHomeData = (uid) => {
return Promise.all([_getUserProfileData(uid), _getInfoNumData(uid)]);
};
/**
* 帮助中心列表页
*
* @param data
*
*/
exports.getHelpInfo = (data) => {
let defaultParam = {
method: 'app.help.li'
},
infoData = Object.assign(defaultParam, data);
return api.get('', infoData, {
code: 200
}).then(result => {
const formatData = [];
let helpData = result.data;
helpData = helpData || [];
helpData.forEach(function(item) {
formatData.push({
name: item.caption,
code: item.code,
url: helpers.urlFormat('/help', {
id: item.code,
caption: item.caption,
})
});
});
return formatData;
});
};
/**
* 帮助中心详情页
*
* @param data
*/
exports.getHelpDetail = (data) => {
let defaultParam = {
method: 'app.help.detail',
return_type: 'html'
},
detailData = Object.assign(defaultParam, data);
return api.get('', detailData, {
code: 200
}).then(result => result);
};
/**
* 保存意见反馈数据
*
* @param data
*/
exports.saveFeedback = (data) => {
return serviceAPI.post('suggest/api/v1/suggest/saveSuggest', data).then(result => {
return {
code: result.code,
message: result.message
};
// 参考接口数据
});
};
/**
* 保存个人信息数据
*
* @param data
*/
exports.saveMydetails = (params) => {
let defaultParam = {
method: 'app.passport.modifyBase'
},
data = Object.assign(defaultParam, params);
return api.get('', data).then(result => result);
};