comment.js
5.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/**
* comment model
* @author 陈轩 <xuan.chen@yoho.cn>
*/
'use strict';
const path = require('path');
const imgUtils = require(path.join(global.utils, 'images'));
const Promise = require('bluebird');
const _ = require('lodash');
// 使用 product中的分页逻辑
const pagerPath = path.join(global.appRoot, '/apps/product/models/public-handler.js');
const pager = require(pagerPath).handlePagerData;
const co = Promise.coroutine;
const api = global.yoho.API;
const helpers = global.yoho.helpers;
const NO_COMMENTED_GOODS = '您还没有已评论的商品';
const NO_UNCOMMENT_GOODS = '您还没有未评论的商品';
exports.getCommentList = (uid, isComment, page, limit) => {
limit = limit || 10;
const process = function*() {
let result = yield api.post('', {
method: 'web.show.queryOrderProductCommentList',
uid: uid
});
let commentList = {
isComment: isComment,
goodsNum: 0,
orders: []
};
let pagerObj = {};
// 接口返回成功, 处理数据
if (result.code === 200 && !_.isEmpty(result.data)) {
_.forEach(result.data, (value) => {
let order = {
orderNum: value.orderCode,
orderTime: value.createTime,
orderId: value.orderId,
goods: []
};
_.forEach(value.orderGoods, (v) => {
let cnAlphabet = v.cnAlphabet || '';
let good = {
href: helpers.getUrlBySkc(v.productId, v.goodsId, cnAlphabet),
thumb: imgUtils.getImageUrl(v.imageUrl, 100, 100),
name: v.productName || '',
productSkn: v.productSkn,
productId: v.productId,
goodsId: v.goodsId,
erpSkuId: v.erpSkuId,
orderId: value.orderId,
orderCode: value.orderCode
};
if (isComment === v.hasOwnProperty('comment')) {
if (isComment) {
good.remark = v.comment;
}
order.goods.push(good);
commentList.goodsNum++;
}
});
order.goods.length && commentList.orders.push(order);
});
let total = commentList.orders.length;
// let totalPage = Math.ceil(total / limit);
let begin = (page - 1) * limit;
commentList.orders = commentList.orders.slice(begin, begin + limit); // [begin, begin+limit)
pagerObj = pager(total, {
isComment: isComment ? 'Y' : 'N',
page: page
});
} else {
commentList.empty = isComment ? NO_COMMENTED_GOODS : NO_UNCOMMENT_GOODS; // 空数据 提示文字
}
return {
comment: commentList,
pager: pagerObj
};
};
return co(process)();
};
exports.getCommentList4Order = (uid, orderId) => {
// limit = limit || 10;
// http://api.yoho.cn/?app_version=5.0.0&client_secret=e8098ddd3129372e8c93daea6600eda4&client_type=android&gender=1%2C3&
// method=show.toShareOrderList&
// orderCode=1617595089&os_version=android6.0.1%3AMI_MAX&screen_size=1080x1920&session_key=
// 720e95e42f9c1edc5940f1d49c34b68e&uid=9963947&v=7&yh_channel=1
const process = function*() {
let result = yield api.post('', {
// method: 'web.show.queryOrderProductCommentList',
method: 'show.toShareOrderList',
uid: uid,
orderCode: orderId// ,
// orderId: orderId
});
let commentList = {
goodsNum: 0,
orders: []
};
// 接口返回成功, 处理数据
if (result.code === 200 && !_.isEmpty(result.data)) {
let order = {
// orderNum: value.orderCode,
// orderTime: value.createTime,
orderId: orderId,
goods: []
};
_.forEach(result.data, (v) => {
let cnAlphabet = v.cnAlphabet || '';
let good = {
href: helpers.getUrlBySkc(v.productId, v.goodsId, cnAlphabet),
thumb: imgUtils.getImageUrl(v.imageUrl, 100, 100),
name: v.productName || '',
productSkn: v.productSkn,
productId: v.productId,
goodsId: v.goodsId,
erpSkuId: v.erpSkuId,
orderCode: v.orderCode,
orderId: v.orderId
};
order.goods.push(good);
commentList.goodsNum++;
});
order.goods.length && commentList.orders.push(order);
// let total = commentList.orders.length;
// let totalPage = Math.ceil(total / limit);
// let begin = (page - 1) * limit;
// commentList.orders = commentList.orders.slice(begin, begin + limit); // [begin, begin+limit)
// pagerObj = pager(total, {
// isComment: isComment ? 'Y' : 'N'//,
// //page: page
// });
} else {
commentList.empty = NO_UNCOMMENT_GOODS; // 空数据 提示文字
}
console.log(JSON.stringify(commentList.orders.length));
return {
comment: commentList// ,
// pager: pagerObj
};
};
return co(process)();
};
exports.saveShareOrder = data => {
let process = function*() {
let res = api.post('', {
method: 'show.saveShareOrder',
parameters: JSON.stringify(data)
});
return res;
};
return co(process)();
};