Authored by ccbikai

评价咨询修改

... ... @@ -93,6 +93,7 @@ exports.comments = (req, res, next) => {
detailRelated.comments(req.query).then((result) => {
res.render('detail/comments', Object.assign({
title: '购买评价',
pageHeader: headerData,
pageFooter: true
}, result));
... ... @@ -109,6 +110,7 @@ exports.consults = (req, res, next) => {
detailRelated.consults(req.query).then((result) => {
res.render('detail/consults', Object.assign({
title: '购买咨询',
pageHeader: headerData,
pageFooter: true
}, result));
... ...
... ... @@ -6,8 +6,9 @@
'use strict';
const api = global.yoho.API;
const _ = require('lodash');
const api = global.yoho.API;
const helpers = global.yoho.helpers;
/**
* 获取默认咨询列表
... ... @@ -31,33 +32,6 @@ const _getCommonConsult = () => {
};
/**
* 处理评价列表数据
* @data {[object]} 评价列表原始数据
* @return {[object]}
*/
const _formatCommentsList = (data) => {
let comment = {
list: [],
total: 0
};
if (data.length) {
_.forEach(data, (value) => {
comment.list.push({
userName: value.nickname,
desc: `${value.color_name}/${value.size_name}`,
content: value.content,
time: value.create_time
});
comment.total = value.total;
});
}
return comment;
};
/**
* 处理咨询列表数据
* @data {[object]} 咨询列表原始数据
* @return {[object]}
... ... @@ -84,34 +58,6 @@ const _formatConsultsList = (data) => {
};
/**
* 获取评价数据
* @id {[number]} 商品id
* @page {[number]} 页码
* @limit {[number]} 每页评价数量
* @return {[object]}
*/
const _getComments = (id, page, limit) => {
let params = {
method: 'app.comment.li',
product_id: id,
page: page ? page : 1,
limit: limit ? limit : 300
};
return api.get('', params, {
code: 200
}).then(result => {
let data = {};
if (result.data) {
Object.assign(data, _formatCommentsList(result.data));
}
return data;
});
};
/**
* 获取咨询数据
* @id {[number]} 商品id
* @page {[number]} 页码
... ... @@ -143,20 +89,57 @@ const _getConsults = (id, page, limit) => {
});
};
let _processComment = (data) => {
let result = {
commentsNum: data.pageResponse.totalCount,
comments: []
};
_.forEach(data.pageResponse.list, (item) => {
result.comments.push({
userName: item.userInfo.nickName,
desc: `${item.goods.color_name}/${item.goods.size_name}`,
content: item.content,
time: helpers.dateFormat('YYYY-MM-DD HH:mm:ss', new Date(item.createTime * 1000))
});
});
return result;
};
let getCommentInfo = (params) => {
return api.get('', Object.assign({
method: 'show.productShareOrderList',
limit: '1',
page: '1',
filterId: 7
}, params), {
cache: true
}).then((result) => {
if (result.code === 200) {
return _processComment(result.data);
}
return {};
});
};
/**
* 购买评价列表
* @param {[object]} 查询参数
* @return {[object]}
*/
let comments = (params) => {
return _getComments(params.product_id, 1, 60).then(result => {
return getCommentInfo({
productId: params.product_id,
limit: '20'
}).then(result => {
let data = {};
if (result.list && result.list.length) {
if (result.total) {
_.set(data, 'pageHeader.navTitle', `购买评价(${result.total})`);
if (result.comments && result.comments.length) {
if (result.commentsNum) {
_.set(data, 'pageHeader.navTitle', `购买评价(${result.commentsNum})`);
}
data.comments = result.list;
data.comments = result.comments;
}
return data;
... ... @@ -214,6 +197,7 @@ let addConsult = (uid, productId, content) => {
};
module.exports = {
getCommentInfo, // 商品详情相关,获取评价,来自晒单
comments, // 商品详情相关-购买评价
consults, // 商品详情相关-购买咨询
addConsult // 商品详情相关-添加咨询
... ...
... ... @@ -6,8 +6,10 @@
'use strict';
const api = global.yoho.API;
const _ = require('lodash');
const comment = require('./consult-comment');
const api = global.yoho.API;
const helpers = global.yoho.helpers;
/**
... ... @@ -237,23 +239,6 @@ const _detailDataPkg = (origin, uid, vipLevel, ua) => {
dest.periodOfMarket = `${origin.expectArrivalTime}月`;
}
// 促销信息 TODO: 换新接口
if (origin.promotionBoList) {
let discountList = [];
_.forEach(origin.promotionBoList, function(value) {
discountList.push({
text: `【${value.promotionType}${value.promotionTitle}`
});
});
if (discountList.length) {
dest.goodsDiscount = {
list: discountList
};
}
}
// 商品咨询
dest.feedbacks = {
consults: [],
... ... @@ -277,7 +262,7 @@ const _detailDataPkg = (origin, uid, vipLevel, ua) => {
if (_.has(dest, 'feedbacks.consultsNum')) {
consultParams.total = dest.feedbacks.consultsNum;
dest.feedbacks.consultsUrl = helpers.urlFormat('/product/detail/consult', consultParams);
dest.feedbacks.consultsUrl = helpers.urlFormat('/product/detail/consults', consultParams);
} else {
dest.feedbacks.consultsUrl = helpers.urlFormat('/product/detail/consultform', consultParams);
}
... ... @@ -577,12 +562,20 @@ let getProductData = (data) => {
return api.get('', params, {
cache: true
}).then(result => {
return Promise.all([_getShopsInfo(result.brandId), _getPromotionInfo(result.erpProductId)]).then((info) => {
return Promise.all([
_getShopsInfo(result.brandId),
_getPromotionInfo(result.erpProductId),
comment.getCommentInfo({
productId: result.id
})
]).then((info) => {
result.promotionBoList = info[1];
finalResult = _detailDataPkg(result, data.uid, data.vipLevel, data.ua);
finalResult.enterStore = info[0];
Object.assign(finalResult.feedbacks, info[2]);
return finalResult;
});
... ...
<div class="goods-comments-page yoho-page">
<div class="goods-comments" id="goods-comments">
{{log comments}}
{{# comments}}
<div class="comment-item">
<span class="user-name">{{userName}}</span>
... ...