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标识访问的是男生频道 */
@@ -48,9 +48,9 @@ function getGenderByCookie(req) { @@ -48,9 +48,9 @@ function getGenderByCookie(req) {
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 = {};
@@ -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
@@ -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