Authored by 李奇

接口签名添加

... ... @@ -8,6 +8,7 @@
'use strict';
const aes = require('./aes-pwd');
const common = require('../../../config/common');
const clientApi = require('../models/client-api');
const clientService = require('../models/client-service');
/**
... ... @@ -46,12 +47,75 @@ const domains = (req, res) => {
/**
* 消息记录
* @param req
* @param res
* @param next
*/
const history = (req, res, next) => {
let encryptedUid = aes.encryptionUid(req.user.uid);
let endTime = req.body.endTime;
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;
clientService.getHistory(encryptedUid, endTime)
clientApi.saveMessage(content, encId, cvId)
.then(result => {
res.json(result);
}).catch(next);
... ... @@ -61,5 +125,8 @@ const history = (req, res, next) => {
module.exports = {
index,
domains,
history
history,
saveEval,
queryReason,
saveMessage
};
... ...
... ... @@ -17,10 +17,13 @@ let api = new global.yoho.ApiBase(config.domains.imCs, {
// api urls
let urls = {
qas: '/api/helper/queryAllHelper',
csSetting: '/api/cs/queryByType',
makeEval: '/api/evalute/saveEvalute',
lastTen: '/api/order/queryLastTenOrder',
leaveMsg: '/api/leavemessage/saveLeavemessage',
msgHistory: '/api/conversationMessage/pageList',
csSetting: '/api/cs/queryByType',
qas: '/api/helper/queryAllHelper'
evalReason: '/api/evalute/queryReasonByConversationId'
};
/**
... ... @@ -67,16 +70,58 @@ const getMsgHistory = (encryptedUid, endTime) => {
encryptedUid
};
if(endTime) {
if (endTime) {
params.endTime = endTime;
}
return api.post(urls.msgHistory, params, {timeout: 5000});
};
/**
* 保存评价
* @param params
* @returns {*}
*/
const saveEval = (params) => {
return api.post(urls.makeEval, params);
};
/**
* 评价原因
* @param cvId
* @returns {*}
*/
const queryReason = (cvId) => {
const params = {
conversationId: cvId
};
return api.post(urls.evalReason, params);
};
/**
* 留言
* @param content 内容
* @param encId 加密UID
* @param cvId 会话ID
* @returns {*}
*/
const saveMessage = (content, encId, cvId) => {
const params = {
content,
encryptedUid: encId,
conversationId: cvId
};
return api.post(urls.leaveMsg, params);
};
module.exports = {
getQas,
queryReason,
saveMessage,
getCsSetting,
saveEval,
getMsgHistory,
getLastTenOrders
};
... ...
... ... @@ -68,16 +68,6 @@ const getClientData = (type, encryptedUid) => {
});
};
/**
* 获取最近7天聊天记录
* @param { string } encryptedUid
* @param { string } endTime
*/
const getHistory = (encryptedUid, endTime) => {
return clientAPI.getMsgHistory(encryptedUid, endTime);
};
module.exports = {
getClientData,
getHistory
getClientData
};
... ...
... ... @@ -13,8 +13,11 @@ const cRoot = './controllers';
const client = require(`${cRoot}/client`);
// 在线客服
router.get('/client', auth, client.index); // 在线客服
router.get('/domains', auth, client.domains); // 域名配置
router.post('/history', auth, client.history);// 7天记录
router.get('/client', auth, client.index); // 在线客服
router.get('/domains', auth, client.domains); // 域名配置
router.post('/history', auth, client.history); // 消息记录
router.post('/evaluate', auth, client.saveEval); // 评价
router.post('/leaveMsg', auth, client.saveMessage); // 留言
router.post('/queryReason', auth, client.queryReason);// 评价原因
module.exports = router;
... ...
... ... @@ -24,7 +24,6 @@ var allRTs,
assetsPrefix,
cursorPosition,
configDomains,
hasMore = true,
titleInterval,
$html = $('html'),
$window = $(window),
... ... @@ -60,14 +59,6 @@ var processInfo = {
savedEval: false // 是否保存过评论
};
var key,
urls = {
makeEval: '/evalute/saveEvalute',
leaveMsg: '/leavemessage/saveLeavemessage',
msgHistory: '/conversationMessage/pageList',
evalReason: '/evalute/queryReasonByConversationId'
};
require('bootstrap');
require('../common');
require('blueimp-file-upload/js/jquery.iframe-transport');
... ... @@ -80,6 +71,7 @@ encryptedUid = $encryptedUid.val();
assetsPrefix = $assetsPrefix.val();
socketConfCM = socketConf.conversationMessage;
socketConfCM.encryptedUid = encryptedUid;
// 原始配置信息用于重新连线
originConf = JSON.parse(JSON.stringify(socketConf));
... ... @@ -511,14 +503,12 @@ function pageInit() {
$evalModal.find('.discontent').empty().append(dom);
}
// todo
// 拉取评价原因
$.ajax({
type: 'GET',
url: urls.evalReason,
data: {
conversationId: socketConfCM.conversationId
},
success: function success(res) {
serviceApi.reason({
conversationId: socketConfCM.conversationId
})
.done(function(res) {
var data = res.data,
len = data.length;
... ... @@ -527,8 +517,7 @@ function pageInit() {
len && discontentHtml(len, data);
}
$evalModal.modal('show');
}
});
});
}
/**
... ... @@ -782,15 +771,16 @@ function pageInit() {
* 获取历史聊天记录
*/
function fetchHistoryMsg() {
if(processInfo.loadingHistory) {
return;
}
processInfo.loadingHistory = true;
var msgList = [];
var data = {
encryptedUid: encryptedUid
};
if (processInfo.loadingHistory) {
return;
}
processInfo.loadingHistory = true;
if (endTime) {
data.endTime = endTime;
}
... ... @@ -863,23 +853,15 @@ function pageInit() {
return false;
}
$.ajax({
type: 'POST',
url: urls.leaveMsg,
data: {
content: val,
encryptedUid: encryptedUid,
conversationId: socketConfCM.newConversationId || socketConfCM.conversationId
},
success: function(res) {
if (res && res.code === 200) {
lMsg.modal('hide');
}
},
error: function() {
serviceApi.leaveMsg({
content: val,
encryptedUid: encryptedUid,
conversationId: socketConfCM.conversationId
})
.done(function() {})
.always(function() {
lMsg.modal('hide');
}
});
});
});
// 提交评价
... ... @@ -911,14 +893,9 @@ function pageInit() {
data.reasonMsg = reason;
}
$.ajax({
type: 'POST',
url: urls.makeEval,
data: data,
success: function(res) {
// 提交评价过后,不管是否成功都应该关闭弹框
serviceApi.evaluate(data)
.done(function(res) {
processInfo.promoter = 1;
mEval.modal('hide');
$btnEval.hide();
processInfo.savedEval = true;
... ... @@ -933,11 +910,10 @@ function pageInit() {
window.close();
}
}
},
error: function() {
})
.always(function() {
mEval.modal('hide');
}
});
});
});
// 根节点高度设置
... ... @@ -1193,11 +1169,12 @@ function pageInit() {
// 滚动加载更多
$panelMainBody.scroll(function() {
var isLoadingArea = $panelMainBody.scrollTop() < 100;
isLoadingArea
&& processInfo.scrollLoad
&& !processInfo.loadingHistory
&& processInfo.hasMore
&& fetchHistoryMsg();
isLoadingArea &&
processInfo.scrollLoad &&
!processInfo.loadingHistory &&
processInfo.hasMore &&
fetchHistoryMsg();
});
}
... ... @@ -1209,13 +1186,6 @@ function pageInit() {
success: function(domains) {
configDomains = domains;
// url前缀添加
for (key in urls) {
if (urls.hasOwnProperty(key)) {
urls[key] = configDomains.imCs + urls[key];
}
}
// 检查支持性
(function() {
if (!window.WebSocket) {
... ...
... ... @@ -7,12 +7,15 @@
var $ = require('yoho-jquery');
var reqUrls = {
history: '/service/history'
history: '/service/history',
evaluate: '/service/evaluate',
leaveMsg: '/service/leaveMsg',
reason: '/service/queryReason'
};
var _ajax = function(method, reqUrl, params) {
return $.ajax({
type: method || "GET",
return $.ajax({
type: method || 'GET',
url: reqUrl,
data: params
});
... ... @@ -23,5 +26,29 @@ var _ajax = function(method, reqUrl, params) {
* @param params 参数对象
*/
exports.history = function(params) {
return _ajax("POST", reqUrls.history, params);
return _ajax('POST', reqUrls.history, params);
};
/**
* 保存评价
* @param params 参数对象
*/
exports.evaluate = function(params) {
return _ajax('POST', reqUrls.evaluate, params);
};
/**
* 评价原因
* @param params 参数对象
*/
exports.reason = function(params) {
return _ajax('POST', reqUrls.reason, params);
};
/**
* 留言
* @param params 参数对象
*/
exports.leaveMsg = function(params) {
return _ajax('POST', reqUrls.leaveMsg, params);
};
... ...