Authored by htoooth

add comment

@@ -9,7 +9,7 @@ @@ -9,7 +9,7 @@
9 const mRoot = '../models'; 9 const mRoot = '../models';
10 10
11 // 商品详情model 11 // 商品详情model
12 -const detailHandle = require(`${mRoot}/detail-handle`); 12 +const detail = require(`${mRoot}/detail-handle`);
13 const moment = require('moment'); 13 const moment = require('moment');
14 14
15 /* COOKIE标识访问的是男生频道 */ 15 /* COOKIE标识访问的是男生频道 */
@@ -30,27 +30,27 @@ function getGenderByCookie(req) { @@ -30,27 +30,27 @@ function getGenderByCookie(req) {
30 30
31 switch (channel) { 31 switch (channel) {
32 case 'boys': 32 case 'boys':
33 - {  
34 - gender = '1,3';  
35 - break;  
36 - } 33 + {
  34 + gender = '1,3';
  35 + break;
  36 + }
37 case 'girls': 37 case 'girls':
38 - {  
39 - gender = '2,3';  
40 - break;  
41 - } 38 + {
  39 + gender = '2,3';
  40 + break;
  41 + }
42 default: 42 default:
43 - {  
44 - gender = '1,2,3';  
45 - } 43 + {
  44 + gender = '1,2,3';
  45 + }
46 } 46 }
47 47
48 return gender; 48 return gender;
49 } 49 }
50 50
51 -exports.index = (req, res, next) => {  
52 - // var uid = null, // 需要修改为正式取 UID 的方式  
53 - // vipLevel = 0; // 用户等级 51 +module.exports.show= (req, res, next) => {
  52 + // TODO: 需要修改为正式取 UID 的方式
  53 + // TODO: vipLevel = 0; // 用户等级
54 54
55 let pid = 204503; 55 let pid = 204503;
56 56
@@ -64,7 +64,7 @@ exports.index = (req, res, next) => { @@ -64,7 +64,7 @@ exports.index = (req, res, next) => {
64 64
65 let gender = getGenderByCookie(req); 65 let gender = getGenderByCookie(req);
66 66
67 - detailHandle({ 67 + detail.showAsync({
68 id: pid, 68 id: pid,
69 ua: req.get('user-agent') || '', 69 ua: req.get('user-agent') || '',
70 channel: channel, 70 channel: channel,
@@ -78,3 +78,19 @@ exports.index = (req, res, next) => { @@ -78,3 +78,19 @@ exports.index = (req, res, next) => {
78 }, result)); 78 }, result));
79 }).catch(next); 79 }).catch(next);
80 }; 80 };
  81 +
  82 +/**
  83 + * 获得评论
  84 + * @param req
  85 + * @param res
  86 + * @param next
  87 + */
  88 +module.exports.comments = (req, res, next) => {
  89 + let pid = req.params.productId || 0;
  90 + let page = req.params.page || 1;
  91 + let size = req.params.size || 10;
  92 +
  93 + detail.getCommentsAsync(pid, page, size).then(result => {
  94 + res.json(result)
  95 + }).catch(next);
  96 +}
