comment.js
3.24 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
/**
* 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
};
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.saveShareOrder = data => {
let process = function*() {
let res = api.post('', {
method: 'show.saveShareOrder',
parameters: JSON.stringify(data)
});
return res;
};
return co(process)();
};