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