@@ -8,8 +8,7 @@ const co = Promise.coroutine; @@ -8,8 +8,7 @@ const co = Promise.coroutine;
8 8
9 const api = new API(); 9 const api = new API();
10 10
11 -module.exports.getBannerInfoAsync = function(bid, isUrl) {  
12 - isUrl; 11 +module.exports.getBannerInfoAsync = function(bid) {
13 return api.get('', sign.apiSign({ 12 return api.get('', sign.apiSign({
14 method: 'web.brand.banner', 13 method: 'web.brand.banner',
15 brand_id: bid 14 brand_id: bid
1 'use strict'; 1 'use strict';
2 2
  3 +
3 const library = '../../../library'; 4 const library = '../../../library';
4 const API = require(`${library}/api`).API; 5 const API = require(`${library}/api`).API;
5 const sign = require(`${library}/sign`); 6 const sign = require(`${library}/sign`);
  7 +
6 const api = new API(); 8 const api = new API();
7 9
8 -module.exports.getProductBannerAsync = function(pid) { 10 +module.exports.getProductBannerAsync = function (pid) {
9 return api.get('', sign.apiSign({ 11 return api.get('', sign.apiSign({
10 method: 'web.productBanner.data', 12 method: 'web.productBanner.data',
11 product_id: pid 13 product_id: pid
12 })).catch(err => console.log(err)); 14 })).catch(err => console.log(err));
13 }; 15 };
14 16
15 -module.exports.sizeInfoAsync = function(skn) { 17 +module.exports.sizeInfoAsync = function (skn) {
16 return api.get('', sign.apiSign({ 18 return api.get('', sign.apiSign({
17 method: 'h5.product.intro', 19 method: 'h5.product.intro',
18 productskn: skn 20 productskn: skn
19 })).catch(err => console.log(err)); 21 })).catch(err => console.log(err));
20 }; 22 };
21 23
22 -module.exports.getProductComfortAsync = function(pid) { 24 +module.exports.getProductComfortAsync = function (pid) {
23 return api.get('', sign.apiSign({ 25 return api.get('', sign.apiSign({
24 method: 'web.productComfort.data', 26 method: 'web.productComfort.data',
25 product_id: pid 27 product_id: pid
26 })).catch(err => console.log(err)); 28 })).catch(err => console.log(err));
27 }; 29 };
28 30
29 -module.exports.getProductModelCardAsync = function(pid) { 31 +module.exports.getProductModelCardAsync = function (pid) {
30 return api.get('', sign.apiSign({ 32 return api.get('', sign.apiSign({
31 method: 'web.productModelcard.list', 33 method: 'web.productModelcard.list',
32 product_id: pid 34 product_id: pid
33 })).catch(err => console.log(err)); 35 })).catch(err => console.log(err));
34 }; 36 };
35 37
36 -  
37 -/**  
38 - *  
39 - * @param skn  
40 - * @param isUrl  
41 - * @returns {type[]}  
42 - */  
43 -module.exports.getProductModelTryAsync = function(skn, isUrl) {  
44 - isUrl; 38 +module.exports.getProductModelTryAsync = function (skn) {
45 return api.get('', sign.apiSign({ 39 return api.get('', sign.apiSign({
46 method: 'web.productModelTry.data', 40 method: 'web.productModelTry.data',
47 product_skn: skn 41 product_skn: skn
48 })).catch(err => console.log(err)); 42 })).catch(err => console.log(err));
49 }; 43 };
50 44
  45 +/**
  46 + * 获取评论
  47 + */
  48 +module.exports.getCommentsAsync = function (pid, page, size) {
  49 + return api.get('', sign.apiSign({
  50 + method: 'app.comment.li',
  51 + product_id: pid,
  52 + page: page,
  53 + limit: size
  54 + })).catch(console.log);
  55 +}
  56 +
@@ -26,6 +26,11 @@ const HeaderModel = require('../../../doraemon/models/header'); @@ -26,6 +26,11 @@ const HeaderModel = require('../../../doraemon/models/header');
26 26
27 const BLANK_STR = ' '; 27 const BLANK_STR = ' ';
28 28
  29 +//商品详情页的默认头像
  30 +const DEFAULT_AVATAR_ICO = 'http://static.yohobuy.com/images/v3/boy.jpg';
  31 +
  32 +const IMAGE_SERVICE_URL = "http://head.static.yhbimg.com/yhb-head/";
  33 +
29 var api = new API(); 34 var api = new API();
30 35
31 const multiResourcesUrl = {}; 36 const multiResourcesUrl = {};
@@ -447,41 +452,41 @@ const getFashionTopGoodsStatus = (uid, showStatus, isBeginSale) => { @@ -447,41 +452,41 @@ const getFashionTopGoodsStatus = (uid, showStatus, isBeginSale) => {
447 // 显示获取限购码按钮 452 // 显示获取限购码按钮
448 switch (showStatus) { 453 switch (showStatus) {
449 case 1: // 开售前/后,立即分享获得限购码(用户未领取限购码) 454 case 1: // 开售前/后,立即分享获得限购码(用户未领取限购码)
450 - {  
451 - if (isBeginSale) {  
452 - result.buyNow = true;  
453 - result.dis = true;  
454 - } else {  
455 - result.openSoon = true;  
456 - result.hasLimitedCode = false;  
457 - }  
458 - break;  
459 - }  
460 - case 2: // 开售后,限购码已抢光(用户未领取限购码)  
461 - { 455 + {
  456 + if (isBeginSale) {
462 result.buyNow = true; 457 result.buyNow = true;
463 result.dis = true; 458 result.dis = true;
464 - result.limitedCodeSoldOut = true;  
465 - result.getLimitedCode = false; 459 + } else {
  460 + result.openSoon = true;
466 result.hasLimitedCode = false; 461 result.hasLimitedCode = false;
467 - break;  
468 } 462 }
  463 + break;
  464 + }
  465 + case 2: // 开售后,限购码已抢光(用户未领取限购码)
  466 + {
  467 + result.buyNow = true;
  468 + result.dis = true;
  469 + result.limitedCodeSoldOut = true;
  470 + result.getLimitedCode = false;
  471 + result.hasLimitedCode = false;
  472 + break;
  473 + }
469 case 3: // 开售后,商品已经售罄 474 case 3: // 开售后,商品已经售罄
470 - {  
471 - result.soldOut = true;  
472 - result.getLimitedCode = false;  
473 - break;  
474 - } 475 + {
  476 + result.soldOut = true;
  477 + result.getLimitedCode = false;
  478 + break;
  479 + }
475 case 4:// 开售后,立即购买(用户已领取限购码) 480 case 4:// 开售后,立即购买(用户已领取限购码)
476 - {  
477 - result.buyNow = true;  
478 - result.dis = false;  
479 - result.hasLimitedCode = true;  
480 - if (uid) { // 限购码失效  
481 - result.getLimitedCodeDis = true;  
482 - }  
483 - break; 481 + {
  482 + result.buyNow = true;
  483 + result.dis = false;
  484 + result.hasLimitedCode = true;
  485 + if (uid) { // 限购码失效
  486 + result.getLimitedCodeDis = true;
484 } 487 }
  488 + break;
  489 + }
485 case 5: // 开售前,限购码已被抢光(用户未领取限购码) 490 case 5: // 开售前,限购码已被抢光(用户未领取限购码)
486 result.openSoon = true; 491 result.openSoon = true;
487 result.hasLimitedCode = true; 492 result.hasLimitedCode = true;
@@ -751,19 +756,19 @@ const detailDataPkg = (origin, uid, vipLevel) => { @@ -751,19 +756,19 @@ const detailDataPkg = (origin, uid, vipLevel) => {
751 if (domainBrand.type && domainBrand.shopId) { 756 if (domainBrand.type && domainBrand.shopId) {
752 switch (parseInt(domainBrand.type)) { 757 switch (parseInt(domainBrand.type)) {
753 case 1: 758 case 1:
754 - { 759 + {
755 // 多品店不显示 760 // 多品店不显示
756 - banner = [];  
757 - break;  
758 - } 761 + banner = [];
  762 + break;
  763 + }
759 case 2: 764 case 2:
760 - { 765 + {
761 // TODO:单品店显示新版的店铺banner,item.php 210 766 // TODO:单品店显示新版的店铺banner,item.php 210
762 - let basisData = shopAPI.basisTemplateAsync(domainBrand.shopId); 767 + let basisData = shopAPI.basisTemplateAsync(domainBrand.shopId);
763 768
764 - banner.bgImg = basisData.shopTopBanner.banner || banner.bgImg;  
765 - break;  
766 - } 769 + banner.bgImg = basisData.shopTopBanner.banner || banner.bgImg;
  770 + break;
  771 + }
767 772
768 } 773 }
769 } 774 }
@@ -842,15 +847,15 @@ function getDescriptionDataBySizeInfoAsync(sizeInfo) { @@ -842,15 +847,15 @@ function getDescriptionDataBySizeInfoAsync(sizeInfo) {
842 847
843 switch (sizeInfo.productDescBo.gender) { 848 switch (sizeInfo.productDescBo.gender) {
844 case 1: 849 case 1:
845 - {  
846 - sex = '男款';  
847 - break;  
848 - } 850 + {
  851 + sex = '男款';
  852 + break;
  853 + }
849 case 2: 854 case 2:
850 - {  
851 - sex = '女款';  
852 - break;  
853 - } 855 + {
  856 + sex = '女款';
  857 + break;
  858 + }
854 } 859 }
855 860
856 description.basic = []; 861 description.basic = [];
@@ -1141,9 +1146,9 @@ function getDetailDataBySizeInfo(sizeInfo) { @@ -1141,9 +1146,9 @@ function getDetailDataBySizeInfo(sizeInfo) {
1141 // 图片换成懒加载方式 1146 // 图片换成懒加载方式
1142 const replacePairs = { 1147 const replacePairs = {
1143 '<img src=': '<img class="lazy" src="data:image/gif;base64,R0lGODlhAQABAJEAAAAAAP///93d3f' + 1148 '<img src=': '<img class="lazy" src="data:image/gif;base64,R0lGODlhAQABAJEAAAAAAP///93d3f' +
1144 - '///yH5BAEAAAMALAAAAAABAAEAAAICVAEAOw==" data-original=', 1149 + '///yH5BAEAAAMALAAAAAABAAEAAAICVAEAOw==" data-original=',
1145 '<img border="0" src=': '<img border="0" class="lazy" src="data:image/gif;base64,R0lGODlhAQABAJEAAAAAAP' + 1150 '<img border="0" src=': '<img border="0" class="lazy" src="data:image/gif;base64,R0lGODlhAQABAJEAAAAAAP' +
1146 - '///93d3f///yH5BAEAAAMALAAAAAABAAEAAAICVAEAOw==" data-original=' 1151 + '///93d3f///yH5BAEAAAMALAAAAAABAAEAAAICVAEAOw==" data-original='
1147 }; 1152 };
1148 1153
1149 let intro = sizeInfo.productIntroBo.productIntro; 1154 let intro = sizeInfo.productIntroBo.productIntro;
@@ -1216,25 +1221,25 @@ function getSizeAttrByMaxSortId(maxSortId, sizeList) { @@ -1216,25 +1221,25 @@ function getSizeAttrByMaxSortId(maxSortId, sizeList) {
1216 switch (maxSortId) { 1221 switch (maxSortId) {
1217 case 1: 1222 case 1:
1218 case 2: 1223 case 2:
1219 - {  
1220 - attributeIds = [3, 4];  
1221 - break;  
1222 - } 1224 + {
  1225 + attributeIds = [3, 4];
  1226 + break;
  1227 + }
1223 1228
1224 case 3: 1229 case 3:
1225 - {  
1226 - attributeIds = [6, 10];  
1227 - break;  
1228 - } 1230 + {
  1231 + attributeIds = [6, 10];
  1232 + break;
  1233 + }
1229 case 6: 1234 case 6:
1230 - {  
1231 - attributeIds = [13];  
1232 - break;  
1233 - } 1235 + {
  1236 + attributeIds = [13];
  1237 + break;
  1238 + }
1234 default: 1239 default:
1235 - {  
1236 - attributeIds = [];  
1237 - } 1240 + {
  1241 + attributeIds = [];
  1242 + }
1238 } 1243 }
1239 1244
1240 let sizeInfos = []; 1245 let sizeInfos = [];
@@ -1330,7 +1335,44 @@ const getSizeInfoAsync = (productSkn, maxSortId)=> { @@ -1330,7 +1335,44 @@ const getSizeInfoAsync = (productSkn, maxSortId)=> {
1330 })(); 1335 })();
1331 }; 1336 };
1332 1337
1333 -module.exports = (data) => { 1338 +/**
  1339 + * 获取评论
  1340 + * @param pid
  1341 + * @param page
  1342 + * @param size
  1343 + */
  1344 +module.exports.getCommentsAsync = (pid, page, size) => {
  1345 + return co(function *() {
  1346 + let commentList = yield detailAPI.getCommentsAsync(pid, page, size);
  1347 +
  1348 + if (commentList.code && commentList.code === 200) {
  1349 + return commentList.data.map(value => {
  1350 + let item = {};
  1351 +
  1352 + let avatar = DEFAULT_AVATAR_ICO;
  1353 +
  1354 + if (value.head_ico) {
  1355 + avatar = `${IMAGE_SERVICE_URL}${_.last(value.head_ico.split('headimg'))}`;
  1356 + avatar = helpers.image(avatar, 30, 30);
  1357 + }
  1358 +
  1359 + item.avatar = avatar;
  1360 + item.userName = value.nickname;
  1361 + item.color = value.color_name;
  1362 + item.size = value.size_name;
  1363 + item.comment = value.content || '';
  1364 + item.date = value.create_time;
  1365 + item.total = value.total;
  1366 +
  1367 + return item;
  1368 + });
  1369 + }
  1370 +
  1371 + return [];
  1372 + })();
  1373 +}
  1374 +
  1375 +module.exports.showAsync = (data) => {
1334 1376
1335 return co(function * () { 1377 return co(function * () {
1336 1378
@@ -1355,8 +1397,8 @@ module.exports = (data) => { @@ -1355,8 +1397,8 @@ module.exports = (data) => {
1355 1397
1356 // 导航 1398 // 导航
1357 result.detail.pathNav = _.concat(homeHandle.getHomeChannelNav(data.channel), 1399 result.detail.pathNav = _.concat(homeHandle.getHomeChannelNav(data.channel),
1358 - navs,  
1359 - [{name: productInfo.goodsInfo.name}]); 1400 + navs,
  1401 + [{name: productInfo.goodsInfo.name}]);
1360 result.detail.lastWalk = 5; 1402 result.detail.lastWalk = 5;
1361 1403
1362 result.headerData = yield HeaderModel.requestHeaderData(); 1404 result.headerData = yield HeaderModel.requestHeaderData();
@@ -5,7 +5,7 @@ const API = require(`${library}/api`).SearchAPI; @@ -5,7 +5,7 @@ const API = require(`${library}/api`).SearchAPI;
5 5
6 const api = new API(); 6 const api = new API();
7 7
8 -module.exports.getSortByConditionAsync = function(conddition) {  
9 - return api.get('sortgroup.json', conddition).catch(console.log); 8 +module.exports.getSortByConditionAsync = function(condition) {
  9 + return api.get('sortgroup.json', condition).catch(console.log);
10 }; 10 };
11 11
@@ -2,8 +2,8 @@ @@ -2,8 +2,8 @@
2 const Promise = require('bluebird'); 2 const Promise = require('bluebird');
3 const co = Promise.coroutine; 3 const co = Promise.coroutine;
4 4
5 -module.exports.basisTemplateAsync = function(shopid) { 5 +module.exports.basisTemplateAsync = function (shopId) {
6 return co(function* () { 6 return co(function* () {
7 - return {shopid}; 7 + return {shopId};
8 })(); 8 })();
9 }; 9 };
@@ -31,7 +31,8 @@ router.get('/outlets/index', outlets.index); @@ -31,7 +31,8 @@ router.get('/outlets/index', outlets.index);
31 router.get('/outlets/special/detail', outlets.special); 31 router.get('/outlets/special/detail', outlets.special);
32 router.get('/outlets/:channel', outlets.channel); 32 router.get('/outlets/:channel', outlets.channel);
33 33
34 -//  
35 -router.get('/detail/:id/:gid', detail.index); 34 +// 商品详情routers
  35 +router.get('/detail/:id/:gid', detail.show);
  36 +router.get('/detail/comments', detail.comments);
36 37
37 module.exports = router; 38 module.exports = router;
@@ -536,7 +536,7 @@ lazyLoad($('#details-html img')); @@ -536,7 +536,7 @@ lazyLoad($('#details-html img'));
536 loadingComments = true; 536 loadingComments = true;
537 $.ajax({ 537 $.ajax({
538 type: 'GET', 538 type: 'GET',
539 - url: '/product/item/comments', 539 + url: '/product/detail/comments',
540 data: { 540 data: {
541 productId: id, 541 productId: id,
542 page: commentPage 542 page: commentPage