complaints.js
3.63 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
/**
* 我的投诉 model
* @author: yyq<yanqing.yang@yoho.cn>
* @date: 2016/8/18
*/
'use strict';
const _ = require('lodash');
const Promise = require('bluebird');
const setPager = require(`${global.utils}/pager`).setPager;
const co = Promise.coroutine;
const complaintType = {
0: '全部',
1: '产品相关',
2: '物流相关'
};
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
/**
* 获取投诉列表
* @function getComplaintsList
* @param { Number } uid 用户uid
* @param { Number } page 页码
* @param { Number } limit 每页数目
* @return { Object } 投诉列表数据
*/
getComplaintsList(uid, page, limit) {
page = page || 1;
limit = limit || 10;
const process = function*() {
let resData = {};
let result = yield this.get({
data: {
method: 'web.complaints.getList',
uid: uid,
page: page,
limit: limit
},
param: {
cache: 200
}
});
if (!_.isEmpty(result.data)) {
let list = [];
_.forEach(_.get(result, 'data.complaintList', []), value => {
list.push({
id: value.id,
title: value.title,
target: value.customer,
type: complaintType[value.complaintsType],
order: value.orderCode,
time: value.createTime,
question: value.content,
reply: value.reply,
replyTime: value.replyTime,
revoke: value.status === -1
});
});
if (_.isEmpty(list)) {
resData.complaints = {empty: '您尚未投诉任何内容'};
} else {
resData.complaints = list;
}
resData.pager = Object.assign({
count: _.get(result, 'data.total', 0),
curPage: page,
totalPages: _.get(result, 'data.page_total', 0)
}, setPager(_.get(result, 'data.page_total', 0), {
page: page
}));
if (!_.get(resData, 'pager.pages[1]')) {
_.unset(resData, 'pager.pages');
}
}
return resData;
};
return co(process)();
}
/**
* 添加投诉
* @function addComplaints
* @param { Number } uid 用户uid
* @param { Object } params 投诉内容信息
* @return { Object } 添加投诉结果
*/
addComplaints(uid, params) {
return this.post({
data: {
method: 'web.complaints.add',
uid: uid,
title: _.trim(params.title),
customer: _.trim(params.customer),
complaintsType: _.trim(params.complaintsType),
orderCode: _.trim(params.orderCode),
content: _.trim(params.content)
}
});
}
/**
* 撤销投诉
* @function addComplaints
* @param { Number } uid 用户uid
* @param { Number } id 投诉id
* @return { Object } 撤销投诉结果
*/
cancelComplaints(uid, id) {
return this.post({
data: {
method: 'web.complaints.cancel',
uid: uid,
id: id
}
});
}
};