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标识访问的是男生频道 */
... ... @@ -30,27 +30,27 @@ function getGenderByCookie(req) {
switch (channel) {
case 'boys':
{
gender = '1,3';
break;
}
{
gender = '1,3';
break;
}
case 'girls':
{
gender = '2,3';
break;
}
{
gender = '2,3';
break;
}
default:
{
gender = '1,2,3';
}
{
gender = '1,2,3';
}
}
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 = {};
... ... @@ -447,41 +452,41 @@ const getFashionTopGoodsStatus = (uid, showStatus, isBeginSale) => {
// 显示获取限购码按钮
switch (showStatus) {
case 1: // 开售前/后,立即分享获得限购码(用户未领取限购码)
{
if (isBeginSale) {
result.buyNow = true;
result.dis = true;
} else {
result.openSoon = true;
result.hasLimitedCode = false;
}
break;
}
case 2: // 开售后,限购码已抢光(用户未领取限购码)
{
{
if (isBeginSale) {
result.buyNow = true;
result.dis = true;
result.limitedCodeSoldOut = true;
result.getLimitedCode = false;
} else {
result.openSoon = true;
result.hasLimitedCode = false;
break;
}
break;
}
case 2: // 开售后,限购码已抢光(用户未领取限购码)
{
result.buyNow = true;
result.dis = true;
result.limitedCodeSoldOut = true;
result.getLimitedCode = false;
result.hasLimitedCode = false;
break;
}
case 3: // 开售后,商品已经售罄
{
result.soldOut = true;
result.getLimitedCode = false;
break;
}
{
result.soldOut = true;
result.getLimitedCode = false;
break;
}
case 4:// 开售后,立即购买(用户已领取限购码)
{
result.buyNow = true;
result.dis = false;
result.hasLimitedCode = true;
if (uid) { // 限购码失效
result.getLimitedCodeDis = true;
}
break;
{
result.buyNow = true;
result.dis = false;
result.hasLimitedCode = true;
if (uid) { // 限购码失效
result.getLimitedCodeDis = true;
}
break;
}
case 5: // 开售前,限购码已被抢光(用户未领取限购码)
result.openSoon = true;
result.hasLimitedCode = true;
... ... @@ -751,19 +756,19 @@ const detailDataPkg = (origin, uid, vipLevel) => {
if (domainBrand.type && domainBrand.shopId) {
switch (parseInt(domainBrand.type)) {
case 1:
{
{
// 多品店不显示
banner = [];
break;
}
banner = [];
break;
}
case 2:
{
{
// TODO:单品店显示新版的店铺banner,item.php 210
let basisData = shopAPI.basisTemplateAsync(domainBrand.shopId);
let basisData = shopAPI.basisTemplateAsync(domainBrand.shopId);
banner.bgImg = basisData.shopTopBanner.banner || banner.bgImg;
break;
}
banner.bgImg = basisData.shopTopBanner.banner || banner.bgImg;
break;
}
}
}
... ... @@ -842,15 +847,15 @@ function getDescriptionDataBySizeInfoAsync(sizeInfo) {
switch (sizeInfo.productDescBo.gender) {
case 1:
{
sex = '男款';
break;
}
{
sex = '男款';
break;
}
case 2:
{
sex = '女款';
break;
}
{
sex = '女款';
break;
}
}
description.basic = [];
... ... @@ -1141,9 +1146,9 @@ function getDetailDataBySizeInfo(sizeInfo) {
// 图片换成懒加载方式
const replacePairs = {
'<img src=': '<img class="lazy" src="data:image/gif;base64,R0lGODlhAQABAJEAAAAAAP///93d3f' +
'///yH5BAEAAAMALAAAAAABAAEAAAICVAEAOw==" data-original=',
'///yH5BAEAAAMALAAAAAABAAEAAAICVAEAOw==" data-original=',
'<img border="0" src=': '<img border="0" class="lazy" src="data:image/gif;base64,R0lGODlhAQABAJEAAAAAAP' +
'///93d3f///yH5BAEAAAMALAAAAAABAAEAAAICVAEAOw==" data-original='
'///93d3f///yH5BAEAAAMALAAAAAABAAEAAAICVAEAOw==" data-original='
};
let intro = sizeInfo.productIntroBo.productIntro;
... ... @@ -1216,25 +1221,25 @@ function getSizeAttrByMaxSortId(maxSortId, sizeList) {
switch (maxSortId) {
case 1:
case 2:
{
attributeIds = [3, 4];
break;
}
{
attributeIds = [3, 4];
break;
}
case 3:
{
attributeIds = [6, 10];
break;
}
{
attributeIds = [6, 10];
break;
}
case 6:
{
attributeIds = [13];
break;
}
{
attributeIds = [13];
break;
}
default:
{
attributeIds = [];
}
{
attributeIds = [];
}
}
let sizeInfos = [];
... ... @@ -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 * () {
... ... @@ -1355,8 +1397,8 @@ module.exports = (data) => {
// 导航
result.detail.pathNav = _.concat(homeHandle.getHomeChannelNav(data.channel),
navs,
[{name: productInfo.goodsInfo.name}]);
navs,
[{name: productInfo.goodsInfo.name}]);
result.detail.lastWalk = 5;
result.headerData = yield HeaderModel.requestHeaderData();
... ...
... ... @@ -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
... ...