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