client.js
3.17 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
/**
* 客服用户端 controller
*
* @author: liqi <qi.li@yoho.cn>
* @date: 2016/11/4
*/
'use strict';
const aes = require('./aes-pwd');
const helpers = global.yoho.helpers;
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 uid = req.user.uid;
let reg = /MSIE\s?[987]\.0/i;
let userAgent = req.headers['user-agent'];
let unSupport = reg.test(userAgent);
let encryptedUid = aes.encryptionUid(uid);
let domains = common.domains;
let imCs = domains.imCs;
let imSocket = domains.imSocket;
let data = {
imCs,
imSocket,
encryptedUid,
layout: false
};
if (unSupport) {
res.render('unsupport', {
layout: false
});
} else {
clientService.getClientData(uid, type, encryptedUid)
.then(result => {
if (result.code === 401) {
return res.redirect(helpers.urlFormat('/signin.html'));
}
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 uid = req.user.uid;
const encId = aes.encryptionUid(uid);
const endTime = req.body.endTime;
clientApi.getMsgHistory(uid, encId, endTime)
.then(result => {
res.json(result);
}).catch(next);
};
/**
* 评价
* @param req
* @param res
* @param next
*/
const saveEval = (req, res, next) => {
const uid = req.user.uid;
const params = {
uid
};
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 uid = req.user.uid;
const type = req.body.type;
const encryptedUid = aes.encryptionUid(uid);
clientApi.queryReason(uid, encryptedUid, type)
.then(result => {
res.json(result);
}).catch(next);
};
/**
* 留言
* @param req
* @param res
* @param next
*/
const saveMessage = (req, res, next) => {
const uid = req.user.uid;
const content = req.body.content;
const encId = req.body.encryptedUid;
const cvId = req.body.conversationId;
clientApi.saveMessage(content, encId, cvId, uid)
.then(result => {
res.json(result);
}).catch(next);
};
module.exports = {
index,
domains,
history,
saveEval,
queryReason,
saveMessage
};