Authored by htoooth

refactor comment

@@ -2,6 +2,8 @@ @@ -2,6 +2,8 @@
2 * Created by TaoHuang on 2016/6/13. 2 * Created by TaoHuang on 2016/6/13.
3 */ 3 */
4 4
  5 +'use strict';
  6 +
5 const library = '../../../library'; 7 const library = '../../../library';
6 const API = require(`${library}/api`).API; 8 const API = require(`${library}/api`).API;
7 const sign = require(`${library}/sign`); 9 const sign = require(`${library}/sign`);
  1 +/**
  2 + * Created by TaoHuang on 2016/6/14.
  3 + */
  4 +
  5 +'use strict';
  6 +
  7 +const Promise = require('bluebird');
  8 +const co = Promise.coroutine;
  9 +const _ = require('lodash');
  10 +
  11 +const library = '../../../library';
  12 +const helpers = require(`${library}/helpers`);
  13 +
  14 +const api = require('./detail-comment-api');
  15 +
  16 +const detailHelper = require('./detail-helper');
  17 +
  18 +module.exports.indexAsync = (pid, page, size) => {
  19 + return co(function *() {
  20 + let commentList = yield api.indexAsync(pid, page, size);
  21 +
  22 + if (commentList.code && commentList.code === 200) {
  23 + return commentList.data.map(value => {
  24 + let item = {};
  25 +
  26 + let avatar = detailHelper.DEFAULT_AVATAR_ICO;
  27 +
  28 + if (value.head_ico) {
  29 + avatar = `${detailHelper.IMAGE_SERVICE_URL}${_.last(value.head_ico.split('headimg'))}`;
  30 + avatar = helpers.image(avatar, 30, 30);
  31 + }
  32 +
  33 + item.avatar = avatar;
  34 + item.userName = value.nickname;
  35 + item.color = value.color_name;
  36 + item.size = value.size_name;
  37 + item.comment = value.content || '';
  38 + item.date = value.create_time;
  39 + item.total = value.total;
  40 +
  41 + return item;
  42 + });
  43 + }
  44 +
  45 + return [];
  46 + })();
  47 +};
@@ -10,6 +10,11 @@ const moment = require('moment'); @@ -10,6 +10,11 @@ const moment = require('moment');
10 const COOKIE_NAME_BOYS = module.exports.COOKIE_NAME_BOYS = 'boys'; 10 const COOKIE_NAME_BOYS = module.exports.COOKIE_NAME_BOYS = 'boys';
11 const COOKIE_DOMAIN = module.exports.COOKIE_DOMAIN = '.yohobuy.com'; 11 const COOKIE_DOMAIN = module.exports.COOKIE_DOMAIN = '.yohobuy.com';
12 12
  13 +// 商品详情页的默认头像
  14 +module.exports.DEFAULT_AVATAR_ICO = 'http://static.yohobuy.com/images/v3/boy.jpg';
  15 +
  16 +module.exports.IMAGE_SERVICE_URL = 'http://head.static.yhbimg.com/yhb-head/';
  17 +
