Merge branch 'feature/channel-op' into gray
Showing
34 changed files
with
676 additions
and
1146 deletions
@@ -8,14 +8,14 @@ | @@ -8,14 +8,14 @@ | ||
8 | 8 | ||
9 | const _ = require('lodash'); | 9 | const _ = require('lodash'); |
10 | 10 | ||
11 | -const channelModel = require('../models/index'); | 11 | +const ChannelModel = require('../models/index'); |
12 | 12 | ||
13 | exports.index = (req, res, next) => { | 13 | exports.index = (req, res, next) => { |
14 | let channelType = req.path.split('/')[1] || 'boys'; | 14 | let channelType = req.path.split('/')[1] || 'boys'; |
15 | let poolId = req.query.template_id; | 15 | let poolId = req.query.template_id; |
16 | let isJKChannel = req.query.mChannel === 'japanKorean'; | 16 | let isJKChannel = req.query.mChannel === 'japanKorean'; |
17 | 17 | ||
18 | - channelModel.getContent(channelType, isJKChannel, poolId).then(data => { | 18 | + req.ctx(ChannelModel).getContent(channelType, isJKChannel, poolId).then(data => { |
19 | 19 | ||
20 | // channel为空不缓存 | 20 | // channel为空不缓存 |
21 | if (_.isEmpty(data.channel)) { | 21 | if (_.isEmpty(data.channel)) { |
@@ -28,7 +28,7 @@ exports.index = (req, res, next) => { | @@ -28,7 +28,7 @@ exports.index = (req, res, next) => { | ||
28 | // 日韩馆频道页 | 28 | // 日韩馆频道页 |
29 | exports.japanKorean = (req, res, next) => { | 29 | exports.japanKorean = (req, res, next) => { |
30 | 30 | ||
31 | - channelModel.getJKContent(req).then(data => { | 31 | + req.ctx(ChannelModel).getJKContent(req).then(data => { |
32 | 32 | ||
33 | // channel为空不缓存 | 33 | // channel为空不缓存 |
34 | if (_.isEmpty(data.channel)) { | 34 | if (_.isEmpty(data.channel)) { |
@@ -55,7 +55,7 @@ exports.getNewArrival = (req, res, next) => { | @@ -55,7 +55,7 @@ exports.getNewArrival = (req, res, next) => { | ||
55 | pageCount = 20; | 55 | pageCount = 20; |
56 | } | 56 | } |
57 | 57 | ||
58 | - channelModel.getNewArrival(channel, isJKChannel, poolId).then(data => { | 58 | + req.ctx(ChannelModel).getNewArrival(channel, isJKChannel, poolId).then(data => { |
59 | goods = _.slice(data, pageIndex, pageIndex + pageCount); | 59 | goods = _.slice(data, pageIndex, pageIndex + pageCount); |
60 | 60 | ||
61 | if (goods.length !== 0) { | 61 | if (goods.length !== 0) { |
@@ -69,15 +69,15 @@ exports.getNewArrival = (req, res, next) => { | @@ -69,15 +69,15 @@ exports.getNewArrival = (req, res, next) => { | ||
69 | }; | 69 | }; |
70 | 70 | ||
71 | exports.getIndexGuide = (req, res, next) => { | 71 | exports.getIndexGuide = (req, res, next) => { |
72 | - channelModel.getIndexGuideData().then(data => { | 72 | + req.ctx(ChannelModel).getIndexGuideData().then(data => { |
73 | if (data.code !== 200) { | 73 | if (data.code !== 200) { |
74 | const err = new Error('异常'); | 74 | const err = new Error('异常'); |
75 | 75 | ||
76 | throw err; | 76 | throw err; |
77 | } | 77 | } |
78 | - return channelModel.formatIndexGuideData(data.data); | 78 | + return req.ctx(ChannelModel).formatIndexGuideData(data.data); |
79 | }).then(data => { | 79 | }).then(data => { |
80 | - return channelModel.getResourceData(data); | 80 | + return req.ctx(ChannelModel).getResourceData(data); |
81 | }).then(data => { | 81 | }).then(data => { |
82 | let result = {list: data, layout: false}; | 82 | let result = {list: data, layout: false}; |
83 | 83 | ||
@@ -87,7 +87,7 @@ exports.getIndexGuide = (req, res, next) => { | @@ -87,7 +87,7 @@ exports.getIndexGuide = (req, res, next) => { | ||
87 | 87 | ||
88 | exports.hasNewUserFloor = (req, res, next) => { | 88 | exports.hasNewUserFloor = (req, res, next) => { |
89 | 89 | ||
90 | - channelModel.hasNewUserFloor(req.yoho.channel, req.user.uid).then(data => { | 90 | + req.ctx(ChannelModel).hasNewUserFloor(req.yoho.channel, req.user.uid).then(data => { |
91 | res.send(data); | 91 | res.send(data); |
92 | }).catch(next); | 92 | }).catch(next); |
93 | }; | 93 | }; |
@@ -13,16 +13,49 @@ const helpers = global.yoho.helpers; | @@ -13,16 +13,49 @@ const helpers = global.yoho.helpers; | ||
13 | const config = global.yoho.config; | 13 | const config = global.yoho.config; |
14 | 14 | ||
15 | const processProduct = require(`${global.utils}/product-process`).processProduct; | 15 | const processProduct = require(`${global.utils}/product-process`).processProduct; |
16 | -const searchApi = require('./search-api'); | 16 | +const SearchApi = require('./search-api'); |
17 | +const headerModel = require('../../../doraemon/models/header'); | ||
17 | 18 | ||
19 | +const needQuery = { | ||
20 | + 'GIRL KIDS': true, | ||
21 | + 'BOY KIDS': true, | ||
22 | + 人气单品: true, | ||
23 | + ACCESSORIES: true | ||
24 | +}; | ||
18 | 25 | ||
19 | -const api = global.yoho.API; | ||
20 | -const serviceApi = global.yoho.ServiceAPI; | 26 | +const channelMap = dataMap.channel; |
21 | 27 | ||
22 | -const headerModel = require('../../../doraemon/models/header'); | 28 | +const sortMap = dataMap.sort; |
29 | + | ||
30 | +module.exports = class extends global.yoho.BaseModel { | ||
31 | + constructor(ctx) { | ||
32 | + super(ctx); | ||
33 | + | ||
34 | + this.searchApi = new SearchApi(ctx); | ||
35 | + | ||
36 | + this.floorMap = { | ||
37 | + slide: this._getSlideData.bind(this), | ||
38 | + hot: this._getHotGoodsFloorData.bind(this), | ||
39 | + 最新速报: this._getNewReportFloorData.bind(this), | ||
40 | + 人气单品: this._getSingleHotFloorData.bind(this), | ||
41 | + 'GIRL KIDS': this._getSingleHotFloorData.bind(this), | ||
42 | + 'BOY KIDS': this._getSingleHotFloorData.bind(this), | ||
43 | + ACCESSORIES: this._getSingleHotFloorData.bind(this), | ||
44 | + 优选品牌: this._getPreBrandTopData.bind(this), | ||
45 | + 最新上架: this._getNewGoodsFloorData.bind(this), | ||
46 | + ad: this._getadbannerData.bind(this), | ||
47 | + category: this._getCategoryFloorData.bind(this), | ||
48 | + accordion: this._getAccordionFloorData.bind(this), | ||
49 | + debrisSlide: this._getDebrisSlide.bind(this), | ||
50 | + jacket: this._getJacketData.bind(this), | ||
51 | + sevenCategory: this._getClothesCategory.bind(this), | ||
52 | + floorTitle: this._getFloorTitleData.bind(this), | ||
53 | + newuser: this._getNewUserFloorData.bind(this) | ||
54 | + }; | ||
55 | + } | ||
23 | 56 | ||
24 | // 获取可用的标题 | 57 | // 获取可用的标题 |
25 | -const _getText = data => { | 58 | + _getText(data) { |
26 | let text = data.split(' ')[0]; | 59 | let text = data.split(' ')[0]; |
27 | const regResult = /\w+/.exec(text); | 60 | const regResult = /\w+/.exec(text); |
28 | const titleWithoutChinese = /^(?=.*[A-Za-z0-9])[A-Za-z0-9 _]*$/; | 61 | const titleWithoutChinese = /^(?=.*[A-Za-z0-9])[A-Za-z0-9 _]*$/; |
@@ -39,21 +72,17 @@ const _getText = data => { | @@ -39,21 +72,17 @@ const _getText = data => { | ||
39 | } | 72 | } |
40 | 73 | ||
41 | return text; | 74 | return text; |
42 | -}; | ||
43 | - | ||
44 | -const channelMap = dataMap.channel; | ||
45 | - | ||
46 | -const sortMap = dataMap.sort; | 75 | + } |
47 | 76 | ||
48 | -/** | 77 | + /** |
49 | * 新人专享 | 78 | * 新人专享 |
50 | * @param {[Object]} data 原始数据 | 79 | * @param {[Object]} data 原始数据 |
51 | * @return {[Object]} 转换后的数据 | 80 | * @return {[Object]} 转换后的数据 |
52 | */ | 81 | */ |
53 | -const _getNewUserFloorData = data => { | 82 | + _getNewUserFloorData(data) { |
54 | let floorData = { | 83 | let floorData = { |
55 | newUserFloor: { | 84 | newUserFloor: { |
56 | - name: _getText(data.title.name), | 85 | + name: this._getText(data.title.name), |
57 | navs: {}, | 86 | navs: {}, |
58 | bannerImage: { | 87 | bannerImage: { |
59 | url: data.banner_image[0].url, | 88 | url: data.banner_image[0].url, |
@@ -87,14 +116,14 @@ const _getNewUserFloorData = data => { | @@ -87,14 +116,14 @@ const _getNewUserFloorData = data => { | ||
87 | } | 116 | } |
88 | 117 | ||
89 | return floorData; | 118 | return floorData; |
90 | -}; | 119 | + } |
91 | 120 | ||
92 | -/** | 121 | + /** |
93 | * 获取带小图的banner | 122 | * 获取带小图的banner |
94 | * @param {[Object]} data 原始数据 | 123 | * @param {[Object]} data 原始数据 |
95 | * @return {[Object]} 转换后的数据 | 124 | * @return {[Object]} 转换后的数据 |
96 | */ | 125 | */ |
97 | -const _getDebrisSlide = data => { | 126 | + _getDebrisSlide(data) { |
98 | let floorData = { | 127 | let floorData = { |
99 | debrisSlider: { | 128 | debrisSlider: { |
100 | left: [], | 129 | left: [], |
@@ -110,27 +139,27 @@ const _getDebrisSlide = data => { | @@ -110,27 +139,27 @@ const _getDebrisSlide = data => { | ||
110 | }); | 139 | }); |
111 | 140 | ||
112 | return floorData; | 141 | return floorData; |
113 | -}; | 142 | + } |
114 | 143 | ||
115 | 144 | ||
116 | -/** | 145 | + /** |
117 | * 获取广告位 | 146 | * 获取广告位 |
118 | * @param {Object} data 原始数据 | 147 | * @param {Object} data 原始数据 |
119 | * @return {Object} 转换后的数据 | 148 | * @return {Object} 转换后的数据 |
120 | */ | 149 | */ |
121 | -const _getadbannerData = data => { | 150 | + _getadbannerData(data) { |
122 | 151 | ||
123 | return { | 152 | return { |
124 | adbanner: data | 153 | adbanner: data |
125 | }; | 154 | }; |
126 | -}; | 155 | + } |
127 | 156 | ||
128 | -/** | 157 | + /** |
129 | * 生成banner模板数据 | 158 | * 生成banner模板数据 |
130 | * @param {Object} srcData 原始数据 | 159 | * @param {Object} srcData 原始数据 |
131 | * @return {Object} 转换后的数据 | 160 | * @return {Object} 转换后的数据 |
132 | */ | 161 | */ |
133 | -const _getSlideData = srcData => { | 162 | + _getSlideData(srcData) { |
134 | const slideData = { | 163 | const slideData = { |
135 | slide: { | 164 | slide: { |
136 | list: [], | 165 | list: [], |
@@ -151,15 +180,15 @@ const _getSlideData = srcData => { | @@ -151,15 +180,15 @@ const _getSlideData = srcData => { | ||
151 | } | 180 | } |
152 | 181 | ||
153 | return slideData; | 182 | return slideData; |
154 | -}; | 183 | + } |
155 | 184 | ||
156 | -/** | 185 | + /** |
157 | * 获取品牌列表数据 | 186 | * 获取品牌列表数据 |
158 | * @param {[Object]} args 参数列表 | 187 | * @param {[Object]} args 参数列表 |
159 | * @param {String} type 频道类型 | 188 | * @param {String} type 频道类型 |
160 | * @return {Object} | 189 | * @return {Object} |
161 | */ | 190 | */ |
162 | -const _getBrandLogosData = (args, showNum) => { | 191 | + _getBrandLogosData(args, showNum) { |
163 | let items = [], | 192 | let items = [], |
164 | brandLogos = [], | 193 | brandLogos = [], |
165 | i = 0, | 194 | i = 0, |
@@ -214,14 +243,14 @@ const _getBrandLogosData = (args, showNum) => { | @@ -214,14 +243,14 @@ const _getBrandLogosData = (args, showNum) => { | ||
214 | isMore: true | 243 | isMore: true |
215 | }); | 244 | }); |
216 | return brandLogos; | 245 | return brandLogos; |
217 | -}; | 246 | + } |
218 | 247 | ||
219 | -/** | 248 | + /** |
220 | * 获取最新速报模板数据 : 大图+小图+大图+single_image(广告位)/+floor(logo列表) | 249 | * 获取最新速报模板数据 : 大图+小图+大图+single_image(广告位)/+floor(logo列表) |
221 | * @param {Object} srcData 原始数据 | 250 | * @param {Object} srcData 原始数据 |
222 | * @return {Object} 转换后的数据 | 251 | * @return {Object} 转换后的数据 |
223 | */ | 252 | */ |
224 | -const _getNewReportFloorData = (args) => { | 253 | + _getNewReportFloorData(args) { |
225 | const title = args[0].data.text; | 254 | const title = args[0].data.text; |
226 | let floorId = args[0].template_id; | 255 | let floorId = args[0].template_id; |
227 | let item = args[1].data; | 256 | let item = args[1].data; |
@@ -258,7 +287,7 @@ const _getNewReportFloorData = (args) => { | @@ -258,7 +287,7 @@ const _getNewReportFloorData = (args) => { | ||
258 | 287 | ||
259 | // 广告位 | 288 | // 广告位 |
260 | if (forthItem.template_name && forthItem.template_name === 'single_image') { | 289 | if (forthItem.template_name && forthItem.template_name === 'single_image') { |
261 | - adData = _getadbannerData(forthItem.data[0]); | 290 | + adData = this._getadbannerData(forthItem.data[0]); |
262 | floorDatas.push(adData); | 291 | floorDatas.push(adData); |
263 | } | 292 | } |
264 | 293 | ||
@@ -269,30 +298,30 @@ const _getNewReportFloorData = (args) => { | @@ -269,30 +298,30 @@ const _getNewReportFloorData = (args) => { | ||
269 | brandLogoObj.moreBrand = args[5].data[0].url || ''; | 298 | brandLogoObj.moreBrand = args[5].data[0].url || ''; |
270 | } | 299 | } |
271 | 300 | ||
272 | - brandLogoObj.brandLogos = _getBrandLogosData(forthItem.data, brandLogoObj.showNum); | 301 | + brandLogoObj.brandLogos = this._getBrandLogosData(forthItem.data, brandLogoObj.showNum); |
273 | data.newReport.brandLogoObj = brandLogoObj; | 302 | data.newReport.brandLogoObj = brandLogoObj; |
274 | } | 303 | } |
275 | return floorDatas; | 304 | return floorDatas; |
276 | -}; | 305 | + } |
277 | 306 | ||
278 | 307 | ||
279 | -/** | 308 | + /** |
280 | * 给目标对象绑定频道属性 | 309 | * 给目标对象绑定频道属性 |
281 | * @param {Object} obj 需要绑定频道属性的对象 | 310 | * @param {Object} obj 需要绑定频道属性的对象 |
282 | * @param {String} type 需要设置的频道类型 | 311 | * @param {String} type 需要设置的频道类型 |
283 | * @return undefined | 312 | * @return undefined |
284 | */ | 313 | */ |
285 | -const _setChannelType = (obj, type) => { | 314 | + _setChannelType(obj, type) { |
286 | obj[type + 'Channel'] = true; | 315 | obj[type + 'Channel'] = true; |
287 | -}; | 316 | + } |
288 | 317 | ||
289 | -/** | 318 | + /** |
290 | * 获取优选品牌模板数据 | 319 | * 获取优选品牌模板数据 |
291 | * @param {[Object]} args 参数列表 | 320 | * @param {[Object]} args 参数列表 |
292 | * @param {String} type 频道类型 | 321 | * @param {String} type 频道类型 |
293 | * @return {Object} | 322 | * @return {Object} |
294 | */ | 323 | */ |
295 | -const _getPreBrandTopData = (args, type) => { | 324 | + _getPreBrandTopData(args, type) { |
296 | const title = args[0].data.text; | 325 | const title = args[0].data.text; |
297 | let item = args[1].data, | 326 | let item = args[1].data, |
298 | logoItems = args[2] || {}, | 327 | logoItems = args[2] || {}, |
@@ -314,25 +343,25 @@ const _getPreBrandTopData = (args, type) => { | @@ -314,25 +343,25 @@ const _getPreBrandTopData = (args, type) => { | ||
314 | if (_.get(args[3], 'data[0].url', '')) { | 343 | if (_.get(args[3], 'data[0].url', '')) { |
315 | brandLogoObj.moreBrand = args[3].data[0].url; | 344 | brandLogoObj.moreBrand = args[3].data[0].url; |
316 | } | 345 | } |
317 | - brandLogoObj.brandLogos = _getBrandLogosData(args[2].data, showNum); | 346 | + brandLogoObj.brandLogos = this._getBrandLogosData(args[2].data, showNum); |
318 | data.preferenceBrands.brandLogoObj = brandLogoObj; | 347 | data.preferenceBrands.brandLogoObj = brandLogoObj; |
319 | } | 348 | } |
320 | data.preferenceBrands.imgBrand = item; | 349 | data.preferenceBrands.imgBrand = item; |
321 | if (type === 'kids') { | 350 | if (type === 'kids') { |
322 | data.preferenceBrands.sliderColor = '#7AD3F8'; | 351 | data.preferenceBrands.sliderColor = '#7AD3F8'; |
323 | } | 352 | } |
324 | - _setChannelType(data.preferenceBrands, type); | 353 | + this._setChannelType(data.preferenceBrands, type); |
325 | 354 | ||
326 | return data; | 355 | return data; |
327 | -}; | 356 | + } |
328 | 357 | ||
329 | -/** | 358 | + /** |
330 | * 获取热门分类模板数据 | 359 | * 获取热门分类模板数据 |
331 | * @param {[Object]} args 参数列表 | 360 | * @param {[Object]} args 参数列表 |
332 | * @param {String} type 频道类型 | 361 | * @param {String} type 频道类型 |
333 | * @return {Object} | 362 | * @return {Object} |
334 | */ | 363 | */ |
335 | -const _getHotGoodsFloorData = (args, type) => { | 364 | + _getHotGoodsFloorData(args, type) { |
336 | let item = args[0]; | 365 | let item = args[0]; |
337 | let nextItem = args[1]; | 366 | let nextItem = args[1]; |
338 | 367 | ||
@@ -376,19 +405,19 @@ const _getHotGoodsFloorData = (args, type) => { | @@ -376,19 +405,19 @@ const _getHotGoodsFloorData = (args, type) => { | ||
376 | list.push(object); | 405 | list.push(object); |
377 | data.recommend.tplrecommend = list; | 406 | data.recommend.tplrecommend = list; |
378 | 407 | ||
379 | - _setChannelType(data.recommend, type); | 408 | + this._setChannelType(data.recommend, type); |
380 | 409 | ||
381 | 410 | ||
382 | return data; | 411 | return data; |
383 | -}; | 412 | + } |
384 | 413 | ||
385 | -/** | 414 | + /** |
386 | * 获取japanKorean潮流上装Jacket,title+左大图+右6小图模板数据 | 415 | * 获取japanKorean潮流上装Jacket,title+左大图+右6小图模板数据 |
387 | * @param {[Object]} args 参数列表 | 416 | * @param {[Object]} args 参数列表 |
388 | * @param {String} type 频道类型 | 417 | * @param {String} type 频道类型 |
389 | * @return {Object} | 418 | * @return {Object} |
390 | */ | 419 | */ |
391 | -const _getJacketData = (arg) => { | 420 | + _getJacketData(arg) { |
392 | let resData = { | 421 | let resData = { |
393 | tpltopic: { | 422 | tpltopic: { |
394 | bigPic: arg.big_image[0], | 423 | bigPic: arg.big_image[0], |
@@ -401,29 +430,29 @@ const _getJacketData = (arg) => { | @@ -401,29 +430,29 @@ const _getJacketData = (arg) => { | ||
401 | } | 430 | } |
402 | 431 | ||
403 | return resData; | 432 | return resData; |
404 | -}; | 433 | + } |
405 | 434 | ||
406 | -/** | 435 | + /** |
407 | * 获取7个品类图 | 436 | * 获取7个品类图 |
408 | * @param {[Object]} args 参数列表 | 437 | * @param {[Object]} args 参数列表 |
409 | * @param {String} type 频道类型 | 438 | * @param {String} type 频道类型 |
410 | * @return {Object} | 439 | * @return {Object} |
411 | */ | 440 | */ |
412 | -const _getClothesCategory = (arg) => { | 441 | + _getClothesCategory(arg) { |
413 | return { | 442 | return { |
414 | sevenCategory: { | 443 | sevenCategory: { |
415 | categorys: arg.list | 444 | categorys: arg.list |
416 | } | 445 | } |
417 | }; | 446 | }; |
418 | -}; | 447 | + } |
419 | 448 | ||
420 | -/** | 449 | + /** |
421 | * 获取boys人气单品模版数据 | 450 | * 获取boys人气单品模版数据 |
422 | * @param {[Object]} args 参数列表 | 451 | * @param {[Object]} args 参数列表 |
423 | * @param {String} type 频道类型 | 452 | * @param {String} type 频道类型 |
424 | * @return {Object} | 453 | * @return {Object} |
425 | */ | 454 | */ |
426 | -const _getBoysSingleHot = (args, type) => { | 455 | + _getBoysSingleHot(args, type) { |
427 | const len = 10; | 456 | const len = 10; |
428 | const data = { | 457 | const data = { |
429 | singlehot: { | 458 | singlehot: { |
@@ -460,24 +489,24 @@ const _getBoysSingleHot = (args, type) => { | @@ -460,24 +489,24 @@ const _getBoysSingleHot = (args, type) => { | ||
460 | }); | 489 | }); |
461 | 490 | ||
462 | data.singlehot.imgHot = list; | 491 | data.singlehot.imgHot = list; |
463 | - _setChannelType(data.singlehot, type); | 492 | + this._setChannelType(data.singlehot, type); |
464 | floorDatas.push(data); | 493 | floorDatas.push(data); |
465 | 494 | ||
466 | if (args[3].template_name === 'single_image') { | 495 | if (args[3].template_name === 'single_image') { |
467 | - adData = _getadbannerData(args[3].data[0]); | 496 | + adData = this._getadbannerData(args[3].data[0]); |
468 | floorDatas.push(adData); | 497 | floorDatas.push(adData); |
469 | } | 498 | } |
470 | 499 | ||
471 | return floorDatas; | 500 | return floorDatas; |
472 | -}; | 501 | + } |
473 | 502 | ||
474 | -/** | 503 | + /** |
475 | * 获取girls人气单品模版数据 | 504 | * 获取girls人气单品模版数据 |
476 | * @param {[Object]} args 参数列表 | 505 | * @param {[Object]} args 参数列表 |
477 | * @param {String} type 频道类型 | 506 | * @param {String} type 频道类型 |
478 | * @return {Object} | 507 | * @return {Object} |
479 | */ | 508 | */ |
480 | -const _getGirlsSingleHot = (args, type) => { | 509 | + _getGirlsSingleHot(args, type) { |
481 | let goods = args[2] && args[2].data; | 510 | let goods = args[2] && args[2].data; |
482 | let skns = ''; | 511 | let skns = ''; |
483 | 512 | ||
@@ -489,7 +518,7 @@ const _getGirlsSingleHot = (args, type) => { | @@ -489,7 +518,7 @@ const _getGirlsSingleHot = (args, type) => { | ||
489 | return; | 518 | return; |
490 | } | 519 | } |
491 | 520 | ||
492 | - return searchApi.getProductList({ | 521 | + return this.searchApi.getProductList({ |
493 | client_type: 'web', | 522 | client_type: 'web', |
494 | query: skns, | 523 | query: skns, |
495 | order: 'shelve_time:desc', | 524 | order: 'shelve_time:desc', |
@@ -501,30 +530,30 @@ const _getGirlsSingleHot = (args, type) => { | @@ -501,30 +530,30 @@ const _getGirlsSingleHot = (args, type) => { | ||
501 | gender: channelMap[type].gender, | 530 | gender: channelMap[type].gender, |
502 | limit: 60 | 531 | limit: 60 |
503 | }, config.apiCache); | 532 | }, config.apiCache); |
504 | -}; | 533 | + } |
505 | 534 | ||
506 | 535 | ||
507 | -/** | 536 | + /** |
508 | * 人气单品入口 | 537 | * 人气单品入口 |
509 | * @param {[Object]} args 参数列表 | 538 | * @param {[Object]} args 参数列表 |
510 | * @param {String} type 频道类型 | 539 | * @param {String} type 频道类型 |
511 | * @return {Object} | 540 | * @return {Object} |
512 | */ | 541 | */ |
513 | -const _getSingleHotFloorData = (args, type) => { | 542 | + _getSingleHotFloorData(args, type) { |
514 | if (type === 'boys') { | 543 | if (type === 'boys') { |
515 | - return _getBoysSingleHot(args, type); | 544 | + return this._getBoysSingleHot(args, type); |
516 | } else { | 545 | } else { |
517 | - return _getGirlsSingleHot(args, type); | 546 | + return this._getGirlsSingleHot(args, type); |
547 | + } | ||
518 | } | 548 | } |
519 | -}; | ||
520 | 549 | ||
521 | -/** | 550 | + /** |
522 | * 组装最新上架楼层数据 | 551 | * 组装最新上架楼层数据 |
523 | * | 552 | * |
524 | * @param string data | 553 | * @param string data |
525 | * return obj | 554 | * return obj |
526 | */ | 555 | */ |
527 | -const _getNewGoodsFloorData = args => { | 556 | + _getNewGoodsFloorData(args) { |
528 | const data = {}; | 557 | const data = {}; |
529 | 558 | ||
530 | if (!_.isEmpty(args)) { | 559 | if (!_.isEmpty(args)) { |
@@ -537,15 +566,15 @@ const _getNewGoodsFloorData = args => { | @@ -537,15 +566,15 @@ const _getNewGoodsFloorData = args => { | ||
537 | data.newArrivls.navs = args[1] ? args[1].data : {}; | 566 | data.newArrivls.navs = args[1] ? args[1].data : {}; |
538 | } | 567 | } |
539 | return data; | 568 | return data; |
540 | -}; | 569 | + } |
541 | 570 | ||
542 | -/** | 571 | + /** |
543 | * 文本标题 | 572 | * 文本标题 |
544 | * @param {[Object]} args 参数列表 | 573 | * @param {[Object]} args 参数列表 |
545 | * @param {String} type 频道类型 | 574 | * @param {String} type 频道类型 |
546 | * @return {Object} | 575 | * @return {Object} |
547 | */ | 576 | */ |
548 | -const _getFloorTitleData = (args) => { | 577 | + _getFloorTitleData(args) { |
549 | let resData = { | 578 | let resData = { |
550 | floorHeader: {} | 579 | floorHeader: {} |
551 | }; | 580 | }; |
@@ -560,12 +589,12 @@ const _getFloorTitleData = (args) => { | @@ -560,12 +589,12 @@ const _getFloorTitleData = (args) => { | ||
560 | } | 589 | } |
561 | 590 | ||
562 | if (resData.floorHeader.name.indexOf('最新上架') >= 0) { | 591 | if (resData.floorHeader.name.indexOf('最新上架') >= 0) { |
563 | - resData = _getNewGoodsFloorData(args); | 592 | + resData = this._getNewGoodsFloorData(args); |
564 | } | 593 | } |
565 | return resData; | 594 | return resData; |
566 | -}; | 595 | + } |
567 | 596 | ||
568 | -/** | 597 | + /** |
569 | * 处理异步获取的人气单品数据 | 598 | * 处理异步获取的人气单品数据 |
570 | * @param {[Object]} args 参数列表 | 599 | * @param {[Object]} args 参数列表 |
571 | * @param {String} originQuery 原始skns | 600 | * @param {String} originQuery 原始skns |
@@ -573,7 +602,7 @@ const _getFloorTitleData = (args) => { | @@ -573,7 +602,7 @@ const _getFloorTitleData = (args) => { | ||
573 | * @param {String} type 频道类型 | 602 | * @param {String} type 频道类型 |
574 | * @return {Object} | 603 | * @return {Object} |
575 | */ | 604 | */ |
576 | -const _getSingehotViaResult = (args, originQuery, queryResult, type) => { | 605 | + _getSingehotViaResult(args, originQuery, queryResult, type) { |
577 | let data = { | 606 | let data = { |
578 | singlehot: { | 607 | singlehot: { |
579 | name: args[0].data.text, | 608 | name: args[0].data.text, |
@@ -643,11 +672,11 @@ const _getSingehotViaResult = (args, originQuery, queryResult, type) => { | @@ -643,11 +672,11 @@ const _getSingehotViaResult = (args, originQuery, queryResult, type) => { | ||
643 | } | 672 | } |
644 | }); | 673 | }); |
645 | data.singlehot.navs = args[1].data; | 674 | data.singlehot.navs = args[1].data; |
646 | - _setChannelType(data.singlehot, type); | 675 | + this._setChannelType(data.singlehot, type); |
647 | return data; | 676 | return data; |
648 | -}; | 677 | + } |
649 | 678 | ||
650 | -/** | 679 | + /** |
651 | * 异步获取人气单品 | 680 | * 异步获取人气单品 |
652 | * @param {[Object]} rawData 接口返回的原始数据 | 681 | * @param {[Object]} rawData 接口返回的原始数据 |
653 | * @param {[Object]} floorData 已经经过处理的楼层数据 | 682 | * @param {[Object]} floorData 已经经过处理的楼层数据 |
@@ -657,27 +686,25 @@ const _getSingehotViaResult = (args, originQuery, queryResult, type) => { | @@ -657,27 +686,25 @@ const _getSingehotViaResult = (args, originQuery, queryResult, type) => { | ||
657 | * @param {Type} type 人气单品楼层的类型 | 686 | * @param {Type} type 人气单品楼层的类型 |
658 | * @return {Object} | 687 | * @return {Object} |
659 | */ | 688 | */ |
660 | -const _processFloorDataWithQueryReusult = (rawData, originQuery, queryResult, title, type) => { | 689 | + _processFloorDataWithQueryReusult(rawData, originQuery, queryResult, title, type) { |
661 | let data = {}; | 690 | let data = {}; |
662 | 691 | ||
663 | _.forEach(rawData, (subData, index) => { | 692 | _.forEach(rawData, (subData, index) => { |
664 | 693 | ||
665 | if (subData && subData.data && subData.data.text) { | 694 | if (subData && subData.data && subData.data.text) { |
666 | - const text = subData.data.text && _getText(subData.data.text); | 695 | + const text = subData.data.text && this._getText(subData.data.text); |
667 | 696 | ||
668 | 697 | ||
669 | if (text === title) { | 698 | if (text === title) { |
670 | - data = _getSingehotViaResult(rawData.slice(index, index + 4), originQuery, queryResult, type); | 699 | + data = this._getSingehotViaResult(rawData.slice(index, index + 4), originQuery, queryResult, type); |
671 | } | 700 | } |
672 | } | 701 | } |
673 | }); | 702 | }); |
674 | 703 | ||
675 | return data; | 704 | return data; |
676 | -}; | ||
677 | - | ||
678 | - | 705 | + } |
679 | 706 | ||
680 | -const _getCategoryFloorData = args => { | 707 | + _getCategoryFloorData(args) { |
681 | const data = { | 708 | const data = { |
682 | category: { | 709 | category: { |
683 | name: args[0].data.text, | 710 | name: args[0].data.text, |
@@ -701,9 +728,9 @@ const _getCategoryFloorData = args => { | @@ -701,9 +728,9 @@ const _getCategoryFloorData = args => { | ||
701 | }); | 728 | }); |
702 | 729 | ||
703 | return data; | 730 | return data; |
704 | -}; | 731 | + } |
705 | 732 | ||
706 | -const _getAccordionFloorData = args => { | 733 | + _getAccordionFloorData(args) { |
707 | let data = { | 734 | let data = { |
708 | accordion: { | 735 | accordion: { |
709 | name: args[0].data.text, | 736 | name: args[0].data.text, |
@@ -715,9 +742,9 @@ const _getAccordionFloorData = args => { | @@ -715,9 +742,9 @@ const _getAccordionFloorData = args => { | ||
715 | data.accordion.slide = args[2].data; | 742 | data.accordion.slide = args[2].data; |
716 | 743 | ||
717 | return data; | 744 | return data; |
718 | -}; | 745 | + } |
719 | 746 | ||
720 | -const _requestContent = (type, params, code) => { | 747 | + _requestContent(type, params, code) { |
721 | let data = { | 748 | let data = { |
722 | client_type: 'web', | 749 | client_type: 'web', |
723 | content_code: code || channelMap[type || 'boys'].code, | 750 | content_code: code || channelMap[type || 'boys'].code, |
@@ -727,43 +754,22 @@ const _requestContent = (type, params, code) => { | @@ -727,43 +754,22 @@ const _requestContent = (type, params, code) => { | ||
727 | }; | 754 | }; |
728 | 755 | ||
729 | Object.assign(data, params); | 756 | Object.assign(data, params); |
730 | - return serviceApi.get('operations/api/v5/resource/home', data, { | 757 | + |
758 | + return this.get({ | ||
759 | + url: 'operations/api/v5/resource/home', | ||
760 | + data, | ||
761 | + param: { | ||
731 | cache: true, | 762 | cache: true, |
732 | code: 200 | 763 | code: 200 |
764 | + }, | ||
765 | + api: global.yoho.ServiceAPI | ||
733 | }).then(result => { | 766 | }).then(result => { |
734 | return result; | 767 | return result; |
735 | }); | 768 | }); |
736 | -}; | ||
737 | - | ||
738 | -const floorMap = { | ||
739 | - slide: _getSlideData, | ||
740 | - hot: _getHotGoodsFloorData, | ||
741 | - 最新速报: _getNewReportFloorData, | ||
742 | - 人气单品: _getSingleHotFloorData, | ||
743 | - 'GIRL KIDS': _getSingleHotFloorData, | ||
744 | - 'BOY KIDS': _getSingleHotFloorData, | ||
745 | - ACCESSORIES: _getSingleHotFloorData, | ||
746 | - 优选品牌: _getPreBrandTopData, | ||
747 | - 最新上架: _getNewGoodsFloorData, | ||
748 | - ad: _getadbannerData, | ||
749 | - category: _getCategoryFloorData, | ||
750 | - accordion: _getAccordionFloorData, | ||
751 | - debrisSlide: _getDebrisSlide, | ||
752 | - jacket: _getJacketData, | ||
753 | - sevenCategory: _getClothesCategory, | ||
754 | - floorTitle: _getFloorTitleData, | ||
755 | - newuser: _getNewUserFloorData | ||
756 | -}; | ||
757 | - | 769 | + } |
758 | 770 | ||
759 | -const needQuery = { | ||
760 | - 'GIRL KIDS': true, | ||
761 | - 'BOY KIDS': true, | ||
762 | - 人气单品: true, | ||
763 | - ACCESSORIES: true | ||
764 | -}; | ||
765 | 771 | ||
766 | -const getQuery = args => { | 772 | + getQuery(args) { |
767 | let goods = args[2] && args[2].data; | 773 | let goods = args[2] && args[2].data; |
768 | let skns = ''; | 774 | let skns = ''; |
769 | 775 | ||
@@ -774,10 +780,9 @@ const getQuery = args => { | @@ -774,10 +780,9 @@ const getQuery = args => { | ||
774 | } | 780 | } |
775 | 781 | ||
776 | return skns; | 782 | return skns; |
777 | -}; | ||
778 | - | 783 | + } |
779 | 784 | ||
780 | -const _processFloorData = (rawData, type) => { | 785 | + _processFloorData(rawData, type) { |
781 | let floorList = []; | 786 | let floorList = []; |
782 | let searchPromise = []; | 787 | let searchPromise = []; |
783 | let singlehotFloorIndex = []; | 788 | let singlehotFloorIndex = []; |
@@ -796,29 +801,29 @@ const _processFloorData = (rawData, type) => { | @@ -796,29 +801,29 @@ const _processFloorData = (rawData, type) => { | ||
796 | 801 | ||
797 | if (data && data.template_name === 'recommend_content_three' || | 802 | if (data && data.template_name === 'recommend_content_three' || |
798 | (data.template_intro === '焦点图' && index === 0)) { // 处理banner | 803 | (data.template_intro === '焦点图' && index === 0)) { // 处理banner |
799 | - floorData = floorMap.slide.call(null, data.data); | 804 | + floorData = this.floorMap.slide(data.data); |
800 | } else if (data && data.template_intro === '热门品类') { // 处理热门品类 | 805 | } else if (data && data.template_intro === '热门品类') { // 处理热门品类 |
801 | - floorData = floorMap.hot.call(null, rawData.slice(index, index + hotCategoryLength), type); | 806 | + floorData = this.floorMap.hot(rawData.slice(index, index + hotCategoryLength), type); |
802 | } else if (data && data.data && data.data.text) { // 处理一般楼层 | 807 | } else if (data && data.data && data.data.text) { // 处理一般楼层 |
803 | - let text = _getText(data.data.text); | 808 | + let text = this._getText(data.data.text); |
804 | let lastIndex = index + bigFloorLength < rawData.length ? | 809 | let lastIndex = index + bigFloorLength < rawData.length ? |
805 | index + bigFloorLength : index + (rawData.length - index - 1); | 810 | index + bigFloorLength : index + (rawData.length - index - 1); |
806 | 811 | ||
807 | - floorData = floorMap[text] && | ||
808 | - floorMap[text].call(null, rawData.slice(index, lastIndex), type); | 812 | + floorData = this.floorMap[text] && |
813 | + this.floorMap[text](rawData.slice(index, lastIndex), type); | ||
809 | 814 | ||
810 | if (needQuery[text]) { | 815 | if (needQuery[text]) { |
811 | - queryParam = getQuery(rawData.slice(index, lastIndex)); | 816 | + queryParam = this.getQuery(rawData.slice(index, lastIndex)); |
812 | if (queryParam.length > 0) { | 817 | if (queryParam.length > 0) { |
813 | params.push(queryParam); | 818 | params.push(queryParam); |
814 | } | 819 | } |
815 | } | 820 | } |
816 | 821 | ||
817 | } else if (data && data.template_name === 'debrisSlider') { // 处理girls的banner | 822 | } else if (data && data.template_name === 'debrisSlider') { // 处理girls的banner |
818 | - floorData = floorMap.debrisSlide.call(null, data.data); | 823 | + floorData = this.floorMap.debrisSlide(data.data); |
819 | } else if (data.template_name === 'new_user_floor' || data.template_intro === '新人专享') { | 824 | } else if (data.template_name === 'new_user_floor' || data.template_intro === '新人专享') { |
820 | if (!hasNewUser) { | 825 | if (!hasNewUser) { |
821 | - floorData = floorMap.newuser.call(null, data.data); | 826 | + floorData = this.floorMap.newuser(data.data); |
822 | hasNewUser = true; | 827 | hasNewUser = true; |
823 | } | 828 | } |
824 | 829 | ||
@@ -828,14 +833,14 @@ const _processFloorData = (rawData, type) => { | @@ -828,14 +833,14 @@ const _processFloorData = (rawData, type) => { | ||
828 | if (!floorData && index + normalFloorLength < rawData.length && | 833 | if (!floorData && index + normalFloorLength < rawData.length && |
829 | rawData[index + 1].template_name === 'textNav' && | 834 | rawData[index + 1].template_name === 'textNav' && |
830 | rawData[index + 2].template_name === 'floor') { | 835 | rawData[index + 2].template_name === 'floor') { |
831 | - floorData = floorMap.category.call(null, rawData.slice(index, index + normalFloorLength)); | 836 | + floorData = this.floorMap.category(rawData.slice(index, index + normalFloorLength)); |
832 | } | 837 | } |
833 | 838 | ||
834 | // 处理手风琴楼层 | 839 | // 处理手风琴楼层 |
835 | if (!floorData && index + normalFloorLength < rawData.length && | 840 | if (!floorData && index + normalFloorLength < rawData.length && |
836 | rawData[index + 1].template_name === 'textNav' && | 841 | rawData[index + 1].template_name === 'textNav' && |
837 | rawData[index + 2].template_name === 'focus') { | 842 | rawData[index + 2].template_name === 'focus') { |
838 | - floorData = floorMap.accordion.call(null, rawData.slice(index, index + normalFloorLength)); | 843 | + floorData = this.floorMap.accordion(rawData.slice(index, index + normalFloorLength)); |
839 | } | 844 | } |
840 | 845 | ||
841 | 846 | ||
@@ -847,7 +852,7 @@ const _processFloorData = (rawData, type) => { | @@ -847,7 +852,7 @@ const _processFloorData = (rawData, type) => { | ||
847 | singlehotFloorIndex.push(floorList.length); | 852 | singlehotFloorIndex.push(floorList.length); |
848 | 853 | ||
849 | // 记住楼层标题, 以便后面promise获取数据后插入楼层数据 | 854 | // 记住楼层标题, 以便后面promise获取数据后插入楼层数据 |
850 | - singlehotFloorTitle.push(_getText(data.data.text)); | 855 | + singlehotFloorTitle.push(this._getText(data.data.text)); |
851 | } else if (!_.isNil(floorData)) { | 856 | } else if (!_.isNil(floorData)) { |
852 | _.isArray(floorData) ? | 857 | _.isArray(floorData) ? |
853 | floorList = floorList.concat(floorData) : | 858 | floorList = floorList.concat(floorData) : |
@@ -862,9 +867,9 @@ const _processFloorData = (rawData, type) => { | @@ -862,9 +867,9 @@ const _processFloorData = (rawData, type) => { | ||
862 | singlehotFloorTitle: _.reverse(singlehotFloorTitle), | 867 | singlehotFloorTitle: _.reverse(singlehotFloorTitle), |
863 | singlehotFloorIndex: _.reverse(singlehotFloorIndex) | 868 | singlehotFloorIndex: _.reverse(singlehotFloorIndex) |
864 | }; | 869 | }; |
865 | -}; | 870 | + } |
866 | 871 | ||
867 | -const _processJKFloorData = (rawData) => { | 872 | + _processJKFloorData(rawData) { |
868 | let floorList = []; | 873 | let floorList = []; |
869 | let searchPromise = []; | 874 | let searchPromise = []; |
870 | let singlehotFloorIndex = []; | 875 | let singlehotFloorIndex = []; |
@@ -877,14 +882,14 @@ const _processJKFloorData = (rawData) => { | @@ -877,14 +882,14 @@ const _processJKFloorData = (rawData) => { | ||
877 | 882 | ||
878 | if (data && data.template_name === 'recommend_content_three' || | 883 | if (data && data.template_name === 'recommend_content_three' || |
879 | (data.template_intro === '焦点图' && index === 0)) { // 处理banner | 884 | (data.template_intro === '焦点图' && index === 0)) { // 处理banner |
880 | - floorData = floorMap.slide.call(null, data.data); | 885 | + floorData = this.floorMap.slide.call(null, data.data); |
881 | floorData.slide.floorId = data.template_id; | 886 | floorData.slide.floorId = data.template_id; |
882 | } else if (data && data.data && data.data.text) { // 处理一般楼层 | 887 | } else if (data && data.data && data.data.text) { // 处理一般楼层 |
883 | - let text = _getText(data.data.text); | 888 | + let text = this._getText(data.data.text); |
884 | 889 | ||
885 | // 最新速报 | 890 | // 最新速报 |
886 | if (text.indexOf('最新速报') >= 0) { | 891 | if (text.indexOf('最新速报') >= 0) { |
887 | - floorData = _getNewReportFloorData(rawData.slice(index, index + 6)); | 892 | + floorData = this._getNewReportFloorData(rawData.slice(index, index + 6)); |
888 | 893 | ||
889 | // 单个图作为最新速报模块用过的,标识一下,不作为广告位了 | 894 | // 单个图作为最新速报模块用过的,标识一下,不作为广告位了 |
890 | _.filter(rawData.slice(index, index + 5), function(o) { | 895 | _.filter(rawData.slice(index, index + 5), function(o) { |
@@ -897,19 +902,19 @@ const _processJKFloorData = (rawData) => { | @@ -897,19 +902,19 @@ const _processJKFloorData = (rawData) => { | ||
897 | let href = rawData[index + 1].template_name === 'textNav' ? | 902 | let href = rawData[index + 1].template_name === 'textNav' ? |
898 | rawData.slice(index, index + 2) : data; | 903 | rawData.slice(index, index + 2) : data; |
899 | 904 | ||
900 | - floorData = floorMap.floorTitle.call(null, href); | 905 | + floorData = this.floorMap.floorTitle.call(null, href); |
901 | } | 906 | } |
902 | 907 | ||
903 | } else if (data && data.template_name === 'jk_floor') { // 左1大图,右6小图,title | 908 | } else if (data && data.template_name === 'jk_floor') { // 左1大图,右6小图,title |
904 | - floorData = floorMap.jacket.call(null, data.data); | 909 | + floorData = this.floorMap.jacket.call(null, data.data); |
905 | } else if (data && data.template_name === 'recommend_content_five') { | 910 | } else if (data && data.template_name === 'recommend_content_five') { |
906 | // 1标题12图,在日韩馆频道页,作为7个品类显示 | 911 | // 1标题12图,在日韩馆频道页,作为7个品类显示 |
907 | - floorData = floorMap.sevenCategory.call(null, data.data); | 912 | + floorData = this.floorMap.sevenCategory.call(null, data.data); |
908 | floorData.sevenCategory.floorId = data.template_id; | 913 | floorData.sevenCategory.floorId = data.template_id; |
909 | } else if (data && data.template_name === 'single_image') { | 914 | } else if (data && data.template_name === 'single_image') { |
910 | if (!data.hasUser) { | 915 | if (!data.hasUser) { |
911 | // 一张图,在日韩馆频道页,做广告位 | 916 | // 一张图,在日韩馆频道页,做广告位 |
912 | - floorData = floorMap.ad.call(null, data.data); | 917 | + floorData = this.floorMap.ad.call(null, data.data); |
913 | } | 918 | } |
914 | } | 919 | } |
915 | 920 | ||
@@ -921,7 +926,7 @@ const _processJKFloorData = (rawData) => { | @@ -921,7 +926,7 @@ const _processJKFloorData = (rawData) => { | ||
921 | singlehotFloorIndex.push(floorList.length); | 926 | singlehotFloorIndex.push(floorList.length); |
922 | 927 | ||
923 | // 记住楼层标题, 以便后面promise获取数据后插入楼层数据 | 928 | // 记住楼层标题, 以便后面promise获取数据后插入楼层数据 |
924 | - singlehotFloorTitle.push(_getText(data.data.text)); | 929 | + singlehotFloorTitle.push(this._getText(data.data.text)); |
925 | } else if (!_.isNil(floorData)) { | 930 | } else if (!_.isNil(floorData)) { |
926 | _.isArray(floorData) ? | 931 | _.isArray(floorData) ? |
927 | floorList = floorList.concat(floorData) : | 932 | floorList = floorList.concat(floorData) : |
@@ -938,10 +943,15 @@ const _processJKFloorData = (rawData) => { | @@ -938,10 +943,15 @@ const _processJKFloorData = (rawData) => { | ||
938 | singlehotFloorTitle: _.reverse(singlehotFloorTitle), | 943 | singlehotFloorTitle: _.reverse(singlehotFloorTitle), |
939 | singlehotFloorIndex: _.reverse(singlehotFloorIndex) | 944 | singlehotFloorIndex: _.reverse(singlehotFloorIndex) |
940 | }; | 945 | }; |
941 | -}; | 946 | + } |
942 | 947 | ||
943 | -const _formatResourceParams = (channel, code) => { | ||
944 | - return serviceApi.get('operations/api/v5/resource/get', {content_code: code}, config.apiCache).then(data => { | 948 | + _formatResourceParams(channel, code) { |
949 | + return this.get({ | ||
950 | + url: 'operations/api/v5/resource/get', | ||
951 | + data: { content_code: code }, | ||
952 | + param: config.apiCache, | ||
953 | + api: global.yoho.ServiceAPI | ||
954 | + }).then(data => { | ||
945 | let result = data && data.data[0] && data.data[0].data[0]; | 955 | let result = data && data.data[0] && data.data[0].data[0]; |
946 | 956 | ||
947 | if (result) { | 957 | if (result) { |
@@ -950,14 +960,14 @@ const _formatResourceParams = (channel, code) => { | @@ -950,14 +960,14 @@ const _formatResourceParams = (channel, code) => { | ||
950 | 960 | ||
951 | return result || {}; | 961 | return result || {}; |
952 | }); | 962 | }); |
953 | -}; | 963 | + } |
954 | 964 | ||
955 | -/** | 965 | + /** |
956 | * 频道页首次登陆导航并行调接口数据 | 966 | * 频道页首次登陆导航并行调接口数据 |
957 | * @param {Object} data | 967 | * @param {Object} data |
958 | * @return {Object} formatData | 968 | * @return {Object} formatData |
959 | */ | 969 | */ |
960 | -const _formatParams = (channel, data) => { | 970 | + _formatParams(channel, data) { |
961 | let params = {}; | 971 | let params = {}; |
962 | 972 | ||
963 | // 排序数据映射表 | 973 | // 排序数据映射表 |
@@ -1005,7 +1015,7 @@ const _formatParams = (channel, data) => { | @@ -1005,7 +1015,7 @@ const _formatParams = (channel, data) => { | ||
1005 | params = Object.assign(data); | 1015 | params = Object.assign(data); |
1006 | } | 1016 | } |
1007 | 1017 | ||
1008 | - return searchApi.getProductList(params).then(result => { | 1018 | + return this.searchApi.getProductList(params).then(result => { |
1009 | let ret = result.data; | 1019 | let ret = result.data; |
1010 | 1020 | ||
1011 | if (ret) { | 1021 | if (ret) { |
@@ -1014,14 +1024,14 @@ const _formatParams = (channel, data) => { | @@ -1014,14 +1024,14 @@ const _formatParams = (channel, data) => { | ||
1014 | 1024 | ||
1015 | return ret; | 1025 | return ret; |
1016 | }); | 1026 | }); |
1017 | -}; | 1027 | + } |
1018 | 1028 | ||
1019 | -/** | 1029 | + /** |
1020 | * 格式化频道页首次登陆导航数据 | 1030 | * 格式化频道页首次登陆导航数据 |
1021 | * @param {Object} data | 1031 | * @param {Object} data |
1022 | * @return {Object} formatData | 1032 | * @return {Object} formatData |
1023 | */ | 1033 | */ |
1024 | -const formatIndexGuideData = data => { | 1034 | + formatIndexGuideData(data) { |
1025 | let channels = { | 1035 | let channels = { |
1026 | boys: {gender: '1,3', limit: 1}, | 1036 | boys: {gender: '1,3', limit: 1}, |
1027 | girls: {gender: '2,3', limit: 1}, | 1037 | girls: {gender: '2,3', limit: 1}, |
@@ -1045,7 +1055,7 @@ const formatIndexGuideData = data => { | @@ -1045,7 +1055,7 @@ const formatIndexGuideData = data => { | ||
1045 | }); | 1055 | }); |
1046 | 1056 | ||
1047 | if (channels[channel]) { | 1057 | if (channels[channel]) { |
1048 | - promiseArr.push(_formatParams(channel, channels[channel])); | 1058 | + promiseArr.push(this._formatParams(channel, channels[channel])); |
1049 | } | 1059 | } |
1050 | }); | 1060 | }); |
1051 | 1061 | ||
@@ -1060,22 +1070,21 @@ const formatIndexGuideData = data => { | @@ -1060,22 +1070,21 @@ const formatIndexGuideData = data => { | ||
1060 | 1070 | ||
1061 | return formatData; | 1071 | return formatData; |
1062 | }); | 1072 | }); |
1063 | -}; | 1073 | + } |
1064 | 1074 | ||
1065 | -/** | 1075 | + /** |
1066 | * 获取最新上架商品数据 | 1076 | * 获取最新上架商品数据 |
1067 | * | 1077 | * |
1068 | * @param string $channel | 1078 | * @param string $channel |
1069 | * @return array | 1079 | * @return array |
1070 | */ | 1080 | */ |
1071 | -const getNewArrival = (channel, isJKChannel, poolId)=> { | 1081 | + getNewArrival(channel, isJKChannel, poolId) { |
1072 | let rel = [], | 1082 | let rel = [], |
1073 | sortList = sortMap[channel], | 1083 | sortList = sortMap[channel], |
1074 | params = {}, | 1084 | params = {}, |
1075 | method = ''; | 1085 | method = ''; |
1076 | 1086 | ||
1077 | 1087 | ||
1078 | - | ||
1079 | if (isJKChannel) { | 1088 | if (isJKChannel) { |
1080 | method = 'app.search.sales'; | 1089 | method = 'app.search.sales'; |
1081 | params = { | 1090 | params = { |
@@ -1104,9 +1113,12 @@ const getNewArrival = (channel, isJKChannel, poolId)=> { | @@ -1104,9 +1113,12 @@ const getNewArrival = (channel, isJKChannel, poolId)=> { | ||
1104 | _.forEach(sortList, (item) => { | 1113 | _.forEach(sortList, (item) => { |
1105 | let data = Object.assign(item, params, {limit: item.viewNum}); | 1114 | let data = Object.assign(item, params, {limit: item.viewNum}); |
1106 | 1115 | ||
1107 | - rel.push(api.get('', Object.assign({ | 1116 | + rel.push(this.get({ |
1117 | + data: Object.assign({ | ||
1108 | method: method | 1118 | method: method |
1109 | - }, data), {cache: true})); | 1119 | + }, data), |
1120 | + param: {cache: true} | ||
1121 | + })); | ||
1110 | }); | 1122 | }); |
1111 | 1123 | ||
1112 | return Promise.all(rel).then(res => { | 1124 | return Promise.all(rel).then(res => { |
@@ -1130,22 +1142,22 @@ const getNewArrival = (channel, isJKChannel, poolId)=> { | @@ -1130,22 +1142,22 @@ const getNewArrival = (channel, isJKChannel, poolId)=> { | ||
1130 | }); | 1142 | }); |
1131 | return result; | 1143 | return result; |
1132 | }); | 1144 | }); |
1133 | -}; | 1145 | + } |
1134 | 1146 | ||
1135 | 1147 | ||
1136 | -/** | 1148 | + /** |
1137 | * 获取频道页数据 | 1149 | * 获取频道页数据 |
1138 | * @param {String} type 传入频道页类型,值可以是: boys, girls, kids, lifestyle | 1150 | * @param {String} type 传入频道页类型,值可以是: boys, girls, kids, lifestyle |
1139 | * @return {Object} | 1151 | * @return {Object} |
1140 | */ | 1152 | */ |
1141 | -const getContent = (type, isJKChannel, poolId) => { | 1153 | + getContent(type, isJKChannel, poolId) { |
1142 | 1154 | ||
1143 | let params = {new_device: 'Y'}; | 1155 | let params = {new_device: 'Y'}; |
1144 | 1156 | ||
1145 | return Promise.all([ | 1157 | return Promise.all([ |
1146 | headerModel.requestHeaderData(type), | 1158 | headerModel.requestHeaderData(type), |
1147 | - _requestContent(type, params), | ||
1148 | - getNewArrival(type, isJKChannel, poolId) | 1159 | + this._requestContent(type, params), |
1160 | + this.getNewArrival(type, isJKChannel, poolId) | ||
1149 | ]).then(res => { | 1161 | ]).then(res => { |
1150 | 1162 | ||
1151 | let headerData = res[0].data || res[0], | 1163 | let headerData = res[0].data || res[0], |
@@ -1153,7 +1165,7 @@ const getContent = (type, isJKChannel, poolId) => { | @@ -1153,7 +1165,7 @@ const getContent = (type, isJKChannel, poolId) => { | ||
1153 | 1165 | ||
1154 | let data = {}; | 1166 | let data = {}; |
1155 | 1167 | ||
1156 | - const processResult = _processFloorData(contentData, type); | 1168 | + const processResult = this._processFloorData(contentData, type); |
1157 | 1169 | ||
1158 | data = headerData; | 1170 | data = headerData; |
1159 | data.module = 'channel'; | 1171 | data.module = 'channel'; |
@@ -1187,7 +1199,7 @@ const getContent = (type, isJKChannel, poolId) => { | @@ -1187,7 +1199,7 @@ const getContent = (type, isJKChannel, poolId) => { | ||
1187 | _.forEach(res, (data, index) => { | 1199 | _.forEach(res, (data, index) => { |
1188 | result.floorData.channel | 1200 | result.floorData.channel |
1189 | .splice(result.singlehotFloorIndex[index], 0, | 1201 | .splice(result.singlehotFloorIndex[index], 0, |
1190 | - _processFloorDataWithQueryReusult( | 1202 | + this._processFloorDataWithQueryReusult( |
1191 | result.rawData, | 1203 | result.rawData, |
1192 | result.queryParams[index], | 1204 | result.queryParams[index], |
1193 | data, | 1205 | data, |
@@ -1202,21 +1214,21 @@ const getContent = (type, isJKChannel, poolId) => { | @@ -1202,21 +1214,21 @@ const getContent = (type, isJKChannel, poolId) => { | ||
1202 | 1214 | ||
1203 | return result.floorData || result; | 1215 | return result.floorData || result; |
1204 | }); | 1216 | }); |
1205 | -}; | 1217 | + } |
1206 | 1218 | ||
1207 | -/** | 1219 | + /** |
1208 | * 获取日韩馆频道页数据 | 1220 | * 获取日韩馆频道页数据 |
1209 | * @param {String} type 传入频道页类型,值可以是: boys, girls, kids, lifestyle | 1221 | * @param {String} type 传入频道页类型,值可以是: boys, girls, kids, lifestyle |
1210 | * @return {Object} | 1222 | * @return {Object} |
1211 | */ | 1223 | */ |
1212 | -const getJKContent = (req) => { | 1224 | + getJKContent(req) { |
1213 | let channel = req.query.channel || req.yoho.channel || 'boys', | 1225 | let channel = req.query.channel || req.yoho.channel || 'boys', |
1214 | contentCode = req.query.content_code; | 1226 | contentCode = req.query.content_code; |
1215 | 1227 | ||
1216 | return Promise.all([ | 1228 | return Promise.all([ |
1217 | headerModel.requestHeaderData(channel), | 1229 | headerModel.requestHeaderData(channel), |
1218 | - _requestContent(channel, {}, contentCode), | ||
1219 | - getNewArrival(channel, true, req.query.template_id) | 1230 | + this._requestContent(channel, {}, contentCode), |
1231 | + this.getNewArrival(channel, true, req.query.template_id) | ||
1220 | ]).then(res => { | 1232 | ]).then(res => { |
1221 | 1233 | ||
1222 | let headerData = res[0].data || res[0], | 1234 | let headerData = res[0].data || res[0], |
@@ -1224,7 +1236,7 @@ const getJKContent = (req) => { | @@ -1224,7 +1236,7 @@ const getJKContent = (req) => { | ||
1224 | 1236 | ||
1225 | let data = {}; | 1237 | let data = {}; |
1226 | 1238 | ||
1227 | - const processResult = _processJKFloorData(contentData); | 1239 | + const processResult = this._processJKFloorData(contentData); |
1228 | 1240 | ||
1229 | data = headerData; | 1241 | data = headerData; |
1230 | data.module = 'channel'; | 1242 | data.module = 'channel'; |
@@ -1259,7 +1271,7 @@ const getJKContent = (req) => { | @@ -1259,7 +1271,7 @@ const getJKContent = (req) => { | ||
1259 | _.forEach(res, (data, index) => { | 1271 | _.forEach(res, (data, index) => { |
1260 | result.floorData.channel | 1272 | result.floorData.channel |
1261 | .splice(result.singlehotFloorIndex[index], 0, | 1273 | .splice(result.singlehotFloorIndex[index], 0, |
1262 | - _processFloorDataWithQueryReusult( | 1274 | + this._processFloorDataWithQueryReusult( |
1263 | result.rawData, | 1275 | result.rawData, |
1264 | result.queryParams[index], | 1276 | result.queryParams[index], |
1265 | data, | 1277 | data, |
@@ -1274,14 +1286,14 @@ const getJKContent = (req) => { | @@ -1274,14 +1286,14 @@ const getJKContent = (req) => { | ||
1274 | 1286 | ||
1275 | return result.floorData || result; | 1287 | return result.floorData || result; |
1276 | }); | 1288 | }); |
1277 | -}; | 1289 | + } |
1278 | 1290 | ||
1279 | -const getResourceData = (formatData) => { | 1291 | + getResourceData(formatData) { |
1280 | let promiseArr = []; | 1292 | let promiseArr = []; |
1281 | 1293 | ||
1282 | _.forEach(formatData, item => { | 1294 | _.forEach(formatData, item => { |
1283 | if (item.content_code) { | 1295 | if (item.content_code) { |
1284 | - promiseArr.push(_formatResourceParams(item.channel, item.content_code)); | 1296 | + promiseArr.push(this._formatResourceParams(item.channel, item.content_code)); |
1285 | } | 1297 | } |
1286 | }); | 1298 | }); |
1287 | return Promise.all(promiseArr).then(data => { | 1299 | return Promise.all(promiseArr).then(data => { |
@@ -1295,26 +1307,31 @@ const getResourceData = (formatData) => { | @@ -1295,26 +1307,31 @@ const getResourceData = (formatData) => { | ||
1295 | 1307 | ||
1296 | return formatData; | 1308 | return formatData; |
1297 | }); | 1309 | }); |
1298 | -}; | 1310 | + } |
1299 | 1311 | ||
1300 | -/** | 1312 | + /** |
1301 | * 获取频道页首次登陆导航数据 | 1313 | * 获取频道页首次登陆导航数据 |
1302 | * @param {String} type 传入频道页类型,值可以是: boys, girls, kids, lifestyle | 1314 | * @param {String} type 传入频道页类型,值可以是: boys, girls, kids, lifestyle |
1303 | * @return {Object} | 1315 | * @return {Object} |
1304 | */ | 1316 | */ |
1305 | -const getIndexGuideData = () => { | 1317 | + getIndexGuideData() { |
1306 | let params = { | 1318 | let params = { |
1307 | client_type: 'web', | 1319 | client_type: 'web', |
1308 | private_key: '0ed29744ed318fd28d2c07985d3ba633' | 1320 | private_key: '0ed29744ed318fd28d2c07985d3ba633' |
1309 | }; | 1321 | }; |
1310 | 1322 | ||
1311 | - return serviceApi.get('operations/api/v6/category/getCategory', params, config.apiCache); | ||
1312 | -}; | 1323 | + return this.get({ |
1324 | + url: 'operations/api/v6/category/getCategory', | ||
1325 | + data: params, | ||
1326 | + param: config.apiCache, | ||
1327 | + api: global.yoho.ServiceAPI | ||
1328 | + }); | ||
1329 | + } | ||
1313 | 1330 | ||
1314 | -const hasNewUserFloor = (channelType, uid) => { | 1331 | + hasNewUserFloor(channelType, uid) { |
1315 | let params = {uid: uid}; | 1332 | let params = {uid: uid}; |
1316 | 1333 | ||
1317 | - return _requestContent(channelType, params).then(res => { | 1334 | + return this._requestContent(channelType, params).then(res => { |
1318 | let isNewUser = false, | 1335 | let isNewUser = false, |
1319 | contentData = res.data ? res.data.list : res; | 1336 | contentData = res.data ? res.data.list : res; |
1320 | 1337 | ||
@@ -1329,16 +1346,5 @@ const hasNewUserFloor = (channelType, uid) => { | @@ -1329,16 +1346,5 @@ const hasNewUserFloor = (channelType, uid) => { | ||
1329 | isNewUser: isNewUser | 1346 | isNewUser: isNewUser |
1330 | }; | 1347 | }; |
1331 | }); | 1348 | }); |
1332 | -}; | ||
1333 | - | ||
1334 | - | ||
1335 | -module.exports = { | ||
1336 | - getNewArrival: getNewArrival, | ||
1337 | - getContent: getContent, | ||
1338 | - getJKContent: getJKContent, | ||
1339 | - getIndexGuideData: getIndexGuideData, | ||
1340 | - formatIndexGuideData: formatIndexGuideData, | ||
1341 | - getResourceData: getResourceData, | ||
1342 | - hasNewUserFloor: hasNewUserFloor | ||
1343 | - | 1349 | + } |
1344 | }; | 1350 | }; |
1 | /** | 1 | /** |
2 | * Created by TaoHuang on 2016/6/14. | 2 | * Created by TaoHuang on 2016/6/14. |
3 | */ | 3 | */ |
4 | -'use strict'; | ||
5 | -const _ = require('lodash'); | 4 | + |
6 | const Fn = require('lodash/fp'); | 5 | const Fn = require('lodash/fp'); |
7 | const md5 = require('md5'); | 6 | const md5 = require('md5'); |
8 | 7 | ||
9 | -const api = global.yoho.API; | ||
10 | -const serviceApi = global.yoho.ServiceAPI; | ||
11 | const config = global.yoho.config; | 8 | const config = global.yoho.config; |
12 | - | ||
13 | -const helpers = global.yoho.helpers; | ||
14 | const cache = global.yoho.cache; | 9 | const cache = global.yoho.cache; |
15 | const logger = global.yoho.logger; | 10 | const logger = global.yoho.logger; |
16 | 11 | ||
17 | -// 判断用户是否收藏品牌 | ||
18 | -const isFavoriteBrandUrl = '/shops/service/v1/favorite/getUidBrandFav'; | ||
19 | - | ||
20 | -// 根据品牌查询相关文章 | ||
21 | -const relateArticleUrl = 'guang/service/v2/article/getArticleByBrand'; | ||
22 | - | ||
23 | -const GLOBAL_BASE_URI = '/product/global/list'; | ||
24 | - | ||
25 | // 缓存生效时间 | 12 | // 缓存生效时间 |
26 | const CACHE_TIME_S = 60; | 13 | const CACHE_TIME_S = 60; |
27 | 14 | ||
@@ -38,23 +25,20 @@ const saveCache = (key, kv, cacheTime) => { | @@ -38,23 +25,20 @@ const saveCache = (key, kv, cacheTime) => { | ||
38 | .catch(err => logger.debug(`product query save cache data fail:${err.toString()}`)); | 25 | .catch(err => logger.debug(`product query save cache data fail:${err.toString()}`)); |
39 | }; | 26 | }; |
40 | 27 | ||
41 | -const getProductListOrig = finalParams => api.get('', finalParams); | 28 | +module.exports = class extends global.yoho.BaseModel { |
29 | + constructor(ctx) { | ||
30 | + super(ctx); | ||
31 | + } | ||
42 | 32 | ||
43 | -const getKeyActivityAsync = (query) => { | ||
44 | - return api.get('', { | ||
45 | - method: 'app.search.word', | ||
46 | - query: query | ||
47 | - }, { | ||
48 | - catch: true, | ||
49 | - code: 200 | ||
50 | - }); | ||
51 | -}; | 33 | + getProductListOrig(finalParams) { |
34 | + return this.get({data: finalParams}); | ||
35 | + } | ||
52 | 36 | ||
53 | -/** | 37 | + /** |
54 | * 获取商品列表 | 38 | * 获取商品列表 |
55 | * @return | 39 | * @return |
56 | */ | 40 | */ |
57 | -const getProductList = (params, from) => { | 41 | + getProductList(params, from) { |
58 | let finalParams = { | 42 | let finalParams = { |
59 | method: 'web.search.search', | 43 | method: 'web.search.search', |
60 | sales: 'Y', | 44 | sales: 'Y', |
@@ -76,7 +60,7 @@ const getProductList = (params, from) => { | @@ -76,7 +60,7 @@ const getProductList = (params, from) => { | ||
76 | } | 60 | } |
77 | 61 | ||
78 | if (!config.useCache) { | 62 | if (!config.useCache) { |
79 | - return getProductListOrig(finalParams); | 63 | + return this.getProductListOrig(finalParams); |
80 | } else { | 64 | } else { |
81 | let cKey = getSearchCacheKey(finalParams); | 65 | let cKey = getSearchCacheKey(finalParams); |
82 | 66 | ||
@@ -99,7 +83,7 @@ const getProductList = (params, from) => { | @@ -99,7 +83,7 @@ const getProductList = (params, from) => { | ||
99 | } | 83 | } |
100 | } | 84 | } |
101 | 85 | ||
102 | - return getProductListOrig(finalParams).then(result => { | 86 | + return this.getProductListOrig(finalParams).then(result => { |
103 | if (hasCache && result && result.data) { | 87 | if (hasCache && result && result.data) { |
104 | Object.assign(result.data, cdata); | 88 | Object.assign(result.data, cdata); |
105 | } else { | 89 | } else { |
@@ -115,412 +99,6 @@ const getProductList = (params, from) => { | @@ -115,412 +99,6 @@ const getProductList = (params, from) => { | ||
115 | }); | 99 | }); |
116 | }); | 100 | }); |
117 | } | 101 | } |
118 | -}; | ||
119 | - | ||
120 | -/** | ||
121 | - * 获取seo商品列表 | ||
122 | - * @return | ||
123 | - */ | ||
124 | -const getSeoProductList = (params, from) => { | ||
125 | - let finalParams = { | ||
126 | - method: 'web.search.forseo', | ||
127 | - sales: 'Y', | ||
128 | - outlets: 2, | ||
129 | - stocknumber: 1, | ||
130 | - need_filter: 'no', | ||
131 | - limit: 60 | ||
132 | - }; | ||
133 | - | ||
134 | - Object.assign(finalParams, params); | ||
135 | - | ||
136 | - if (from) { | ||
137 | - finalParams.from = from; | ||
138 | - } | ||
139 | - | ||
140 | - return getProductListOrig(finalParams); | ||
141 | -}; | ||
142 | - | ||
143 | -const getSortListOrig = (finalParams) => api.get('', finalParams, config.apiCache); | ||
144 | - | ||
145 | -/** | ||
146 | - * 获取分类列表 | ||
147 | - * @return | ||
148 | - */ | ||
149 | -const getSortList = (params, channel) => { | ||
150 | - let finalParams = { | ||
151 | - method: 'web.regular.groupsort.sale', | ||
152 | - sales: 'Y', // 在销售商品分类 | ||
153 | - status: 1, // 上架商品分类 | ||
154 | - stocknumber: 1 // 过滤掉已售罄 | ||
155 | - }; | ||
156 | - | ||
157 | - Object.assign(finalParams, params); | ||
158 | - | ||
159 | - if (channel) { | ||
160 | - switch (channel) { | ||
161 | - case 'boys': | ||
162 | - finalParams.yh_channel = 1; | ||
163 | - break; | ||
164 | - case 'girls': | ||
165 | - finalParams.yh_channel = 2; | ||
166 | - break; | ||
167 | - case 'kids': | ||
168 | - finalParams.yh_channel = 3; | ||
169 | - break; | ||
170 | - case 'lifestyle': | ||
171 | - finalParams.yh_channel = 4; | ||
172 | - break; | ||
173 | - default: | ||
174 | - break; | ||
175 | - } | ||
176 | - } | ||
177 | - | ||
178 | - if (!config.useCache) { | ||
179 | - return getSortListOrig(finalParams); | ||
180 | - } else { | ||
181 | - let cKey = getSearchCacheKey(finalParams); | ||
182 | - | ||
183 | - return cache.get(cKey) | ||
184 | - .catch(err => logger.debug(`product query save cache data fail:${err.toString()}`)) | ||
185 | - .then(cdata => { | ||
186 | - let cdataObj; | ||
187 | - | ||
188 | - if (cdata) { | ||
189 | - try { | ||
190 | - cdataObj = JSON.parse(cdata); | ||
191 | - } catch (e) { | ||
192 | - logger.debug('getSortList cache data parse fail.'); | ||
193 | - } | ||
194 | } | 102 | } |
195 | 103 | ||
196 | - if (cdataObj) { | ||
197 | - return cdataObj; | ||
198 | - } else { | ||
199 | - return getSortListOrig(finalParams).then(ret => { | ||
200 | - if (ret && ret.code === 200) { | ||
201 | - saveCache(cKey, ret, CACHE_TIME_S); | ||
202 | - } | ||
203 | - return ret; | ||
204 | - }); | ||
205 | - } | ||
206 | - }); | ||
207 | - } | ||
208 | -}; | ||
209 | - | ||
210 | -/** | ||
211 | - * 获取分类图文介绍 | ||
212 | - * @return | ||
213 | - */ | ||
214 | -const getSortIntro = (params) => { | ||
215 | - let finalParams = { | ||
216 | - method: 'web.search.banner' | ||
217 | - }; | ||
218 | - | ||
219 | - Object.assign(finalParams, params); | ||
220 | - return api.get('', finalParams, config.apiCache); | ||
221 | -}; | ||
222 | - | ||
223 | -/** | ||
224 | - * 获取分类广告 | ||
225 | - * @return | ||
226 | - */ | ||
227 | -const getSortAds = (params) => { | ||
228 | - let finalParams = { | ||
229 | - method: 'app.ads.list' | ||
230 | - }; | ||
231 | - | ||
232 | - Object.assign(finalParams, params); | ||
233 | - return api.get('', finalParams, config.apiCache); | ||
234 | -}; | ||
235 | - | ||
236 | -/** | ||
237 | - * 获取品牌系列 | ||
238 | - * @return | ||
239 | - */ | ||
240 | -const getBrandShopSeries = (params) => { | ||
241 | - let finalParams = { | ||
242 | - method: 'web.brand.series', | ||
243 | - status: params.status || 1 | ||
244 | - }; | ||
245 | - | ||
246 | - if (params.brandId) { | ||
247 | - finalParams.brand_id = params.brandId; | ||
248 | - } else if (params.shopId) { | ||
249 | - Object.assign(finalParams, { | ||
250 | - method: 'web.shop.series', | ||
251 | - shop_id: params.shopId | ||
252 | - }); | ||
253 | - } | ||
254 | - | ||
255 | - return api.get('', finalParams, config.apiCache); | ||
256 | -}; | ||
257 | - | ||
258 | -/** | ||
259 | - * 获取品牌folder | ||
260 | - * @return | ||
261 | - */ | ||
262 | -const getBrandShopFolder = (params) => { | ||
263 | - let finalParams = { | ||
264 | - method: 'web.brand.folder', | ||
265 | - status: params.status || 1 | ||
266 | - }; | ||
267 | - | ||
268 | - if (params.brandId) { | ||
269 | - finalParams.brand_id = params.brandId; | ||
270 | - } else if (params.shopId) { | ||
271 | - Object.assign(finalParams, { | ||
272 | - method: 'web.shop.folder', | ||
273 | - shop_id: params.shopId | ||
274 | - }); | ||
275 | - } | ||
276 | - | ||
277 | - return api.get('', finalParams, config.apiCache); | ||
278 | -}; | ||
279 | - | ||
280 | -/** | ||
281 | - * 获取品牌水牌 | ||
282 | - * @return | ||
283 | - */ | ||
284 | -const getNodeContent = (params) => { | ||
285 | - let finalParams = { | ||
286 | - method: 'web.html.content', | ||
287 | - mode: params.mode || 'release', | ||
288 | - node: params.node || '' | ||
289 | - }; | ||
290 | - | ||
291 | - return api.get('', finalParams, config.apiCache); | ||
292 | -}; | ||
293 | - | ||
294 | -/** | ||
295 | - * 一周新品上架 | ||
296 | - * @return | ||
297 | - */ | ||
298 | -const getWeekNew = (params) => { | ||
299 | - | ||
300 | - let finalParams = { | ||
301 | - method: 'web.regular.recent' | ||
302 | - }; | ||
303 | - | ||
304 | - Object.assign(finalParams, params); | ||
305 | - return api.get('', finalParams, config.apiCache); | ||
306 | -}; | ||
307 | - | ||
308 | -const getBrandCouponAsync = (brandId, uid) => { | ||
309 | - let extra = {code: 200}; | ||
310 | - | ||
311 | - if (!uid) { | ||
312 | - extra.cache = true; | ||
313 | - } | ||
314 | - | ||
315 | - return api.get('', { | ||
316 | - method: 'app.brand.getBrandIntro', | ||
317 | - brand_id: brandId, | ||
318 | - uid: uid | ||
319 | - }, extra); | ||
320 | -}; | ||
321 | - | ||
322 | -/** | ||
323 | - * 根据关键词搜索品牌店铺信息 | ||
324 | - * @return | ||
325 | - */ | ||
326 | -const getBrandShop = (query) => { | ||
327 | - let finalParams = { | ||
328 | - method: 'web.search.shopListInfo' | ||
329 | - }; | ||
330 | - | ||
331 | - return api.get('', Object.assign(finalParams, {keyword: query}), config.apiCache); | ||
332 | -}; | ||
333 | - | ||
334 | -/** | ||
335 | - * 根据搜索得到店铺/品牌 | ||
336 | - */ | ||
337 | -const getShopList = params => { | ||
338 | - if (!params || !params.query) { | ||
339 | - return; | ||
340 | - } | ||
341 | - | ||
342 | - return getBrandShop(params.query).then(shops => { | ||
343 | - let shopEntry = []; | ||
344 | - | ||
345 | - _.forEach(_.get(shops, 'data.shopList', []), value => { | ||
346 | - let shopInfo = { | ||
347 | - home: helpers.urlFormat('', null, value.shop_domain || value.brand_domain), | ||
348 | - logo: value.shop_logo || value.brand_ico, | ||
349 | - shopName: value.shop_name || value.brand_name, | ||
350 | - shopType: '', | ||
351 | - sort: [] | ||
352 | - }; | ||
353 | - | ||
354 | - if (value.is_global === 'Y') { | ||
355 | - shopInfo.home = helpers.urlFormat(GLOBAL_BASE_URI, {brand: value.global_brand_id}); | ||
356 | - shopInfo.shopType = 'global-brand'; | ||
357 | - } | ||
358 | - | ||
359 | - // 店铺/品牌的小分类 | ||
360 | - _.forEach(_.get(value, 'sortInfo.sort', []), sortInfo => { | ||
361 | - _.forEach(_.get(sortInfo, 'sub', []), subSort => { | ||
362 | - let sortHref; | ||
363 | - | ||
364 | - if (value.is_global !== 'Y') { | ||
365 | - sortHref = helpers.urlFormat('', {misort: subSort.sort_id}, | ||
366 | - value.shop_domain || value.brand_domain); | ||
367 | - } else { | ||
368 | - sortHref = helpers.urlFormat(GLOBAL_BASE_URI, { | ||
369 | - misort: subSort.sort_id, | ||
370 | - brand: value.global_brand_id | ||
371 | - }); | ||
372 | - } | ||
373 | - shopInfo.sort.push({ | ||
374 | - href: sortHref, | ||
375 | - name: subSort.sort_name | ||
376 | - }); | ||
377 | - }); | ||
378 | - }); | ||
379 | - | ||
380 | - shopEntry.push(shopInfo); | ||
381 | - }); | ||
382 | - | ||
383 | - return shopEntry; | ||
384 | - }); | ||
385 | -}; | ||
386 | - | ||
387 | -/** | ||
388 | - * 搜索提示 | ||
389 | - * @return | ||
390 | - */ | ||
391 | -const getSuggest = (params) => { | ||
392 | - | ||
393 | - let finalParams = { | ||
394 | - method: 'app.search.fuzzy', | ||
395 | - keyword: params.keyword || '' | ||
396 | - }; | ||
397 | - | ||
398 | - return api.get('', finalParams, config.apiCache); | ||
399 | -}; | ||
400 | - | ||
401 | - | ||
402 | -/** | ||
403 | - * 根据品牌域名获取品牌信息 | ||
404 | - * @return | ||
405 | - */ | ||
406 | -const getBrandData = (params) => { | ||
407 | - let finalParams = { | ||
408 | - method: 'web.brand.byDomain', | ||
409 | - domain: params.domain || '' | ||
410 | - }; | ||
411 | - | ||
412 | - return api.get('', finalParams, config.apiCache); | ||
413 | -}; | ||
414 | - | ||
415 | -/** | ||
416 | - * 根据uid和品牌id判断品牌是否收藏 | ||
417 | - * @return | ||
418 | - */ | ||
419 | -const isFavoriteBrand = (uid, brandId) => { | ||
420 | - return serviceApi.get(isFavoriteBrandUrl, { | ||
421 | - uid: uid, | ||
422 | - brandId: brandId | ||
423 | - }); | ||
424 | -}; | ||
425 | - | ||
426 | -/** | ||
427 | - * 根据shopId获取店铺基本信息 | ||
428 | - * @return | ||
429 | - */ | ||
430 | -const getShopInfo = (shopId, uid) => { | ||
431 | - let finalParams = { | ||
432 | - method: 'app.shops.getIntro', | ||
433 | - shop_id: shopId || 0, | ||
434 | - uid: uid || 0 | ||
435 | - }; | ||
436 | - | ||
437 | - return api.get('', finalParams, config.apiCache); | ||
438 | - | ||
439 | -}; | ||
440 | - | ||
441 | -/** | ||
442 | - * 查询店铺下面的所有品牌 | ||
443 | - */ | ||
444 | -const getShopBrands = (shopId) => { | ||
445 | - return api.get('', {method: 'app.shops.getShopsBrands', shop_id: shopId || 0}, config.apiCache); | ||
446 | -}; | ||
447 | - | ||
448 | -/** | ||
449 | - * 查询店铺装修 | ||
450 | - */ | ||
451 | -const getShopDecorator = (shopId) => { | ||
452 | - return api.get('', {method: 'app.shopsdecorator.getList', shop_id: shopId || 0}, config.apiCache); | ||
453 | -}; | ||
454 | - | ||
455 | -/** | ||
456 | - * 通过品牌获取相关文章 | ||
457 | - */ | ||
458 | -const getArticleByBrand = (brand, udid, limit) => { | ||
459 | - let params = { | ||
460 | - brand_id: brand || 0, | ||
461 | - udid: udid, | ||
462 | - limit: limit || 6 | ||
463 | - }; | ||
464 | - | ||
465 | - return serviceApi.get(relateArticleUrl, params); | ||
466 | -}; | ||
467 | - | ||
468 | -const getBrands4Filter = (params) => { | ||
469 | - return api.get('', Object.assign({ | ||
470 | - method: 'web.regular.aggBrand' | ||
471 | - }, params)); | ||
472 | -}; | ||
473 | - | ||
474 | -/** | ||
475 | - * 有可能喜欢的商品 | ||
476 | - | ||
477 | - * @param int $channel 频道,1代表男生,2代表女生,3代表潮童,4代表创意生活 | ||
478 | - * @param $uid 用户ID | ||
479 | - * @param $udid 设备ID | ||
480 | - * @param $rec_pos 位置码 | ||
481 | - * @param $limit 数量限制 | ||
482 | - * @return array 接口返回的数据 | ||
483 | - * */ | ||
484 | - | ||
485 | -const lessRecommend = (channelNum, uid, udid, recPos, limit) => { | ||
486 | - let param = { | ||
487 | - method: 'app.search.newLast7day', | ||
488 | - yh_channel: channelNum, | ||
489 | - udid: udid, | ||
490 | - rec_pos: recPos, | ||
491 | - limit: limit | ||
492 | - }; | ||
493 | - | ||
494 | - if (uid) { | ||
495 | - param.uid = uid; | ||
496 | - } | ||
497 | - | ||
498 | - return api.get('', param); | ||
499 | -}; | ||
500 | - | ||
501 | -module.exports = { | ||
502 | - getKeyActivityAsync, | ||
503 | - getProductList, | ||
504 | - getSeoProductList, | ||
505 | - getSortList, | ||
506 | - getSortIntro, | ||
507 | - getSortAds, | ||
508 | - getBrandShopFolder, | ||
509 | - getBrandShopSeries, | ||
510 | - getWeekNew, | ||
511 | - getBrandCouponAsync, | ||
512 | - getBrandShop, | ||
513 | - getSuggest, | ||
514 | - getBrandData, | ||
515 | - getNodeContent, | ||
516 | - isFavoriteBrand, | ||
517 | - getShopInfo, | ||
518 | - getShopBrands, | ||
519 | - getShopDecorator, | ||
520 | - getArticleByBrand, | ||
521 | - getShopList, | ||
522 | - getBrands4Filter, | ||
523 | - getProductListOrig, | ||
524 | - getSearchCacheKey, | ||
525 | - lessRecommend | ||
526 | }; | 104 | }; |
@@ -58,7 +58,7 @@ passport.use('local', new LocalStrategy({ | @@ -58,7 +58,7 @@ passport.use('local', new LocalStrategy({ | ||
58 | getLoginStat(clientIp).then((times) => { | 58 | getLoginStat(clientIp).then((times) => { |
59 | let errLoginTimes = _.parseInt(times) || 0; | 59 | let errLoginTimes = _.parseInt(times) || 0; |
60 | 60 | ||
61 | - return LoginApi.signin(type, area, username, password, shoppingKey, clientIp, close).then((result) => { | 61 | + return req.ctx(LoginApi).signin(type, area, username, password, shoppingKey, close).then((result) => { |
62 | if (result.code && (result.code === 200 || result.code === 510) && result.data.uid) { | 62 | if (result.code && (result.code === 200 || result.code === 510) && result.data.uid) { |
63 | cache.del(errorLoginKey).catch(() => {}); | 63 | cache.del(errorLoginKey).catch(() => {}); |
64 | req.session.type = ''; | 64 | req.session.type = ''; |
@@ -7,7 +7,7 @@ | @@ -7,7 +7,7 @@ | ||
7 | 7 | ||
8 | const helpers = global.yoho.helpers; | 8 | const helpers = global.yoho.helpers; |
9 | const config = global.yoho.config; | 9 | const config = global.yoho.config; |
10 | -const service = require('../models/back-service'); | 10 | +const BackService = require('../models/back-service'); |
11 | const passportHelper = require('../models/passport-helper'); | 11 | const passportHelper = require('../models/passport-helper'); |
12 | const simpleHeaderModel = require('../../../doraemon/models/simple-header'); | 12 | const simpleHeaderModel = require('../../../doraemon/models/simple-header'); |
13 | const _ = require('lodash'); | 13 | const _ = require('lodash'); |
@@ -24,7 +24,7 @@ const index = (req, res, next) => { | @@ -24,7 +24,7 @@ const index = (req, res, next) => { | ||
24 | domain: config.cookieDomain | 24 | domain: config.cookieDomain |
25 | }); | 25 | }); |
26 | 26 | ||
27 | - service.indexPageDataAsync() | 27 | + req.ctx(BackService).indexPageDataAsync() |
28 | .then(result => { | 28 | .then(result => { |
29 | res.render('back/index', Object.assign({ | 29 | res.render('back/index', Object.assign({ |
30 | module: 'passport', | 30 | module: 'passport', |
@@ -43,7 +43,7 @@ const validateInputAPI = (req, res, next) => { | @@ -43,7 +43,7 @@ const validateInputAPI = (req, res, next) => { | ||
43 | let userInput = req.body.phoneNum || ''; | 43 | let userInput = req.body.phoneNum || ''; |
44 | let areaCode = (req.body.area || '86').replace('+', ''); | 44 | let areaCode = (req.body.area || '86').replace('+', ''); |
45 | 45 | ||
46 | - service.validateEmailOrMobileAsync(userInput, areaCode) | 46 | + req.ctx(BackService).validateEmailOrMobileAsync(userInput, areaCode) |
47 | .then(result => { | 47 | .then(result => { |
48 | req.inputInfo = result; | 48 | req.inputInfo = result; |
49 | next(); | 49 | next(); |
@@ -63,7 +63,7 @@ const validateInputPage = (req, res, next) => { | @@ -63,7 +63,7 @@ const validateInputPage = (req, res, next) => { | ||
63 | let userInput = req.body.phoneNum || ''; | 63 | let userInput = req.body.phoneNum || ''; |
64 | let areaCode = (req.body.area || '86').replace('+', ''); | 64 | let areaCode = (req.body.area || '86').replace('+', ''); |
65 | 65 | ||
66 | - service.validateEmailOrMobileAsync(userInput, areaCode) | 66 | + req.ctx(BackService).validateEmailOrMobileAsync(userInput, areaCode) |
67 | .then(result => { | 67 | .then(result => { |
68 | req.inputInfo = result; | 68 | req.inputInfo = result; |
69 | next(); | 69 | next(); |
@@ -81,7 +81,7 @@ const getUserInfoAPI = (req, res, next) => { | @@ -81,7 +81,7 @@ const getUserInfoAPI = (req, res, next) => { | ||
81 | 81 | ||
82 | req.session.type = 'back-step1'; | 82 | req.session.type = 'back-step1'; |
83 | 83 | ||
84 | - service.findUserAsync(inputInfo.type, inputInfo.phone, inputInfo.area) | 84 | + req.ctx(BackService).findUserAsync(inputInfo.type, inputInfo.phone, inputInfo.area) |
85 | .then(result => { | 85 | .then(result => { |
86 | res.json(result); | 86 | res.json(result); |
87 | }) | 87 | }) |
@@ -96,7 +96,7 @@ const sendCodePage = (req, res, next) => { | @@ -96,7 +96,7 @@ const sendCodePage = (req, res, next) => { | ||
96 | let inputInfo = req.inputInfo; | 96 | let inputInfo = req.inputInfo; |
97 | 97 | ||
98 | req.session.type = 'back-step1'; | 98 | req.session.type = 'back-step1'; |
99 | - service.sendCodeToUserAsync(inputInfo.type, inputInfo.phone, inputInfo.area) | 99 | + req.ctx(BackService).sendCodeToUserAsync(inputInfo.type, inputInfo.phone, inputInfo.area) |
100 | .then(result => { | 100 | .then(result => { |
101 | if (!(result.code && result.code === 200)) { | 101 | if (!(result.code && result.code === 200)) { |
102 | return res.json({ | 102 | return res.json({ |
@@ -160,7 +160,7 @@ const sendBackMobileAPI = (req, res, next) => { | @@ -160,7 +160,7 @@ const sendBackMobileAPI = (req, res, next) => { | ||
160 | let mobile = req.body.mobile || ''; | 160 | let mobile = req.body.mobile || ''; |
161 | let area = req.body.area || '86'; | 161 | let area = req.body.area || '86'; |
162 | 162 | ||
163 | - service.sendCodeToMobileAsync(area, mobile) | 163 | + req.ctx(BackService).sendCodeToMobileAsync(area, mobile) |
164 | .then(result => { | 164 | .then(result => { |
165 | res.json(result); | 165 | res.json(result); |
166 | }) | 166 | }) |
@@ -230,7 +230,7 @@ const validateCodeByEmailPage = (req, res, next) => { | @@ -230,7 +230,7 @@ const validateCodeByEmailPage = (req, res, next) => { | ||
230 | return next(); | 230 | return next(); |
231 | } | 231 | } |
232 | 232 | ||
233 | - service.checkEmailCodeAsync(code) | 233 | + req.ctx(BackService).checkEmailCodeAsync(code) |
234 | .then(result => { | 234 | .then(result => { |
235 | if (!result) { | 235 | if (!result) { |
236 | return res.redirect(helpers.urlFormat('/passport/back/index')); | 236 | return res.redirect(helpers.urlFormat('/passport/back/index')); |
@@ -338,7 +338,7 @@ const verifyCodeByMobileAPI = (req, res) => { | @@ -338,7 +338,7 @@ const verifyCodeByMobileAPI = (req, res) => { | ||
338 | return res.json(ERR); | 338 | return res.json(ERR); |
339 | } | 339 | } |
340 | 340 | ||
341 | - service.verifyCodyByMobileAsync(area, mobile, mobileCode) | 341 | + req.ctx(BackService).verifyCodyByMobileAsync(area, mobile, mobileCode) |
342 | .then(result => { | 342 | .then(result => { |
343 | res.json(result); | 343 | res.json(result); |
344 | }) | 344 | }) |
@@ -377,7 +377,7 @@ const validateCodeByMobilePage = (req, res, next) => { | @@ -377,7 +377,7 @@ const validateCodeByMobilePage = (req, res, next) => { | ||
377 | }; | 377 | }; |
378 | 378 | ||
379 | code = new Buffer(code, 'base64').toString(); | 379 | code = new Buffer(code, 'base64').toString(); |
380 | - req.mobileAuth = service.authRequest(data, code); | 380 | + req.mobileAuth = req.ctx(BackService).authRequest(data, code); |
381 | 381 | ||
382 | next(); | 382 | next(); |
383 | }; | 383 | }; |
@@ -397,7 +397,7 @@ const updatePwdAPI = (req, res, next) => { | @@ -397,7 +397,7 @@ const updatePwdAPI = (req, res, next) => { | ||
397 | let mobileAuth = req.mobileAuth || {}; | 397 | let mobileAuth = req.mobileAuth || {}; |
398 | let newPassword = req.body.pwd || ''; | 398 | let newPassword = req.body.pwd || ''; |
399 | 399 | ||
400 | - service.updatePwdAsync(code, mobileAuth, newPassword) | 400 | + req.ctx(BackService).updatePwdAsync(code, mobileAuth, newPassword) |
401 | .then(result => { | 401 | .then(result => { |
402 | if (result.status) { | 402 | if (result.status) { |
403 | req.session.successType = result.type; | 403 | req.session.successType = result.type; |
@@ -470,7 +470,7 @@ const weakPwdSuccessPage = (req, res, next) => { | @@ -470,7 +470,7 @@ const weakPwdSuccessPage = (req, res, next) => { | ||
470 | const modPwdByCodeAPI = (req, res, next) => { | 470 | const modPwdByCodeAPI = (req, res, next) => { |
471 | let body = req.body; | 471 | let body = req.body; |
472 | 472 | ||
473 | - service.modPwdByCodeAsync({ | 473 | + req.ctx(BackService).modPwdByCodeAsync({ |
474 | uid: req.user.uid, | 474 | uid: req.user.uid, |
475 | oldPwd: body.oldPwd, | 475 | oldPwd: body.oldPwd, |
476 | newPwd: body.newPwd, | 476 | newPwd: body.newPwd, |
@@ -9,9 +9,9 @@ | @@ -9,9 +9,9 @@ | ||
9 | const _ = require('lodash'); | 9 | const _ = require('lodash'); |
10 | const helpers = global.yoho.helpers; | 10 | const helpers = global.yoho.helpers; |
11 | const passportHelper = require('../models/passport-helper'); | 11 | const passportHelper = require('../models/passport-helper'); |
12 | -const bindService = require('../models/bind-service'); | ||
13 | -const loginService = require('../models/login-service'); | ||
14 | -const userService = require('../models/user-service'); | 12 | +const BindService = require('../models/bind-service'); |
13 | +const LoginService = require('../models/login-service'); | ||
14 | +const UserService = require('../models/user-service'); | ||
15 | 15 | ||
16 | // const UserService = require('../models/user-service'); | 16 | // const UserService = require('../models/user-service'); |
17 | const simpleHeaderModel = require('../../../doraemon/models/simple-header'); | 17 | const simpleHeaderModel = require('../../../doraemon/models/simple-header'); |
@@ -77,19 +77,7 @@ const bind = { | @@ -77,19 +77,7 @@ const bind = { | ||
77 | return next(); | 77 | return next(); |
78 | } | 78 | } |
79 | 79 | ||
80 | - // UserService.findByMobileAsync(area, mobile).then(user => { | ||
81 | - // if (user) { | ||
82 | - // return { | ||
83 | - // thumb: user.headImg, | ||
84 | - // userName: user.username, | ||
85 | - // loginHref: user.bindLogin | ||
86 | - // }; | ||
87 | - // } else { | ||
88 | - // return {}; | ||
89 | - // } | ||
90 | - // }) | ||
91 | - | ||
92 | - userService.getUserInfo(area, mobile).then(user => { | 80 | + req.ctx(UserService).getUserInfo(area, mobile).then(user => { |
93 | let data = _.assign(user, { | 81 | let data = _.assign(user, { |
94 | phoneNum: mobile, | 82 | phoneNum: mobile, |
95 | areaCode: area, | 83 | areaCode: area, |
@@ -125,8 +113,8 @@ const bind = { | @@ -125,8 +113,8 @@ const bind = { | ||
125 | 113 | ||
126 | res.render('bind/success', data); | 114 | res.render('bind/success', data); |
127 | }, | 115 | }, |
128 | - _bindCheck: (mobile, openId, area, sourceType) => { | ||
129 | - return bindService.bindCheck(mobile, openId, sourceType, area).then(result => { | 116 | + _bindCheck: (req, mobile, openId, area, sourceType) => { |
117 | + return req.ctx(BindService).bindCheck(mobile, openId, sourceType, area).then(result => { | ||
130 | if (!result || !result.code) { | 118 | if (!result || !result.code) { |
131 | return {code: 400, message: '', data: ''}; | 119 | return {code: 400, message: '', data: ''}; |
132 | } else if (result.code === 200 && result.data.is_register === 0) { | 120 | } else if (result.code === 200 && result.data.is_register === 0) { |
@@ -135,17 +123,17 @@ const bind = { | @@ -135,17 +123,17 @@ const bind = { | ||
135 | // 绑定流程:code=200 未注册,可绑定 | 123 | // 绑定流程:code=200 未注册,可绑定 |
136 | return {code: 200, message: result.message, data: {next: nextUrl}}; | 124 | return {code: 200, message: result.message, data: {next: nextUrl}}; |
137 | } else if (result.code === 200 && result.data.is_register === 1) { | 125 | } else if (result.code === 200 && result.data.is_register === 1) { |
138 | - return userService.getUserInfo(area, mobile).then(user => { | 126 | + return req.ctx(UserService).getUserInfo(area, mobile).then(user => { |
139 | // 绑定流程:code=201 已注册 绑定过其他第三方 | 127 | // 绑定流程:code=201 已注册 绑定过其他第三方 |
140 | return {code: 201, message: result.message, data: {user: user}}; | 128 | return {code: 201, message: result.message, data: {user: user}}; |
141 | }); | 129 | }); |
142 | } else if (result.code === 200 && result.data.is_register === 3) { | 130 | } else if (result.code === 200 && result.data.is_register === 3) { |
143 | // 关联流程 | 131 | // 关联流程 |
144 | - return userService.getUserInfo(area, mobile).then(user => { | 132 | + return req.ctx(UserService).getUserInfo(area, mobile).then(user => { |
145 | return {code: 203, message: result.message, data: {user: user}}; | 133 | return {code: 203, message: result.message, data: {user: user}}; |
146 | }); | 134 | }); |
147 | } else if (result.code === 506 || result.code === 505) { | 135 | } else if (result.code === 506 || result.code === 505) { |
148 | - return userService.getUserInfo(area, mobile).then(user => { | 136 | + return req.ctx(UserService).getUserInfo(area, mobile).then(user => { |
149 | // 绑定流程:code=506 手机号码注册过,而且该手机号码也已经绑定过该类型第三方 | 137 | // 绑定流程:code=506 手机号码注册过,而且该手机号码也已经绑定过该类型第三方 |
150 | // code=505 手机号码注册过,而且该第三方也已经绑定过手机号 | 138 | // code=505 手机号码注册过,而且该第三方也已经绑定过手机号 |
151 | return {code: 205, message: result.message, data: {user: user}}; | 139 | return {code: 205, message: result.message, data: {user: user}}; |
@@ -176,7 +164,7 @@ const bind = { | @@ -176,7 +164,7 @@ const bind = { | ||
176 | * code:506 // 手机号码注册过,而且该手机号码也已经绑定过该类型第三方 | 164 | * code:506 // 手机号码注册过,而且该手机号码也已经绑定过该类型第三方 |
177 | */ | 165 | */ |
178 | 166 | ||
179 | - bind._bindCheck(mobile, openId, area, sourceType).then(result => { | 167 | + bind._bindCheck(req, mobile, openId, area, sourceType).then(result => { |
180 | return res.json(result); | 168 | return res.json(result); |
181 | }).catch(next); | 169 | }).catch(next); |
182 | } else { | 170 | } else { |
@@ -207,7 +195,7 @@ const bind = { | @@ -207,7 +195,7 @@ const bind = { | ||
207 | */ | 195 | */ |
208 | bind._bindCheck(mobile, openId, area, sourceType).then(result => { | 196 | bind._bindCheck(mobile, openId, area, sourceType).then(result => { |
209 | if (result.code === 201) { | 197 | if (result.code === 201) { |
210 | - bindService.sendBindMsg(area, mobile).then(d => { | 198 | + req.ctx(BindService).sendBindMsg(area, mobile).then(d => { |
211 | if (d && d.code) { | 199 | if (d && d.code) { |
212 | return res.json(result); | 200 | return res.json(result); |
213 | } else { | 201 | } else { |
@@ -230,7 +218,7 @@ const bind = { | @@ -230,7 +218,7 @@ const bind = { | ||
230 | return res.json({code: 400, message: '非法请求'}); | 218 | return res.json({code: 400, message: '非法请求'}); |
231 | } | 219 | } |
232 | 220 | ||
233 | - bindService.sendBindMsg(area, mobile).then(result => { | 221 | + req.ctx(BindService).sendBindMsg(area, mobile).then(result => { |
234 | if (result && result.code) { | 222 | if (result && result.code) { |
235 | return res.json(result); | 223 | return res.json(result); |
236 | } else { | 224 | } else { |
@@ -243,7 +231,7 @@ const bind = { | @@ -243,7 +231,7 @@ const bind = { | ||
243 | let area = req.body.area; | 231 | let area = req.body.area; |
244 | let code = req.body.code; | 232 | let code = req.body.code; |
245 | 233 | ||
246 | - bindService.checkBindCode(area, mobile, code).then(result => { | 234 | + req.ctx(BindService).checkBindCode(area, mobile, code).then(result => { |
247 | if (result && result.code) { | 235 | if (result && result.code) { |
248 | return res.json(result); | 236 | return res.json(result); |
249 | } else { | 237 | } else { |
@@ -259,11 +247,11 @@ const bind = { | @@ -259,11 +247,11 @@ const bind = { | ||
259 | let code = _.trim(req.body.code); | 247 | let code = _.trim(req.body.code); |
260 | let password = _.trim(req.body.password) || ''; | 248 | let password = _.trim(req.body.password) || ''; |
261 | 249 | ||
262 | - bindService.checkBindCode(area, mobile, code).then(result => { | 250 | + req.ctx(BindService).checkBindCode(area, mobile, code).then(result => { |
263 | if (result && result.code !== 200) { | 251 | if (result && result.code !== 200) { |
264 | return {code: 402, message: '短信验证码不正确', data: ''}; | 252 | return {code: 402, message: '短信验证码不正确', data: ''}; |
265 | } else { | 253 | } else { |
266 | - return bindService.bindMobile(openId, sourceType, mobile, area, password); | 254 | + return req.ctx(BindService).bindMobile(openId, sourceType, mobile, area, password); |
267 | } | 255 | } |
268 | }).then(result => { | 256 | }).then(result => { |
269 | if (result && result.code) { | 257 | if (result && result.code) { |
@@ -272,7 +260,7 @@ const bind = { | @@ -272,7 +260,7 @@ const bind = { | ||
272 | sourceType: sourceType + '_bind' | 260 | sourceType: sourceType + '_bind' |
273 | }); | 261 | }); |
274 | 262 | ||
275 | - return loginService.syncUserSession(result.data, req, res).then(() => { | 263 | + return req.ctx(LoginService).syncUserSession(result.data, req, res).then(() => { |
276 | return {code: 200, message: result.message, data: {refer: refer}}; | 264 | return {code: 200, message: result.message, data: {refer: refer}}; |
277 | }); | 265 | }); |
278 | } else { | 266 | } else { |
@@ -293,9 +281,9 @@ const bind = { | @@ -293,9 +281,9 @@ const bind = { | ||
293 | let code = req.body.code; | 281 | let code = req.body.code; |
294 | 282 | ||
295 | if (_.toNumber(mobile) && openId && areaCode && sourceType && code) { | 283 | if (_.toNumber(mobile) && openId && areaCode && sourceType && code) { |
296 | - bindService.checkBindCode(areaCode, mobile, code).then(result => { | 284 | + req.ctx(BindService).checkBindCode(areaCode, mobile, code).then(result => { |
297 | if (result && result.code && result.code === 200) { | 285 | if (result && result.code && result.code === 200) { |
298 | - return bindService.relateMobile(openId, sourceType, mobile, areaCode); | 286 | + return req.ctx(BindService).relateMobile(openId, sourceType, mobile, areaCode); |
299 | } else { | 287 | } else { |
300 | return {code: 402, message: '短信验证码错误', data: ''}; | 288 | return {code: 402, message: '短信验证码错误', data: ''}; |
301 | } | 289 | } |
@@ -306,7 +294,7 @@ const bind = { | @@ -306,7 +294,7 @@ const bind = { | ||
306 | sourceType: sourceType + '_relate' | 294 | sourceType: sourceType + '_relate' |
307 | }); | 295 | }); |
308 | 296 | ||
309 | - return loginService.syncUserSession( | 297 | + return req.ctx(LoginService).syncUserSession( |
310 | result.data, | 298 | result.data, |
311 | req, | 299 | req, |
312 | res | 300 | res |
@@ -9,8 +9,8 @@ | @@ -9,8 +9,8 @@ | ||
9 | const _ = require('lodash'); | 9 | const _ = require('lodash'); |
10 | const helpers = global.yoho.helpers; | 10 | const helpers = global.yoho.helpers; |
11 | const passportHelper = require('../models/passport-helper'); | 11 | const passportHelper = require('../models/passport-helper'); |
12 | -const certService = require('../models/cert-service'); | ||
13 | -const userService = require('../models/user-service'); | 12 | +const CertService = require('../models/cert-service'); |
13 | +const UserService = require('../models/user-service'); | ||
14 | const simpleHeaderModel = require('../../../doraemon/models/simple-header'); | 14 | const simpleHeaderModel = require('../../../doraemon/models/simple-header'); |
15 | const config = global.yoho.config; | 15 | const config = global.yoho.config; |
16 | 16 | ||
@@ -28,7 +28,7 @@ const cert = { | @@ -28,7 +28,7 @@ const cert = { | ||
28 | return res.send(req.query.callback + '(' + JSON.stringify(dest) + ')'); | 28 | return res.send(req.query.callback + '(' + JSON.stringify(dest) + ')'); |
29 | } | 29 | } |
30 | 30 | ||
31 | - certService.checkEmailCertTip(uid) | 31 | + req.ctx(CertService).checkEmailCertTip(uid) |
32 | .then(ret => { | 32 | .then(ret => { |
33 | dest.data = _.get(ret, 'data.isBindedOrRelated') === 'N' ? 'Y' : 'N'; | 33 | dest.data = _.get(ret, 'data.isBindedOrRelated') === 'N' ? 'Y' : 'N'; |
34 | res.type('text/javascript'); | 34 | res.type('text/javascript'); |
@@ -87,7 +87,7 @@ const cert = { | @@ -87,7 +87,7 @@ const cert = { | ||
87 | let area = req.body.area; | 87 | let area = req.body.area; |
88 | let refer = req.body.refer; | 88 | let refer = req.body.refer; |
89 | 89 | ||
90 | - userService.getUserInfo(area, mobile).then(user => { | 90 | + req.ctx(UserService).getUserInfo(area, mobile).then(user => { |
91 | let data = _.assign(user, { | 91 | let data = _.assign(user, { |
92 | phoneNum: mobile, | 92 | phoneNum: mobile, |
93 | areaCode: area, | 93 | areaCode: area, |
@@ -131,7 +131,7 @@ const cert = { | @@ -131,7 +131,7 @@ const cert = { | ||
131 | * code:200,isCanBind=Y // 不可绑定 | 131 | * code:200,isCanBind=Y // 不可绑定 |
132 | */ | 132 | */ |
133 | 133 | ||
134 | - certService.certCheck(mobile, area).then(result => { | 134 | + req.ctx(CertService).certCheck(mobile, area).then(result => { |
135 | if (!result || !result.code) { | 135 | if (!result || !result.code) { |
136 | return {code: 400, message: '', data: ''}; | 136 | return {code: 400, message: '', data: ''}; |
137 | } else if (result.code === 200) { | 137 | } else if (result.code === 200) { |
@@ -158,7 +158,7 @@ const cert = { | @@ -158,7 +158,7 @@ const cert = { | ||
158 | let mobile = req.body.mobile; | 158 | let mobile = req.body.mobile; |
159 | let area = req.body.area; | 159 | let area = req.body.area; |
160 | 160 | ||
161 | - certService.sendCertMsg(mobile, area).then(result => { | 161 | + req.ctx(CertService).sendCertMsg(mobile, area).then(result => { |
162 | if (result && result.code) { | 162 | if (result && result.code) { |
163 | return res.json(result); | 163 | return res.json(result); |
164 | } else { | 164 | } else { |
@@ -174,7 +174,7 @@ const cert = { | @@ -174,7 +174,7 @@ const cert = { | ||
174 | let code = _.trim(req.body.code); | 174 | let code = _.trim(req.body.code); |
175 | let refer = req.body.refer; | 175 | let refer = req.body.refer; |
176 | 176 | ||
177 | - certService.certMobile(uid, mobile, code, area).then(result => { | 177 | + req.ctx(CertService).certMobile(uid, mobile, code, area).then(result => { |
178 | 178 | ||
179 | if (result && result.code === 200) { | 179 | if (result && result.code === 200) { |
180 | let url = helpers.urlFormat('/passport/cert/success', { | 180 | let url = helpers.urlFormat('/passport/cert/success', { |
@@ -207,7 +207,7 @@ const cert = { | @@ -207,7 +207,7 @@ const cert = { | ||
207 | let refer = req.body.refer; | 207 | let refer = req.body.refer; |
208 | let email; | 208 | let email; |
209 | 209 | ||
210 | - userService.profile(uid).then(info => { | 210 | + req.ctx(UserService).profile(uid).then(info => { |
211 | if (info && info.code === 200) { | 211 | if (info && info.code === 200) { |
212 | email = _.get(info, 'data.email'); | 212 | email = _.get(info, 'data.email'); |
213 | } else { | 213 | } else { |
@@ -217,7 +217,7 @@ const cert = { | @@ -217,7 +217,7 @@ const cert = { | ||
217 | }); | 217 | }); |
218 | } | 218 | } |
219 | 219 | ||
220 | - certService.relateMobile(uid, email, code, mobile, area).then(result => { | 220 | + req.ctx(CertService).relateMobile(uid, email, code, mobile, area).then(result => { |
221 | if (result && result.code === 200) { | 221 | if (result && result.code === 200) { |
222 | let url = helpers.urlFormat('/passport/cert/success', { | 222 | let url = helpers.urlFormat('/passport/cert/success', { |
223 | type: 'relate', | 223 | type: 'relate', |
@@ -17,7 +17,7 @@ const helpers = global.yoho.helpers; | @@ -17,7 +17,7 @@ const helpers = global.yoho.helpers; | ||
17 | const log = global.yoho.logger; | 17 | const log = global.yoho.logger; |
18 | const config = global.yoho.config; | 18 | const config = global.yoho.config; |
19 | const cache = global.yoho.cache; | 19 | const cache = global.yoho.cache; |
20 | -const loginService = require('../models/login-service'); | 20 | +const LoginService = require('../models/login-service'); |
21 | const referWhiteListService = require('../models/refer-service'); | 21 | const referWhiteListService = require('../models/refer-service'); |
22 | const PassportHelper = require('../models/passport-helper'); | 22 | const PassportHelper = require('../models/passport-helper'); |
23 | const simpleHeaderModel = require('../../../doraemon/models/simple-header'); | 23 | const simpleHeaderModel = require('../../../doraemon/models/simple-header'); |
@@ -54,7 +54,7 @@ function doPassportCallback(req, res, user) { | @@ -54,7 +54,7 @@ function doPassportCallback(req, res, user) { | ||
54 | user.openId = user.unionId; | 54 | user.openId = user.unionId; |
55 | } | 55 | } |
56 | 56 | ||
57 | - return loginService.signinByOpenID(user.nickname, user.openId, user.sourceType, shoppingKey) | 57 | + return req.ctx(LoginService).signinByOpenID(user.nickname, user.openId, user.sourceType, shoppingKey) |
58 | .then((result) => { | 58 | .then((result) => { |
59 | if (result.code !== 200) { | 59 | if (result.code !== 200) { |
60 | return res.redirect(config.siteUrl); | 60 | return res.redirect(config.siteUrl); |
@@ -67,7 +67,7 @@ function doPassportCallback(req, res, user) { | @@ -67,7 +67,7 @@ function doPassportCallback(req, res, user) { | ||
67 | }); | 67 | }); |
68 | } else if (result.data['is_bind'] === 'Y' && result.data.uid) {//eslint-disable-line | 68 | } else if (result.data['is_bind'] === 'Y' && result.data.uid) {//eslint-disable-line |
69 | 69 | ||
70 | - return loginService.syncUserSession(result.data, req, res).then(() => { | 70 | + return req.ctx(LoginService).syncUserSession(result.data, req, res).then(() => { |
71 | return refer; | 71 | return refer; |
72 | }); | 72 | }); |
73 | } | 73 | } |
@@ -178,7 +178,7 @@ const local = { | @@ -178,7 +178,7 @@ const local = { | ||
178 | } | 178 | } |
179 | 179 | ||
180 | if (_.get(req.body, 'isRemember', 'false') === 'true') { | 180 | if (_.get(req.body, 'isRemember', 'false') === 'true') { |
181 | - loginService.rememberAccount({ | 181 | + req.ctx(LoginService).rememberAccount({ |
182 | area: req.body.areaCode || '86', | 182 | area: req.body.areaCode || '86', |
183 | account: req.body.account, | 183 | account: req.body.account, |
184 | password: req.body.password | 184 | password: req.body.password |
@@ -199,7 +199,7 @@ const local = { | @@ -199,7 +199,7 @@ const local = { | ||
199 | } | 199 | } |
200 | }()); | 200 | }()); |
201 | 201 | ||
202 | - loginService.syncUserSession(user, req, res).then((noCertTip) => { | 202 | + req.ctx(LoginService).syncUserSession(user, req, res).then((noCertTip) => { |
203 | // 弱密码 | 203 | // 弱密码 |
204 | if (user.code === 510) { | 204 | if (user.code === 510) { |
205 | refer = `${config.siteUrl}/passport/back/weak?refer=${refer}`; | 205 | refer = `${config.siteUrl}/passport/back/weak?refer=${refer}`; |
@@ -268,7 +268,7 @@ const local = { | @@ -268,7 +268,7 @@ const local = { | ||
268 | }); | 268 | }); |
269 | } | 269 | } |
270 | 270 | ||
271 | - loginService.sendPasswordBySMS(area, mobile).then((result) => { | 271 | + req.ctx(LoginService).sendPasswordBySMS(area, mobile).then((result) => { |
272 | return res.json(result); | 272 | return res.json(result); |
273 | }).then(() => { | 273 | }).then(() => { |
274 | req.session.captcha = 'yoho4946abcdef#$%&!@'; | 274 | req.session.captcha = 'yoho4946abcdef#$%&!@'; |
@@ -286,7 +286,7 @@ const local = { | @@ -286,7 +286,7 @@ const local = { | ||
286 | }); | 286 | }); |
287 | } | 287 | } |
288 | 288 | ||
289 | - loginService.verifyPasswordBySMS(area, mobile, code).then((result) => { | 289 | + req.ctx(LoginService).verifyPasswordBySMS(area, mobile, code).then((result) => { |
290 | if (_.get(result, 'code', 200) !== 200) { | 290 | if (_.get(result, 'code', 200) !== 200) { |
291 | return res.json(result); | 291 | return res.json(result); |
292 | } | 292 | } |
@@ -316,7 +316,7 @@ const local = { | @@ -316,7 +316,7 @@ const local = { | ||
316 | }); | 316 | }); |
317 | } | 317 | } |
318 | 318 | ||
319 | - loginService.checkUserExitBySMS(area, mobile).then((result) => { | 319 | + req.ctx(LoginService).checkUserExitBySMS(area, mobile).then((result) => { |
320 | if (_.get(result, 'code') !== 200) { | 320 | if (_.get(result, 'code') !== 200) { |
321 | return Promise.reject('check user by sms error'); | 321 | return Promise.reject('check user by sms error'); |
322 | } | 322 | } |
@@ -336,7 +336,7 @@ const local = { | @@ -336,7 +336,7 @@ const local = { | ||
336 | }, | 336 | }, |
337 | qrcode: { | 337 | qrcode: { |
338 | refresh: (req, res, next) => { | 338 | refresh: (req, res, next) => { |
339 | - loginService.fetchByQrCode().then((result) => { | 339 | + req.ctx(LoginService).fetchByQrCode().then((result) => { |
340 | if (result.code === 200) { | 340 | if (result.code === 200) { |
341 | return res.json({ | 341 | return res.json({ |
342 | code: 200, | 342 | code: 200, |
@@ -371,7 +371,7 @@ const local = { | @@ -371,7 +371,7 @@ const local = { | ||
371 | 371 | ||
372 | let token = decodeURIComponent(qrcode.substring(qrcode.indexOf('=') + 1)); | 372 | let token = decodeURIComponent(qrcode.substring(qrcode.indexOf('=') + 1)); |
373 | 373 | ||
374 | - loginService.checkByQrCode(token).then((result) => { | 374 | + req.ctx(LoginService).checkByQrCode(token).then((result) => { |
375 | if (_.isEmpty(result)) { | 375 | if (_.isEmpty(result)) { |
376 | return res.json({ | 376 | return res.json({ |
377 | code: 400, | 377 | code: 400, |
@@ -5,9 +5,9 @@ | @@ -5,9 +5,9 @@ | ||
5 | const _ = require('lodash'); | 5 | const _ = require('lodash'); |
6 | const Promise = require('bluebird'); | 6 | const Promise = require('bluebird'); |
7 | const passportHelper = require('../models/passport-helper'); | 7 | const passportHelper = require('../models/passport-helper'); |
8 | -const regService = require('../models/reg-service'); | ||
9 | -const userService = require('../models/user-service'); | ||
10 | -const loginService = require('../models/login-service'); | 8 | +const RegService = require('../models/reg-service'); |
9 | +const UserService = require('../models/user-service'); | ||
10 | +const LoginService = require('../models/login-service'); | ||
11 | const config = require('../../../config/common'); | 11 | const config = require('../../../config/common'); |
12 | const simpleHeaderModel = require('../../../doraemon/models/simple-header'); | 12 | const simpleHeaderModel = require('../../../doraemon/models/simple-header'); |
13 | let helpers = global.yoho.helpers; | 13 | let helpers = global.yoho.helpers; |
@@ -76,7 +76,7 @@ let index = (req, res, next) => { | @@ -76,7 +76,7 @@ let index = (req, res, next) => { | ||
76 | domain: config.cookieDomain | 76 | domain: config.cookieDomain |
77 | }); | 77 | }); |
78 | 78 | ||
79 | - regService.getRegData().then((result) => { | 79 | + req.ctx(RegService).getRegData().then((result) => { |
80 | res.render('reg/index', { | 80 | res.render('reg/index', { |
81 | simpleHeader: simpleHeaderModel.setSimpleHeaderData(), | 81 | simpleHeader: simpleHeaderModel.setSimpleHeaderData(), |
82 | title: '新用户注册', | 82 | title: '新用户注册', |
@@ -125,7 +125,7 @@ let checkMobile = (req, res, next) => { | @@ -125,7 +125,7 @@ let checkMobile = (req, res, next) => { | ||
125 | } | 125 | } |
126 | 126 | ||
127 | // 判断用户是否存在 | 127 | // 判断用户是否存在 |
128 | - return userService.findByMobileAsync(area, mobile).then((user) => { | 128 | + return req.ctx(UserService).findByMobileAsync(area, mobile).then((user) => { |
129 | if (!_.isEmpty(user)) { | 129 | if (!_.isEmpty(user)) { |
130 | data.message = '手机号码已经存在'; | 130 | data.message = '手机号码已经存在'; |
131 | return res.json(data); | 131 | return res.json(data); |
@@ -182,7 +182,7 @@ let sendBindMsg = (req, res, next) => { | @@ -182,7 +182,7 @@ let sendBindMsg = (req, res, next) => { | ||
182 | } | 182 | } |
183 | 183 | ||
184 | /* 向手机发送注册验证码 */ | 184 | /* 向手机发送注册验证码 */ |
185 | - let result = yield regService.sendCodeToMobile(area, mobile); | 185 | + let result = yield req.ctx(RegService).sendCodeToMobile(area, mobile); |
186 | 186 | ||
187 | req.session.type = 'register-step1'; | 187 | req.session.type = 'register-step1'; |
188 | 188 | ||
@@ -210,7 +210,7 @@ let msgCaptcha = (req, res, next) => { | @@ -210,7 +210,7 @@ let msgCaptcha = (req, res, next) => { | ||
210 | let mobile = req.body.mobile; | 210 | let mobile = req.body.mobile; |
211 | let code = req.body.code; // 短信验证码 | 211 | let code = req.body.code; // 短信验证码 |
212 | 212 | ||
213 | - regService.validMobileCode(area, mobile, code).then((result) => { | 213 | + req.ctx(RegService).validMobileCode(area, mobile, code).then((result) => { |
214 | if (result.code) { | 214 | if (result.code) { |
215 | return res.json(result); | 215 | return res.json(result); |
216 | } else { | 216 | } else { |
@@ -266,7 +266,7 @@ let mobileRegister = (req, res, next) => { | @@ -266,7 +266,7 @@ let mobileRegister = (req, res, next) => { | ||
266 | let password = req.body.password; | 266 | let password = req.body.password; |
267 | let inviteCode = req.body.inviteCode; | 267 | let inviteCode = req.body.inviteCode; |
268 | let clientIp = req.yoho.clientIp; | 268 | let clientIp = req.yoho.clientIp; |
269 | - let result = yield regService.validMobileCode(area, mobile, code); // 验证注册的标识码是否有效 | 269 | + let result = yield req.ctx(RegService).validMobileCode(area, mobile, code); // 验证注册的标识码是否有效 |
270 | 270 | ||
271 | if (!result.code || result.code !== 200) { | 271 | if (!result.code || result.code !== 200) { |
272 | data.message = '验证码错误'; | 272 | data.message = '验证码错误'; |
@@ -274,7 +274,7 @@ let mobileRegister = (req, res, next) => { | @@ -274,7 +274,7 @@ let mobileRegister = (req, res, next) => { | ||
274 | } | 274 | } |
275 | 275 | ||
276 | /* 手机注册: 调用注册接口*/ | 276 | /* 手机注册: 调用注册接口*/ |
277 | - let regResult = yield regService.regMobileAes( | 277 | + let regResult = yield req.ctx(RegService).regMobileAes( |
278 | area, mobile, password, code, cookie.getShoppingKey(req), inviteCode, clientIp | 278 | area, mobile, password, code, cookie.getShoppingKey(req), inviteCode, clientIp |
279 | ); | 279 | ); |
280 | 280 | ||
@@ -286,7 +286,7 @@ let mobileRegister = (req, res, next) => { | @@ -286,7 +286,7 @@ let mobileRegister = (req, res, next) => { | ||
286 | // 清除 session type | 286 | // 清除 session type |
287 | req.session.type = ''; | 287 | req.session.type = ''; |
288 | 288 | ||
289 | - return loginService.syncUserSession(regResult.data, req, res).then(() => { | 289 | + return req.ctx(LoginService).syncUserSession(regResult.data, req, res).then(() => { |
290 | return res.json({ | 290 | return res.json({ |
291 | code: 200, | 291 | code: 200, |
292 | message: '注册成功', | 292 | message: '注册成功', |
@@ -305,7 +305,7 @@ let success = (req, res, next) => { | @@ -305,7 +305,7 @@ let success = (req, res, next) => { | ||
305 | let goUrl = req.query.next || config.siteUrl; | 305 | let goUrl = req.query.next || config.siteUrl; |
306 | let goShoppingUrl = req.query.goShoppingUrl || config.siteUrl; | 306 | let goShoppingUrl = req.query.goShoppingUrl || config.siteUrl; |
307 | 307 | ||
308 | - regService.getRegData().then((result) => { | 308 | + req.ctx(RegService).getRegData().then((result) => { |
309 | res.render('reg/success', { | 309 | res.render('reg/success', { |
310 | title: '注册成功', | 310 | title: '注册成功', |
311 | module: 'passport', | 311 | module: 'passport', |
@@ -4,16 +4,22 @@ | @@ -4,16 +4,22 @@ | ||
4 | 4 | ||
5 | 'use strict'; | 5 | 'use strict'; |
6 | 6 | ||
7 | -const api = global.yoho.API; | ||
8 | const aes = require('./aes-pwd'); | 7 | const aes = require('./aes-pwd'); |
9 | const YOHOBUY_URL = 'https//www.yohobuy.com/'; | 8 | const YOHOBUY_URL = 'https//www.yohobuy.com/'; |
10 | 9 | ||
11 | -/** | 10 | +module.exports = class extends global.yoho.BaseModel { |
11 | + constructor(ctx) { | ||
12 | + super(ctx); | ||
13 | + } | ||
14 | + | ||
15 | + /** | ||
12 | * 获取地区数据 | 16 | * 获取地区数据 |
13 | */ | 17 | */ |
14 | -const getAreaDataAsync = () => { | ||
15 | - return api.get('', { | 18 | + getAreaDataAsync() { |
19 | + return this.get({ | ||
20 | + data: { | ||
16 | method: 'app.passport.getArea' | 21 | method: 'app.passport.getArea' |
22 | + } | ||
17 | }).then(result => { | 23 | }).then(result => { |
18 | result.data = result.data.map(value => { | 24 | result.data = result.data.map(value => { |
19 | value.areaCode = `+${value.area}`; | 25 | value.areaCode = `+${value.area}`; |
@@ -30,27 +36,29 @@ const getAreaDataAsync = () => { | @@ -30,27 +36,29 @@ const getAreaDataAsync = () => { | ||
30 | 36 | ||
31 | return result; | 37 | return result; |
32 | }); | 38 | }); |
33 | -}; | 39 | + } |
34 | 40 | ||
35 | -/** | 41 | + /** |
36 | * 通过邮箱找回密码 | 42 | * 通过邮箱找回密码 |
37 | * | 43 | * |
38 | * @param string mail 邮箱地址 | 44 | * @param string mail 邮箱地址 |
39 | */ | 45 | */ |
40 | -const sendCodeToEmailAsync = (email) => { | ||
41 | - return api.get('', { | 46 | + sendCodeToEmailAsync(email) { |
47 | + return this.get({ | ||
48 | + data: { | ||
42 | method: 'app.register.backpwdByEmail', | 49 | method: 'app.register.backpwdByEmail', |
43 | email: email | 50 | email: email |
51 | + } | ||
44 | }); | 52 | }); |
45 | -}; | 53 | + } |
46 | 54 | ||
47 | -/** | 55 | + /** |
48 | * 根据邮箱验证码修改密码(调用www.yohobuy.com接口) | 56 | * 根据邮箱验证码修改密码(调用www.yohobuy.com接口) |
49 | * | 57 | * |
50 | * @param string pwd 新密码 | 58 | * @param string pwd 新密码 |
51 | * @param string code 邮箱验证码 | 59 | * @param string code 邮箱验证码 |
52 | */ | 60 | */ |
53 | -const modifyPasswordByEmailAsync = (pwd, code) => { | 61 | + modifyPasswordByEmailAsync(pwd, code) { |
54 | const options = { | 62 | const options = { |
55 | url: `${YOHOBUY_URL}passport/back/update`, | 63 | url: `${YOHOBUY_URL}passport/back/update`, |
56 | form: { | 64 | form: { |
@@ -61,124 +69,127 @@ const modifyPasswordByEmailAsync = (pwd, code) => { | @@ -61,124 +69,127 @@ const modifyPasswordByEmailAsync = (pwd, code) => { | ||
61 | timeout: 3000 | 69 | timeout: 3000 |
62 | }; | 70 | }; |
63 | 71 | ||
64 | - return api._requestFromAPI(options); | ||
65 | -}; | 72 | + return this._requestFromAPI(options); |
73 | + } | ||
66 | 74 | ||
67 | -/** | 75 | + /** |
68 | * 通过手机找回密码 | 76 | * 通过手机找回密码 |
69 | * | 77 | * |
70 | * @param string mobile 手机号 | 78 | * @param string mobile 手机号 |
71 | * @param integer area 地区码ID | 79 | * @param integer area 地区码ID |
72 | */ | 80 | */ |
73 | -const sendCodeToMobileAsync = (mobile, area) => { | ||
74 | - return api.get('', { | 81 | + sendCodeToMobileAsync(mobile, area) { |
82 | + return this.get({ | ||
83 | + data: { | ||
75 | mobile: mobile, | 84 | mobile: mobile, |
76 | area: area, | 85 | area: area, |
77 | method: 'app.register.sendBackpwdCodeToMobile' | 86 | method: 'app.register.sendBackpwdCodeToMobile' |
87 | + } | ||
78 | }); | 88 | }); |
79 | -}; | 89 | + } |
80 | 90 | ||
81 | -/** | 91 | + /** |
82 | * 校验密码修改手机验证码 | 92 | * 校验密码修改手机验证码 |
83 | * | 93 | * |
84 | * @param string mobile 手机号 | 94 | * @param string mobile 手机号 |
85 | * @param string code 验证码 | 95 | * @param string code 验证码 |
86 | * @param integer area 地区码ID | 96 | * @param integer area 地区码ID |
87 | */ | 97 | */ |
88 | -const validateMobileCodeAsync = (mobile, code, area) => { | 98 | + validateMobileCodeAsync(mobile, code, area) { |
89 | area = area || 86; | 99 | area = area || 86; |
90 | - return api.get('', { | 100 | + return this.get({ |
101 | + data: { | ||
91 | mobile: mobile, | 102 | mobile: mobile, |
92 | code: code, | 103 | code: code, |
93 | area: area, | 104 | area: area, |
94 | method: 'app.register.validBackpwdCode' | 105 | method: 'app.register.validBackpwdCode' |
106 | + } | ||
95 | }); | 107 | }); |
96 | -}; | 108 | + } |
97 | 109 | ||
98 | -/** | 110 | + /** |
99 | * 根据手机验证码修改密码 | 111 | * 根据手机验证码修改密码 |
100 | * | 112 | * |
101 | * @param string mobile 手机号 | 113 | * @param string mobile 手机号 |
102 | * @param string token 验证手机验证码返回的token | 114 | * @param string token 验证手机验证码返回的token |
103 | * @param integer area 地区码ID | 115 | * @param integer area 地区码ID |
104 | */ | 116 | */ |
105 | -const modifyPasswordByMobileAsync = (mobile, token, newpwd, area)=> { | ||
106 | - return api.get('', { | 117 | + modifyPasswordByMobileAsync(mobile, token, newpwd, area) { |
118 | + return this.get({ | ||
119 | + data: { | ||
107 | mobile: mobile, | 120 | mobile: mobile, |
108 | token: token, | 121 | token: token, |
109 | newpwd: newpwd, | 122 | newpwd: newpwd, |
110 | area: area, | 123 | area: area, |
111 | method: 'app.register.changepwdByMobileCode' | 124 | method: 'app.register.changepwdByMobileCode' |
125 | + } | ||
112 | }); | 126 | }); |
113 | -}; | 127 | + } |
114 | 128 | ||
115 | -/** | 129 | + /** |
116 | * 根据手机验证码修改密码(密码AES加密) | 130 | * 根据手机验证码修改密码(密码AES加密) |
117 | * | 131 | * |
118 | * @param string mobile 手机号 | 132 | * @param string mobile 手机号 |
119 | * @param string token 验证手机验证码返回的token | 133 | * @param string token 验证手机验证码返回的token |
120 | * @param integer area 地区码ID | 134 | * @param integer area 地区码ID |
121 | */ | 135 | */ |
122 | -const modifyPasswordByMobileAsyncAes = (mobile, token, newpwd, area)=> { | ||
123 | - return api.get('', { | 136 | + modifyPasswordByMobileAsyncAes(mobile, token, newpwd, area) { |
137 | + return this.get({ | ||
138 | + data: { | ||
124 | mobile: mobile, | 139 | mobile: mobile, |
125 | token: token, | 140 | token: token, |
126 | newpwd: aes.aesPwd(newpwd), | 141 | newpwd: aes.aesPwd(newpwd), |
127 | area: area, | 142 | area: area, |
128 | method: 'app.register.changepwdByMobileCodeAES' | 143 | method: 'app.register.changepwdByMobileCodeAES' |
144 | + } | ||
129 | }); | 145 | }); |
130 | -}; | 146 | + } |
131 | 147 | ||
132 | -/** | 148 | + /** |
133 | * 验证找回邮件code | 149 | * 验证找回邮件code |
134 | */ | 150 | */ |
135 | -const checkEmailCodeAsync = (code) => { | ||
136 | - return api.get('', { | 151 | + checkEmailCodeAsync(code) { |
152 | + return this.get({ | ||
153 | + data: { | ||
137 | code: code, | 154 | code: code, |
138 | method: 'web.passport.checkCodeValid' | 155 | method: 'web.passport.checkCodeValid' |
156 | + } | ||
139 | }); | 157 | }); |
140 | -}; | 158 | + } |
141 | 159 | ||
142 | -/** | 160 | + /** |
143 | * 根据邮箱code修改密码 | 161 | * 根据邮箱code修改密码 |
144 | */ | 162 | */ |
145 | -const modifyPasswordByEmailCodeAsync = (code, password) => { | ||
146 | - return api.get('', { | 163 | + modifyPasswordByEmailCodeAsync(code, password) { |
164 | + return this.get({ | ||
165 | + data: { | ||
147 | code: code, | 166 | code: code, |
148 | newPwd: password, | 167 | newPwd: password, |
149 | method: 'app.register.resetPwdByCode' | 168 | method: 'app.register.resetPwdByCode' |
169 | + } | ||
150 | }); | 170 | }); |
151 | -}; | 171 | + } |
152 | 172 | ||
153 | -/** | 173 | + /** |
154 | * 根据邮箱code修改密码(AES密码加密) | 174 | * 根据邮箱code修改密码(AES密码加密) |
155 | */ | 175 | */ |
156 | -const modifyPasswordByEmailCodeAsyncAes = (code, password) => { | ||
157 | - return api.get('', { | 176 | + modifyPasswordByEmailCodeAsyncAes(code, password) { |
177 | + return this.get({ | ||
178 | + data: { | ||
158 | code: code, | 179 | code: code, |
159 | newPwd: aes.aesPwd(password), | 180 | newPwd: aes.aesPwd(password), |
160 | method: 'app.register.resetPwdByCodeAES' | 181 | method: 'app.register.resetPwdByCodeAES' |
182 | + } | ||
161 | }); | 183 | }); |
162 | -}; | 184 | + } |
163 | 185 | ||
164 | -const modPwdByCodeAsync = (params) => { | ||
165 | - return api.get('', Object.assign(params, { | 186 | + modPwdByCodeAsync(params) { |
187 | + return this.get({ | ||
188 | + data: Object.assign(params, { | ||
166 | method: 'app.password.modPwdByCode', | 189 | method: 'app.password.modPwdByCode', |
167 | oldPwd: aes.aesPwd(params.oldPwd), | 190 | oldPwd: aes.aesPwd(params.oldPwd), |
168 | newPwd: aes.aesPwd(params.newPwd) | 191 | newPwd: aes.aesPwd(params.newPwd) |
169 | - })); | ||
170 | -}; | ||
171 | - | ||
172 | -module.exports = { | ||
173 | - getAreaDataAsync, | ||
174 | - sendCodeToEmailAsync, | ||
175 | - modifyPasswordByEmailAsync, | ||
176 | - sendCodeToMobileAsync, | ||
177 | - validateMobileCodeAsync, | ||
178 | - modifyPasswordByMobileAsync, | ||
179 | - modifyPasswordByMobileAsyncAes, | ||
180 | - checkEmailCodeAsync, | ||
181 | - modifyPasswordByEmailCodeAsync, | ||
182 | - modifyPasswordByEmailCodeAsyncAes, | ||
183 | - modPwdByCodeAsync | 192 | + }) |
193 | + }); | ||
194 | + } | ||
184 | }; | 195 | }; |
@@ -10,17 +10,33 @@ const _ = require('lodash'); | @@ -10,17 +10,33 @@ const _ = require('lodash'); | ||
10 | const moment = require('moment'); | 10 | const moment = require('moment'); |
11 | 11 | ||
12 | const helpers = global.yoho.helpers; | 12 | const helpers = global.yoho.helpers; |
13 | -const api = require('./back-api'); | ||
14 | -const userService = require('./user-service'); | 13 | +const Api = require('./back-api'); |
14 | +const UserService = require('./user-service'); | ||
15 | const passportHelper = require('./passport-helper'); | 15 | const passportHelper = require('./passport-helper'); |
16 | const backHelper = require('./back-helper'); | 16 | const backHelper = require('./back-helper'); |
17 | 17 | ||
18 | const BACK_LEFT_BANNER_CODE = '3bbaf502c447a2ddad60879042e286d8'; // 找回密码左边的banner | 18 | const BACK_LEFT_BANNER_CODE = '3bbaf502c447a2ddad60879042e286d8'; // 找回密码左边的banner |
19 | 19 | ||
20 | -/** | 20 | +module.exports = class extends global.yoho.BaseModel { |
21 | + constructor(ctx) { | ||
22 | + super(ctx); | ||
23 | + | ||
24 | + this.api = new Api(ctx); | ||
25 | + this.userService = new UserService(ctx); | ||
26 | + | ||
27 | + /** | ||
28 | + * 验证邮件验证码 | ||
29 | + */ | ||
30 | + this.checkEmailCodeAsync = this.api.checkEmailCodeAsync.bind(this.api); | ||
31 | + | ||
32 | + // 弱密码重置 | ||
33 | + this.modPwdByCodeAsync = this.api.modPwdByCodeAsync.bind(this.api); | ||
34 | + } | ||
35 | + | ||
36 | + /** | ||
21 | * 验证手机和邮箱输入正确性 | 37 | * 验证手机和邮箱输入正确性 |
22 | */ | 38 | */ |
23 | -const validateEmailOrMobileAsync = (userInput, areaCode) => { | 39 | + validateEmailOrMobileAsync(userInput, areaCode) { |
24 | return new Promise(function(resolve, rejected) { | 40 | return new Promise(function(resolve, rejected) { |
25 | let result = {type: 'email', area: '', phone: ''}; | 41 | let result = {type: 'email', area: '', phone: ''}; |
26 | 42 | ||
@@ -42,13 +58,13 @@ const validateEmailOrMobileAsync = (userInput, areaCode) => { | @@ -42,13 +58,13 @@ const validateEmailOrMobileAsync = (userInput, areaCode) => { | ||
42 | 58 | ||
43 | }); | 59 | }); |
44 | 60 | ||
45 | -}; | 61 | + } |
46 | 62 | ||
47 | -/** | 63 | + /** |
48 | * 查找用户 | 64 | * 查找用户 |
49 | */ | 65 | */ |
50 | -const findUserAsync = (type, phone, area) => { | ||
51 | - return co(function * () { | 66 | + findUserAsync(type, phone, area) { |
67 | + return co(function* () { | ||
52 | const MESSAGE = { | 68 | const MESSAGE = { |
53 | mobile: '您输入的手机号码尚未注册!', | 69 | mobile: '您输入的手机号码尚未注册!', |
54 | email: '您输入的邮件账户尚未注册!', | 70 | email: '您输入的邮件账户尚未注册!', |
@@ -56,8 +72,8 @@ const findUserAsync = (type, phone, area) => { | @@ -56,8 +72,8 @@ const findUserAsync = (type, phone, area) => { | ||
56 | }; | 72 | }; |
57 | 73 | ||
58 | const findBy = { | 74 | const findBy = { |
59 | - email: userService.findByEmailAsync, | ||
60 | - mobile: _.rearg(userService.findByMobileAsync, [1, 0]) // 交换参数 | 75 | + email: this.userService.findByEmailAsync.bind(this.userService), |
76 | + mobile: _.rearg(this.userService.findByMobileAsync.bind(this.userService), [1, 0]) // 交换参数 | ||
61 | }; | 77 | }; |
62 | 78 | ||
63 | const OK = {code: 200, message: MESSAGE.ok}; | 79 | const OK = {code: 200, message: MESSAGE.ok}; |
@@ -72,33 +88,33 @@ const findUserAsync = (type, phone, area) => { | @@ -72,33 +88,33 @@ const findUserAsync = (type, phone, area) => { | ||
72 | } | 88 | } |
73 | 89 | ||
74 | return OK; | 90 | return OK; |
75 | - })(); | ||
76 | -}; | 91 | + }).bind(this)(); |
92 | + } | ||
77 | 93 | ||
78 | -/** | 94 | + /** |
79 | * 发送验证码到用户 | 95 | * 发送验证码到用户 |
80 | */ | 96 | */ |
81 | -const sendCodeToUserAsync = (type, mobile, areaCode) => { | 97 | + sendCodeToUserAsync(type, mobile, areaCode) { |
82 | let sendTo = { | 98 | let sendTo = { |
83 | - email: api.sendCodeToEmailAsync, | ||
84 | - mobile: api.sendCodeToMobileAsync | 99 | + email: this.api.sendCodeToEmailAsync.bind(this.api), |
100 | + mobile: this.api.sendCodeToMobileAsync.bind(this.api) | ||
85 | }; | 101 | }; |
86 | 102 | ||
87 | return sendTo[type](mobile, areaCode); | 103 | return sendTo[type](mobile, areaCode); |
88 | -}; | 104 | + } |
89 | 105 | ||
90 | -/** | 106 | + /** |
91 | * 发送找回手机号短信 | 107 | * 发送找回手机号短信 |
92 | */ | 108 | */ |
93 | -const sendCodeToMobileAsync = (areaCode, mobile) => { | ||
94 | - return api.sendCodeToMobileAsync(mobile, areaCode); | ||
95 | -}; | 109 | + sendCodeToMobileAsync(areaCode, mobile) { |
110 | + return this.api.sendCodeToMobileAsync(mobile, areaCode); | ||
111 | + } | ||
96 | 112 | ||
97 | -/** | 113 | + /** |
98 | * 获得首页的数据 | 114 | * 获得首页的数据 |
99 | */ | 115 | */ |
100 | -const indexPageDataAsync = () => { | ||
101 | - return co(function *() { | 116 | + indexPageDataAsync() { |
117 | + return co(function* () { | ||
102 | let banner = yield passportHelper.getLeftBannerAsync(BACK_LEFT_BANNER_CODE); | 118 | let banner = yield passportHelper.getLeftBannerAsync(BACK_LEFT_BANNER_CODE); |
103 | let countryList = passportHelper.getCountry(); | 119 | let countryList = passportHelper.getCountry(); |
104 | 120 | ||
@@ -113,19 +129,19 @@ const indexPageDataAsync = () => { | @@ -113,19 +129,19 @@ const indexPageDataAsync = () => { | ||
113 | } | 129 | } |
114 | }; | 130 | }; |
115 | })(); | 131 | })(); |
116 | -}; | 132 | + } |
117 | 133 | ||
118 | -/** | 134 | + /** |
119 | * 验证手机验证码 | 135 | * 验证手机验证码 |
120 | */ | 136 | */ |
121 | -const verifyCodyByMobileAsync = (area, mobile, mobileCode) => { | 137 | + verifyCodyByMobileAsync(area, mobile, mobileCode) { |
122 | const ERR = { | 138 | const ERR = { |
123 | code: 400, | 139 | code: 400, |
124 | message: '验证码错误!', | 140 | message: '验证码错误!', |
125 | data: helpers.urlFormat('/passport/back/index') | 141 | data: helpers.urlFormat('/passport/back/index') |
126 | }; | 142 | }; |
127 | 143 | ||
128 | - return api.validateMobileCodeAsync(mobile, mobileCode, area) | 144 | + return this.api.validateMobileCodeAsync(mobile, mobileCode, area) |
129 | .then(result => { | 145 | .then(result => { |
130 | if (!(result.code && result.code === 200)) { | 146 | if (!(result.code && result.code === 200)) { |
131 | return ERR; | 147 | return ERR; |
@@ -147,12 +163,12 @@ const verifyCodyByMobileAsync = (area, mobile, mobileCode) => { | @@ -147,12 +163,12 @@ const verifyCodyByMobileAsync = (area, mobile, mobileCode) => { | ||
147 | }; | 163 | }; |
148 | }); | 164 | }); |
149 | 165 | ||
150 | -}; | 166 | + } |
151 | 167 | ||
152 | -/** | 168 | + /** |
153 | * 手机 token 合法性验证 | 169 | * 手机 token 合法性验证 |
154 | */ | 170 | */ |
155 | -const authRequest = (data, token) => { | 171 | + authRequest(data, token) { |
156 | if (!backHelper.validateToken(data, token)) { | 172 | if (!backHelper.validateToken(data, token)) { |
157 | return {}; | 173 | return {}; |
158 | } | 174 | } |
@@ -165,13 +181,13 @@ const authRequest = (data, token) => { | @@ -165,13 +181,13 @@ const authRequest = (data, token) => { | ||
165 | } else { | 181 | } else { |
166 | return data; | 182 | return data; |
167 | } | 183 | } |
168 | -}; | 184 | + } |
169 | 185 | ||
170 | -/** | 186 | + /** |
171 | * 更新密码接口 | 187 | * 更新密码接口 |
172 | */ | 188 | */ |
173 | -const updatePwdAsync = (emailToken, mobileToken, newPassword) => { | ||
174 | - return co(function * () { | 189 | + updatePwdAsync(emailToken, mobileToken, newPassword) { |
190 | + return co(function* () { | ||
175 | let result = {type: 'mobile', status: false}; | 191 | let result = {type: 'mobile', status: false}; |
176 | const ERR = {type: 'unknown', status: false}; | 192 | const ERR = {type: 'unknown', status: false}; |
177 | 193 | ||
@@ -183,7 +199,7 @@ const updatePwdAsync = (emailToken, mobileToken, newPassword) => { | @@ -183,7 +199,7 @@ const updatePwdAsync = (emailToken, mobileToken, newPassword) => { | ||
183 | let mobile = mobileToken.mobile; | 199 | let mobile = mobileToken.mobile; |
184 | let area = mobileToken.area; | 200 | let area = mobileToken.area; |
185 | let token = mobileToken.token; | 201 | let token = mobileToken.token; |
186 | - let modifyStatus = yield api.modifyPasswordByMobileAsyncAes(mobile, token, newPassword, area); | 202 | + let modifyStatus = yield this.api.modifyPasswordByMobileAsyncAes(mobile, token, newPassword, area); |
187 | 203 | ||
188 | if (!modifyStatus.code || modifyStatus.code !== 200) { | 204 | if (!modifyStatus.code || modifyStatus.code !== 200) { |
189 | return ERR; | 205 | return ERR; |
@@ -192,7 +208,7 @@ const updatePwdAsync = (emailToken, mobileToken, newPassword) => { | @@ -192,7 +208,7 @@ const updatePwdAsync = (emailToken, mobileToken, newPassword) => { | ||
192 | result.type = 'mobile'; | 208 | result.type = 'mobile'; |
193 | result.status = true; | 209 | result.status = true; |
194 | } else { | 210 | } else { |
195 | - let modifyStatus = yield api.modifyPasswordByEmailCodeAsyncAes(emailToken, newPassword); | 211 | + let modifyStatus = yield this.api.modifyPasswordByEmailCodeAsyncAes(emailToken, newPassword); |
196 | 212 | ||
197 | if (!modifyStatus.code || modifyStatus.code !== 200) { | 213 | if (!modifyStatus.code || modifyStatus.code !== 200) { |
198 | return ERR; | 214 | return ERR; |
@@ -203,26 +219,6 @@ const updatePwdAsync = (emailToken, mobileToken, newPassword) => { | @@ -203,26 +219,6 @@ const updatePwdAsync = (emailToken, mobileToken, newPassword) => { | ||
203 | } | 219 | } |
204 | 220 | ||
205 | return result; | 221 | return result; |
206 | - })(); | ||
207 | -}; | ||
208 | - | ||
209 | -/** | ||
210 | - * 验证邮件验证码 | ||
211 | - */ | ||
212 | -const checkEmailCodeAsync = api.checkEmailCodeAsync; | ||
213 | - | ||
214 | -// 弱密码重置 | ||
215 | -const modPwdByCodeAsync = api.modPwdByCodeAsync; | ||
216 | - | ||
217 | -module.exports = { | ||
218 | - validateEmailOrMobileAsync, | ||
219 | - findUserAsync, | ||
220 | - sendCodeToUserAsync, | ||
221 | - sendCodeToMobileAsync, | ||
222 | - indexPageDataAsync, | ||
223 | - verifyCodyByMobileAsync, | ||
224 | - authRequest, | ||
225 | - updatePwdAsync, | ||
226 | - checkEmailCodeAsync, | ||
227 | - modPwdByCodeAsync | 222 | + }).bind(this)(); |
223 | + } | ||
228 | }; | 224 | }; |
@@ -5,11 +5,12 @@ | @@ -5,11 +5,12 @@ | ||
5 | * @date 2016/06/21 | 5 | * @date 2016/06/21 |
6 | */ | 6 | */ |
7 | 7 | ||
8 | -'use strict'; | ||
9 | - | ||
10 | -const api = global.yoho.API; | 8 | +module.exports = class extends global.yoho.BaseModel { |
9 | + constructor(ctx) { | ||
10 | + super(ctx); | ||
11 | + } | ||
11 | 12 | ||
12 | -const bindCheck = (mobile, openId, sourceType, area) => { | 13 | + bindCheck(mobile, openId, sourceType, area) { |
13 | let params = { | 14 | let params = { |
14 | method: 'app.passport.signCheck', | 15 | method: 'app.passport.signCheck', |
15 | area: area, | 16 | area: area, |
@@ -18,29 +19,29 @@ const bindCheck = (mobile, openId, sourceType, area) => { | @@ -18,29 +19,29 @@ const bindCheck = (mobile, openId, sourceType, area) => { | ||
18 | source_type: sourceType | 19 | source_type: sourceType |
19 | }; | 20 | }; |
20 | 21 | ||
21 | - return api.get('', params); | ||
22 | -}; | 22 | + return this.get({data: params}); |
23 | + } | ||
23 | 24 | ||
24 | -const sendBindMsg = (area, mobile) => { | 25 | + sendBindMsg(area, mobile) { |
25 | let params = { | 26 | let params = { |
26 | method: 'app.passport.smsbind', | 27 | method: 'app.passport.smsbind', |
27 | mobile: mobile, | 28 | mobile: mobile, |
28 | area: area | 29 | area: area |
29 | }; | 30 | }; |
30 | 31 | ||
31 | - return api.get('', params); | ||
32 | -}; | 32 | + return this.get({data: params}); |
33 | + } | ||
33 | 34 | ||
34 | -const checkBindCode = (area, mobile, code) => { | ||
35 | - return api.get('', { | 35 | + checkBindCode(area, mobile, code) { |
36 | + return this.get({data: { | ||
36 | method: 'app.register.validRegCode', | 37 | method: 'app.register.validRegCode', |
37 | mobile: mobile, | 38 | mobile: mobile, |
38 | area: area, | 39 | area: area, |
39 | code: code | 40 | code: code |
40 | - }); | ||
41 | -}; | 41 | + }}); |
42 | + } | ||
42 | 43 | ||
43 | -const bindMobile = (openId, sourceType, mobile, area, password, nickname) => { | 44 | + bindMobile(openId, sourceType, mobile, area, password, nickname) { |
44 | let params = { | 45 | let params = { |
45 | method: 'app.passport.bind', | 46 | method: 'app.passport.bind', |
46 | mobile: mobile, | 47 | mobile: mobile, |
@@ -57,43 +58,34 @@ const bindMobile = (openId, sourceType, mobile, area, password, nickname) => { | @@ -57,43 +58,34 @@ const bindMobile = (openId, sourceType, mobile, area, password, nickname) => { | ||
57 | params.nickname = nickname; | 58 | params.nickname = nickname; |
58 | } | 59 | } |
59 | 60 | ||
60 | - return api.get('', params); | ||
61 | -}; | 61 | + return this.get({data: params}); |
62 | + } | ||
62 | 63 | ||
63 | -const relateMobile = (openId, sourceType, mobile, area) => { | ||
64 | - return api.get('', { | 64 | + relateMobile(openId, sourceType, mobile, area) { |
65 | + return this.get({data: { | ||
65 | method: 'app.passport.relatedMobile', | 66 | method: 'app.passport.relatedMobile', |
66 | mobile: mobile, | 67 | mobile: mobile, |
67 | openId: openId, | 68 | openId: openId, |
68 | source_type: sourceType, | 69 | source_type: sourceType, |
69 | area: area | 70 | area: area |
70 | - }); | ||
71 | -}; | 71 | + }}); |
72 | + } | ||
72 | 73 | ||
73 | -const changeCheck = (mobile, area) => { | ||
74 | - return api.get('', { | 74 | + changeCheck(mobile, area) { |
75 | + return this.get({data: { | ||
75 | method: 'app.passport.changeCheck', | 76 | method: 'app.passport.changeCheck', |
76 | mobile: mobile, | 77 | mobile: mobile, |
77 | area: area | 78 | area: area |
78 | - }); | ||
79 | -}; | 79 | + }}); |
80 | + } | ||
80 | 81 | ||
81 | -const changeMobile = (uid, mobile, area, code) => { | ||
82 | - return api.get('', { | 82 | + changeMobile(uid, mobile, area, code) { |
83 | + return this.get({data: { | ||
83 | method: 'app.passport.changeMobile', | 84 | method: 'app.passport.changeMobile', |
84 | mobile: mobile, | 85 | mobile: mobile, |
85 | uid: uid, | 86 | uid: uid, |
86 | code: code, | 87 | code: code, |
87 | area: area | 88 | area: area |
88 | - }); | ||
89 | -}; | ||
90 | - | ||
91 | -module.exports = { | ||
92 | - bindCheck, | ||
93 | - sendBindMsg, | ||
94 | - checkBindCode, | ||
95 | - bindMobile, | ||
96 | - relateMobile, | ||
97 | - changeCheck, | ||
98 | - changeMobile | 89 | + }}); |
90 | + } | ||
99 | }; | 91 | }; |
@@ -4,9 +4,12 @@ | @@ -4,9 +4,12 @@ | ||
4 | 4 | ||
5 | 'use strict'; | 5 | 'use strict'; |
6 | 6 | ||
7 | -const api = global.yoho.API; | 7 | +module.exports = class extends global.yoho.BaseModel { |
8 | + constructor(ctx) { | ||
9 | + super(ctx); | ||
10 | + } | ||
8 | 11 | ||
9 | -const goodsCount = (uid, shoppingKey) => { | 12 | + goodsCount(uid, shoppingKey) { |
10 | let params = { | 13 | let params = { |
11 | method: 'app.Shopping.count' | 14 | method: 'app.Shopping.count' |
12 | }; | 15 | }; |
@@ -19,9 +22,6 @@ const goodsCount = (uid, shoppingKey) => { | @@ -19,9 +22,6 @@ const goodsCount = (uid, shoppingKey) => { | ||
19 | params.shopping_key = shoppingKey; | 22 | params.shopping_key = shoppingKey; |
20 | } | 23 | } |
21 | 24 | ||
22 | - return api.get('', params); | ||
23 | -}; | ||
24 | - | ||
25 | -module.exports = { | ||
26 | - goodsCount | 25 | + return this.get({data: params}); |
26 | + } | ||
27 | }; | 27 | }; |
@@ -5,15 +5,19 @@ | @@ -5,15 +5,19 @@ | ||
5 | 'use strict'; | 5 | 'use strict'; |
6 | 6 | ||
7 | 7 | ||
8 | -const api = require('./cart-api'); | 8 | +const Api = require('./cart-api'); |
9 | 9 | ||
10 | const _ = require('lodash'); | 10 | const _ = require('lodash'); |
11 | 11 | ||
12 | -const goodsCount = (uid, shoppingKey) => { | ||
13 | - return api.goodsCount(uid, shoppingKey).then(result => _.get(result, 'data.cart_goods_count', 0)); | ||
14 | -}; | 12 | +module.exports = class extends global.yoho.BaseModel { |
13 | + constructor(ctx) { | ||
14 | + super(ctx); | ||
15 | + | ||
16 | + this.api = new Api(ctx); | ||
17 | + } | ||
15 | 18 | ||
16 | -module.exports = { | ||
17 | - goodsCount | 19 | + goodsCount(uid, shoppingKey) { |
20 | + return this.api.goodsCount(uid, shoppingKey).then(result => _.get(result, 'data.cart_goods_count', 0)); | ||
21 | + } | ||
18 | }; | 22 | }; |
19 | 23 |
@@ -4,38 +4,32 @@ | @@ -4,38 +4,32 @@ | ||
4 | 4 | ||
5 | 'use strict'; | 5 | 'use strict'; |
6 | 6 | ||
7 | -const api = global.yoho.API; | 7 | +module.exports = class extends global.yoho.BaseModel { |
8 | + constructor(ctx) { | ||
9 | + super(ctx); | ||
10 | + } | ||
8 | 11 | ||
9 | -const certCheck = (mobile, area) => { | 12 | + certCheck(mobile, area) { |
10 | let params = { | 13 | let params = { |
11 | method: 'app.passport.checkIsCanBind', | 14 | method: 'app.passport.checkIsCanBind', |
12 | area: area, | 15 | area: area, |
13 | mobile: mobile | 16 | mobile: mobile |
14 | }; | 17 | }; |
15 | 18 | ||
16 | - return api.get('', params); | ||
17 | -}; | 19 | + return this.get({data: params}); |
20 | + } | ||
18 | 21 | ||
19 | -const sendCertMsg = (mobile, area) => { | 22 | + sendCertMsg(mobile, area) { |
20 | let params = { | 23 | let params = { |
21 | method: 'app.passport.smsbind', | 24 | method: 'app.passport.smsbind', |
22 | mobile: mobile, | 25 | mobile: mobile, |
23 | area: area | 26 | area: area |
24 | }; | 27 | }; |
25 | 28 | ||
26 | - return api.get('', params); | ||
27 | -}; | ||
28 | - | ||
29 | -/* const checkCertCode = (area, mobile, code) => { | ||
30 | - return api.get('', { | ||
31 | - method: 'app.register.validRegCode', | ||
32 | - mobile: mobile, | ||
33 | - area: area, | ||
34 | - code: code | ||
35 | - }); | ||
36 | -};*/ | 29 | + return this.get({data: params}); |
30 | + } | ||
37 | 31 | ||
38 | -const certMobile = (uid, mobile, code, area) => { | 32 | + certMobile(uid, mobile, code, area) { |
39 | let params = { | 33 | let params = { |
40 | method: 'app.passport.changeMobile', | 34 | method: 'app.passport.changeMobile', |
41 | uid: uid, | 35 | uid: uid, |
@@ -44,52 +38,27 @@ const certMobile = (uid, mobile, code, area) => { | @@ -44,52 +38,27 @@ const certMobile = (uid, mobile, code, area) => { | ||
44 | code: code | 38 | code: code |
45 | }; | 39 | }; |
46 | 40 | ||
47 | - return api.get('', params); | ||
48 | -}; | 41 | + return this.get({data: params}); |
42 | + } | ||
49 | 43 | ||
50 | -const relateMobile = (uid, email, code, mobile, area) => { | ||
51 | - return api.get('', { | 44 | + relateMobile(uid, email, code, mobile, area) { |
45 | + return this.get({data: { | ||
52 | method: 'app.passport.relatedMobileAndEmail', | 46 | method: 'app.passport.relatedMobileAndEmail', |
53 | uid: uid, | 47 | uid: uid, |
54 | email: email, | 48 | email: email, |
55 | mobile: mobile, | 49 | mobile: mobile, |
56 | code: code, | 50 | code: code, |
57 | area: area | 51 | area: area |
58 | - }); | ||
59 | -}; | ||
60 | - | ||
61 | -/* const changeCheck = (mobile, area) => { | ||
62 | - return api.get('', { | ||
63 | - method: 'app.passport.changeCheck', | ||
64 | - mobile: mobile, | ||
65 | - area: area | ||
66 | - }); | ||
67 | -};*/ | ||
68 | - | ||
69 | -/* const changeMobile = (uid, mobile, area, code) => { | ||
70 | - return api.get('', { | ||
71 | - method: 'app.passport.changeMobile', | ||
72 | - mobile: mobile, | ||
73 | - uid: uid, | ||
74 | - code: code, | ||
75 | - area: area | ||
76 | - }); | ||
77 | -};*/ | ||
78 | - | ||
79 | -const checkEmailCertTip = (uid) => { | 52 | + }}); |
53 | + } | ||
80 | 54 | ||
55 | + checkEmailCertTip(uid) { | ||
81 | let param = { | 56 | let param = { |
82 | method: 'app.passport.checkIsBindedOrRelated', | 57 | method: 'app.passport.checkIsBindedOrRelated', |
83 | uid: uid | 58 | uid: uid |
84 | }; | 59 | }; |
85 | 60 | ||
86 | - return api.get('', param); | 61 | + return this.get({data: param}); |
62 | + } | ||
87 | }; | 63 | }; |
88 | 64 | ||
89 | -module.exports = { | ||
90 | - certCheck, | ||
91 | - sendCertMsg, | ||
92 | - certMobile, | ||
93 | - relateMobile, | ||
94 | - checkEmailCertTip | ||
95 | -}; |
@@ -5,10 +5,13 @@ | @@ -5,10 +5,13 @@ | ||
5 | 'use strict'; | 5 | 'use strict'; |
6 | 6 | ||
7 | const aes = require('./aes-pwd'); | 7 | const aes = require('./aes-pwd'); |
8 | -const api = global.yoho.API; | ||
9 | -const logger = global.yoho.logger; | ||
10 | 8 | ||
11 | -const signinByPasswordWithAes = (area, profile, password, shoppingKey, clientIp) => { | 9 | +module.exports = class extends global.yoho.BaseModel { |
10 | + constructor(ctx) { | ||
11 | + super(ctx); | ||
12 | + } | ||
13 | + | ||
14 | + signinByPasswordWithAes(area, profile, password, shoppingKey) { | ||
12 | let param = { | 15 | let param = { |
13 | method: 'sesame.flowering.higher', | 16 | method: 'sesame.flowering.higher', |
14 | area: area, | 17 | area: area, |
@@ -20,17 +23,10 @@ const signinByPasswordWithAes = (area, profile, password, shoppingKey, clientIp) | @@ -20,17 +23,10 @@ const signinByPasswordWithAes = (area, profile, password, shoppingKey, clientIp) | ||
20 | param.shopping_key = shoppingKey; | 23 | param.shopping_key = shoppingKey; |
21 | } | 24 | } |
22 | 25 | ||
23 | - logger.info('login successfully by password from', clientIp); | ||
24 | - | ||
25 | - return api.post('', param, { | ||
26 | - headers: { | ||
27 | - 'user-agent': 'yoho/nodejs', | ||
28 | - 'X-YOHO-IP': clientIp | 26 | + return this.post({data: param}); |
29 | } | 27 | } |
30 | - }); | ||
31 | -}; | ||
32 | 28 | ||
33 | -const signinBySMS = (area, mobile, token, shoppingKey) => { | 29 | + signinBySMS(area, mobile, token, shoppingKey) { |
34 | let param = { | 30 | let param = { |
35 | method: 'app.passport.autoSignin', | 31 | method: 'app.passport.autoSignin', |
36 | area: area, | 32 | area: area, |
@@ -42,10 +38,10 @@ const signinBySMS = (area, mobile, token, shoppingKey) => { | @@ -42,10 +38,10 @@ const signinBySMS = (area, mobile, token, shoppingKey) => { | ||
42 | param.shopping_key = shoppingKey; | 38 | param.shopping_key = shoppingKey; |
43 | } | 39 | } |
44 | 40 | ||
45 | - return api.post('', param); | ||
46 | -}; | 41 | + return this.post({data: param}); |
42 | + } | ||
47 | 43 | ||
48 | -const signinByQrCode = (__1, __2, code, shoppingKey) => { // eslint-disable-line | 44 | + signinByQrCode(__1, __2, code, shoppingKey) { // eslint-disable-line |
49 | let param = { | 45 | let param = { |
50 | method: 'app.twoDimen.qrCodeLogin', | 46 | method: 'app.twoDimen.qrCodeLogin', |
51 | code: code.substring(code.indexOf('=') + 1) | 47 | code: code.substring(code.indexOf('=') + 1) |
@@ -55,19 +51,19 @@ const signinByQrCode = (__1, __2, code, shoppingKey) => { // eslint-disable-line | @@ -55,19 +51,19 @@ const signinByQrCode = (__1, __2, code, shoppingKey) => { // eslint-disable-line | ||
55 | param.shopping_key = shoppingKey; | 51 | param.shopping_key = shoppingKey; |
56 | } | 52 | } |
57 | 53 | ||
58 | - return api.post('', param); | ||
59 | -}; | 54 | + return this.post({data: param}); |
55 | + } | ||
60 | 56 | ||
61 | -const checkByQrCode = (code) => { | 57 | + checkByQrCode(code) { |
62 | let param = { | 58 | let param = { |
63 | method: 'app.twoDimen.loginCheck', | 59 | method: 'app.twoDimen.loginCheck', |
64 | code: code | 60 | code: code |
65 | }; | 61 | }; |
66 | 62 | ||
67 | - return api.post('', param); | ||
68 | -}; | 63 | + return this.post({data: param}); |
64 | + } | ||
69 | 65 | ||
70 | -const sendPasswordBySMS = (area, mobile) => { | 66 | + sendPasswordBySMS(area, mobile) { |
71 | let param = { | 67 | let param = { |
72 | method: 'app.message.sendSms', | 68 | method: 'app.message.sendSms', |
73 | area: area, | 69 | area: area, |
@@ -75,28 +71,28 @@ const sendPasswordBySMS = (area, mobile) => { | @@ -75,28 +71,28 @@ const sendPasswordBySMS = (area, mobile) => { | ||
75 | type: 1 // 手机快捷登录短信验证码 | 71 | type: 1 // 手机快捷登录短信验证码 |
76 | }; | 72 | }; |
77 | 73 | ||
78 | - return api.get('', param); | ||
79 | -}; | 74 | + return this.get({data: param}); |
75 | + } | ||
80 | 76 | ||
81 | -const checkUserExitBySMS = (area, mobile) => { | ||
82 | - return api.get('', { | 77 | + checkUserExitBySMS(area, mobile) { |
78 | + return this.get({data: { | ||
83 | method: 'app.passport.checkUserExist', | 79 | method: 'app.passport.checkUserExist', |
84 | area: area, | 80 | area: area, |
85 | mobile: mobile | 81 | mobile: mobile |
86 | - }); | ||
87 | -}; | 82 | + }}); |
83 | + } | ||
88 | 84 | ||
89 | -const verifyPasswordBySMS = (area, mobile, code) => { | ||
90 | - return api.get('', { | 85 | + verifyPasswordBySMS(area, mobile, code) { |
86 | + return this.get({data: { | ||
91 | method: 'app.message.verifySmsCode', | 87 | method: 'app.message.verifySmsCode', |
92 | area: area, | 88 | area: area, |
93 | mobile: mobile, | 89 | mobile: mobile, |
94 | code: code, | 90 | code: code, |
95 | type: 1 // 手机快捷登录短信验证码 | 91 | type: 1 // 手机快捷登录短信验证码 |
96 | - }); | ||
97 | -}; | 92 | + }}); |
93 | + } | ||
98 | 94 | ||
99 | -const signinByOpenID = (nickname, openId, sourceType, shoppingKey) => { | 95 | + signinByOpenID(nickname, openId, sourceType, shoppingKey) { |
100 | let param = { | 96 | let param = { |
101 | nickname: nickname, | 97 | nickname: nickname, |
102 | openId: openId, | 98 | openId: openId, |
@@ -108,16 +104,6 @@ const signinByOpenID = (nickname, openId, sourceType, shoppingKey) => { | @@ -108,16 +104,6 @@ const signinByOpenID = (nickname, openId, sourceType, shoppingKey) => { | ||
108 | param.shopping_key = shoppingKey; | 104 | param.shopping_key = shoppingKey; |
109 | } | 105 | } |
110 | 106 | ||
111 | - return api.get('', param); | ||
112 | -}; | ||
113 | - | ||
114 | -module.exports = { | ||
115 | - signinByPasswordWithAes, | ||
116 | - signinBySMS, | ||
117 | - signinByQrCode, | ||
118 | - checkByQrCode, | ||
119 | - sendPasswordBySMS, | ||
120 | - checkUserExitBySMS, | ||
121 | - verifyPasswordBySMS, | ||
122 | - signinByOpenID | 107 | + return this.get({data: param}); |
108 | + } | ||
123 | }; | 109 | }; |
@@ -15,26 +15,40 @@ const AUTH_TIME = 2592000000; | @@ -15,26 +15,40 @@ const AUTH_TIME = 2592000000; | ||
15 | 15 | ||
16 | const Promise = require('bluebird'); | 16 | const Promise = require('bluebird'); |
17 | 17 | ||
18 | -const cartService = require('./cart-service'); | ||
19 | -const userService = require('./user-service'); | ||
20 | -const api = require('./login-api'); | 18 | +const CartService = require('./cart-service'); |
19 | +const UserService = require('./user-service'); | ||
20 | +const LoginApi = require('./login-api'); | ||
21 | const logger = global.yoho.logger; | 21 | const logger = global.yoho.logger; |
22 | 22 | ||
23 | -const signin = (type, area, profile, password, shoppingKey, clientIp, closePasswordLogin) => { | 23 | +module.exports = class extends global.yoho.BaseModel { |
24 | + constructor(ctx) { | ||
25 | + super(ctx); | ||
26 | + this.api = new LoginApi(ctx); | ||
27 | + this.cartService = new CartService(ctx); | ||
28 | + this.userService = new UserService(ctx); | ||
29 | + | ||
30 | + this.checkByQrCode = this.api.checkByQrCode.bind(this.api); | ||
31 | + this.sendPasswordBySMS = this.api.sendPasswordBySMS.bind(this.api); | ||
32 | + this.checkUserExitBySMS = this.api.checkUserExitBySMS.bind(this.api); | ||
33 | + this.verifyPasswordBySMS = this.api.verifyPasswordBySMS.bind(this.api); | ||
34 | + this.signinByOpenID = this.api.signinByOpenID.bind(this.api); | ||
35 | + } | ||
36 | + | ||
37 | + signin(type, area, profile, password, shoppingKey, close) { | ||
24 | let loginBy = { | 38 | let loginBy = { |
25 | - password: api.signinByPasswordWithAes, | ||
26 | - sms: api.signinBySMS, | ||
27 | - qrcode: api.signinByQrCode | 39 | + password: this.api.signinByPasswordWithAes.bind(this.api), |
40 | + sms: this.api.signinBySMS.bind(this.api), | ||
41 | + qrcode: this.api.signinByQrCode.bind(this.api) | ||
28 | }; | 42 | }; |
29 | 43 | ||
30 | - if (closePasswordLogin) { | 44 | + if (close) { |
31 | delete loginBy.password; | 45 | delete loginBy.password; |
32 | } | 46 | } |
33 | 47 | ||
34 | - return loginBy[type](area, profile, password, shoppingKey, clientIp); | ||
35 | -}; | 48 | + return loginBy[type](area, profile, password, shoppingKey); |
49 | + } | ||
36 | 50 | ||
37 | -const syncUserSession = (user, req, res) => { | 51 | + syncUserSession(user, req, res) { |
38 | let uid = user.uid; | 52 | let uid = user.uid; |
39 | let sessionKey = user.session_key; | 53 | let sessionKey = user.session_key; |
40 | 54 | ||
@@ -56,9 +70,10 @@ const syncUserSession = (user, req, res) => { | @@ -56,9 +70,10 @@ const syncUserSession = (user, req, res) => { | ||
56 | }; | 70 | }; |
57 | 71 | ||
58 | return Promise.all([ | 72 | return Promise.all([ |
59 | - userService.profile(uidObj), | ||
60 | - cartService.goodsCount(uidObj), | ||
61 | - userService.checkNoCertEmailUser(uidObj).catch(err => logger(`checkNoCertEmailUser【${uid}】err: ${err}`)) | 73 | + this.userService.profile(uidObj), |
74 | + this.cartService.goodsCount(uidObj), | ||
75 | + this.userService.checkNoCertEmailUser(uidObj) | ||
76 | + .catch(err => logger(`checkNoCertEmailUser【${uid}】err: ${err}`)) | ||
62 | ]).spread((userInfo, count, isTipCert) => { | 77 | ]).spread((userInfo, count, isTipCert) => { |
63 | let salt = uuid.v4().substr(0, 8); | 78 | let salt = uuid.v4().substr(0, 8); |
64 | let saltedUid = uid + salt; | 79 | let saltedUid = uid + salt; |
@@ -130,9 +145,9 @@ const syncUserSession = (user, req, res) => { | @@ -130,9 +145,9 @@ const syncUserSession = (user, req, res) => { | ||
130 | } | 145 | } |
131 | 146 | ||
132 | }); | 147 | }); |
133 | -}; | 148 | + } |
134 | 149 | ||
135 | -const rememberAccount = (accountInfo, req, res) => { | 150 | + rememberAccount(accountInfo, req, res) { |
136 | let aWeek = (new Date()).getTime() / 1000 + 504000; // 504000-一周 | 151 | let aWeek = (new Date()).getTime() / 1000 + 504000; // 504000-一周 |
137 | let rememKey = md5(md5(accountInfo.account + accountInfo.password + accountInfo.area)); | 152 | let rememKey = md5(md5(accountInfo.account + accountInfo.password + accountInfo.area)); |
138 | 153 | ||
@@ -148,9 +163,9 @@ const rememberAccount = (accountInfo, req, res) => { | @@ -148,9 +163,9 @@ const rememberAccount = (accountInfo, req, res) => { | ||
148 | // if (!cache.get(rememKey)) { | 163 | // if (!cache.get(rememKey)) { |
149 | // cache.set(rememKey, accountInfo, aWeek); | 164 | // cache.set(rememKey, accountInfo, aWeek); |
150 | // } | 165 | // } |
151 | -}; | 166 | + } |
152 | 167 | ||
153 | -const fetchByQrCode = () => { | 168 | + fetchByQrCode() { |
154 | let code = { | 169 | let code = { |
155 | qrcode: uuid.v4(), | 170 | qrcode: uuid.v4(), |
156 | time: new Date().getTime() | 171 | time: new Date().getTime() |
@@ -164,16 +179,5 @@ const fetchByQrCode = () => { | @@ -164,16 +179,5 @@ const fetchByQrCode = () => { | ||
164 | }, | 179 | }, |
165 | code: 200 | 180 | code: 200 |
166 | }); | 181 | }); |
167 | -}; | ||
168 | - | ||
169 | -module.exports = { | ||
170 | - signin, | ||
171 | - syncUserSession, | ||
172 | - rememberAccount, | ||
173 | - fetchByQrCode, | ||
174 | - checkByQrCode: api.checkByQrCode, | ||
175 | - sendPasswordBySMS: api.sendPasswordBySMS, | ||
176 | - checkUserExitBySMS: api.checkUserExitBySMS, | ||
177 | - verifyPasswordBySMS: api.verifyPasswordBySMS, | ||
178 | - signinByOpenID: api.signinByOpenID | 182 | + } |
179 | }; | 183 | }; |
@@ -13,7 +13,7 @@ const indexService = require('./index-service'); | @@ -13,7 +13,7 @@ const indexService = require('./index-service'); | ||
13 | /** | 13 | /** |
14 | * 获得图片 | 14 | * 获得图片 |
15 | */ | 15 | */ |
16 | -const getLeftBannerAsync = (resourceCode) => { | 16 | +function getLeftBannerAsync(resourceCode) { |
17 | const DEFAULT_VALUE = { | 17 | const DEFAULT_VALUE = { |
18 | img: 'https://img12.static.yhbimg.com/' + | 18 | img: 'https://img12.static.yhbimg.com/' + |
19 | 'yhb-img01/2015/12/01/07/020a0b6e7ff908d0c2bc4045b4fef42b9f.png?imageView/2/w/252/h/190', | 19 | 'yhb-img01/2015/12/01/07/020a0b6e7ff908d0c2bc4045b4fef42b9f.png?imageView/2/w/252/h/190', |
@@ -35,7 +35,7 @@ const getLeftBannerAsync = (resourceCode) => { | @@ -35,7 +35,7 @@ const getLeftBannerAsync = (resourceCode) => { | ||
35 | 35 | ||
36 | return value; | 36 | return value; |
37 | })(); | 37 | })(); |
38 | -}; | 38 | +} |
39 | 39 | ||
40 | /** | 40 | /** |
41 | * 国家数据 | 41 | * 国家数据 |
@@ -8,19 +8,23 @@ | @@ -8,19 +8,23 @@ | ||
8 | 'use strict'; | 8 | 'use strict'; |
9 | 9 | ||
10 | const aes = require('./aes-pwd'); | 10 | const aes = require('./aes-pwd'); |
11 | -const api = global.yoho.API; | ||
12 | 11 | ||
13 | -let sendCodeToMobile = (area, mobile) => { | 12 | +module.exports = class extends global.yoho.BaseModel { |
13 | + constructor(ctx) { | ||
14 | + super(ctx); | ||
15 | + } | ||
16 | + | ||
17 | + sendCodeToMobile(area, mobile) { | ||
14 | let params = { | 18 | let params = { |
15 | method: 'app.register.sendRegCodeToMobile', | 19 | method: 'app.register.sendRegCodeToMobile', |
16 | area: area, | 20 | area: area, |
17 | mobile: mobile | 21 | mobile: mobile |
18 | }; | 22 | }; |
19 | 23 | ||
20 | - return api.post('', params); | ||
21 | -}; | 24 | + return this.post({data: params}); |
25 | + } | ||
22 | 26 | ||
23 | -let validMobileCode = (area, mobile, code) => { | 27 | + validMobileCode(area, mobile, code) { |
24 | let params = { | 28 | let params = { |
25 | method: 'app.register.validRegCode', | 29 | method: 'app.register.validRegCode', |
26 | area: area, | 30 | area: area, |
@@ -28,10 +32,10 @@ let validMobileCode = (area, mobile, code) => { | @@ -28,10 +32,10 @@ let validMobileCode = (area, mobile, code) => { | ||
28 | code: code | 32 | code: code |
29 | }; | 33 | }; |
30 | 34 | ||
31 | - return api.post('', params); | ||
32 | -}; | 35 | + return this.post({data: params}); |
36 | + } | ||
33 | 37 | ||
34 | -let regMobileAes = (area, mobile, password, code, shoppingKey, inviteCode, clientIp)=> { | 38 | + regMobileAes(area, mobile, password, code, shoppingKey, inviteCode) { |
35 | let params = { | 39 | let params = { |
36 | method: 'app.passport.registerAES', | 40 | method: 'app.passport.registerAES', |
37 | area: area, | 41 | area: area, |
@@ -48,16 +52,6 @@ let regMobileAes = (area, mobile, password, code, shoppingKey, inviteCode, clien | @@ -48,16 +52,6 @@ let regMobileAes = (area, mobile, password, code, shoppingKey, inviteCode, clien | ||
48 | params.inviteCode = inviteCode; | 52 | params.inviteCode = inviteCode; |
49 | } | 53 | } |
50 | 54 | ||
51 | - return api.post('', params, { | ||
52 | - headers: { | ||
53 | - 'user-agent': 'yoho/nodejs', | ||
54 | - 'X-YOHO-IP': clientIp | 55 | + return this.post({data: params}); |
55 | } | 56 | } |
56 | - }); | ||
57 | -}; | ||
58 | - | ||
59 | -module.exports = { | ||
60 | - sendCodeToMobile, | ||
61 | - validMobileCode, | ||
62 | - regMobileAes | ||
63 | }; | 57 | }; |
@@ -3,14 +3,22 @@ | @@ -3,14 +3,22 @@ | ||
3 | */ | 3 | */ |
4 | 'use strict'; | 4 | 'use strict'; |
5 | const passportHelper = require('./passport-helper'); | 5 | const passportHelper = require('./passport-helper'); |
6 | -const api = require('./reg-api'); | 6 | +const Api = require('./reg-api'); |
7 | 7 | ||
8 | const REGISTER_LEFT_BANNER_CODE = 'c479ec90120cae7f96e52922b4917064'; // 注册左边的banner | 8 | const REGISTER_LEFT_BANNER_CODE = 'c479ec90120cae7f96e52922b4917064'; // 注册左边的banner |
9 | 9 | ||
10 | -let getRegData = () => { | 10 | + |
11 | +module.exports = class extends global.yoho.BaseModel { | ||
12 | + constructor(ctx) { | ||
13 | + super(ctx); | ||
14 | + this.api = new Api(); | ||
15 | + | ||
16 | + this.sendCodeToMobile = this.api.sendCodeToMobile.bind(this.api); | ||
17 | + this.validMobileCode = this.api.validMobileCode.bind(this.api); | ||
18 | + this.regMobileAes = this.api.regMobileAes.bind(this.api); | ||
19 | + } | ||
20 | + | ||
21 | + getRegData() { | ||
11 | return passportHelper.getLeftBannerAsync(REGISTER_LEFT_BANNER_CODE); | 22 | return passportHelper.getLeftBannerAsync(REGISTER_LEFT_BANNER_CODE); |
23 | + } | ||
12 | }; | 24 | }; |
13 | - | ||
14 | -module.exports = Object.assign(api, { | ||
15 | - getRegData | ||
16 | -}); |
@@ -4,18 +4,23 @@ | @@ -4,18 +4,23 @@ | ||
4 | 'use strict'; | 4 | 'use strict'; |
5 | 5 | ||
6 | const _ = require('lodash'); | 6 | const _ = require('lodash'); |
7 | -const api = global.yoho.API; | ||
8 | const EMPTY = {}; | 7 | const EMPTY = {}; |
9 | 8 | ||
10 | -/** | 9 | +module.exports = class extends global.yoho.BaseModel { |
10 | + constructor(ctx) { | ||
11 | + super(ctx); | ||
12 | + } | ||
13 | + | ||
14 | + /** | ||
11 | * 根据手机号获取用户信息 | 15 | * 根据手机号获取用户信息 |
12 | */ | 16 | */ |
13 | -const findByMobileAsync = (area, mobile) => { | ||
14 | - | ||
15 | - return api.get('', { | 17 | + findByMobileAsync(area, mobile) { |
18 | + return this.get({ | ||
19 | + data: { | ||
16 | mobile: mobile, | 20 | mobile: mobile, |
17 | area: area, | 21 | area: area, |
18 | method: 'app.passport.getProfileByMobile' | 22 | method: 'app.passport.getProfileByMobile' |
23 | + } | ||
19 | }).then(result => { | 24 | }).then(result => { |
20 | if (!result.code || result.code !== 200 || !result.data || _.isEmpty(result.data)) { | 25 | if (!result.code || result.code !== 200 || !result.data || _.isEmpty(result.data)) { |
21 | return EMPTY; | 26 | return EMPTY; |
@@ -25,15 +30,17 @@ const findByMobileAsync = (area, mobile) => { | @@ -25,15 +30,17 @@ const findByMobileAsync = (area, mobile) => { | ||
25 | }).catch(() => { | 30 | }).catch(() => { |
26 | return EMPTY; | 31 | return EMPTY; |
27 | }); | 32 | }); |
28 | -}; | 33 | + } |
29 | 34 | ||
30 | -/** | 35 | + /** |
31 | * 根据邮箱获取用户信息 | 36 | * 根据邮箱获取用户信息 |
32 | */ | 37 | */ |
33 | -const findByEmailAsync = (email) => { | ||
34 | - return api.get('', { | 38 | + findByEmailAsync(email) { |
39 | + return this.get({ | ||
40 | + data: { | ||
35 | email: email, | 41 | email: email, |
36 | method: 'app.passport.getProfileByEmail' | 42 | method: 'app.passport.getProfileByEmail' |
43 | + } | ||
37 | }).then(result => { | 44 | }).then(result => { |
38 | if (!result.code || result.code !== 200 || !result.data || _.isEmpty(result.data)) { | 45 | if (!result.code || result.code !== 200 || !result.data || _.isEmpty(result.data)) { |
39 | return EMPTY; | 46 | return EMPTY; |
@@ -44,32 +51,25 @@ const findByEmailAsync = (email) => { | @@ -44,32 +51,25 @@ const findByEmailAsync = (email) => { | ||
44 | }).catch(() => { | 51 | }).catch(() => { |
45 | return EMPTY; | 52 | return EMPTY; |
46 | }); | 53 | }); |
47 | -}; | 54 | + } |
48 | 55 | ||
49 | -const profile = (uid) => { | 56 | + profile(uid) { |
50 | let param = { | 57 | let param = { |
51 | uid: uid, | 58 | uid: uid, |
52 | method: 'app.passport.profile' | 59 | method: 'app.passport.profile' |
53 | }; | 60 | }; |
54 | 61 | ||
55 | - return api.get('', param); | ||
56 | -}; | ||
57 | - | 62 | + return this.get({data: param}); |
63 | + } | ||
58 | 64 | ||
59 | -const checkNoCertEmailUser = (uid) => { | ||
60 | 65 | ||
66 | + checkNoCertEmailUser(uid) { | ||
61 | let param = { | 67 | let param = { |
62 | method: 'app.passport.checkIsNeedPopupRelated', | 68 | method: 'app.passport.checkIsNeedPopupRelated', |
63 | uid: uid | 69 | uid: uid |
64 | }; | 70 | }; |
65 | 71 | ||
66 | - return api.get('', param); | 72 | + return this.get({data: param}); |
73 | + } | ||
67 | }; | 74 | }; |
68 | 75 | ||
69 | - | ||
70 | -module.exports = { | ||
71 | - findByMobileAsync, | ||
72 | - findByEmailAsync, | ||
73 | - profile, | ||
74 | - checkNoCertEmailUser | ||
75 | -}; |
@@ -3,17 +3,29 @@ | @@ -3,17 +3,29 @@ | ||
3 | */ | 3 | */ |
4 | 'use strict'; | 4 | 'use strict'; |
5 | 5 | ||
6 | -const api = require('./user-api'); | 6 | +const Api = require('./user-api'); |
7 | 7 | ||
8 | const helpers = global.yoho.helpers; | 8 | const helpers = global.yoho.helpers; |
9 | 9 | ||
10 | const DEFAULT_HEAD_IMG_ICO = 'https://img10.static.yhbimg.com/headimg/2013/11/28/09/01cae078abe5fe320c88cdf4c220212688.gif?imageView/2/w/100/h/100'; | 10 | const DEFAULT_HEAD_IMG_ICO = 'https://img10.static.yhbimg.com/headimg/2013/11/28/09/01cae078abe5fe320c88cdf4c220212688.gif?imageView/2/w/100/h/100'; |
11 | 11 | ||
12 | -/** | 12 | + |
13 | +module.exports = class extends global.yoho.BaseModel { | ||
14 | + constructor(ctx) { | ||
15 | + super(ctx); | ||
16 | + this.api = new Api(ctx); | ||
17 | + | ||
18 | + this.findByMobileAsync = this.api.findByMobileAsync.bind(this.api); | ||
19 | + this.findByEmailAsync = this.api.findByEmailAsync.bind(this.api); | ||
20 | + this.profile = this.api.profile.bind(this.api); | ||
21 | + this.checkNoCertEmailUser = this.api.checkNoCertEmailUser.bind(this.api); | ||
22 | + } | ||
23 | + | ||
24 | + /** | ||
13 | * 第三方登录 根据手机号获取用户相关信息 | 25 | * 第三方登录 根据手机号获取用户相关信息 |
14 | */ | 26 | */ |
15 | -const getUserInfo = (area, mobile) => { | ||
16 | - return api.findByMobileAsync(area, mobile).then(user => { | 27 | + getUserInfo(area, mobile) { |
28 | + return this.api.findByMobileAsync(area, mobile).then(user => { | ||
17 | let profile = (user.profile_name || mobile).toString(); | 29 | let profile = (user.profile_name || mobile).toString(); |
18 | 30 | ||
19 | if ((profile.length === 11 && profile.indexOf('*') < 0) || (profile.indexOf('-') >= 0 && | 31 | if ((profile.length === 11 && profile.indexOf('*') < 0) || (profile.indexOf('-') >= 0 && |
@@ -27,8 +39,5 @@ const getUserInfo = (area, mobile) => { | @@ -27,8 +39,5 @@ const getUserInfo = (area, mobile) => { | ||
27 | bindLogin: helpers.urlFormat('/signin.html', {bindMobile: mobile, bindArea: area}) | 39 | bindLogin: helpers.urlFormat('/signin.html', {bindMobile: mobile, bindArea: area}) |
28 | }; | 40 | }; |
29 | }); | 41 | }); |
42 | + } | ||
30 | }; | 43 | }; |
31 | - | ||
32 | -module.exports = Object.assign(api, { | ||
33 | - getUserInfo | ||
34 | -}); |
@@ -12,12 +12,12 @@ module.exports = class extends global.yoho.BaseModel { | @@ -12,12 +12,12 @@ module.exports = class extends global.yoho.BaseModel { | ||
12 | } | 12 | } |
13 | 13 | ||
14 | getBannerInfoAsync(bid) { | 14 | getBannerInfoAsync(bid) { |
15 | - return this.get({data: { | 15 | + return this.get({ |
16 | + data: { | ||
16 | method: 'web.brand.banner', | 17 | method: 'web.brand.banner', |
17 | brand_id: bid | 18 | brand_id: bid |
18 | - }, params: { | ||
19 | - cache: config.apiCache | ||
20 | - }}); | 19 | + }, param: config.apiCache |
20 | + }); | ||
21 | } | 21 | } |
22 | }; | 22 | }; |
23 | 23 |
@@ -17,8 +17,6 @@ module.exports = class extends global.yoho.BaseModel { | @@ -17,8 +17,6 @@ module.exports = class extends global.yoho.BaseModel { | ||
17 | product_id: pid | 17 | product_id: pid |
18 | }; | 18 | }; |
19 | 19 | ||
20 | - return this.get({data, params: { | ||
21 | - cache: config.apiCache | ||
22 | - }}); | 20 | + return this.get({data, param: config.apiCache }); |
23 | } | 21 | } |
24 | }; | 22 | }; |
@@ -71,9 +71,8 @@ module.exports = class extends global.yoho.BaseModel { | @@ -71,9 +71,8 @@ module.exports = class extends global.yoho.BaseModel { | ||
71 | data: { | 71 | data: { |
72 | method: 'web.productBanner.data', | 72 | method: 'web.productBanner.data', |
73 | product_id: pid | 73 | product_id: pid |
74 | - }, params: { | ||
75 | - cache: config.apiCache | ||
76 | - } | 74 | + }, param: config.apiCache |
75 | + | ||
77 | }); | 76 | }); |
78 | } | 77 | } |
79 | 78 | ||
@@ -85,9 +84,7 @@ module.exports = class extends global.yoho.BaseModel { | @@ -85,9 +84,7 @@ module.exports = class extends global.yoho.BaseModel { | ||
85 | data: { | 84 | data: { |
86 | method: 'h5.product.intro', | 85 | method: 'h5.product.intro', |
87 | productskn: skn | 86 | productskn: skn |
88 | - }, params: { | ||
89 | - cache: config.apiCache | ||
90 | - } | 87 | + }, param: config.apiCache |
91 | }); | 88 | }); |
92 | } | 89 | } |
93 | 90 | ||
@@ -99,9 +96,7 @@ module.exports = class extends global.yoho.BaseModel { | @@ -99,9 +96,7 @@ module.exports = class extends global.yoho.BaseModel { | ||
99 | data: { | 96 | data: { |
100 | method: 'web.product.refundExchange', | 97 | method: 'web.product.refundExchange', |
101 | product_skn: skn | 98 | product_skn: skn |
102 | - }, params: { | ||
103 | - cache: config.apiCache | ||
104 | - } | 99 | + }, param: config.apiCache |
105 | }); | 100 | }); |
106 | } | 101 | } |
107 | 102 | ||
@@ -113,9 +108,7 @@ module.exports = class extends global.yoho.BaseModel { | @@ -113,9 +108,7 @@ module.exports = class extends global.yoho.BaseModel { | ||
113 | data: { | 108 | data: { |
114 | method: 'web.productComfort.data', | 109 | method: 'web.productComfort.data', |
115 | product_id: pid | 110 | product_id: pid |
116 | - }, params: { | ||
117 | - cache: config.apiCache | ||
118 | - } | 111 | + }, param: config.apiCache |
119 | }); | 112 | }); |
120 | } | 113 | } |
121 | 114 | ||
@@ -127,9 +120,7 @@ module.exports = class extends global.yoho.BaseModel { | @@ -127,9 +120,7 @@ module.exports = class extends global.yoho.BaseModel { | ||
127 | data: { | 120 | data: { |
128 | method: 'web.productModelTry.data', | 121 | method: 'web.productModelTry.data', |
129 | product_skn: skn | 122 | product_skn: skn |
130 | - }, params: { | ||
131 | - cache: config.apiCache | ||
132 | - } | 123 | + }, param: config.apiCache |
133 | }); | 124 | }); |
134 | } | 125 | } |
135 | 126 | ||
@@ -162,11 +153,7 @@ module.exports = class extends global.yoho.BaseModel { | @@ -162,11 +153,7 @@ module.exports = class extends global.yoho.BaseModel { | ||
162 | data.current_vip_level = vipLevel; | 153 | data.current_vip_level = vipLevel; |
163 | } | 154 | } |
164 | 155 | ||
165 | - return this.get({ | ||
166 | - data, params: { | ||
167 | - cache: config.apiCache | ||
168 | - } | ||
169 | - }); | 156 | + return this.get({ data, param: config.apiCache }); |
170 | } | 157 | } |
171 | 158 | ||
172 | /** | 159 | /** |
@@ -178,11 +165,7 @@ module.exports = class extends global.yoho.BaseModel { | @@ -178,11 +165,7 @@ module.exports = class extends global.yoho.BaseModel { | ||
178 | product_skn: skn | 165 | product_skn: skn |
179 | }; | 166 | }; |
180 | 167 | ||
181 | - return this.get({ | ||
182 | - data, params: { | ||
183 | - cache: config.apiCache | ||
184 | - } | ||
185 | - }); | 168 | + return this.get({ data, param: config.apiCache }); |
186 | } | 169 | } |
187 | 170 | ||
188 | /** | 171 | /** |
@@ -202,11 +185,7 @@ module.exports = class extends global.yoho.BaseModel { | @@ -202,11 +185,7 @@ module.exports = class extends global.yoho.BaseModel { | ||
202 | data.product_skn = skn; | 185 | data.product_skn = skn; |
203 | } | 186 | } |
204 | 187 | ||
205 | - return this.get({ | ||
206 | - data, params: { | ||
207 | - cache: config.apiCache | ||
208 | - } | ||
209 | - }); | 188 | + return this.get({ data, param: config.apiCache }); |
210 | } | 189 | } |
211 | 190 | ||
212 | /** | 191 | /** |
@@ -244,7 +223,7 @@ module.exports = class extends global.yoho.BaseModel { | @@ -244,7 +223,7 @@ module.exports = class extends global.yoho.BaseModel { | ||
244 | method: 'web.search.findLike', | 223 | method: 'web.search.findLike', |
245 | limit: limit || 10, | 224 | limit: limit || 10, |
246 | product_skn: skn | 225 | product_skn: skn |
247 | - }, params: { | 226 | + }, param: { |
248 | cache: 86400 | 227 | cache: 86400 |
249 | } | 228 | } |
250 | }); | 229 | }); |
@@ -27,7 +27,7 @@ module.exports = class extends global.yoho.BaseModel { | @@ -27,7 +27,7 @@ module.exports = class extends global.yoho.BaseModel { | ||
27 | return this.get({ | 27 | return this.get({ |
28 | url: 'product/api/v2/detail/getlist', | 28 | url: 'product/api/v2/detail/getlist', |
29 | data: finalParams, | 29 | data: finalParams, |
30 | - params: {cache: config.apiCache}, | 30 | + param: config.apiCache, |
31 | api: global.yoho.GlobalAPI | 31 | api: global.yoho.GlobalAPI |
32 | }); | 32 | }); |
33 | } | 33 | } |
@@ -39,7 +39,7 @@ module.exports = class extends global.yoho.BaseModel { | @@ -39,7 +39,7 @@ module.exports = class extends global.yoho.BaseModel { | ||
39 | physical_channel: channelNum, | 39 | physical_channel: channelNum, |
40 | product_skn: skn | 40 | product_skn: skn |
41 | }, | 41 | }, |
42 | - params: { cache: config.apiCache }, | 42 | + param: config.apiCache, |
43 | api: global.yoho.GlobalAPI | 43 | api: global.yoho.GlobalAPI |
44 | }); | 44 | }); |
45 | } | 45 | } |
@@ -52,7 +52,7 @@ module.exports = class extends global.yoho.BaseModel { | @@ -52,7 +52,7 @@ module.exports = class extends global.yoho.BaseModel { | ||
52 | product_skn: skn, | 52 | product_skn: skn, |
53 | return_type: 'html' | 53 | return_type: 'html' |
54 | }, | 54 | }, |
55 | - params: {cache: config.apiCache}, | 55 | + param: config.apiCache, |
56 | api: global.yoho.GlobalAPI | 56 | api: global.yoho.GlobalAPI |
57 | }); | 57 | }); |
58 | } | 58 | } |
@@ -61,7 +61,7 @@ module.exports = class extends global.yoho.BaseModel { | @@ -61,7 +61,7 @@ module.exports = class extends global.yoho.BaseModel { | ||
61 | return this.get({ | 61 | return this.get({ |
62 | url: 'editor/api/v1/brand/get', | 62 | url: 'editor/api/v1/brand/get', |
63 | data: { brandId: brand }, | 63 | data: { brandId: brand }, |
64 | - params: {cache: config.apiCache}, | 64 | + param: config.apiCache, |
65 | api: global.yoho.GlobalAPI | 65 | api: global.yoho.GlobalAPI |
66 | }); | 66 | }); |
67 | } | 67 | } |
@@ -54,7 +54,7 @@ module.exports = class extends global.yoho.BaseModel { | @@ -54,7 +54,7 @@ module.exports = class extends global.yoho.BaseModel { | ||
54 | size: params.size || 0, | 54 | size: params.size || 0, |
55 | yh_channel: yhChannel[tempChannel].channel, | 55 | yh_channel: yhChannel[tempChannel].channel, |
56 | type: params.type || 0 | 56 | type: params.type || 0 |
57 | - }, params: {cache: config.apiCache} | 57 | + }, param: config.apiCache |
58 | }); | 58 | }); |
59 | } | 59 | } |
60 | 60 | ||
@@ -67,7 +67,7 @@ module.exports = class extends global.yoho.BaseModel { | @@ -67,7 +67,7 @@ module.exports = class extends global.yoho.BaseModel { | ||
67 | return this.get({ | 67 | return this.get({ |
68 | url: 'operations/api/v5/resource/home', | 68 | url: 'operations/api/v5/resource/home', |
69 | data: params, | 69 | data: params, |
70 | - params: {cache: config.apiCache}, | 70 | + param: config.apiCache, |
71 | api: global.yoho.ServiceAPI | 71 | api: global.yoho.ServiceAPI |
72 | }); | 72 | }); |
73 | } | 73 | } |
@@ -89,7 +89,7 @@ module.exports = class extends global.yoho.BaseModel { | @@ -89,7 +89,7 @@ module.exports = class extends global.yoho.BaseModel { | ||
89 | stocknumber: 1, // 过滤出库存 > 1的商品 | 89 | stocknumber: 1, // 过滤出库存 > 1的商品 |
90 | limit: params.limit || 5, | 90 | limit: params.limit || 5, |
91 | outlets: params.outlets || 1 // 默认取奥莱商品 | 91 | outlets: params.outlets || 1 // 默认取奥莱商品 |
92 | - }, params: {cache: config.apiCache} | 92 | + }, param: config.apiCache |
93 | }); | 93 | }); |
94 | } | 94 | } |
95 | 95 | ||
@@ -123,6 +123,6 @@ module.exports = class extends global.yoho.BaseModel { | @@ -123,6 +123,6 @@ module.exports = class extends global.yoho.BaseModel { | ||
123 | tempParams[paramsName] = params[paramsName]; | 123 | tempParams[paramsName] = params[paramsName]; |
124 | } | 124 | } |
125 | }); | 125 | }); |
126 | - return this.get({data: tempParams, params: {cache: config.apiCache}}); | 126 | + return this.get({data: tempParams, param: config.apiCache}); |
127 | } | 127 | } |
128 | }; | 128 | }; |
@@ -47,7 +47,7 @@ module.exports = class extends global.yoho.BaseModel { | @@ -47,7 +47,7 @@ module.exports = class extends global.yoho.BaseModel { | ||
47 | finalParams.yh_channel = yhChannel[params.channel].channel; | 47 | finalParams.yh_channel = yhChannel[params.channel].channel; |
48 | } | 48 | } |
49 | 49 | ||
50 | - return this.get({data: Object.assign(finalParams, params), params: {cache: config.apiCache}}); | 50 | + return this.get({data: Object.assign(finalParams, params), param: config.apiCache}); |
51 | } | 51 | } |
52 | 52 | ||
53 | /** | 53 | /** |
@@ -61,7 +61,7 @@ module.exports = class extends global.yoho.BaseModel { | @@ -61,7 +61,7 @@ module.exports = class extends global.yoho.BaseModel { | ||
61 | data: { | 61 | data: { |
62 | method: 'app.sale.getBreakingSort', | 62 | method: 'app.sale.getBreakingSort', |
63 | yh_channel: yhChannel[tempChannel].channel | 63 | yh_channel: yhChannel[tempChannel].channel |
64 | - }, params: {cache: config.apiCache} | 64 | + }, param: config.apiCache |
65 | }); | 65 | }); |
66 | } | 66 | } |
67 | 67 | ||
@@ -79,7 +79,7 @@ module.exports = class extends global.yoho.BaseModel { | @@ -79,7 +79,7 @@ module.exports = class extends global.yoho.BaseModel { | ||
79 | sort: '2', | 79 | sort: '2', |
80 | plateform: '1', | 80 | plateform: '1', |
81 | yh_channel: tempChannel.channel | 81 | yh_channel: tempChannel.channel |
82 | - }, params: {cache: config.apiCache} | 82 | + }, param: config.apiCache |
83 | }); | 83 | }); |
84 | } | 84 | } |
85 | 85 | ||
@@ -93,7 +93,7 @@ module.exports = class extends global.yoho.BaseModel { | @@ -93,7 +93,7 @@ module.exports = class extends global.yoho.BaseModel { | ||
93 | data: { | 93 | data: { |
94 | content_code: cCode | 94 | content_code: cCode |
95 | }, | 95 | }, |
96 | - params: {cache: config.apiCache}, | 96 | + param: config.apiCache, |
97 | api: global.yoho.ServiceAPI | 97 | api: global.yoho.ServiceAPI |
98 | }); | 98 | }); |
99 | } | 99 | } |
@@ -106,7 +106,7 @@ module.exports = class extends global.yoho.BaseModel { | @@ -106,7 +106,7 @@ module.exports = class extends global.yoho.BaseModel { | ||
106 | return this.get({ | 106 | return this.get({ |
107 | data: { | 107 | data: { |
108 | method: 'app.sort.get' | 108 | method: 'app.sort.get' |
109 | - }, params: {cache: config.apiCache} | 109 | + }, param: config.apiCache |
110 | }); | 110 | }); |
111 | } | 111 | } |
112 | 112 | ||
@@ -126,7 +126,7 @@ module.exports = class extends global.yoho.BaseModel { | @@ -126,7 +126,7 @@ module.exports = class extends global.yoho.BaseModel { | ||
126 | data: { | 126 | data: { |
127 | method: 'app.passport.profile', | 127 | method: 'app.passport.profile', |
128 | uid: uid | 128 | uid: uid |
129 | - }, params: {cache: true} | 129 | + }, param: {cache: true} |
130 | }); | 130 | }); |
131 | } | 131 | } |
132 | 132 | ||
@@ -141,7 +141,7 @@ module.exports = class extends global.yoho.BaseModel { | @@ -141,7 +141,7 @@ module.exports = class extends global.yoho.BaseModel { | ||
141 | method: 'app.resources.getOneSpecial', | 141 | method: 'app.resources.getOneSpecial', |
142 | special_id: specialId | 142 | special_id: specialId |
143 | }, | 143 | }, |
144 | - params: { | 144 | + param: { |
145 | code: 200, | 145 | code: 200, |
146 | cache: true | 146 | cache: true |
147 | } | 147 | } |
@@ -45,7 +45,7 @@ function getKeyActivityAsync(query) { | @@ -45,7 +45,7 @@ function getKeyActivityAsync(query) { | ||
45 | data: { | 45 | data: { |
46 | method: 'app.search.word', | 46 | method: 'app.search.word', |
47 | query: query | 47 | query: query |
48 | - }, params: { | 48 | + }, param: { |
49 | catch: true, | 49 | catch: true, |
50 | code: 200 | 50 | code: 200 |
51 | } | 51 | } |
@@ -143,7 +143,7 @@ function getSeoProductList(params, from) { | @@ -143,7 +143,7 @@ function getSeoProductList(params, from) { | ||
143 | } | 143 | } |
144 | 144 | ||
145 | function getSortListOrig(finalParams) { | 145 | function getSortListOrig(finalParams) { |
146 | - return this.get({data: finalParams, params: {cache: config.apiCache}}); | 146 | + return this.get({data: finalParams, param: config.apiCache}); |
147 | } | 147 | } |
148 | 148 | ||
149 | /** | 149 | /** |
@@ -221,7 +221,7 @@ function getSortIntro(params) { | @@ -221,7 +221,7 @@ function getSortIntro(params) { | ||
221 | }; | 221 | }; |
222 | 222 | ||
223 | Object.assign(finalParams, params); | 223 | Object.assign(finalParams, params); |
224 | - return this.get({data: finalParams, params: {cache: config.apiCache}}); | 224 | + return this.get({data: finalParams, param: config.apiCache}); |
225 | } | 225 | } |
226 | 226 | ||
227 | /** | 227 | /** |
@@ -234,7 +234,7 @@ function getSortAds(params) { | @@ -234,7 +234,7 @@ function getSortAds(params) { | ||
234 | }; | 234 | }; |
235 | 235 | ||
236 | Object.assign(finalParams, params); | 236 | Object.assign(finalParams, params); |
237 | - return this.get({data: finalParams, params: {cache: config.apiCache}}); | 237 | + return this.get({data: finalParams, param: config.apiCache}); |
238 | } | 238 | } |
239 | 239 | ||
240 | /** | 240 | /** |
@@ -256,7 +256,7 @@ function getBrandShopSeries(params) { | @@ -256,7 +256,7 @@ function getBrandShopSeries(params) { | ||
256 | }); | 256 | }); |
257 | } | 257 | } |
258 | 258 | ||
259 | - return this.get({data: finalParams, params: {cache: config.apiCache}}); | 259 | + return this.get({data: finalParams, param: config.apiCache}); |
260 | } | 260 | } |
261 | 261 | ||
262 | /** | 262 | /** |
@@ -278,7 +278,7 @@ function getBrandShopFolder(params) { | @@ -278,7 +278,7 @@ function getBrandShopFolder(params) { | ||
278 | }); | 278 | }); |
279 | } | 279 | } |
280 | 280 | ||
281 | - return this.get({data: finalParams, params: {cache: config.apiCache}}); | 281 | + return this.get({data: finalParams, param: config.apiCache}); |
282 | } | 282 | } |
283 | 283 | ||
284 | /** | 284 | /** |
@@ -292,7 +292,7 @@ function getNodeContent(params) { | @@ -292,7 +292,7 @@ function getNodeContent(params) { | ||
292 | node: params.node || '' | 292 | node: params.node || '' |
293 | }; | 293 | }; |
294 | 294 | ||
295 | - return this.get({data: finalParams, params: {cache: config.apiCache}}); | 295 | + return this.get({data: finalParams, param: config.apiCache}); |
296 | } | 296 | } |
297 | 297 | ||
298 | /** | 298 | /** |
@@ -306,7 +306,7 @@ function getWeekNew(params) { | @@ -306,7 +306,7 @@ function getWeekNew(params) { | ||
306 | }; | 306 | }; |
307 | 307 | ||
308 | Object.assign(finalParams, params); | 308 | Object.assign(finalParams, params); |
309 | - return this.get({data: finalParams, params: {cache: config.apiCache}}); | 309 | + return this.get({data: finalParams, param: {cache: config.apiCache}}); |
310 | } | 310 | } |
311 | 311 | ||
312 | function getBrandCouponAsync(brandId, uid) { | 312 | function getBrandCouponAsync(brandId, uid) { |
@@ -321,7 +321,7 @@ function getBrandCouponAsync(brandId, uid) { | @@ -321,7 +321,7 @@ function getBrandCouponAsync(brandId, uid) { | ||
321 | method: 'app.brand.getBrandIntro', | 321 | method: 'app.brand.getBrandIntro', |
322 | brand_id: brandId, | 322 | brand_id: brandId, |
323 | uid: uid | 323 | uid: uid |
324 | - }, params: extra | 324 | + }, param: extra |
325 | }); | 325 | }); |
326 | } | 326 | } |
327 | 327 | ||
@@ -334,7 +334,7 @@ function getBrandShop(query) { | @@ -334,7 +334,7 @@ function getBrandShop(query) { | ||
334 | method: 'web.search.shopListInfo' | 334 | method: 'web.search.shopListInfo' |
335 | }; | 335 | }; |
336 | 336 | ||
337 | - return this.get({data: Object.assign(finalParams, {keyword: query}), params: {cache: config.apiCache}}); | 337 | + return this.get({data: Object.assign(finalParams, {keyword: query}), param: config.apiCache}); |
338 | } | 338 | } |
339 | 339 | ||
340 | /** | 340 | /** |
@@ -401,7 +401,7 @@ function getSuggest(params) { | @@ -401,7 +401,7 @@ function getSuggest(params) { | ||
401 | keyword: params.keyword || '' | 401 | keyword: params.keyword || '' |
402 | }; | 402 | }; |
403 | 403 | ||
404 | - return this.get({data: finalParams, params: {cache: config.apiCache}}); | 404 | + return this.get({data: finalParams, param: config.apiCache}); |
405 | } | 405 | } |
406 | 406 | ||
407 | 407 | ||
@@ -415,7 +415,7 @@ function getBrandData(params) { | @@ -415,7 +415,7 @@ function getBrandData(params) { | ||
415 | domain: params.domain || '' | 415 | domain: params.domain || '' |
416 | }; | 416 | }; |
417 | 417 | ||
418 | - return this.get({data: finalParams, params: {cache: config.apiCache}}); | 418 | + return this.get({data: finalParams, param: config.apiCache}); |
419 | } | 419 | } |
420 | 420 | ||
421 | /** | 421 | /** |
@@ -444,7 +444,7 @@ function getShopInfo(shopId, uid) { | @@ -444,7 +444,7 @@ function getShopInfo(shopId, uid) { | ||
444 | uid: uid || 0 | 444 | uid: uid || 0 |
445 | }; | 445 | }; |
446 | 446 | ||
447 | - return this.get({data: finalParams, params: {cache: config.apiCache}}); | 447 | + return this.get({data: finalParams, param: config.apiCache}); |
448 | 448 | ||
449 | } | 449 | } |
450 | 450 | ||
@@ -454,7 +454,7 @@ function getShopInfo(shopId, uid) { | @@ -454,7 +454,7 @@ function getShopInfo(shopId, uid) { | ||
454 | function getShopBrands(shopId) { | 454 | function getShopBrands(shopId) { |
455 | return this.get({ | 455 | return this.get({ |
456 | data: {method: 'app.shops.getShopsBrands', shop_id: shopId || 0}, | 456 | data: {method: 'app.shops.getShopsBrands', shop_id: shopId || 0}, |
457 | - params: {cache: config.apiCache} | 457 | + param: config.apiCache |
458 | }); | 458 | }); |
459 | } | 459 | } |
460 | 460 | ||
@@ -464,7 +464,7 @@ function getShopBrands(shopId) { | @@ -464,7 +464,7 @@ function getShopBrands(shopId) { | ||
464 | function getShopDecorator(shopId) { | 464 | function getShopDecorator(shopId) { |
465 | return this.get({ | 465 | return this.get({ |
466 | data: {method: 'app.shopsdecorator.getList', shop_id: shopId || 0}, | 466 | data: {method: 'app.shopsdecorator.getList', shop_id: shopId || 0}, |
467 | - params: {cache: config.apiCache} | 467 | + param: config.apiCache |
468 | }); | 468 | }); |
469 | } | 469 | } |
470 | 470 |
@@ -18,7 +18,7 @@ module.exports = class extends global.yoho.BaseModel { | @@ -18,7 +18,7 @@ module.exports = class extends global.yoho.BaseModel { | ||
18 | data: { | 18 | data: { |
19 | method: 'app.shopsdecorator.getList', | 19 | method: 'app.shopsdecorator.getList', |
20 | shop_id: shopId | 20 | shop_id: shopId |
21 | - }, params: {cache: config.apiCache} | 21 | + }, param: config.apiCache |
22 | }); | 22 | }); |
23 | } | 23 | } |
24 | 24 | ||
@@ -39,7 +39,7 @@ module.exports = class extends global.yoho.BaseModel { | @@ -39,7 +39,7 @@ module.exports = class extends global.yoho.BaseModel { | ||
39 | method: 'shop.coupons.list', | 39 | method: 'shop.coupons.list', |
40 | shop_id: shopId, | 40 | shop_id: shopId, |
41 | uid: uid | 41 | uid: uid |
42 | - }, params: extra | 42 | + }, param: extra |
43 | }); | 43 | }); |
44 | } | 44 | } |
45 | 45 | ||
@@ -75,7 +75,7 @@ module.exports = class extends global.yoho.BaseModel { | @@ -75,7 +75,7 @@ module.exports = class extends global.yoho.BaseModel { | ||
75 | 75 | ||
76 | return this.get({ | 76 | return this.get({ |
77 | data: finalParams, | 77 | data: finalParams, |
78 | - params: {cache: config.apiCache} | 78 | + param: config.apiCache |
79 | }); | 79 | }); |
80 | } | 80 | } |
81 | }; | 81 | }; |
@@ -22,7 +22,7 @@ module.exports = class extends global.yoho.BaseModel { | @@ -22,7 +22,7 @@ module.exports = class extends global.yoho.BaseModel { | ||
22 | */ | 22 | */ |
23 | getVerifiedTotal() { | 23 | getVerifiedTotal() { |
24 | 24 | ||
25 | - return this.get({data: {method: 'app.student.verifiedStudentTotal'}, params: {cache: config.apiCache}}); | 25 | + return this.get({data: {method: 'app.student.verifiedStudentTotal'}, param: config.apiCache}); |
26 | } | 26 | } |
27 | 27 | ||
28 | /** | 28 | /** |
@@ -31,7 +31,7 @@ module.exports = class extends global.yoho.BaseModel { | @@ -31,7 +31,7 @@ module.exports = class extends global.yoho.BaseModel { | ||
31 | */ | 31 | */ |
32 | getEduLevelList() { | 32 | getEduLevelList() { |
33 | 33 | ||
34 | - return this.get({data: {method: 'app.studentMarket.getEducationLevelList'}, params: {cache: config.apiCache}}); | 34 | + return this.get({data: {method: 'app.studentMarket.getEducationLevelList'}, param: config.apiCache}); |
35 | } | 35 | } |
36 | 36 | ||
37 | /** | 37 | /** |
@@ -43,7 +43,7 @@ module.exports = class extends global.yoho.BaseModel { | @@ -43,7 +43,7 @@ module.exports = class extends global.yoho.BaseModel { | ||
43 | method: 'app.studentMarket.getAddressList' | 43 | method: 'app.studentMarket.getAddressList' |
44 | }; | 44 | }; |
45 | 45 | ||
46 | - return this.get({data: finalParams, params: {cache: config.apiCache}}); | 46 | + return this.get({data: finalParams, param: config.apiCache}); |
47 | } | 47 | } |
48 | 48 | ||
49 | /** | 49 | /** |
@@ -56,7 +56,7 @@ module.exports = class extends global.yoho.BaseModel { | @@ -56,7 +56,7 @@ module.exports = class extends global.yoho.BaseModel { | ||
56 | areaCode: areaCode | 56 | areaCode: areaCode |
57 | }; | 57 | }; |
58 | 58 | ||
59 | - return this.get({data: finalParams, params: {cache: config.apiCache}}); | 59 | + return this.get({data: finalParams, param: config.apiCache}); |
60 | } | 60 | } |
61 | 61 | ||
62 | /** | 62 | /** |
@@ -71,7 +71,7 @@ module.exports = class extends global.yoho.BaseModel { | @@ -71,7 +71,7 @@ module.exports = class extends global.yoho.BaseModel { | ||
71 | }; | 71 | }; |
72 | 72 | ||
73 | Object.assign(finalParams, params); | 73 | Object.assign(finalParams, params); |
74 | - return this.get({data: finalParams, params: {cache: config.apiCache}}); | 74 | + return this.get({data: finalParams, param: config.apiCache}); |
75 | } | 75 | } |
76 | 76 | ||
77 | /** | 77 | /** |
@@ -87,7 +87,7 @@ module.exports = class extends global.yoho.BaseModel { | @@ -87,7 +87,7 @@ module.exports = class extends global.yoho.BaseModel { | ||
87 | page_url: pageUrl | 87 | page_url: pageUrl |
88 | }; | 88 | }; |
89 | 89 | ||
90 | - return this.get({data: finalParams, params: {cache: config.apiCache}}); | 90 | + return this.get({data: finalParams, param: config.apiCache}); |
91 | } | 91 | } |
92 | 92 | ||
93 | /** | 93 | /** |
@@ -104,7 +104,7 @@ module.exports = class extends global.yoho.BaseModel { | @@ -104,7 +104,7 @@ module.exports = class extends global.yoho.BaseModel { | ||
104 | enrollment_year: enrollmentYear | 104 | enrollment_year: enrollmentYear |
105 | }; | 105 | }; |
106 | 106 | ||
107 | - return this.get({data: finalParams, params: {cache: config.apiCache}}); | 107 | + return this.get({data: finalParams, param: config.apiCache}); |
108 | } | 108 | } |
109 | 109 | ||
110 | /** | 110 | /** |
@@ -122,7 +122,7 @@ module.exports = class extends global.yoho.BaseModel { | @@ -122,7 +122,7 @@ module.exports = class extends global.yoho.BaseModel { | ||
122 | finalParams.uid = uid; | 122 | finalParams.uid = uid; |
123 | } | 123 | } |
124 | 124 | ||
125 | - return this.get({data: finalParams, params: {cache: config.apiCache}}); | 125 | + return this.get({data: finalParams, param: config.apiCache}); |
126 | } | 126 | } |
127 | 127 | ||
128 | 128 |
@@ -41,10 +41,10 @@ module.exports = { | @@ -41,10 +41,10 @@ module.exports = { | ||
41 | // platformApi: 'http://172.16.6.210:8088/', | 41 | // platformApi: 'http://172.16.6.210:8088/', |
42 | 42 | ||
43 | // gray | 43 | // gray |
44 | - // singleApi: 'http://single.gray.yohops.com/', | ||
45 | - // api: 'http://api.gray.yohops.com/', | ||
46 | - // service: 'http://service.gray.yohops.com/', | ||
47 | - // platformApi: 'http://172.16.6.210:8088/', | 44 | + singleApi: 'http://single.gray.yohops.com/', |
45 | + api: 'http://api.gray.yohops.com/', | ||
46 | + service: 'http://service.gray.yohops.com/', | ||
47 | + platformApi: 'http://172.16.6.210:8088/', | ||
48 | 48 | ||
49 | // dev | 49 | // dev |
50 | // api: 'http://dev-api.yohops.com:9999/', | 50 | // api: 'http://dev-api.yohops.com:9999/', |
-
Please register or login to post a comment