Showing
1 changed file
with
474 additions
and
417 deletions
1 | 'use strict'; | 1 | 'use strict'; |
2 | -const api = global.yoho.API; | ||
3 | -const serviceAPI = global.yoho.ServiceAPI; | ||
4 | const helpers = global.yoho.helpers; | 2 | const helpers = global.yoho.helpers; |
5 | const _ = require('lodash'); | 3 | const _ = require('lodash'); |
6 | const config = global.yoho.config; | 4 | const config = global.yoho.config; |
7 | -const singleAPI = global.yoho.SingleAPI; | ||
8 | - | ||
9 | - | ||
10 | -/** | ||
11 | - * 查询用户信息 | ||
12 | - * | ||
13 | - * @param int uid 用户ID | ||
14 | - * @return Object 个人详情数据 | ||
15 | - */ | ||
16 | -const _getUserProfileData = exports.getUserProfileData = (uid) => { | ||
17 | - if (!uid) { | ||
18 | - return Promise.resolve({}); | ||
19 | - } | ||
20 | 5 | ||
21 | - return api.get('', { | ||
22 | - uid: uid, | ||
23 | - method: 'app.passport.profile' | ||
24 | - }, { | ||
25 | - code: 200 | ||
26 | - }).then(result => { | ||
27 | - return result.data || {}; | ||
28 | - }); | 6 | +const iconId = (id) => { |
7 | + return { | ||
8 | + 1: 'icon-5', | ||
9 | + 2: 'icon-0', | ||
10 | + 3: 'icon-8', | ||
11 | + 4: 'icon-niandu', | ||
12 | + 5: 'icon-kuaisu', | ||
13 | + 6: 'icon-zazhi', | ||
14 | + 9: 'icon-youhui', | ||
15 | + 10: 'icon-vip' | ||
16 | + }[id]; | ||
29 | }; | 17 | }; |
30 | 18 | ||
31 | -/** | ||
32 | - * 个人中心页面收藏及订单等的数目数据 | ||
33 | - * | ||
34 | - * @param int uid 用户ID | ||
35 | - * @return Object 处理之后的数据 | ||
36 | - */ | ||
37 | -const _getInfoNumData = (uid) => { | ||
38 | - if (!uid) { | ||
39 | - return Promise.resolve({}); | 19 | +module.exports = class extends global.yoho.BaseModel { |
20 | + constructor(ctx) { | ||
21 | + super(ctx); | ||
40 | } | 22 | } |
41 | 23 | ||
42 | - return api.all([api.get('', { | ||
43 | - uid: uid, | ||
44 | - method: 'app.home.getInfoNum' // 收藏及订单数目数据 | ||
45 | - }, { | ||
46 | - code: 200 | ||
47 | - }), api.get('', { | ||
48 | - uid: uid, | ||
49 | - method: 'app.address.gethidden' // 用户地址的数据 | ||
50 | - }, { | ||
51 | - code: 200 | ||
52 | - })]).then(data => { | ||
53 | - const res = { | ||
54 | - wait_pay_num: '', | ||
55 | - wait_cargo_num: '', | ||
56 | - send_cargo_num: '', | ||
57 | - refund_exchange_num: '', | ||
58 | - yoho_coin_num: '' | ||
59 | - }; | ||
60 | - | ||
61 | - for (let k in data[0].data) { | ||
62 | - if (res[k] !== null) { | ||
63 | - res[k] = data[0].data[k] ? data[0].data[k] : ''; | ||
64 | - if (k !== 'yoho_coin_num' && res[k] > 99) { | ||
65 | - res[k] = '99+'; | ||
66 | - } | ||
67 | - } | 24 | + /** |
25 | + * 查询用户信息 | ||
26 | + * | ||
27 | + * @param int uid 用户ID | ||
28 | + * @return Object 个人详情数据 | ||
29 | + */ | ||
30 | + getUserProfileData(uid) { | ||
31 | + if (!uid) { | ||
32 | + return Promise.resolve({}); | ||
68 | } | 33 | } |
69 | 34 | ||
70 | - return Object.assign(res, { | ||
71 | - address_num: data[1].data && data[1].data.length ? data[1].data.length : '' | 35 | + return this.get({ |
36 | + data: { | ||
37 | + uid: uid, | ||
38 | + method: 'app.passport.profile' | ||
39 | + }, | ||
40 | + param: { | ||
41 | + code: 200 | ||
42 | + } | ||
43 | + }).then(result => { | ||
44 | + return result.data || {}; | ||
72 | }); | 45 | }); |
73 | - }); | ||
74 | -}; | ||
75 | - | ||
76 | -/** | ||
77 | - * 根据性别来决定 默认图片获取字段 如果是 2、3 | ||
78 | - * | ||
79 | - * 则优先从cover_2 --》 cover_1 -- 》 images_url | ||
80 | - * 否则优先从cover_1 --》 cover_2 -- 》 images_url | ||
81 | - * | ||
82 | - */ | ||
83 | -const _procProductImg = (product) => { | ||
84 | - if (product.gender === '2,3' || product.gender === '2' || product.gender === '3') { | ||
85 | - return product.cover_2 || product.images_url || product.cover_1 || ''; | ||
86 | - } | ||
87 | - | ||
88 | - return product.cover_1 || product.images_url || product.cover_2 || ''; | ||
89 | -}; | ||
90 | - | ||
91 | -const _processProduct = (list) => { | ||
92 | - let newRes = []; | ||
93 | - | ||
94 | - list = list || []; | ||
95 | - | ||
96 | - list.forEach(item => { | ||
97 | - let defaultGoods = _.find(item.goods_list, {is_default: 'Y'}); | ||
98 | - | ||
99 | - // 无默认商品取商品列表第一个 | ||
100 | - if (!defaultGoods) { | ||
101 | - defaultGoods = item.goods_list[0]; | 46 | + }; |
47 | + | ||
48 | + /** | ||
49 | + * 个人中心页面收藏及订单等的数目数据 | ||
50 | + * | ||
51 | + * @param int uid 用户ID | ||
52 | + * @return Object 处理之后的数据 | ||
53 | + */ | ||
54 | + _getInfoNumData(uid) { | ||
55 | + if (!uid) { | ||
56 | + return Promise.resolve({}); | ||
102 | } | 57 | } |
103 | 58 | ||
104 | - item.default_images = _procProductImg(defaultGoods); | ||
105 | - item.goodsUrl = `${config.siteUrl}/product/pro_${item.product_id}_${defaultGoods.goods_id}/${item.cn_alphabet}.html`; // eslint-disable-line | ||
106 | - }); | ||
107 | - | ||
108 | - _.chunk(list, 5).forEach(item => { | ||
109 | - newRes.push({ | ||
110 | - list: item | ||
111 | - }); | ||
112 | - }); | ||
113 | - return newRes; | ||
114 | -}; | ||
115 | - | 59 | + return Promise.all([this.get({ |
60 | + data: { | ||
61 | + uid: uid, | ||
62 | + method: 'app.home.getInfoNum' // 收藏及订单数目数据 | ||
63 | + }, | ||
64 | + param: { | ||
65 | + code: 200 | ||
66 | + } | ||
67 | + }), this.get({ | ||
68 | + data: { | ||
69 | + uid: uid, | ||
70 | + method: 'app.address.gethidden' // 用户地址的数据 | ||
71 | + }, | ||
72 | + param: { | ||
73 | + code: 200 | ||
74 | + } | ||
75 | + })]).then(data => { | ||
76 | + const res = { | ||
77 | + wait_pay_num: '', | ||
78 | + wait_cargo_num: '', | ||
79 | + send_cargo_num: '', | ||
80 | + refund_exchange_num: '', | ||
81 | + yoho_coin_num: '' | ||
82 | + }; | ||
116 | 83 | ||
117 | -/** | ||
118 | - * 个人中心主页数据 | ||
119 | - * | ||
120 | - * @param int uid 用户ID | ||
121 | - * @return Object 处理之后的数据 | ||
122 | - */ | ||
123 | -exports.getUserHomeData = (uid) => { | ||
124 | - return Promise.all([_getUserProfileData(uid), _getInfoNumData(uid)]); | ||
125 | -}; | 84 | + for (let k in data[0].data) { |
85 | + if (res[k] !== null) { | ||
86 | + res[k] = data[0].data[k] ? data[0].data[k] : ''; | ||
87 | + if (k !== 'yoho_coin_num' && res[k] > 99) { | ||
88 | + res[k] = '99+'; | ||
89 | + } | ||
90 | + } | ||
91 | + } | ||
126 | 92 | ||
127 | -/** | ||
128 | - * 帮助中心列表页 | ||
129 | - * | ||
130 | - * @param data | ||
131 | - * | ||
132 | - */ | ||
133 | -exports.getHelpInfo = (data) => { | ||
134 | - let defaultParam = { | ||
135 | - method: 'app.help.li' | ||
136 | - }, | ||
137 | - infoData = Object.assign(defaultParam, data); | ||
138 | - | ||
139 | - return api.get('', infoData, { | ||
140 | - code: 200 | ||
141 | - }).then(result => { | ||
142 | - const formatData = []; | ||
143 | - let helpData = result.data; | ||
144 | - | ||
145 | - helpData = helpData || []; | ||
146 | - helpData.forEach(function(item) { | ||
147 | - formatData.push({ | ||
148 | - name: item.caption, | ||
149 | - code: item.code, | ||
150 | - url: helpers.urlFormat('/help', { | ||
151 | - id: item.code, | ||
152 | - caption: item.caption, | ||
153 | - }) | 93 | + return Object.assign(res, { |
94 | + address_num: data[1].data && data[1].data.length ? data[1].data.length : '' | ||
154 | }); | 95 | }); |
155 | }); | 96 | }); |
156 | - return formatData; | ||
157 | - }); | ||
158 | -}; | 97 | + }; |
98 | + | ||
99 | + /** | ||
100 | + * 根据性别来决定 默认图片获取字段 如果是 2、3 | ||
101 | + * | ||
102 | + * 则优先从cover_2 --》 cover_1 -- 》 images_url | ||
103 | + * 否则优先从cover_1 --》 cover_2 -- 》 images_url | ||
104 | + * | ||
105 | + */ | ||
106 | + _procProductImg(product) { | ||
107 | + if (product.gender === '2,3' || product.gender === '2' || product.gender === '3') { | ||
108 | + return product.cover_2 || product.images_url || product.cover_1 || ''; | ||
109 | + } | ||
159 | 110 | ||
160 | -/** | ||
161 | - * 帮助中心详情页 | ||
162 | - * | ||
163 | - * @param data | ||
164 | - */ | ||
165 | -exports.getHelpDetail = (data) => { | ||
166 | - let defaultParam = { | ||
167 | - method: 'app.help.detail', | ||
168 | - return_type: 'html' | ||
169 | - }, | ||
170 | - detailData = Object.assign(defaultParam, data); | ||
171 | - | ||
172 | - return api.get('', detailData, { | ||
173 | - code: 200 | ||
174 | - }).then(result => result); | ||
175 | -}; | 111 | + return product.cover_1 || product.images_url || product.cover_2 || ''; |
112 | + }; | ||
176 | 113 | ||
177 | -/** | ||
178 | - * 保存意见反馈数据 | ||
179 | - * | ||
180 | - * @param data | ||
181 | - */ | ||
182 | -exports.saveFeedback = (data) => { | ||
183 | - return serviceAPI.post('suggest/api/v1/suggest/saveSuggest', data).then(result => { | ||
184 | - return { | ||
185 | - code: result.code, | ||
186 | - message: result.message | ||
187 | - }; | ||
188 | - | ||
189 | - // 参考接口数据 | ||
190 | - }); | ||
191 | -}; | 114 | + _processProduct(list) { |
115 | + let newRes = []; | ||
192 | 116 | ||
193 | -/** | ||
194 | - * 保存个人信息数据 | ||
195 | - * | ||
196 | - * @param data | ||
197 | - */ | ||
198 | -exports.saveMydetails = (params) => { | ||
199 | - let defaultParam = { | ||
200 | - method: 'app.passport.modifyBase' | ||
201 | - }, | ||
202 | - data = Object.assign(defaultParam, params); | ||
203 | - | ||
204 | - return api.get('', data).then(result => result); | ||
205 | -}; | 117 | + list = list || []; |
206 | 118 | ||
207 | -/** | ||
208 | - * 最近浏览 | ||
209 | - * | ||
210 | - * @param data | ||
211 | - */ | ||
212 | -exports.recentPreview = (skn, limit) => { | ||
213 | - return api.get('', { | ||
214 | - method: 'h5.product.batch', | ||
215 | - productSkn: skn, | ||
216 | - limit: limit, | ||
217 | - page: 1 | ||
218 | - }, { | ||
219 | - code: 200 | ||
220 | - }).then(data => { | ||
221 | - return _processProduct(data.data.product_list); | ||
222 | - }); | ||
223 | -}; | 119 | + list.forEach(item => { |
120 | + let defaultGoods = _.find(item.goods_list, {is_default: 'Y'}); | ||
224 | 121 | ||
225 | -exports.recentPreviewNew = (uid, limit) => { | ||
226 | - return api.get('', { | ||
227 | - method: 'app.browse.product', | ||
228 | - uid: uid, | ||
229 | - limit: limit, | ||
230 | - page: 1 | ||
231 | - }, { | ||
232 | - code: 200 | ||
233 | - }).then(data => { | ||
234 | - return data; | ||
235 | - }); | ||
236 | -}; | 122 | + // 无默认商品取商品列表第一个 |
123 | + if (!defaultGoods) { | ||
124 | + defaultGoods = item.goods_list[0]; | ||
125 | + } | ||
237 | 126 | ||
238 | -exports.getSknUrl = (skn, originArr) => { | ||
239 | - return api.get('', { | ||
240 | - method: 'h5.product.batch', | ||
241 | - productSkn: skn, | ||
242 | - page: 1 | ||
243 | - }, { | ||
244 | - code: 200 | ||
245 | - }).then(data => { | ||
246 | - let urls = data.data.product_list.map((item)=> { | 127 | + item.default_images = this._procProductImg(defaultGoods); |
128 | + item.goodsUrl = `${config.siteUrl}/product/pro_${item.product_id}_${defaultGoods.goods_id}/${item.cn_alphabet}.html`; // eslint-disable-line | ||
129 | + }); | ||
130 | + | ||
131 | + _.chunk(list, 5).forEach(item => { | ||
132 | + newRes.push({ | ||
133 | + list: item | ||
134 | + }); | ||
135 | + }); | ||
136 | + return newRes; | ||
137 | + }; | ||
138 | + | ||
139 | + | ||
140 | + /** | ||
141 | + * 个人中心主页数据 | ||
142 | + * | ||
143 | + * @param int uid 用户ID | ||
144 | + * @return Object 处理之后的数据 | ||
145 | + */ | ||
146 | + getUserHomeData(uid) { | ||
147 | + return Promise.all([this.getUserProfileData(uid), this._getInfoNumData(uid)]); | ||
148 | + }; | ||
149 | + | ||
150 | + /** | ||
151 | + * 帮助中心列表页 | ||
152 | + * | ||
153 | + * @param data | ||
154 | + * | ||
155 | + */ | ||
156 | + getHelpInfo(data) { | ||
157 | + let defaultParam = { | ||
158 | + method: 'app.help.li' | ||
159 | + }, | ||
160 | + infoData = Object.assign(defaultParam, data); | ||
161 | + | ||
162 | + return this.get({ | ||
163 | + data: infoData, | ||
164 | + param: { | ||
165 | + code: 200 | ||
166 | + } | ||
167 | + }).then(result => { | ||
168 | + const formatData = []; | ||
169 | + let helpData = result.data; | ||
170 | + | ||
171 | + helpData = helpData || []; | ||
172 | + helpData.forEach(function(item) { | ||
173 | + formatData.push({ | ||
174 | + name: item.caption, | ||
175 | + code: item.code, | ||
176 | + url: helpers.urlFormat('/help', { | ||
177 | + id: item.code, | ||
178 | + caption: item.caption, | ||
179 | + }) | ||
180 | + }); | ||
181 | + }); | ||
182 | + return formatData; | ||
183 | + }); | ||
184 | + }; | ||
185 | + | ||
186 | + /** | ||
187 | + * 帮助中心详情页 | ||
188 | + * | ||
189 | + * @param data | ||
190 | + */ | ||
191 | + getHelpDetail(data) { | ||
192 | + let defaultParam = { | ||
193 | + method: 'app.help.detail', | ||
194 | + return_type: 'html' | ||
195 | + }, | ||
196 | + detailData = Object.assign(defaultParam, data); | ||
197 | + | ||
198 | + return this.get({ | ||
199 | + data: detailData, | ||
200 | + param: { | ||
201 | + code: 200 | ||
202 | + } | ||
203 | + }).then(result => result); | ||
204 | + }; | ||
205 | + | ||
206 | + /** | ||
207 | + * 保存意见反馈数据 | ||
208 | + * | ||
209 | + * @param data | ||
210 | + */ | ||
211 | + saveFeedback(data) { | ||
212 | + return this.post({ | ||
213 | + url: 'suggest/api/v1/suggest/saveSuggest', | ||
214 | + data: data, | ||
215 | + api: global.yoho.ServiceAPI | ||
216 | + }).then(result => { | ||
247 | return { | 217 | return { |
248 | - skn: item.product_skn, | ||
249 | - url: `/product/pro_${item.product_id}_${item.goods_list[0].goods_id}/${item.cn_alphabet}.html` | 218 | + code: result.code, |
219 | + message: result.message | ||
250 | }; | 220 | }; |
251 | - });//eslint-disable-line | ||
252 | - | ||
253 | - _.each(originArr.data.product_list, product => { | ||
254 | - let urlItem = _.find(urls, url => url.skn === product.product_skn); | ||
255 | 221 | ||
256 | - product.goodsUrl = _.get(urlItem, 'url', ''); | 222 | + // 参考接口数据 |
257 | }); | 223 | }); |
258 | - return originArr; | ||
259 | - }); | ||
260 | -}; | 224 | + }; |
225 | + | ||
226 | + /** | ||
227 | + * 保存个人信息数据 | ||
228 | + * | ||
229 | + * @param data | ||
230 | + */ | ||
231 | + saveMydetails(params) { | ||
232 | + let defaultParam = { | ||
233 | + method: 'app.passport.modifyBase' | ||
234 | + }, | ||
235 | + data = Object.assign(defaultParam, params); | ||
236 | + | ||
237 | + return this.get({ | ||
238 | + data: data | ||
239 | + }).then(result => result); | ||
240 | + }; | ||
241 | + | ||
242 | + /** | ||
243 | + * 最近浏览 | ||
244 | + * | ||
245 | + * @param data | ||
246 | + */ | ||
247 | + recentPreview(skn, limit) { | ||
248 | + return this.get({ | ||
249 | + data: { | ||
250 | + method: 'h5.product.batch', | ||
251 | + productSkn: skn, | ||
252 | + limit: limit, | ||
253 | + page: 1 | ||
254 | + }, | ||
255 | + param: { | ||
256 | + code: 200 | ||
257 | + } | ||
258 | + }).then(data => { | ||
259 | + return this._processProduct(data.data.product_list); | ||
260 | + }); | ||
261 | + }; | ||
262 | + | ||
263 | + recentPreviewNew(uid, limit) { | ||
264 | + return this.get({ | ||
265 | + data: { | ||
266 | + method: 'app.browse.product', | ||
267 | + uid: uid, | ||
268 | + limit: limit, | ||
269 | + page: 1 | ||
270 | + }, | ||
271 | + param: { | ||
272 | + code: 200 | ||
273 | + } | ||
274 | + }).then(data => { | ||
275 | + return data; | ||
276 | + }); | ||
277 | + }; | ||
278 | + | ||
279 | + getSknUrl(skn, originArr) { | ||
280 | + return this.get({ | ||
281 | + data: { | ||
282 | + method: 'h5.product.batch', | ||
283 | + productSkn: skn, | ||
284 | + page: 1 | ||
285 | + }, | ||
286 | + param: { | ||
287 | + code: 200 | ||
288 | + } | ||
289 | + }).then(data => { | ||
290 | + let urls = data.data.product_list.map((item)=> { | ||
291 | + return { | ||
292 | + skn: item.product_skn, | ||
293 | + url: `/product/pro_${item.product_id}_${item.goods_list[0].goods_id}/${item.cn_alphabet}.html` | ||
294 | + }; | ||
295 | + });//eslint-disable-line | ||
296 | + | ||
297 | + _.each(originArr.data.product_list, product => { | ||
298 | + let urlItem = _.find(urls, url => url.skn === product.product_skn); | ||
299 | + | ||
300 | + product.goodsUrl = _.get(urlItem, 'url', ''); | ||
301 | + }); | ||
302 | + return originArr; | ||
303 | + }); | ||
304 | + }; | ||
305 | + | ||
306 | + deleteRecordData(uid, skn) { | ||
307 | + return this.get({ | ||
308 | + data: { | ||
309 | + method: 'app.browse.delete', | ||
310 | + uid: uid, | ||
311 | + skn: skn | ||
312 | + }, | ||
313 | + param: { | ||
314 | + code: 200 | ||
315 | + } | ||
316 | + }).then(data => { | ||
317 | + return data; | ||
318 | + }); | ||
319 | + }; | ||
320 | + | ||
321 | + recordNum(uid, udid) { | ||
322 | + return this.get({ | ||
323 | + data: { | ||
324 | + method: 'app.browse.total', | ||
325 | + uid: uid, | ||
326 | + udid: udid | ||
327 | + }, | ||
328 | + param: { | ||
329 | + code: 200 | ||
330 | + } | ||
331 | + }).then(data => { | ||
332 | + return data; | ||
333 | + }); | ||
334 | + }; | ||
335 | + | ||
336 | + addRecords(uid, udid, browseList) { | ||
337 | + return this.get({ | ||
338 | + data: { | ||
339 | + method: 'app.browse.addBrowseBatch', | ||
340 | + uid: uid, | ||
341 | + udid: udid, | ||
342 | + browseList: browseList | ||
343 | + }, | ||
344 | + param: { | ||
345 | + code: 200 | ||
346 | + } | ||
347 | + }).then(data => { | ||
348 | + return data; | ||
349 | + }); | ||
350 | + }; | ||
351 | + | ||
352 | + _getGradeGrade(uid, channel) { | ||
353 | + return this.get({ | ||
354 | + data: { | ||
355 | + method: 'app.passport.vip', | ||
356 | + uid: uid, | ||
357 | + channel: channel || 1 | ||
358 | + }, | ||
359 | + param: { | ||
360 | + code: 200 | ||
361 | + } | ||
362 | + }); | ||
363 | + }; | ||
364 | + | ||
365 | + getGrade(uid, channel) { | ||
366 | + if (uid) { | ||
367 | + return Promise.all([ | ||
368 | + this._getGradeGrade(uid, channel), | ||
369 | + this.getUserProfileData(uid) | ||
370 | + ]).then((result) => { | ||
371 | + let obj = { | ||
372 | + privilege: [] | ||
373 | + }; | ||
374 | + | ||
375 | + if (result[0] && result[0].data) { | ||
376 | + let perf = (100 * (result[0].data.current_year_cost / result[0].data.next_need_cost)).toFixed(2); | ||
377 | + | ||
378 | + _.forEach(result[0].data.enjoy_preferential, function(val) { | ||
379 | + | ||
380 | + if (parseInt(val.id, 10) === 7 || parseInt(val.id, 10) === 8) { | ||
381 | + return true; | ||
382 | + } | ||
383 | + | ||
384 | + obj.privilege.push({ | ||
385 | + description: val.description, | ||
386 | + pic: iconId(parseInt(val.id, 10)), | ||
387 | + title: val.title | ||
388 | + }); | ||
261 | 389 | ||
262 | -exports.deleteRecordData = (uid, skn) => { | ||
263 | - return api.get('', { | ||
264 | - method: 'app.browse.delete', | ||
265 | - uid: uid, | ||
266 | - skn: skn | ||
267 | - }, { | ||
268 | - code: 200 | ||
269 | - }).then(data => { | ||
270 | - return data; | ||
271 | - }); | ||
272 | -}; | 390 | + }); |
273 | 391 | ||
274 | -exports.recordNum = (uid, udid) => { | ||
275 | - return api.get('', { | ||
276 | - method: 'app.browse.total', | ||
277 | - uid: uid, | ||
278 | - udid: udid | ||
279 | - }, { | ||
280 | - code: 200 | ||
281 | - }).then(data => { | ||
282 | - return data; | ||
283 | - }); | ||
284 | -}; | 392 | + switch (result[0].data.current_vip_level) { |
393 | + case '0': // 普通会员 | ||
394 | + obj = _.assign(obj, { | ||
395 | + vip0: true, | ||
396 | + percent: perf | ||
397 | + }); | ||
398 | + break; | ||
399 | + case '1': // 银卡会员 | ||
400 | + obj = _.assign(obj, { | ||
401 | + vip1: true, | ||
402 | + percent: perf | ||
403 | + }); | ||
404 | + break; | ||
405 | + case '2': // 金卡会员 | ||
406 | + obj = _.assign(obj, { | ||
407 | + vip2: true, | ||
408 | + percent: perf | ||
409 | + }); | ||
410 | + break; | ||
411 | + case '3': // 白金会员 | ||
412 | + obj = _.assign(obj, { | ||
413 | + vip3: true, | ||
414 | + percent: 100 | ||
415 | + }); | ||
416 | + break; | ||
417 | + default: | ||
418 | + } | ||
285 | 419 | ||
286 | -exports.addRecords = (uid, udid, browseList) => { | ||
287 | - return api.get('', { | ||
288 | - method: 'app.browse.addBrowseBatch', | ||
289 | - uid: uid, | ||
290 | - udid: udid, | ||
291 | - browseList: browseList | ||
292 | - }, { | ||
293 | - code: 200 | ||
294 | - }).then(data => { | ||
295 | - return data; | ||
296 | - }); | ||
297 | -}; | 420 | + let upg = (1 * (result[0].data.upgrade_need_cost)).toFixed(2); |
298 | 421 | ||
299 | -const _getGradeGrade = (uid, channel) => { | ||
300 | - return api.get('', { | ||
301 | - method: 'app.passport.vip', | ||
302 | - uid: uid, | ||
303 | - channel: channel || 1 | ||
304 | - }, { | ||
305 | - code: 200 | ||
306 | - }); | ||
307 | -}; | 422 | + obj = _.assign(obj, { |
423 | + costOfThisYear: result[0].data.current_year_cost, | ||
424 | + sumCost: result[0].data.current_total_cost, | ||
425 | + costGap: upg | ||
426 | + }); | ||
308 | 427 | ||
309 | -const iconId = (id) => { | ||
310 | - return { | ||
311 | - 1: 'icon-5', | ||
312 | - 2: 'icon-0', | ||
313 | - 3: 'icon-8', | ||
314 | - 4: 'icon-niandu', | ||
315 | - 5: 'icon-kuaisu', | ||
316 | - 6: 'icon-zazhi', | ||
317 | - 9: 'icon-youhui', | ||
318 | - 10: 'icon-vip' | ||
319 | - }[id]; | ||
320 | -}; | 428 | + // if (result[0].data.current_vip_level === '3') { |
429 | + // // 当vip等级升至顶级时,进度条满格 | ||
430 | + // obj = _.assign(obj, { | ||
431 | + // percent: 100 | ||
432 | + // }); | ||
433 | + // } else { | ||
321 | 434 | ||
322 | -exports.getGrade = (uid, channel) => { | ||
323 | - if (uid) { | ||
324 | - return api.all([ | ||
325 | - _getGradeGrade(uid, channel), | ||
326 | - _getUserProfileData(uid) | ||
327 | - ]).then((result) => { | ||
328 | - let obj = { | ||
329 | - privilege: [] | ||
330 | - }; | 435 | + // let perf = (100 * (result[0].data.current_year_cost / result[0].data.next_need_cost)).toFixed(2); |
331 | 436 | ||
332 | - if (result[0] && result[0].data) { | ||
333 | - let perf = (100 * (result[0].data.current_year_cost / result[0].data.next_need_cost)).toFixed(2); | 437 | + // obj = _.assign(obj, { |
438 | + // percent: perf | ||
439 | + // }); | ||
334 | 440 | ||
335 | - _.forEach(result[0].data.enjoy_preferential, function(val) { | 441 | + // } |
336 | 442 | ||
337 | - if (parseInt(val.id, 10) === 7 || parseInt(val.id, 10) === 8) { | ||
338 | - return true; | ||
339 | - } | 443 | + } |
340 | 444 | ||
341 | - obj.privilege.push({ | ||
342 | - description: val.description, | ||
343 | - pic: iconId(parseInt(val.id, 10)), | ||
344 | - title: val.title | 445 | + if (result[0] && result[0].data) { |
446 | + obj = _.assign(obj, { | ||
447 | + name: result[1].nickname | ||
345 | }); | 448 | }); |
346 | - | ||
347 | - }); | ||
348 | - | ||
349 | - switch (result[0].data.current_vip_level) { | ||
350 | - case '0': // 普通会员 | ||
351 | - obj = _.assign(obj, { | ||
352 | - vip0: true, | ||
353 | - percent: perf | ||
354 | - }); | ||
355 | - break; | ||
356 | - case '1': // 银卡会员 | ||
357 | - obj = _.assign(obj, { | ||
358 | - vip1: true, | ||
359 | - percent: perf | ||
360 | - }); | ||
361 | - break; | ||
362 | - case '2': // 金卡会员 | ||
363 | - obj = _.assign(obj, { | ||
364 | - vip2: true, | ||
365 | - percent: perf | ||
366 | - }); | ||
367 | - break; | ||
368 | - case '3': // 白金会员 | ||
369 | - obj = _.assign(obj, { | ||
370 | - vip3: true, | ||
371 | - percent: 100 | ||
372 | - }); | ||
373 | - break; | ||
374 | - default: | ||
375 | } | 449 | } |
376 | 450 | ||
377 | - let upg = (1 * (result[0].data.upgrade_need_cost)).toFixed(2); | ||
378 | - | ||
379 | - obj = _.assign(obj, { | ||
380 | - costOfThisYear: result[0].data.current_year_cost, | ||
381 | - sumCost: result[0].data.current_total_cost, | ||
382 | - costGap: upg | ||
383 | - }); | ||
384 | - | ||
385 | - // if (result[0].data.current_vip_level === '3') { | ||
386 | - // // 当vip等级升至顶级时,进度条满格 | ||
387 | - // obj = _.assign(obj, { | ||
388 | - // percent: 100 | ||
389 | - // }); | ||
390 | - // } else { | ||
391 | - | ||
392 | - // let perf = (100 * (result[0].data.current_year_cost / result[0].data.next_need_cost)).toFixed(2); | ||
393 | - | ||
394 | - // obj = _.assign(obj, { | ||
395 | - // percent: perf | ||
396 | - // }); | ||
397 | - | ||
398 | - // } | ||
399 | - | ||
400 | - } | ||
401 | - | ||
402 | - if (result[0] && result[0].data) { | ||
403 | - obj = _.assign(obj, { | ||
404 | - name: result[1].nickname | ||
405 | - }); | 451 | + return obj; |
452 | + }); | ||
453 | + } else { | ||
454 | + return Promise.resolve({}); | ||
455 | + } | ||
456 | + }; | ||
457 | + | ||
458 | + getPreferential(params) { | ||
459 | + | ||
460 | + return this.get({ | ||
461 | + data: { | ||
462 | + method: 'app.passport.getPrivilege', | ||
463 | + uid: params.uid, | ||
464 | + channel: params.channel || 1 | ||
465 | + }, | ||
466 | + param: { | ||
467 | + code: 200 | ||
406 | } | 468 | } |
469 | + }).then((result) => { | ||
407 | 470 | ||
408 | - return obj; | ||
409 | - }); | ||
410 | - } else { | ||
411 | - return Promise.resolve({}); | ||
412 | - } | ||
413 | -}; | ||
414 | - | ||
415 | -exports.getPreferential = (params) => { | ||
416 | - | ||
417 | - return api.get('', { | ||
418 | - method: 'app.passport.getPrivilege', | ||
419 | - uid: params.uid, | ||
420 | - channel: params.channel || 1 | ||
421 | - }, { | ||
422 | - code: 200 | ||
423 | - }).then((result) => { | 471 | + let resu = { |
472 | + privilege: [] | ||
473 | + }; | ||
424 | 474 | ||
425 | - let resu = { | ||
426 | - privilege: [] | ||
427 | - }; | 475 | + _.forEach(result.data, function(val) { |
428 | 476 | ||
429 | - _.forEach(result.data, function(val) { | 477 | + if (parseInt(val.id, 10) === 7 || parseInt(val.id, 10) === 8) { |
478 | + return true; | ||
479 | + } | ||
430 | 480 | ||
431 | - if (parseInt(val.id, 10) === 7 || parseInt(val.id, 10) === 8) { | ||
432 | - return true; | ||
433 | - } | 481 | + resu.privilege.push({ |
482 | + description: val.description, | ||
483 | + pic: iconId(parseInt(val.id, 10)), | ||
484 | + title: val.title | ||
485 | + }); | ||
434 | 486 | ||
435 | - resu.privilege.push({ | ||
436 | - description: val.description, | ||
437 | - pic: iconId(parseInt(val.id, 10)), | ||
438 | - title: val.title | ||
439 | }); | 487 | }); |
440 | 488 | ||
441 | - }); | ||
442 | - | ||
443 | - return resu; | ||
444 | - | ||
445 | - }); | ||
446 | -}; | ||
447 | - | ||
448 | -// 商品收藏数量接口 | ||
449 | -exports.favoriteNum = (uid) => { | ||
450 | - return singleAPI.get('favorite', { | ||
451 | - method: 'app.favorite.getFavoriteCount', | ||
452 | - uid: uid | ||
453 | - }, { | ||
454 | - code: 200 | ||
455 | - }); | ||
456 | -}; | ||
457 | - | 489 | + return resu; |
458 | 490 | ||
459 | -// 资讯收藏数量接口 | ||
460 | -exports.editorialNum = (uid) => { | ||
461 | - return serviceAPI.post('guang/api/v2/favorite/getFavNum', { | ||
462 | - uid: uid, | ||
463 | - app_type: 1 | ||
464 | - }, { | ||
465 | - code: 200 | ||
466 | - }); | ||
467 | -}; | 491 | + }); |
492 | + }; | ||
493 | + | ||
494 | + // 商品收藏数量接口 | ||
495 | + favoriteNum(uid) { | ||
496 | + return this.get({ | ||
497 | + url: 'favorite', | ||
498 | + data: { | ||
499 | + method: 'app.favorite.getFavoriteCount', | ||
500 | + uid: uid | ||
501 | + }, | ||
502 | + param: { | ||
503 | + code: 200 | ||
504 | + }, | ||
505 | + api: global.yoho.SingleAPI | ||
506 | + }); | ||
507 | + }; | ||
508 | + | ||
509 | + | ||
510 | + // 资讯收藏数量接口 | ||
511 | + editorialNum(uid) { | ||
512 | + return this.post({ | ||
513 | + url: 'guang/api/v2/favorite/getFavNum', | ||
514 | + data: { | ||
515 | + uid: uid, | ||
516 | + app_type: 1 | ||
517 | + }, | ||
518 | + param: { | ||
519 | + code: 200 | ||
520 | + }, | ||
521 | + api: global.yoho.ServiceAPI | ||
522 | + }); | ||
523 | + }; | ||
524 | +}; |
-
Please register or login to post a comment