13 module.exports.setSwitchToCookie = (res) => { 18 module.exports.setSwitchToCookie = (res) => {
14 res.cookie('_Channel', COOKIE_NAME_BOYS, { 19 res.cookie('_Channel', COOKIE_NAME_BOYS, {
15 domain: COOKIE_DOMAIN, 20 domain: COOKIE_DOMAIN,
@@ -15,9 +15,9 @@ const library = '../../../library'; @@ -15,9 +15,9 @@ const library = '../../../library';
15 const helpers = require(`${library}/helpers`); 15 const helpers = require(`${library}/helpers`);
16 16
17 const productAPI = require('./detail-product-api'); 17 const productAPI = require('./detail-product-api');
18 -const commentAPI = require('./detail-comment-api');  
19 const consultAPI = require('./detail-consult-api'); 18 const consultAPI = require('./detail-consult-api');
20 19
  20 +const commentService = require('./detail-comment-service');
21 const hotAreaService = require('./detail-hotarea-service'); 21 const hotAreaService = require('./detail-hotarea-service');
22 const brandService = require('./brand-service'); 22 const brandService = require('./brand-service');
23 const favoriteBrandService = require('./favorite-brand-service'); 23 const favoriteBrandService = require('./favorite-brand-service');
@@ -33,9 +33,6 @@ const BLANK_STR = ' '; @@ -33,9 +33,6 @@ const BLANK_STR = ' ';
33 // 商品详情页的默认头像 33 // 商品详情页的默认头像
34 const DEFAULT_AVATAR_ICO = 'http://static.yohobuy.com/images/v3/boy.jpg'; 34 const DEFAULT_AVATAR_ICO = 'http://static.yohobuy.com/images/v3/boy.jpg';
35 35
36 -const IMAGE_SERVICE_URL = 'http://head.static.yhbimg.com/yhb-head/';  
37 -  
38 -  
39 const multiResourcesUrl = {}; 36 const multiResourcesUrl = {};
40 const setMultiResourceByProductBaseInfo = (data) => { 37 const setMultiResourceByProductBaseInfo = (data) => {
41 return co(function * () { 38 return co(function * () {
@@ -448,41 +445,41 @@ const getFashionTopGoodsStatus = (uid, showStatus, isBeginSale) => { @@ -448,41 +445,41 @@ const getFashionTopGoodsStatus = (uid, showStatus, isBeginSale) => {
448 // 显示获取限购码按钮 445 // 显示获取限购码按钮
449 switch (showStatus) { 446 switch (showStatus) {
450 case 1: // 开售前/后,立即分享获得限购码(用户未领取限购码) 447 case 1: // 开售前/后,立即分享获得限购码(用户未领取限购码)
451 - {  
452 - if (isBeginSale) {  
453 - result.buyNow = true;  
454 - result.dis = true;  
455 - } else {  
456 - result.openSoon = true;  
457 - result.hasLimitedCode = false;  
458 - }  
459 - break;  
460 - }  
461 - case 2: // 开售后,限购码已抢光(用户未领取限购码)  
462 - { 448 + {
  449 + if (isBeginSale) {
463 result.buyNow = true; 450 result.buyNow = true;
464 result.dis = true; 451 result.dis = true;
465 - result.limitedCodeSoldOut = true;  
466 - result.getLimitedCode = false; 452 + } else {
  453 + result.openSoon = true;
467 result.hasLimitedCode = false; 454 result.hasLimitedCode = false;
468 - break;  
469 } 455 }
  456 + break;
  457 + }
  458 + case 2: // 开售后,限购码已抢光(用户未领取限购码)
  459 + {
  460 + result.buyNow = true;
  461 + result.dis = true;
  462 + result.limitedCodeSoldOut = true;
  463 + result.getLimitedCode = false;
  464 + result.hasLimitedCode = false;
  465 + break;
  466 + }
470 case 3: // 开售后,商品已经售罄 467 case 3: // 开售后,商品已经售罄
471 - {  
472 - result.soldOut = true;  
473 - result.getLimitedCode = false;  
474 - break;  
475 - } 468 + {
  469 + result.soldOut = true;
  470 + result.getLimitedCode = false;
  471 + break;
  472 + }
476 case 4:// 开售后,立即购买(用户已领取限购码) 473 case 4:// 开售后,立即购买(用户已领取限购码)
477 - {  
478 - result.buyNow = true;  
479 - result.dis = false;  
480 - result.hasLimitedCode = true;  
481 - if (uid) { // 限购码失效  
482 - result.getLimitedCodeDis = true;  
483 - }  
484 - break; 474 + {
  475 + result.buyNow = true;
  476 + result.dis = false;
  477 + result.hasLimitedCode = true;
  478 + if (uid) { // 限购码失效
  479 + result.getLimitedCodeDis = true;
485 } 480 }
  481 + break;
  482 + }
486 case 5: // 开售前,限购码已被抢光(用户未领取限购码) 483 case 5: // 开售前,限购码已被抢光(用户未领取限购码)
487 result.openSoon = true; 484 result.openSoon = true;
488 result.hasLimitedCode = true; 485 result.hasLimitedCode = true;
@@ -751,19 +748,19 @@ const detailDataPkg = (origin, uid, vipLevel) => { @@ -751,19 +748,19 @@ const detailDataPkg = (origin, uid, vipLevel) => {
751 if (domainBrand.type && domainBrand.shopId) { 748 if (domainBrand.type && domainBrand.shopId) {
752 switch (parseInt(domainBrand.type)) { 749 switch (parseInt(domainBrand.type)) {
753 case 1: 750 case 1:
754 - { 751 + {
755 // 多品店不显示 752 // 多品店不显示
756 - banner = [];  
757 - break;  
758 - } 753 + banner = [];
  754 + break;
  755 + }
759 case 2: 756 case 2:
760 - { 757 + {
761 // TODO:单品店显示新版的店铺banner,item.php 210 758 // TODO:单品店显示新版的店铺banner,item.php 210
762 - let basisData = shopAPI.basisTemplateAsync(domainBrand.shopId); 759 + let basisData = shopAPI.basisTemplateAsync(domainBrand.shopId);
763 760
764 - banner.bgImg = basisData.shopTopBanner.banner || banner.bgImg;  
765 - break;  
766 - } 761 + banner.bgImg = basisData.shopTopBanner.banner || banner.bgImg;
  762 + break;
  763 + }
767 764
768 } 765 }
769 } 766 }
@@ -842,15 +839,15 @@ function getDescriptionDataBySizeInfoAsync(sizeInfo) { @@ -842,15 +839,15 @@ function getDescriptionDataBySizeInfoAsync(sizeInfo) {
842 839
843 switch (sizeInfo.productDescBo.gender) { 840 switch (sizeInfo.productDescBo.gender) {
844 case 1: 841 case 1:
845 - {  
846 - sex = '男款';  
847 - break;  
848 - } 842 + {
  843 + sex = '男款';
  844 + break;
  845 + }
849 case 2: 846 case 2:
850 - {  
851 - sex = '女款';  
852 - break;  
853 - } 847 + {
  848 + sex = '女款';
  849 + break;
  850 + }
854 } 851 }
855 852
856 description.basic = []; 853 description.basic = [];
@@ -1216,25 +1213,25 @@ function getSizeAttrByMaxSortId(maxSortId, sizeList) { @@ -1216,25 +1213,25 @@ function getSizeAttrByMaxSortId(maxSortId, sizeList) {
1216 switch (maxSortId) { 1213 switch (maxSortId) {
1217 case 1: 1214 case 1:
1218 case 2: 1215 case 2:
1219 - {  
1220 - attributeIds = [3, 4];  
1221 - break;  
1222 - } 1216 + {
  1217 + attributeIds = [3, 4];
  1218 + break;
  1219 + }
1223 1220
1224 case 3: 1221 case 3:
1225 - {  
1226 - attributeIds = [6, 10];  
1227 - break;  
1228 - } 1222 + {
  1223 + attributeIds = [6, 10];
  1224 + break;
  1225 + }
1229 case 6: 1226 case 6:
1230 - {  
1231 - attributeIds = [13];  
1232 - break;  
1233 - } 1227 + {
  1228 + attributeIds = [13];
  1229 + break;
  1230 + }
1234 default: 1231 default:
1235 - {  
1236 - attributeIds = [];  
1237 - } 1232 + {
  1233 + attributeIds = [];
  1234 + }
1238 } 1235 }
1239 1236
1240 let sizeInfos = []; 1237 let sizeInfos = [];
@@ -1333,36 +1330,7 @@ const getSizeInfoAsync = (productSkn, maxSortId)=> { @@ -1333,36 +1330,7 @@ const getSizeInfoAsync = (productSkn, maxSortId)=> {
1333 /** 1330 /**
1334 * 获取评论 1331 * 获取评论
1335 */ 1332 */
1336 -module.exports.indexCommentAsync = (pid, page, size) => {  
1337 - return co(function *() {  
1338 - let commentList = yield commentAPI.indexAsync(pid, page, size);  
1339 -  
1340 - if (commentList.code && commentList.code === 200) {  
1341 - return commentList.data.map(value => {  
1342 - let item = {};  
1343 -  
1344 - let avatar = DEFAULT_AVATAR_ICO;  
1345 -  
1346 - if (value.head_ico) {  
1347 - avatar = `${IMAGE_SERVICE_URL}${_.last(value.head_ico.split('headimg'))}`;  
1348 - avatar = helpers.image(avatar, 30, 30);  
1349 - }  
1350 -  
1351 - item.avatar = avatar;  
1352 - item.userName = value.nickname;  
1353 - item.color = value.color_name;  
1354 - item.size = value.size_name;  
1355 - item.comment = value.content || '';  
1356 - item.date = value.create_time;  
1357 - item.total = value.total;  
1358 -  
1359 - return item;  
1360 - });  
1361 - }  
1362 -  
1363 - return [];  
1364 - })();  
1365 -}; 1333 +module.exports.indexCommentAsync = commentService.indexAsync;
1366 1334
1367 /** 1335 /**
1368 * 获取咨询列表 1336 * 获取咨询列表