Authored by yyq

购买评价

... ... @@ -11,7 +11,7 @@ const headerModel = require('../../../doraemon/models/header'); // 头部model
const detail = require(`${mRoot}/detail`); // 商品详情 model
const intro = require(`${mRoot}/intro`); // 商品尺码信息 model
const preference = require(`${mRoot}/preference`); // 商品偏好 model
const ccModel = require(`${mRoot}/consult-comment`); // 商品评论咨询 model
const detailRelated = require(`${mRoot}/consult-comment`); // 商品评论咨询 model
const _ = require('lodash');
/**
... ... @@ -82,14 +82,30 @@ exports.preference = (req, res) => {
};
/**
* 购买评价页
*/
exports.comments = (req, res, next) => {
let headerData = headerModel.setNav({
navTitle: '购买评价'
});
detailRelated.comments(req.query).then((result) => {
res.render('detail/comments', Object.assign({
pageHeader: headerData,
pageFooter: true
}, result));
}).catch(next);
};
/**
* 购买咨询
*/
exports.consults = (req, res, next) => {
ccModel.consults(req.query).then((result) => {
let headerData = headerModel.setNav({
navTitle: '购买咨询'
});
let headerData = headerModel.setNav({
navTitle: '购买咨询'
});
detailRelated.consults(req.query).then((result) => {
res.render('detail/consults', Object.assign({
pageHeader: headerData,
pageFooter: true
... ... @@ -128,7 +144,7 @@ exports.consultsubmit = (req, res, next) => {
return res.json(data);
}
ccModel.addConsult(req.user.uid, req.body.product_id, req.body.content).then((result) => {
detailRelated.addConsult(req.user.uid, req.body.product_id, req.body.content).then((result) => {
if (result) {
Object.assign(data, result);
... ...
... ... @@ -9,6 +9,9 @@
const api = global.yoho.API;
const _ = require('lodash');
/**
* 获取默认咨询列表
*/
const _getCommonConsult = () => {
let params = {
method: 'app.consult.common'
... ... @@ -27,6 +30,38 @@ 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]}
*/
const _formatConsultsList = (data) => {
let list = [];
... ... @@ -48,12 +83,47 @@ const _formatConsultsList = (data) => {
return list;
};
/**
* 获取评价数据
* @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]} 页码
* @limit {[number]} 每页咨询数量
* @return {[object]}
*/
const _getConsults = (id, page, limit) => {
let params = {
method: 'app.consult.li',
product_id: id,
page: page ? page : 1,
limit: limit ? limit : 10
limit: limit ? limit : 300
};
return api.get('', params, {
... ... @@ -73,10 +143,35 @@ const _getConsults = (id, page, limit) => {
});
};
/**
* 购买评价列表
* @param {[object]} 查询参数
* @return {[object]}
*/
let comments = (params) => {
return _getComments(params.product_id, 1, 60).then(result => {
let data = {};
if (result.list && result.list.length) {
if (result.total) {
_.set(data, 'pageHeader.navTitle', `购买评价(${result.total})`);
}
data.comments = result.list;
}
return data;
});
};
/**
* 购买咨询列表
* @params {[object]} 查询参数
* @return {[object]}
*/
let consults = (params) => {
return api.all([
_getCommonConsult(),
_getConsults(params.product_id, 1, 10)
_getConsults(params.product_id, 1, 60)
]).then(result => {
let data = {
link: `/product/detail/consultform?product_id=${params.product_id}`
... ... @@ -95,6 +190,13 @@ let consults = (params) => {
});
};
/**
* 购买咨询列表
* @uid {[number]} 用户id
* @productId {[number]} 商品id
* @content {[string]} 咨询内容
* @return {[object]}
*/
let addConsult = (uid, productId, content) => {
let params = {
method: 'h5.consult.add',
... ... @@ -112,6 +214,7 @@ let addConsult = (uid, productId, content) => {
};
module.exports = {
comments, // 商品详情相关-购买评价
consults, // 商品详情相关-购买咨询
addConsult // 商品详情相关-添加咨询
};
... ...
... ... @@ -29,7 +29,7 @@ router.get('/detail/intro/:productskn', detail.intro); // 商品内嵌页
router.get('/detail/preference', detail.preference); // 为你优选
router.get('/detail/consults', detail.consults); // 商品咨询页
router.get('/detail/consultform', auth, detail.consultform); // 商品咨询表单页
router.get('/detail/comments', detail.preference);
router.get('/detail/comments', detail.comments);
router.post('/detail/consultsubmit', auth, detail.consultsubmit); // 商品咨询提交接口
router.get('/sale', sale.index);
... ...
<div class="goods-comments-page yoho-page">
<div class="goods-comments" id="goods-comments">
{{# comments}}
<div class="comment-item">
<span class="user-name">{{userName}}</span>
<span class="goods-spec">&nbsp;购买了&nbsp;&nbsp;{{desc}}</span>
<p class="detail-content">{{content}}</p>
<span class="comment-time">{{time}}</span>
</div>
{{/ comments}}
</div>
{{#if loadmore}}
<input id="loadMoreUrl" type="hidden" value="{{loadMoreUrl}}">
{{/if}}
</div>
\ No newline at end of file
... ...