|
@@ -9,6 +9,9 @@ |
|
@@ -9,6 +9,9 @@ |
9
|
const api = global.yoho.API;
|
9
|
const api = global.yoho.API;
|
10
|
const _ = require('lodash');
|
10
|
const _ = require('lodash');
|
11
|
|
11
|
|
|
|
12
|
+/**
|
|
|
13
|
+ * 获取默认咨询列表
|
|
|
14
|
+ */
|
12
|
const _getCommonConsult = () => {
|
15
|
const _getCommonConsult = () => {
|
13
|
let params = {
|
16
|
let params = {
|
14
|
method: 'app.consult.common'
|
17
|
method: 'app.consult.common'
|
|
@@ -27,6 +30,38 @@ const _getCommonConsult = () => { |
|
@@ -27,6 +30,38 @@ const _getCommonConsult = () => { |
27
|
});
|
30
|
});
|
28
|
};
|
31
|
};
|
29
|
|
32
|
|
|
|
33
|
+/**
|
|
|
34
|
+ * 处理评价列表数据
|
|
|
35
|
+ * @data {[object]} 评价列表原始数据
|
|
|
36
|
+ * @return {[object]}
|
|
|
37
|
+ */
|
|
|
38
|
+const _formatCommentsList = (data) => {
|
|
|
39
|
+ let comment = {
|
|
|
40
|
+ list: [],
|
|
|
41
|
+ total: 0
|
|
|
42
|
+ };
|
|
|
43
|
+
|
|
|
44
|
+ if (data.length) {
|
|
|
45
|
+ _.forEach(data, (value) => {
|
|
|
46
|
+ comment.list.push({
|
|
|
47
|
+ userName: value.nickname,
|
|
|
48
|
+ desc: `${value.color_name}/${value.size_name}`,
|
|
|
49
|
+ content: value.content,
|
|
|
50
|
+ time: value.create_time
|
|
|
51
|
+ });
|
|
|
52
|
+
|
|
|
53
|
+ comment.total = value.total;
|
|
|
54
|
+ });
|
|
|
55
|
+ }
|
|
|
56
|
+
|
|
|
57
|
+ return comment;
|
|
|
58
|
+};
|
|
|
59
|
+
|
|
|
60
|
+/**
|
|
|
61
|
+ * 处理咨询列表数据
|
|
|
62
|
+ * @data {[object]} 咨询列表原始数据
|
|
|
63
|
+ * @return {[object]}
|
|
|
64
|
+ */
|
30
|
const _formatConsultsList = (data) => {
|
65
|
const _formatConsultsList = (data) => {
|
31
|
let list = [];
|
66
|
let list = [];
|
32
|
|
67
|
|
|
@@ -48,12 +83,47 @@ const _formatConsultsList = (data) => { |
|
@@ -48,12 +83,47 @@ const _formatConsultsList = (data) => { |
48
|
return list;
|
83
|
return list;
|
49
|
};
|
84
|
};
|
50
|
|
85
|
|
|
|
86
|
+/**
|
|
|
87
|
+ * 获取评价数据
|
|
|
88
|
+ * @id {[number]} 商品id
|
|
|
89
|
+ * @page {[number]} 页码
|
|
|
90
|
+ * @limit {[number]} 每页评价数量
|
|
|
91
|
+ * @return {[object]}
|
|
|
92
|
+ */
|
|
|
93
|
+const _getComments = (id, page, limit) => {
|
|
|
94
|
+ let params = {
|
|
|
95
|
+ method: 'app.comment.li',
|
|
|
96
|
+ product_id: id,
|
|
|
97
|
+ page: page ? page : 1,
|
|
|
98
|
+ limit: limit ? limit : 300
|
|
|
99
|
+ };
|
|
|
100
|
+
|
|
|
101
|
+ return api.get('', params, {
|
|
|
102
|
+ code: 200
|
|
|
103
|
+ }).then(result => {
|
|
|
104
|
+ let data = {};
|
|
|
105
|
+
|
|
|
106
|
+ if (result.data) {
|
|
|
107
|
+ Object.assign(data, _formatCommentsList(result.data));
|
|
|
108
|
+ }
|
|
|
109
|
+
|
|
|
110
|
+ return data;
|
|
|
111
|
+ });
|
|
|
112
|
+};
|
|
|
113
|
+
|
|
|
114
|
+/**
|
|
|
115
|
+ * 获取咨询数据
|
|
|
116
|
+ * @id {[number]} 商品id
|
|
|
117
|
+ * @page {[number]} 页码
|
|
|
118
|
+ * @limit {[number]} 每页咨询数量
|
|
|
119
|
+ * @return {[object]}
|
|
|
120
|
+ */
|
51
|
const _getConsults = (id, page, limit) => {
|
121
|
const _getConsults = (id, page, limit) => {
|
52
|
let params = {
|
122
|
let params = {
|
53
|
method: 'app.consult.li',
|
123
|
method: 'app.consult.li',
|
54
|
product_id: id,
|
124
|
product_id: id,
|
55
|
page: page ? page : 1,
|
125
|
page: page ? page : 1,
|
56
|
- limit: limit ? limit : 10
|
126
|
+ limit: limit ? limit : 300
|
57
|
};
|
127
|
};
|
58
|
|
128
|
|
59
|
return api.get('', params, {
|
129
|
return api.get('', params, {
|
|
@@ -73,10 +143,35 @@ const _getConsults = (id, page, limit) => { |
|
@@ -73,10 +143,35 @@ const _getConsults = (id, page, limit) => { |
73
|
});
|
143
|
});
|
74
|
};
|
144
|
};
|
75
|
|
145
|
|
|
|
146
|
+/**
|
|
|
147
|
+ * 购买评价列表
|
|
|
148
|
+ * @param {[object]} 查询参数
|
|
|
149
|
+ * @return {[object]}
|
|
|
150
|
+ */
|
|
|
151
|
+let comments = (params) => {
|
|
|
152
|
+ return _getComments(params.product_id, 1, 60).then(result => {
|
|
|
153
|
+ let data = {};
|
|
|
154
|
+
|
|
|
155
|
+ if (result.list && result.list.length) {
|
|
|
156
|
+ if (result.total) {
|
|
|
157
|
+ _.set(data, 'pageHeader.navTitle', `购买评价(${result.total})`);
|
|
|
158
|
+ }
|
|
|
159
|
+ data.comments = result.list;
|
|
|
160
|
+ }
|
|
|
161
|
+
|
|
|
162
|
+ return data;
|
|
|
163
|
+ });
|
|
|
164
|
+};
|
|
|
165
|
+
|
|
|
166
|
+/**
|
|
|
167
|
+ * 购买咨询列表
|
|
|
168
|
+ * @params {[object]} 查询参数
|
|
|
169
|
+ * @return {[object]}
|
|
|
170
|
+ */
|
76
|
let consults = (params) => {
|
171
|
let consults = (params) => {
|
77
|
return api.all([
|
172
|
return api.all([
|
78
|
_getCommonConsult(),
|
173
|
_getCommonConsult(),
|
79
|
- _getConsults(params.product_id, 1, 10)
|
174
|
+ _getConsults(params.product_id, 1, 60)
|
80
|
]).then(result => {
|
175
|
]).then(result => {
|
81
|
let data = {
|
176
|
let data = {
|
82
|
link: `/product/detail/consultform?product_id=${params.product_id}`
|
177
|
link: `/product/detail/consultform?product_id=${params.product_id}`
|
|
@@ -95,6 +190,13 @@ let consults = (params) => { |
|
@@ -95,6 +190,13 @@ let consults = (params) => { |
95
|
});
|
190
|
});
|
96
|
};
|
191
|
};
|
97
|
|
192
|
|
|
|
193
|
+/**
|
|
|
194
|
+ * 购买咨询列表
|
|
|
195
|
+ * @uid {[number]} 用户id
|
|
|
196
|
+ * @productId {[number]} 商品id
|
|
|
197
|
+ * @content {[string]} 咨询内容
|
|
|
198
|
+ * @return {[object]}
|
|
|
199
|
+ */
|
98
|
let addConsult = (uid, productId, content) => {
|
200
|
let addConsult = (uid, productId, content) => {
|
99
|
let params = {
|
201
|
let params = {
|
100
|
method: 'h5.consult.add',
|
202
|
method: 'h5.consult.add',
|
|
@@ -112,6 +214,7 @@ let addConsult = (uid, productId, content) => { |
|
@@ -112,6 +214,7 @@ let addConsult = (uid, productId, content) => { |
112
|
};
|
214
|
};
|
113
|
|
215
|
|
114
|
module.exports = {
|
216
|
module.exports = {
|
|
|
217
|
+ comments, // 商品详情相关-购买评价
|
115
|
consults, // 商品详情相关-购买咨询
|
218
|
consults, // 商品详情相关-购买咨询
|
116
|
addConsult // 商品详情相关-添加咨询
|
219
|
addConsult // 商品详情相关-添加咨询
|
117
|
}; |
220
|
}; |