...
|
...
|
@@ -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 // 商品详情相关-添加咨询
|
...
|
...
|
|