Authored by 郭成尧

detail-backend-process

@@ -4,6 +4,7 @@ @@ -4,6 +4,7 @@
4 * @date: 2016/09/07 4 * @date: 2016/09/07
5 */ 5 */
6 'use strict'; 6 'use strict';
  7 +const co = require('bluebird').coroutine;
7 const helpers = global.yoho.helpers; 8 const helpers = global.yoho.helpers;
8 const mRoot = '../models'; 9 const mRoot = '../models';
9 const typeLib = require('../../../config/type-lib'); 10 const typeLib = require('../../../config/type-lib');
@@ -344,10 +345,6 @@ const index = (req, res, next) => { @@ -344,10 +345,6 @@ const index = (req, res, next) => {
344 345
345 res.locals.appPath = `yohobuy://yohobuy.com/goapp?openby:yohobuy={"action":"go.h5","params":{"id":"${id}","share":"/guang/api/v1/share/guang?id=${id}","shareparam":{"id":"${id}"},"islogin":"N","type":1,"url":"http://guang.m.yohobuy.com/info/index","param":{"id":"${id}"}}}`; 346 res.locals.appPath = `yohobuy://yohobuy.com/goapp?openby:yohobuy={"action":"go.h5","params":{"id":"${id}","share":"/guang/api/v1/share/guang?id=${id}","shareparam":{"id":"${id}"},"islogin":"N","type":1,"url":"http://guang.m.yohobuy.com/info/index","param":{"id":"${id}"}}}`;
346 347
347 - // pagecache 前端做  
348 - // userAgent = req.get('User-Agent'),  
349 - // isWeixin = userAgent.includes('MicroMessenger'); // 标识是否是微信访问  
350 -  
351 // 判断参数是否有效, 无效会跳转到错误页面 348 // 判断参数是否有效, 无效会跳转到错误页面
352 if (!stringProcess.isNumeric(id)) { 349 if (!stringProcess.isNumeric(id)) {
353 res.json({ 350 res.json({
@@ -366,17 +363,8 @@ const index = (req, res, next) => { @@ -366,17 +363,8 @@ const index = (req, res, next) => {
366 363
367 isShare = isWeixin || isqq || isWeibo ? true : false; 364 isShare = isWeixin || isqq || isWeibo ? true : false;
368 365
369 - // WAP上设置头部导航 pagecache  
370 - // if (!isApp && !isWeixin) {  
371 - // parameter = {  
372 - // pageHeader: headerModel.setNav({  
373 - // navTitle: title  
374 - // })  
375 - // };  
376 - // }  
377 -  
378 - // 获取详情内容信息, 异常则跳到错误页面  
379 - return req.ctx(DetailModel).packageData(id, isApp, isWeixin, channel, isShare).then(detail => { 366 + co(function* () {
  367 + let detail = yield req.ctx(DetailModel).packageData(id, isApp, isWeixin, channel, isShare);
380 let data = { 368 let data = {
381 guangDetail: true, 369 guangDetail: true,
382 guang: {} 370 guang: {}
@@ -425,65 +413,59 @@ const index = (req, res, next) => { @@ -425,65 +413,59 @@ const index = (req, res, next) => {
425 return next(); 413 return next();
426 } 414 }
427 415
428 - guangProcess.processArticleDetail(detail.getArticleContent, 416 + let processContents = guangProcess.processArticleDetail(detail.getArticleContent,
429 isApp, 417 isApp,
430 gender, 418 gender,
431 isWeixin, 419 isWeixin,
432 isqq, 420 isqq,
433 isWeibo); 421 isWeibo);
434 422
435 - // 生成内容部分  
436 - return _pageArticleContent(detail.getArticleContent,  
437 - isApp,  
438 - gender,  
439 - isWeixin,  
440 - isqq,  
441 - isWeibo).then((contents) => {  
442 - // console.log(contents);  
443 - guang.detail.content = contents; 423 + let goodsList = yield req.ctx(DetailModel).productInfoBySkns(processContents.allgoods);
444 424
445 - // 相关品牌  
446 - if (detail.getBrand && detail.getBrand.length) {  
447 - guang.relatedBrand = _relatedBrand(detail.getBrand, isApp);  
448 - } 425 + guang.detail.content = guangProcess.pushGoodsInfo(processContents.finalDetail, goodsList);
449 426
450 - // 相关标签  
451 - if (detail.getArticle.tags && detail.getArticle.tags.length) {  
452 - guang.relatedTag = _relatedTag(detail.getArticle.tags, isApp);  
453 - } 427 + // 相关品牌
  428 + if (detail.getBrand && detail.getBrand.length) {
  429 + guang.relatedBrand = _relatedBrand(detail.getBrand, isApp);
  430 + }
454 431
455 - // 相关文章  
456 - if (detail.getOtherArticle && detail.getOtherArticle.length) {  
457 - guang.relatedInfo = _relatedInfo(detail.getOtherArticle, isApp);  
458 - } 432 + // 相关标签
  433 + if (detail.getArticle.tags && detail.getArticle.tags.length) {
  434 + guang.relatedTag = _relatedTag(detail.getArticle.tags, isApp);
  435 + }
459 436
460 - // 分享参数  
461 - if (detail.getArticle.cover_image) {  
462 - let shareInfo = _shareInfo(id, detail.getArticle); 437 + // 相关文章
  438 + if (detail.getOtherArticle && detail.getOtherArticle.length) {
  439 + guang.relatedInfo = _relatedInfo(detail.getOtherArticle, isApp);
  440 + }
463 441
464 - Object.assign(guang, shareInfo);  
465 - data.title = detail.getArticle.article_title + ' | Yoho!Buy有货 | 潮流购物逛不停';  
466 - data.title_more = true;  
467 - data.description = detail.getArticle.article_summary;  
468 - data.description_more = true;  
469 - } 442 + // 分享参数
  443 + if (detail.getArticle.cover_image) {
  444 + let shareInfo = _shareInfo(id, detail.getArticle);
470 445
471 - // 标识有微信分享  
472 - data.hasWxShare = true;  
473 - aboutModel.about(req.yoho.isApp).then((resu) => {  
474 - data.guang.wxFooter = resu;  
475 - res.render('info/index', Object.assign({  
476 - page: 'info-index',  
477 - title: '逛',  
478 - gender: gender,  
479 - wechatShare: true,  
480 - isWeixin: isWeixin,  
481 - localCss: true,  
482 - isShare: isShare  
483 - }, data, parameter));  
484 - });  
485 - }).catch(next);  
486 - }).catch(next); 446 + Object.assign(guang, shareInfo);
  447 + data.title = detail.getArticle.article_title + ' | Yoho!Buy有货 | 潮流购物逛不停';
  448 + data.title_more = true;
  449 + data.description = detail.getArticle.article_summary;
  450 + data.description_more = true;
  451 + }
  452 +
  453 + // 标识有微信分享
  454 + data.hasWxShare = true;
  455 +
  456 + let resu = aboutModel.about(req.yoho.isApp);
  457 +
  458 + data.guang.wxFooter = resu;
  459 + res.render('info/index', Object.assign({
  460 + page: 'info-index',
  461 + title: '逛',
  462 + gender: gender,
  463 + wechatShare: true,
  464 + isWeixin: isWeixin,
  465 + localCss: true,
  466 + isShare: isShare
  467 + }, data, parameter));
  468 + })().catch(next);
487 }; 469 };
488 470
489 // 301到新路由 471 // 301到新路由
@@ -112,13 +112,13 @@ @@ -112,13 +112,13 @@
112 <img class="thumb lazy" data-original={{thumb}}> 112 <img class="thumb lazy" data-original={{thumb}}>
113 <div class="content-container"> 113 <div class="content-container">
114 <p> 114 <p>
115 - <span class="reco-name">{{name}}</span> 115 + <span class="reco-name">{{product_name}}</span>
116 </p> 116 </p>
117 <p class="price"> 117 <p class="price">
118 - <span class="sale-price {{^price}}no-price{{/price}}">&yen;{{salePrice}}</span>  
119 - {{#price}} 118 + <span class="sale-price {{^price}}no-price{{/price}}">&yen;{{sales_price}}</span>
  119 + {{#market_price}}
120 <span class="market-price">&yen;{{.}}</span> 120 <span class="market-price">&yen;{{.}}</span>
121 - {{/price}} 121 + {{/market_price}}
122 <a class="check-detail" href={{url}}> 122 <a class="check-detail" href={{url}}>
123 查看详情 123 查看详情
124 </a> 124 </a>
@@ -129,7 +129,7 @@ @@ -129,7 +129,7 @@
129 {{^}} 129 {{^}}
130 <div class="good-list clearfix"> 130 <div class="good-list clearfix">
131 {{# relatedReco}} 131 {{# relatedReco}}
132 - {{> good}} 132 + {{> common/goods}}
133 {{/ relatedReco}} 133 {{/ relatedReco}}
134 </div> 134 </div>
135 {{/if}} 135 {{/if}}
@@ -479,14 +479,25 @@ const processArticleDetail = (articleContent, isApp, gender, isWeixin, isqq, isW @@ -479,14 +479,25 @@ const processArticleDetail = (articleContent, isApp, gender, isWeixin, isqq, isW
479 }; 479 };
480 }; 480 };
481 481
  482 +/**
  483 + * 重新获取商品数据
  484 + */
482 const pushGoodsInfo = (finalDetail, goodsList) => { 485 const pushGoodsInfo = (finalDetail, goodsList) => {
483 let goodsObj = _goodsArrayToObj(productPrcs.processProductList(goodsList)); 486 let goodsObj = _goodsArrayToObj(productPrcs.processProductList(goodsList));
484 487
485 - // console.log(goodsList);  
486 _.forEach(finalDetail, (value, key) => { 488 _.forEach(finalDetail, (value, key) => {
487 - // if (value.relatedReco) {  
488 - // console.log(value.relatedReco);  
489 - // } 489 + if (value.relatedReco && _.isArray(value.relatedReco)) {
  490 +
  491 + _.forEach(value.relatedReco, (item, subKey) => {
  492 + finalDetail[key].relatedReco[subKey] = goodsObj[item.id];
  493 + });
  494 + }
  495 +
  496 + if (value.relatedReco && _.isObject(value.relatedReco)) {
  497 + _.assign(finalDetail[key].relatedReco, goodsObj[_.get(value, 'relatedReco.id', 'false')], {
  498 + thumb: helpers.image(_.get(value, 'relatedReco.src', ''), 235, 314)
  499 + });
  500 + }
490 501
491 if (value.collocation) { 502 if (value.collocation) {
492 _.forEach(value.collocation, (item, subKey) => { 503 _.forEach(value.collocation, (item, subKey) => {
@@ -497,7 +508,6 @@ const pushGoodsInfo = (finalDetail, goodsList) => { @@ -497,7 +508,6 @@ const pushGoodsInfo = (finalDetail, goodsList) => {
497 } 508 }
498 }); 509 });
499 510
500 - // console.log(JSON.stringify(finalDetail, 2, 2));  
501 return finalDetail; 511 return finalDetail;
502 }; 512 };
503 513