Showing
1 changed file
with
250 additions
and
18 deletions
@@ -8,6 +8,7 @@ const Promise = require('bluebird'); | @@ -8,6 +8,7 @@ const Promise = require('bluebird'); | ||
8 | const co = Promise.coroutine; | 8 | const co = Promise.coroutine; |
9 | const headerModel = require('../../../doraemon/models/header'); // 头部model | 9 | const headerModel = require('../../../doraemon/models/header'); // 头部model |
10 | const _ = require('lodash'); | 10 | const _ = require('lodash'); |
11 | +const productProcess = require(`${utils}/product-process`); | ||
11 | 12 | ||
12 | 13 | ||
13 | const getResource = code => { | 14 | const getResource = code => { |
@@ -87,6 +88,32 @@ const getUser = (uid) => { | @@ -87,6 +88,32 @@ const getUser = (uid) => { | ||
87 | }); | 88 | }); |
88 | }; | 89 | }; |
89 | 90 | ||
91 | +/** | ||
92 | + * 商品 | ||
93 | + * @param id | ||
94 | + * @returns {*} | ||
95 | + */ | ||
96 | +const _getRelatedData = (idList) => { | ||
97 | + return api.get('', { | ||
98 | + productSkn: idList, | ||
99 | + method: 'h5.product.batch' | ||
100 | + }).then((result) => { | ||
101 | + | ||
102 | + let goods = []; | ||
103 | + | ||
104 | + if (result && result.code === 200) { | ||
105 | + console.log(result) | ||
106 | + | ||
107 | + goods = productProcess.processProductList(result.data.product_list); | ||
108 | + | ||
109 | + return goods; | ||
110 | + } else { | ||
111 | + logger.error('推荐商品 cood 不是 200'); | ||
112 | + return {}; | ||
113 | + } | ||
114 | + }); | ||
115 | +}; | ||
116 | + | ||
90 | /* 获取用户或者环境相关数据*/ | 117 | /* 获取用户或者环境相关数据*/ |
91 | const getPlatForm = (req) => { | 118 | const getPlatForm = (req) => { |
92 | let userAgent = req.get('User-Agent'); | 119 | let userAgent = req.get('User-Agent'); |
@@ -147,25 +174,30 @@ const getPlatForm = (req) => { | @@ -147,25 +174,30 @@ const getPlatForm = (req) => { | ||
147 | })(); | 174 | })(); |
148 | }; | 175 | }; |
149 | 176 | ||
150 | - | ||
151 | exports.index = (req, res, next) => { | 177 | exports.index = (req, res, next) => { |
152 | - let code = '989396a17443bf61e3e269702e51ef04'; | 178 | + let code = '50b995e190ff8cfe52989972a4943b06'; |
153 | let uid = req.__USER__.uid; | 179 | let uid = req.__USER__.uid; |
154 | let options; | 180 | let options; |
155 | let noLoginUrl = helpers.urlFormat('/activity/student/register') + '?openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"' + req.__USER__.http + '//m.yohobuy.com/activity/student"}}}'; | 181 | let noLoginUrl = helpers.urlFormat('/activity/student/register') + '?openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"' + req.__USER__.http + '//m.yohobuy.com/activity/student"}}}'; |
156 | 182 | ||
157 | - Promise.all([getResource(code), vip()]).then(datas => { | 183 | + return serviceApi.get('operations/api/v5/resource/get', { |
184 | + content_code: code, | ||
185 | + platform: 'iphone' | ||
186 | + }).then((result) => { | ||
187 | + | ||
158 | let coupons, | 188 | let coupons, |
159 | activities, | 189 | activities, |
160 | banner, | 190 | banner, |
161 | icons, | 191 | icons, |
162 | link, | 192 | link, |
193 | + studentGoods, | ||
194 | + idList = [], | ||
163 | 195 | ||
164 | // url, | 196 | // url, |
165 | // param, | 197 | // param, |
166 | couponids = []; | 198 | couponids = []; |
167 | 199 | ||
168 | - (datas[0].data || []).forEach((item) => { | 200 | + (result.data || []).forEach((item) => { |
169 | switch (item.template_name) { | 201 | switch (item.template_name) { |
170 | case 'getCoupon': | 202 | case 'getCoupon': |
171 | coupons = item; | 203 | coupons = item; |
@@ -182,6 +214,9 @@ exports.index = (req, res, next) => { | @@ -182,6 +214,9 @@ exports.index = (req, res, next) => { | ||
182 | case 'link': | 214 | case 'link': |
183 | link = item; | 215 | link = item; |
184 | break; | 216 | break; |
217 | + case 'goods': | ||
218 | + studentGoods = item; | ||
219 | + break; | ||
185 | default: | 220 | default: |
186 | // other = item; | 221 | // other = item; |
187 | break; | 222 | break; |
@@ -206,10 +241,16 @@ exports.index = (req, res, next) => { | @@ -206,10 +241,16 @@ exports.index = (req, res, next) => { | ||
206 | coupons.data = coupons.data.slice(0, 2); | 241 | coupons.data = coupons.data.slice(0, 2); |
207 | } | 242 | } |
208 | 243 | ||
209 | - return userAcquireStatus(uid, couponids.join(',')).then((cous) => { | 244 | + if (studentGoods && studentGoods.data) { |
245 | + _.forEach(studentGoods.data, function(obj) { | ||
246 | + idList.push(obj.id); | ||
247 | + }); | ||
248 | + } | ||
249 | + | ||
250 | + return Promise.all([userAcquireStatus(uid, couponids.join(',')), _getRelatedData(idList.join(','))]).then(datas => { | ||
210 | coupons.data = _.get(coupons, 'data', []).map((item)=>{ | 251 | coupons.data = _.get(coupons, 'data', []).map((item)=>{ |
211 | item.status = 1; | 252 | item.status = 1; |
212 | - (cous.data || []).forEach((it) => { | 253 | + (datas[0].data || []).forEach((it) => { |
213 | 254 | ||
214 | if (+it.couponId === +item.couponID) { | 255 | if (+it.couponId === +item.couponID) { |
215 | item.hasNum = it.hasNum; | 256 | item.hasNum = it.hasNum; |
@@ -220,18 +261,9 @@ exports.index = (req, res, next) => { | @@ -220,18 +261,9 @@ exports.index = (req, res, next) => { | ||
220 | return item; | 261 | return item; |
221 | }); | 262 | }); |
222 | 263 | ||
223 | - // console.log(datas[1]); | ||
224 | - | ||
225 | - datas[1].data = datas[1].data || {}; | ||
226 | - datas[1].data.product_list = (datas[1].data.product_list || []).map(function(value) { | ||
227 | - value.goodsId = value.goods_list[0].goods_id; | ||
228 | - value.url = helpers.urlFormat(`/product/pro_${value.product_id}_${value.goodsId}/${value.cn_alphabet}.html`) + `?openby:yohobuy={"action":"go.productDetail","params":{"product_skn":${value.product_skn}}}`; | ||
229 | - return value; | ||
230 | - }); | ||
231 | - | ||
232 | options = { | 264 | options = { |
233 | isApp: req.__USER__.isApp, | 265 | isApp: req.__USER__.isApp, |
234 | - goods: datas[1].data.product_list, | 266 | + goods: datas[1], |
235 | banner: banner, | 267 | banner: banner, |
236 | icons: icons, | 268 | icons: icons, |
237 | coupons: coupons, | 269 | coupons: coupons, |
@@ -277,10 +309,210 @@ exports.index = (req, res, next) => { | @@ -277,10 +309,210 @@ exports.index = (req, res, next) => { | ||
277 | 309 | ||
278 | // console.log(options); | 310 | // console.log(options); |
279 | res.render('student-market', options); | 311 | res.render('student-market', options); |
280 | - }); | ||
281 | 312 | ||
313 | + }) | ||
314 | + | ||
315 | + // return userAcquireStatus(uid, couponids.join(',')).then((cous) => { | ||
316 | + // coupons.data = _.get(coupons, 'data', []).map((item)=>{ | ||
317 | + // item.status = 1; | ||
318 | + // (cous.data || []).forEach((it) => { | ||
319 | + | ||
320 | + // if (+it.couponId === +item.couponID) { | ||
321 | + // item.hasNum = it.hasNum; | ||
322 | + // item.status = it.status; | ||
323 | + // } | ||
324 | + // }); | ||
325 | + // item.couponID = crypto.encryption('yoho9646abcdefgh', item.couponID); | ||
326 | + // return item; | ||
327 | + // }); | ||
328 | + | ||
329 | + // // console.log(datas[1]); | ||
330 | + | ||
331 | + // // datas[1].data = datas[1].data || {}; | ||
332 | + // // datas[1].data.product_list = (datas[1].data.product_list || []).map(function(value) { | ||
333 | + // // value.goodsId = value.goods_list[0].goods_id; | ||
334 | + // // value.url = helpers.urlFormat(`/product/pro_${value.product_id}_${value.goodsId}/${value.cn_alphabet}.html`) + `?openby:yohobuy={"action":"go.productDetail","params":{"product_skn":${value.product_skn}}}`; | ||
335 | + // // return value; | ||
336 | + // // }); | ||
337 | + | ||
338 | + // options = { | ||
339 | + // isApp: req.__USER__.isApp, | ||
340 | + // // goods: datas[1].data.product_list, | ||
341 | + // banner: banner, | ||
342 | + // icons: icons, | ||
343 | + // coupons: coupons, | ||
344 | + // activities: activities, | ||
345 | + // isStudent: req.__USER__.isStudent, | ||
346 | + // isSupportStudent: req.__USER__.isSupportStudent, | ||
347 | + // isLogin: req.__USER__.isLogin, | ||
348 | + // title: '有货学生专享权益', | ||
349 | + // http: req.__USER__.http, | ||
350 | + // uid: req.__USER__.uid, | ||
351 | + // app_version: req.__USER__.app_version, | ||
352 | + // isAppNoLogin: req.__USER__.isApp && !req.__USER__.isLogin, | ||
353 | + // noLoginUrl: noLoginUrl, | ||
354 | + // page: 'student', | ||
355 | + // showDownloadApp: true | ||
356 | + // }; | ||
357 | + // if (!req.__USER__.isApp) { | ||
358 | + // options.pageHeader = headerModel.setNav({ | ||
359 | + // navTitle: options.title, | ||
360 | + // navBtn: true | ||
361 | + // }); | ||
362 | + // } | ||
282 | 363 | ||
283 | - }).catch(next); | 364 | + // options.loginUrl = '//m.yohobuy.com/activity/student/register'; |
365 | + // if (options.isApp) { | ||
366 | + // if (options.isLogin) { | ||
367 | + // if (options.isStudent) { | ||
368 | + // options.loginUrl = false; | ||
369 | + // } else { | ||
370 | + // options.loginUrl = options.loginUrl + '?openby:yohobuy={"action":"go.h5","params":{"islogin":"N","url":"' + req.__USER__.http + '//m.yohobuy.com/activity/student/register"}}'; | ||
371 | + // } | ||
372 | + // } else { | ||
373 | + // // no login | ||
374 | + // options.loginUrl = options.loginUrl + '?openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"' + req.__USER__.http + '//m.yohobuy.com/activity/student/register","antarget":"1"}}}'; | ||
375 | + // } | ||
376 | + // } else { | ||
377 | + // if (options.isLogin) { | ||
378 | + // if (options.isStudent) { | ||
379 | + // options.loginUrl = false; | ||
380 | + // } | ||
381 | + // } | ||
382 | + // } | ||
383 | + | ||
384 | + // // console.log(options); | ||
385 | + // res.render('student-market', options); | ||
386 | + // }); | ||
387 | + }) | ||
388 | + | ||
389 | + // Promise.all([getResource(code), vip()]).then(datas => { | ||
390 | + // let coupons, | ||
391 | + // activities, | ||
392 | + // banner, | ||
393 | + // icons, | ||
394 | + // link, | ||
395 | + | ||
396 | + // // url, | ||
397 | + // // param, | ||
398 | + // couponids = []; | ||
399 | + | ||
400 | + // (datas[0].data || []).forEach((item) => { | ||
401 | + // switch (item.template_name) { | ||
402 | + // case 'getCoupon': | ||
403 | + // coupons = item; | ||
404 | + // break; | ||
405 | + // case 'image_list': | ||
406 | + // activities = item; | ||
407 | + // break; | ||
408 | + // case 'focus': | ||
409 | + // banner = item; | ||
410 | + // break; | ||
411 | + // case 'recommend_content_five': | ||
412 | + // icons = item; | ||
413 | + // break; | ||
414 | + // case 'link': | ||
415 | + // link = item; | ||
416 | + // break; | ||
417 | + // default: | ||
418 | + // // other = item; | ||
419 | + // break; | ||
420 | + // } | ||
421 | + // }); | ||
422 | + | ||
423 | + // if (coupons && coupons.data) { | ||
424 | + // coupons.link = link && link.data ? link.data[0].url + (req.__USER__.isApp ? '&app_version=' + req.__USER__.app_version : '') : ''; | ||
425 | + | ||
426 | + // coupons.data = (coupons.data || []).map((item) => { | ||
427 | + // // let url = item.image.url; | ||
428 | + // couponids.push(item.couponID); | ||
429 | + | ||
430 | + // // if (!req.__USER__.isLogin) { | ||
431 | + // // url = 'http://m.yohobuy.com/activity/student/register?openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"http://m.yohobuy.com/activity/student"}}}'; | ||
432 | + // // } | ||
433 | + // // | ||
434 | + // // item.image.noLoginUrl=url; | ||
435 | + // return item; | ||
436 | + // }); | ||
437 | + | ||
438 | + // coupons.data = coupons.data.slice(0, 2); | ||
439 | + // } | ||
440 | + | ||
441 | + // return userAcquireStatus(uid, couponids.join(',')).then((cous) => { | ||
442 | + // coupons.data = _.get(coupons, 'data', []).map((item)=>{ | ||
443 | + // item.status = 1; | ||
444 | + // (cous.data || []).forEach((it) => { | ||
445 | + | ||
446 | + // if (+it.couponId === +item.couponID) { | ||
447 | + // item.hasNum = it.hasNum; | ||
448 | + // item.status = it.status; | ||
449 | + // } | ||
450 | + // }); | ||
451 | + // item.couponID = crypto.encryption('yoho9646abcdefgh', item.couponID); | ||
452 | + // return item; | ||
453 | + // }); | ||
454 | + | ||
455 | + // // console.log(datas[1]); | ||
456 | + | ||
457 | + // datas[1].data = datas[1].data || {}; | ||
458 | + // datas[1].data.product_list = (datas[1].data.product_list || []).map(function(value) { | ||
459 | + // value.goodsId = value.goods_list[0].goods_id; | ||
460 | + // value.url = helpers.urlFormat(`/product/pro_${value.product_id}_${value.goodsId}/${value.cn_alphabet}.html`) + `?openby:yohobuy={"action":"go.productDetail","params":{"product_skn":${value.product_skn}}}`; | ||
461 | + // return value; | ||
462 | + // }); | ||
463 | + | ||
464 | + // options = { | ||
465 | + // isApp: req.__USER__.isApp, | ||
466 | + // goods: datas[1].data.product_list, | ||
467 | + // banner: banner, | ||
468 | + // icons: icons, | ||
469 | + // coupons: coupons, | ||
470 | + // activities: activities, | ||
471 | + // isStudent: req.__USER__.isStudent, | ||
472 | + // isSupportStudent: req.__USER__.isSupportStudent, | ||
473 | + // isLogin: req.__USER__.isLogin, | ||
474 | + // title: '有货学生专享权益', | ||
475 | + // http: req.__USER__.http, | ||
476 | + // uid: req.__USER__.uid, | ||
477 | + // app_version: req.__USER__.app_version, | ||
478 | + // isAppNoLogin: req.__USER__.isApp && !req.__USER__.isLogin, | ||
479 | + // noLoginUrl: noLoginUrl, | ||
480 | + // page: 'student', | ||
481 | + // showDownloadApp: true | ||
482 | + // }; | ||
483 | + // if (!req.__USER__.isApp) { | ||
484 | + // options.pageHeader = headerModel.setNav({ | ||
485 | + // navTitle: options.title, | ||
486 | + // navBtn: true | ||
487 | + // }); | ||
488 | + // } | ||
489 | + | ||
490 | + // options.loginUrl = '//m.yohobuy.com/activity/student/register'; | ||
491 | + // if (options.isApp) { | ||
492 | + // if (options.isLogin) { | ||
493 | + // if (options.isStudent) { | ||
494 | + // options.loginUrl = false; | ||
495 | + // } else { | ||
496 | + // options.loginUrl = options.loginUrl + '?openby:yohobuy={"action":"go.h5","params":{"islogin":"N","url":"' + req.__USER__.http + '//m.yohobuy.com/activity/student/register"}}'; | ||
497 | + // } | ||
498 | + // } else { | ||
499 | + // // no login | ||
500 | + // options.loginUrl = options.loginUrl + '?openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"' + req.__USER__.http + '//m.yohobuy.com/activity/student/register","antarget":"1"}}}'; | ||
501 | + // } | ||
502 | + // } else { | ||
503 | + // if (options.isLogin) { | ||
504 | + // if (options.isStudent) { | ||
505 | + // options.loginUrl = false; | ||
506 | + // } | ||
507 | + // } | ||
508 | + // } | ||
509 | + | ||
510 | + // // console.log(options); | ||
511 | + // res.render('student-market', options); | ||
512 | + // }); | ||
513 | + | ||
514 | + | ||
515 | + // }).catch(next); | ||
284 | }; | 516 | }; |
285 | 517 | ||
286 | 518 |
-
Please register or login to post a comment