client.js
2.65 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
/**
* 客服用户端 controller
*
* @author: liqi <qi.li@yoho.cn>
* @date: 2016/11/4
*/
'use strict';
const aes = require('./aes-pwd');
const common = require('../../../config/common');
const clientApi = require('../models/client-api');
const clientService = require('../models/client-service');
/**
* 在线客服客户端
*/
const index = (req, res, next) => {
let type = 2;
let reg = /MSIE\s?[987]\.0/i;
let userAgent = req.headers['user-agent'];
let unSupport = reg.test(userAgent);
let encryptedUid = aes.encryptionUid(req.user.uid);
let data = {
encryptedUid,
layout: false
};
if (unSupport) {
res.render('unsupport', {
layout: false
});
} else {
clientService.getClientData(type, encryptedUid)
.then(result => {
res.render('client', Object.assign(data, result));
}).catch(next);
}
};
/**
* 在线客服客户端
*/
const domains = (req, res) => {
// 返回当前环境的配置信息
res.json(common.domains);
};
/**
* 消息记录
* @param req
* @param res
* @param next
*/
const history = (req, res, next) => {
const encId = aes.encryptionUid(req.user.uid);
const endTime = req.body.endTime;
clientApi.getMsgHistory(encId, endTime)
.then(result => {
res.json(result);
}).catch(next);
};
/**
* 评价
* @param req
* @param res
* @param next
*/
const saveEval = (req, res, next) => {
const params = {};
params.stars = req.body.stars;
params.promoter = req.body.promoter;
params.encryptedUid = req.body.encryptedUid;
params.conversationId = req.body.conversationId;
if (req.body.reasonIds) {
params.reasonIds = req.body.reasonIds;
}
if (req.body.reasonMsg) {
params.reasonMsg = req.body.reasonMsg;
}
clientApi.saveEval(params)
.then(result => {
res.json(result);
}).catch(next);
};
/**
* 评价原因
* @param req
* @param res
* @param next
*/
const queryReason = (req, res, next) => {
const cvId = req.body.conversationId;
clientApi.queryReason(cvId)
.then(result => {
res.json(result);
}).catch(next);
};
/**
* 留言
* @param req
* @param res
* @param next
*/
const saveMessage = (req, res, next) => {
const content = req.body.content;
const encId = req.body.encryptedUid;
const cvId = req.body.conversationId;
clientApi.saveMessage(content, encId, cvId)
.then(result => {
res.json(result);
}).catch(next);
};
module.exports = {
index,
domains,
history,
saveEval,
queryReason,
saveMessage
};