Authored by htoooth

add comment

... ... @@ -9,7 +9,7 @@
const mRoot = '../models';
// 商品详情model
const detailHandle = require(`${mRoot}/detail-handle`);
const detail = require(`${mRoot}/detail-handle`);
const moment = require('moment');
/* COOKIE标识访问的是男生频道 */
... ... @@ -48,9 +48,9 @@ function getGenderByCookie(req) {
return gender;
}
exports.index = (req, res, next) => {
// var uid = null, // 需要修改为正式取 UID 的方式
// vipLevel = 0; // 用户等级
module.exports.show= (req, res, next) => {
// TODO: 需要修改为正式取 UID 的方式
// TODO: vipLevel = 0; // 用户等级
let pid = 204503;
... ... @@ -64,7 +64,7 @@ exports.index = (req, res, next) => {
let gender = getGenderByCookie(req);
detailHandle({
detail.showAsync({
id: pid,
ua: req.get('user-agent') || '',
channel: channel,
... ... @@ -78,3 +78,19 @@ exports.index = (req, res, next) => {
}, result));
}).catch(next);
};
/**
* 获得评论
* @param req
* @param res
* @param next
*/
module.exports.comments = (req, res, next) => {
let pid = req.params.productId || 0;
let page = req.params.page || 1;
let size = req.params.size || 10;
detail.getCommentsAsync(pid, page, size).then(result => {
res.json(result)
}).catch(next);
}
... ...
... ... @@ -8,8 +8,7 @@ const co = Promise.coroutine;
const api = new API();
module.exports.getBannerInfoAsync = function(bid, isUrl) {
isUrl;
module.exports.getBannerInfoAsync = function(bid) {
return api.get('', sign.apiSign({
method: 'web.brand.banner',
brand_id: bid
... ...
'use strict';
const library = '../../../library';
const API = require(`${library}/api`).API;
const sign = require(`${library}/sign`);
const api = new API();
module.exports.getProductBannerAsync = function(pid) {
module.exports.getProductBannerAsync = function (pid) {
return api.get('', sign.apiSign({
method: 'web.productBanner.data',
product_id: pid
})).catch(err => console.log(err));
};
module.exports.sizeInfoAsync = function(skn) {
module.exports.sizeInfoAsync = function (skn) {
return api.get('', sign.apiSign({
method: 'h5.product.intro',
productskn: skn
})).catch(err => console.log(err));
};
module.exports.getProductComfortAsync = function(pid) {
module.exports.getProductComfortAsync = function (pid) {
return api.get('', sign.apiSign({
method: 'web.productComfort.data',
product_id: pid
})).catch(err => console.log(err));
};
module.exports.getProductModelCardAsync = function(pid) {
module.exports.getProductModelCardAsync = function (pid) {
return api.get('', sign.apiSign({
method: 'web.productModelcard.list',
product_id: pid
})).catch(err => console.log(err));
};
/**
*
* @param skn
* @param isUrl
* @returns {type[]}
*/
module.exports.getProductModelTryAsync = function(skn, isUrl) {
isUrl;
module.exports.getProductModelTryAsync = function (skn) {
return api.get('', sign.apiSign({
method: 'web.productModelTry.data',
product_skn: skn
})).catch(err => console.log(err));
};
/**
* 获取评论
*/
module.exports.getCommentsAsync = function (pid, page, size) {
return api.get('', sign.apiSign({
method: 'app.comment.li',
product_id: pid,
page: page,
limit: size
})).catch(console.log);
}
... ...
... ... @@ -26,6 +26,11 @@ const HeaderModel = require('../../../doraemon/models/header');
const BLANK_STR = ' ';
//商品详情页的默认头像
const DEFAULT_AVATAR_ICO = 'http://static.yohobuy.com/images/v3/boy.jpg';
const IMAGE_SERVICE_URL = "http://head.static.yhbimg.com/yhb-head/";
var api = new API();
const multiResourcesUrl = {};
... ... @@ -1330,7 +1335,44 @@ const getSizeInfoAsync = (productSkn, maxSortId)=> {
})();
};
module.exports = (data) => {
/**
* 获取评论
* @param pid
* @param page
* @param size
*/
module.exports.getCommentsAsync = (pid, page, size) => {
return co(function *() {
let commentList = yield detailAPI.getCommentsAsync(pid, page, size);
if (commentList.code && commentList.code === 200) {
return commentList.data.map(value => {
let item = {};
let avatar = DEFAULT_AVATAR_ICO;
if (value.head_ico) {
avatar = `${IMAGE_SERVICE_URL}${_.last(value.head_ico.split('headimg'))}`;
avatar = helpers.image(avatar, 30, 30);
}
item.avatar = avatar;
item.userName = value.nickname;
item.color = value.color_name;
item.size = value.size_name;
item.comment = value.content || '';
item.date = value.create_time;
item.total = value.total;
return item;
});
}
return [];
})();
}
module.exports.showAsync = (data) => {
return co(function * () {
... ...
... ... @@ -5,7 +5,7 @@ const API = require(`${library}/api`).SearchAPI;
const api = new API();
module.exports.getSortByConditionAsync = function(conddition) {
return api.get('sortgroup.json', conddition).catch(console.log);
module.exports.getSortByConditionAsync = function(condition) {
return api.get('sortgroup.json', condition).catch(console.log);
};
... ...
... ... @@ -2,8 +2,8 @@
const Promise = require('bluebird');
const co = Promise.coroutine;
module.exports.basisTemplateAsync = function(shopid) {
module.exports.basisTemplateAsync = function (shopId) {
return co(function* () {
return {shopid};
return {shopId};
})();
};
... ...
... ... @@ -31,7 +31,8 @@ router.get('/outlets/index', outlets.index);
router.get('/outlets/special/detail', outlets.special);
router.get('/outlets/:channel', outlets.channel);
//
router.get('/detail/:id/:gid', detail.index);
// 商品详情routers
router.get('/detail/:id/:gid', detail.show);
router.get('/detail/comments', detail.comments);
module.exports = router;
... ...
... ... @@ -536,7 +536,7 @@ lazyLoad($('#details-html img'));
loadingComments = true;
$.ajax({
type: 'GET',
url: '/product/item/comments',
url: '/product/detail/comments',
data: {
productId: id,
page: commentPage
... ...