1
0
mirror of https://github.com/chatopera/cosin.git synced 2025-07-11 20:17:03 +08:00

https://gitee.com/cskefu/cskefu/issues/I836RO enable billing for agentuser resources

Signed-off-by: Hai Liang Wang <hai@chatopera.com>
This commit is contained in:
Hai Liang Wang 2023-09-25 15:23:40 +08:00
parent a14671b70d
commit 8c0448f7fc
12 changed files with 1557 additions and 1425 deletions

View File

@ -1,14 +1,14 @@
/* /*
* Copyright (C) 2023 Beijing Huaxia Chunsong Technology Co., Ltd. * Copyright (C) 2023 Beijing Huaxia Chunsong Technology Co., Ltd.
* <https://www.chatopera.com>, Licensed under the Chunsong Public * <https://www.chatopera.com>, Licensed under the Chunsong Public
* License, Version 1.0 (the "License"), https://docs.cskefu.com/licenses/v1.html * License, Version 1.0 (the "License"), https://docs.cskefu.com/licenses/v1.html
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
* Copyright (C) 2019-2022 Chatopera Inc, <https://www.chatopera.com>, * Copyright (C) 2019-2022 Chatopera Inc, <https://www.chatopera.com>,
* Licensed under the Apache License, Version 2.0, * Licensed under the Apache License, Version 2.0,
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
*/ */
@ -22,12 +22,14 @@ import com.cskefu.cc.cache.Cache;
import com.cskefu.cc.model.AgentUser; import com.cskefu.cc.model.AgentUser;
import com.cskefu.cc.model.AgentUserContacts; import com.cskefu.cc.model.AgentUserContacts;
import com.cskefu.cc.model.Contacts; import com.cskefu.cc.model.Contacts;
import com.cskefu.cc.model.ExecuteResult;
import com.cskefu.cc.persistence.repository.ContactsRepository; import com.cskefu.cc.persistence.repository.ContactsRepository;
import com.cskefu.cc.persistence.repository.AgentUserContactsRepository; import com.cskefu.cc.persistence.repository.AgentUserContactsRepository;
import com.cskefu.cc.proxy.AgentStatusProxy; import com.cskefu.cc.proxy.AgentStatusProxy;
import com.cskefu.cc.proxy.AgentUserProxy; import com.cskefu.cc.proxy.AgentUserProxy;
import com.chatopera.compose4j.Functional; import com.chatopera.compose4j.Functional;
import com.chatopera.compose4j.Middleware; import com.chatopera.compose4j.Middleware;
import com.cskefu.cc.proxy.LicenseProxy;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -62,6 +64,9 @@ public class ACDVisBodyParserMw implements Middleware<ACDComposeContext> {
@Autowired @Autowired
private ACDMessageHelper acdMessageHelper; private ACDMessageHelper acdMessageHelper;
@Autowired
private LicenseProxy licenseProxy;
/** /**
* 设置AgentUser基本信息 * 设置AgentUser基本信息
* *
@ -87,6 +92,16 @@ public class ACDVisBodyParserMw implements Middleware<ACDComposeContext> {
ctx.getOnlineUserId(), ctx.getOnlineUserId(),
ctx.getOnlineUserNickname(), ctx.getOnlineUserNickname(),
ctx.getAppid()); ctx.getAppid());
// 执行计费逻辑
ExecuteResult writeDownResult = licenseProxy.writeDownAgentUserUsageInStore(p);
if (writeDownResult.getRc() != ExecuteResult.RC_SUCC) {
// 配额操作失败提示座席
p.setLicenseVerifiedPass(false);
p.setLicenseBillingMsg(writeDownResult.getMsg());
}
logger.info("[apply] create new agent user id {}", p.getId()); logger.info("[apply] create new agent user id {}", p.getId());
return p; return p;
}); });

View File

@ -1,14 +1,14 @@
/* /*
* Copyright (C) 2023 Beijing Huaxia Chunsong Technology Co., Ltd. * Copyright (C) 2023 Beijing Huaxia Chunsong Technology Co., Ltd.
* <https://www.chatopera.com>, Licensed under the Chunsong Public * <https://www.chatopera.com>, Licensed under the Chunsong Public
* License, Version 1.0 (the "License"), https://docs.cskefu.com/licenses/v1.html * License, Version 1.0 (the "License"), https://docs.cskefu.com/licenses/v1.html
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
* Copyright (C) 2019-2022 Chatopera Inc, <https://www.chatopera.com>, * Copyright (C) 2019-2022 Chatopera Inc, <https://www.chatopera.com>,
* Licensed under the Apache License, Version 2.0, * Licensed under the Apache License, Version 2.0,
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
*/ */
@ -18,14 +18,17 @@ import com.cskefu.cc.basic.MainContext;
import com.cskefu.cc.cache.Cache; import com.cskefu.cc.cache.Cache;
import com.cskefu.cc.cache.RedisCommand; import com.cskefu.cc.cache.RedisCommand;
import com.cskefu.cc.cache.RedisKey; import com.cskefu.cc.cache.RedisKey;
import com.cskefu.cc.exception.BillingResourceException;
import com.cskefu.cc.model.AgentUser; import com.cskefu.cc.model.AgentUser;
import com.cskefu.cc.proxy.AgentAuditProxy; import com.cskefu.cc.proxy.AgentAuditProxy;
import com.cskefu.cc.proxy.LicenseProxy;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.aspectj.lang.JoinPoint; import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After; import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -51,6 +54,31 @@ public class AgentUserAspect {
@Autowired @Autowired
private AgentAuditProxy agentAuditProxy; private AgentAuditProxy agentAuditProxy;
@Autowired
private LicenseProxy licenseProxy;
@Before("execution(* com.cskefu.cc.persistence.repository.AgentUserRepository.save(..))")
public void beforeSave(final JoinPoint joinPoint) {
final AgentUser agentUser = (AgentUser) joinPoint.getArgs()[0];
if (StringUtils.isBlank(agentUser.getId())) {
logger.info("[beforeSave] agentUser id is blank");
if (StringUtils.isNotBlank(agentUser.getOpttype()) && StringUtils.equals(MainContext.OptType.CHATBOT.toString(), agentUser.getOpttype())) {
// 机器人座席支持的对话跳过计数
agentUser.setLicenseVerifiedPass(true);
return;
}
// 计数加一
try {
licenseProxy.increResourceUsageInMetaKv(MainContext.BillingResource.AGENGUSER, 1);
} catch (BillingResourceException e) {
logger.error("[beforeSave] error", e.toString());
}
}
}
@After("execution(* com.cskefu.cc.persistence.repository.AgentUserRepository.save(..))") @After("execution(* com.cskefu.cc.persistence.repository.AgentUserRepository.save(..))")
public void save(final JoinPoint joinPoint) { public void save(final JoinPoint joinPoint) {
final AgentUser agentUser = (AgentUser) joinPoint.getArgs()[0]; final AgentUser agentUser = (AgentUser) joinPoint.getArgs()[0];

View File

@ -71,9 +71,6 @@ public class AgentAuditController extends Handler {
@Autowired @Autowired
private UserRepository userRes; private UserRepository userRes;
@Autowired
private AgentUserRepository agentUserRepository;
@Autowired @Autowired
private ChatMessageRepository chatMessageRepository; private ChatMessageRepository chatMessageRepository;
@ -245,7 +242,7 @@ public class AgentAuditController extends Handler {
view.addObject( view.addObject(
"agentUserList", agentUserRes.findByStatusAndAgentnoIsNot( "agentUserList", agentUserRes.findByStatusAndAgentnoIsNot(
MainContext.AgentUserStatusEnum.INSERVICE.toString(), logined.getId(), defaultSort)); MainContext.AgentUserStatusEnum.INSERVICE.toString(), logined.getId(), defaultSort));
List<AgentUser> agentUserList = agentUserRepository.findByUserid(userid); List<AgentUser> agentUserList = agentUserRes.findByUserid(userid);
view.addObject( view.addObject(
"curagentuser", agentUserList != null && agentUserList.size() > 0 ? agentUserList.get(0) : null); "curagentuser", agentUserList != null && agentUserList.size() > 0 ? agentUserList.get(0) : null);
@ -266,7 +263,7 @@ public class AgentAuditController extends Handler {
} }
ModelAndView view = request(super.createView(mainagentuser)); ModelAndView view = request(super.createView(mainagentuser));
final User logined = super.getUser(request); final User logined = super.getUser(request);
AgentUser agentUser = agentUserRepository.findById(id).orElse(null); AgentUser agentUser = agentUserRes.findById(id).orElse(null);
if (agentUser != null) { if (agentUser != null) {
view.addObject("curagentuser", agentUser); view.addObject("curagentuser", agentUser);

View File

@ -117,7 +117,7 @@ public class IMController extends Handler {
private LeaveMsgRepository leaveMsgRes; private LeaveMsgRepository leaveMsgRes;
@Autowired @Autowired
private AgentUserRepository agentUserRepository; private AgentUserRepository agentUserRes;
@Autowired @Autowired
private AttachmentRepository attachementRes; private AttachmentRepository attachementRes;
@ -822,7 +822,7 @@ public class IMController extends Handler {
Contacts contacts1 = contactsRes.findOneByWluidAndWlsidAndWlcidAndDatastatus( Contacts contacts1 = contactsRes.findOneByWluidAndWlsidAndWlcidAndDatastatus(
uid, sid, cid, false); uid, sid, cid, false);
if (contacts1 != null) { if (contacts1 != null) {
agentUserRepository.findOneByUserid(userid).ifPresent(p -> { agentUserRes.findOneByUserid(userid).ifPresent(p -> {
// 关联AgentService的联系人 // 关联AgentService的联系人
if (StringUtils.isNotBlank(p.getAgentserviceid())) { if (StringUtils.isNotBlank(p.getAgentserviceid())) {
AgentService agentService = agentServiceRepository.findById(p.getAgentserviceid()).orElse(null); AgentService agentService = agentServiceRepository.findById(p.getAgentserviceid()).orElse(null);

View File

@ -77,9 +77,6 @@ public class ChatServiceController extends Handler {
@Autowired @Autowired
private AgentStatusRepository agentStatusRepository; private AgentStatusRepository agentStatusRepository;
@Autowired
private AgentUserRepository agentUserRepository;
@Autowired @Autowired
private LeaveMsgRepository leaveMsgRes; private LeaveMsgRepository leaveMsgRes;
@ -233,7 +230,7 @@ public class ChatServiceController extends Handler {
if (agentUser != null) { if (agentUser != null) {
agentUser.setAgentno(agentno); agentUser.setAgentno(agentno);
agentUser.setAgentname(targetAgent.getUname()); agentUser.setAgentname(targetAgent.getUname());
agentUserRepository.save(agentUser); agentUserRes.save(agentUser);
if (MainContext.AgentUserStatusEnum.INSERVICE.toString().equals( if (MainContext.AgentUserStatusEnum.INSERVICE.toString().equals(
agentUser.getStatus())) { agentUser.getStatus())) {
// 转接 发送消息给 目标坐席 // 转接 发送消息给 目标坐席
@ -288,11 +285,11 @@ public class ChatServiceController extends Handler {
} }
} }
} else { } else {
agentUser = agentUserRepository.findById(agentService.getAgentuserid()).orElse(null); agentUser = agentUserRes.findById(agentService.getAgentuserid()).orElse(null);
if (agentUser != null) { if (agentUser != null) {
agentUser.setAgentno(agentno); agentUser.setAgentno(agentno);
agentUser.setAgentname(targetAgent.getUname()); agentUser.setAgentname(targetAgent.getUname());
agentUserRepository.save(agentUser); agentUserRes.save(agentUser);
} }
} }
@ -317,7 +314,7 @@ public class ChatServiceController extends Handler {
AgentService agentService = agentServiceRes.findById(id).orElse(null); AgentService agentService = agentServiceRes.findById(id).orElse(null);
if (agentService != null) { if (agentService != null) {
User user = super.getUser(request); User user = super.getUser(request);
AgentUser agentUser = agentUserRepository.findById(agentService.getAgentuserid()).orElse(null); AgentUser agentUser = agentUserRes.findById(agentService.getAgentuserid()).orElse(null);
if (agentUser != null) { if (agentUser != null) {
acdAgentService.finishAgentUser(agentUser); acdAgentService.finishAgentUser(agentUser);
} }

View File

@ -1,15 +1,15 @@
/* /*
* Copyright (C) 2023 Beijing Huaxia Chunsong Technology Co., Ltd. * Copyright (C) 2023 Beijing Huaxia Chunsong Technology Co., Ltd.
* <https://www.chatopera.com>, Licensed under the Chunsong Public * <https://www.chatopera.com>, Licensed under the Chunsong Public
* License, Version 1.0 (the "License"), https://docs.cskefu.com/licenses/v1.html * License, Version 1.0 (the "License"), https://docs.cskefu.com/licenses/v1.html
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
* Copyright (C) 2018- Jun. 2023 Chatopera Inc, <https://www.chatopera.com>, Licensed under the Apache License, Version 2.0, * Copyright (C) 2018- Jun. 2023 Chatopera Inc, <https://www.chatopera.com>, Licensed under the Apache License, Version 2.0,
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* Copyright (C) 2017 优客服-多渠道客服系统, Licensed under the Apache License, Version 2.0, * Copyright (C) 2017 优客服-多渠道客服系统, Licensed under the Apache License, Version 2.0,
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
*/ */
package com.cskefu.cc.model; package com.cskefu.cc.model;
@ -19,6 +19,7 @@ import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Proxy; import org.hibernate.annotations.Proxy;
import jakarta.persistence.*; import jakarta.persistence.*;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date; import java.util.Date;
@ -105,6 +106,7 @@ public class AgentUser implements Serializable, Comparable<AgentUser> {
@Transient @Transient
private boolean tip = false; private boolean tip = false;
@Transient @Transient
private boolean agentTip = false; private boolean agentTip = false;
@ -119,11 +121,25 @@ public class AgentUser implements Serializable, Comparable<AgentUser> {
@Transient @Transient
private boolean fromhis = false; private boolean fromhis = false;
@Transient @Transient
private boolean online = false; private boolean online = false;
@Transient @Transient
private boolean disconnect = false; private boolean disconnect = false;
/**
* 证书验证通过
*/
@Transient
private boolean licenseVerifiedPass = true;
/**
* 证书验证提示信息
*/
@Transient
private String licenseBillingMsg;
public AgentUser() { public AgentUser() {
} }
@ -617,4 +633,22 @@ public class AgentUser implements Serializable, Comparable<AgentUser> {
public void setAgentname(String agentname) { public void setAgentname(String agentname) {
this.agentname = agentname; this.agentname = agentname;
} }
@Transient
public boolean isLicenseVerifiedPass() {
return licenseVerifiedPass;
}
public void setLicenseVerifiedPass(boolean licenseVerifiedPass) {
this.licenseVerifiedPass = licenseVerifiedPass;
}
@Transient
public String getLicenseBillingMsg() {
return licenseBillingMsg;
}
public void setLicenseBillingMsg(String licenseBillingMsg) {
this.licenseBillingMsg = licenseBillingMsg;
}
} }

View File

@ -1,14 +1,14 @@
/* /*
* Copyright (C) 2023 Beijing Huaxia Chunsong Technology Co., Ltd. * Copyright (C) 2023 Beijing Huaxia Chunsong Technology Co., Ltd.
* <https://www.chatopera.com>, Licensed under the Chunsong Public * <https://www.chatopera.com>, Licensed under the Chunsong Public
* License, Version 1.0 (the "License"), https://docs.cskefu.com/licenses/v1.html * License, Version 1.0 (the "License"), https://docs.cskefu.com/licenses/v1.html
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
* Copyright (C) 2019-2022 Chatopera Inc, <https://www.chatopera.com>, * Copyright (C) 2019-2022 Chatopera Inc, <https://www.chatopera.com>,
* Licensed under the Apache License, Version 2.0, * Licensed under the Apache License, Version 2.0,
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
*/ */
package com.cskefu.cc.proxy; package com.cskefu.cc.proxy;
@ -34,6 +34,7 @@ import org.springframework.web.servlet.ModelAndView;
import jakarta.servlet.http.Cookie; import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
import java.util.*; import java.util.*;
@ -96,6 +97,8 @@ public class AgentUserProxy {
@Lazy @Lazy
private PeerSyncIM peerSyncIM; private PeerSyncIM peerSyncIM;
@Autowired
private LicenseProxy licenseProxy;
/** /**
* 与联系人主动聊天前查找获取AgentUser * 与联系人主动聊天前查找获取AgentUser

View File

@ -19,6 +19,7 @@ import com.cskefu.cc.basic.Constants;
import com.cskefu.cc.basic.MainContext; import com.cskefu.cc.basic.MainContext;
import com.cskefu.cc.basic.MainUtils; import com.cskefu.cc.basic.MainUtils;
import com.cskefu.cc.exception.*; import com.cskefu.cc.exception.*;
import com.cskefu.cc.model.AgentUser;
import com.cskefu.cc.model.ExecuteResult; import com.cskefu.cc.model.ExecuteResult;
import com.cskefu.cc.model.MetaKv; import com.cskefu.cc.model.MetaKv;
import com.cskefu.cc.persistence.repository.MetaKvRepository; import com.cskefu.cc.persistence.repository.MetaKvRepository;
@ -511,5 +512,33 @@ public class LicenseProxy {
} }
} }
/**
* 访客会话执行计费
*
* @param agentUser
* @return
*/
public ExecuteResult writeDownAgentUserUsageInStore(final AgentUser agentUser) {
// 检查是否还在体验阶段
ExecuteResult er = new ExecuteResult();
int alreadyUsed = getResourceUsageInMetaKv(MainContext.BillingResource.AGENGUSER);
if (alreadyUsed <= 100) {
// 可以免费创建 100 个访客会话
er.setRc(ExecuteResult.RC_SUCC);
return er;
}
try {
writeDownResourceUsageInStore(MainContext.BillingResource.AGENGUSER, 1);
er.setRc(ExecuteResult.RC_SUCC);
} catch (BillingQuotaException e) {
er.setRc(ExecuteResult.RC_ERR1);
er.setMsg(e.getMessage());
} catch (BillingResourceException e) {
er.setRc(ExecuteResult.RC_ERR2);
er.setMsg(e.getMessage());
}
return er;
}
} }

View File

@ -11,196 +11,203 @@
* Licensed under the Apache License, Version 2.0 * Licensed under the Apache License, Version 2.0
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
*/ */
var title = "春松客服-开源客服系统" ; var title = "春松客服-开源客服系统";
var socket , newuser = [] , newmessage = [] , ring = []; var socket, newuser = [], newmessage = [], ring = [];
newuser['mp3'] = '/images/new.mp3'; newuser['mp3'] = '/images/new.mp3';
newmessage['mp3'] = '/images/message.mp3'; newmessage['mp3'] = '/images/message.mp3';
ring['mp3'] = '/images/ring.mp3'; ring['mp3'] = '/images/ring.mp3';
$(document).ready(function(){ $(document).ready(function () {
var protocol = window.location.protocol.replace(/:/g,''); var protocol = window.location.protocol.replace(/:/g, '');
socket = io(protocol+'://'+hostname+':'+port+"/im/agent?userid="+userid+"&session="+session+"&admin="+adminuser , {transports: ['websocket'], upgrade: false}); socket = io(protocol + '://' + hostname + ':' + port + "/im/agent?userid=" + userid + "&session=" + session + "&admin=" + adminuser, {
socket.on('connect',function() { transports: ['websocket'],
console.log("[IM] 连接初始化成功"); upgrade: false
//请求服务端记录 当前用户在线事件 });
}).on('disconnect',function() { socket.on('connect', function () {
console.log("[IM] 连接已断开"); console.log("[IM] 连接初始化成功");
//请求服务端记录,当前用户离线 //请求服务端记录 当前用户在线事件
}).on('disconnect', function () {
console.log("[IM] 连接已断开");
//请求服务端记录,当前用户离线
}); });
socket.on('chatevent', function(data) {
// console.log(data.messageType + " ..... message:"+data.message);
}).on('task', function(data) {
}).on('new', function(data) {
if($('#customerChatAudit').length > 0){
if(customerChatAudit.$('#agentuser_' + data.userid).length > 0 && customerChatAudit.$("#chat_users li").length>1){
customerChatAudit.$('#agentuser_' + data.userid).remove();
customerChatAudit.$("#chat_users li:first-child a").click();
}else{
customerChatAudit.$('#ccaIndex').html("<div class=\"layui-layout layui-layout-content\" style=\"height: 100%;\">\n" +
" <div class=\"box default-box\" style=\"height: 100%;\">\n" +
" <div class=\"box-body ukefu-im-theme\">\n" +
" <div class=\"ukefu-empty\" style=\"background: none\">\n" +
" <i class=\"layui-icon\">&#xe63a;</i>\n" +
" <div style=\"\">还没有任何对话</div>\n" +
" </div>\n" +
" </div>\n" +
" </div>\n" +
"</div>");
}
}
if($('#multiMediaDialogWin').length > 0 && multiMediaDialogWin != null && multiMediaDialogWin.$ &&multiMediaDialogWin.$('#agentusers').length > 0){
multiMediaDialogWin.Proxy.newAgentUserService(data,"agent");
}else{
//来电弹屏
$('#agentdesktop').attr('data-href' , '/agent/index.html?userid='+data.userid).click();
WebIM.audioplayer('audioplane', newuser, false); // 播放
}
}).on('status', function(data) {
$.post('/lazyAgentStatus').success(function(html){
$('#agents_status').html(html);
});
// $('#agents_status').html("服务中的人数:"+data.users+"人,当前排队人数:"+data.inquene+"人,在线坐席数:"+data.agents+"人,坐席忙:"+data.busy+"人");
}).on('message', function(data) {
if($('#multiMediaDialogWin').length > 0 && multiMediaDialogWin != null && multiMediaDialogWin.$ && multiMediaDialogWin.$('#agentusers').length > 0){
multiMediaDialogWin.Proxy.newAgentUserMessage(data,"agent");
if(data.type == 'message'){
WebIM.audioplayer('audioplane', newmessage, false); // 播放
if(multiMediaDialogWin.isAisuggest && multiMediaDialogWin.isAisuggest == "true"){
multiMediaDialogWin.Proxy.quickReply(data,"agent");
}
}
}else{
//来电弹屏
$('#agentdesktop').attr('data-href' , '/agent/index.html?userid='+data.userid).click();
}
}).on('workorder', function(data) {
}).on('transout', function(data){ socket.on('chatevent', function (data) {
// TODO 坐席会话被转接出去 // console.log(data.messageType + " ..... message:"+data.message);
if($('#multiMediaDialogWin').length > 0){ }).on('task', function (data) {
if(multiMediaDialogWin.document.getElementById('agentusers') != null){ }).on('new', function (data) {
multiMediaDialogWin.Proxy.transoutAgentUserService(data); console.log("new data ...", data);
} if ($('#customerChatAudit').length > 0) {
} if (customerChatAudit.$('#agentuser_' + data.userid).length > 0 && customerChatAudit.$("#chat_users li").length > 1) {
layer.msg("您与"+data.username+"的会话已被转接给"+data.agentname,{time:1500}) customerChatAudit.$('#agentuser_' + data.userid).remove();
customerChatAudit.$("#chat_users li:first-child a").click();
} else {
customerChatAudit.$('#ccaIndex').html("<div class=\"layui-layout layui-layout-content\" style=\"height: 100%;\">\n" +
" <div class=\"box default-box\" style=\"height: 100%;\">\n" +
" <div class=\"box-body ukefu-im-theme\">\n" +
" <div class=\"ukefu-empty\" style=\"background: none\">\n" +
" <i class=\"layui-icon\">&#xe63a;</i>\n" +
" <div style=\"\">还没有任何对话</div>\n" +
" </div>\n" +
" </div>\n" +
" </div>\n" +
"</div>");
}
}
}).on('audit_message', function(data){ if ($('#multiMediaDialogWin').length > 0 &&
// 会话监控:消息 multiMediaDialogWin != null &&
if($('#customerChatAudit').length > 0 && customerChatAudit != null && customerChatAudit.$ && customerChatAudit.$('#agentuserscca').length > 0){ multiMediaDialogWin.$ &&
customerChatAudit.Proxy.newAgentUserMessage(data,"cca"); multiMediaDialogWin.$('#agentusers').length > 0) {
if(data.type == 'message'){ multiMediaDialogWin.Proxy.newAgentUserService(data, "agent");
WebIM.audioplayer('audioplane', newmessage, false); // 播放 } else {
if(customerChatAudit.isCcaAisuggest && customerChatAudit.isCcaAisuggest == "true"){ //来电弹屏
customerChatAudit.Proxy.quickReply(data,"cca"); $('#agentdesktop').attr('data-href', '/agent/index.html?userid=' + data.userid + '&licenseVerifiedPass=' + data.licenseVerifiedPass + '&licenseBillingMsg=' + data.licenseBillingMsg).click();
} WebIM.audioplayer('audioplane', newuser, false); // 播放
} }
} }).on('status', function (data) {
}).on('audit_new', function(data){ $.post('/lazyAgentStatus').success(function (html) {
// 会话监控:新建 $('#agents_status').html(html);
if(skills.indexOf(data.skill)>-1 && $('#customerChatAudit').length > 0 && customerChatAudit != null && customerChatAudit.$){ });
customerChatAudit.Proxy.newAgentUserService(data,"cca"); // $('#agents_status').html("服务中的人数:"+data.users+"人,当前排队人数:"+data.inquene+"人,在线坐席数:"+data.agents+"人,坐席忙:"+data.busy+"人");
if(data.type == 'message'){ }).on('message', function (data) {
WebIM.audioplayer('audioplane', newmessage, false); // 播放 if ($('#multiMediaDialogWin').length > 0 && multiMediaDialogWin != null && multiMediaDialogWin.$ && multiMediaDialogWin.$('#agentusers').length > 0) {
} multiMediaDialogWin.Proxy.newAgentUserMessage(data, "agent");
} if (data.type == 'message') {
}).on('audit_end', function(data){ WebIM.audioplayer('audioplane', newmessage, false); // 播放
// 会话监控:结束 if (multiMediaDialogWin.isAisuggest && multiMediaDialogWin.isAisuggest == "true") {
if($('#customerChatAudit').length > 0){ multiMediaDialogWin.Proxy.quickReply(data, "agent");
if(customerChatAudit.document.getElementById('agentuserscca') != null){ }
customerChatAudit.Proxy.endAgentUserService(data); }
} } else {
} //来电弹屏
}).on('end', function(data) { $('#agentdesktop').attr('data-href', '/agent/index.html?userid=' + data.userid).click();
console.warn(111111, data) }
if($('#multiMediaDialogWin').length > 0){ }).on('workorder', function (data) {
if(multiMediaDialogWin.document.getElementById('agentusers') != null){
multiMediaDialogWin.Proxy.endAgentUserService(data); }).on('transout', function (data) {
} // TODO 坐席会话被转接出去
}else{ if ($('#multiMediaDialogWin').length > 0) {
//来电弹屏 if (multiMediaDialogWin.document.getElementById('agentusers') != null) {
$('#agentdesktop').attr('data-href', '/agent/index.html?userid='+data.userid).click(); multiMediaDialogWin.Proxy.transoutAgentUserService(data);
} }
}).on('leave', function(data){ }
top.layer.msg('当前会话已经过期,稍后将自动登出!',{icon: 1, time: 2000}); layer.msg("您与" + data.username + "的会话已被转接给" + data.agentname, {time: 1500})
setTimeout(function(){
// 执行登出 }).on('audit_message', function (data) {
window.location.href = "/logout.html?code=2"; // 会话监控:消息
}, 2000); if ($('#customerChatAudit').length > 0 && customerChatAudit != null && customerChatAudit.$ && customerChatAudit.$('#agentuserscca').length > 0) {
}); customerChatAudit.Proxy.newAgentUserMessage(data, "cca");
/****每分钟执行一次,与服务器交互,保持会话****/ if (data.type == 'message') {
setInterval(function(){ WebIM.audioplayer('audioplane', newmessage, false); // 播放
WebIM.ping(); if (customerChatAudit.isCcaAisuggest && customerChatAudit.isCcaAisuggest == "true") {
} , 60000); customerChatAudit.Proxy.quickReply(data, "cca");
}
}
}
}).on('audit_new', function (data) {
// 会话监控:新建
if (skills.indexOf(data.skill) > -1 && $('#customerChatAudit').length > 0 && customerChatAudit != null && customerChatAudit.$) {
customerChatAudit.Proxy.newAgentUserService(data, "cca");
if (data.type == 'message') {
WebIM.audioplayer('audioplane', newmessage, false); // 播放
}
}
}).on('audit_end', function (data) {
// 会话监控:结束
if ($('#customerChatAudit').length > 0) {
if (customerChatAudit.document.getElementById('agentuserscca') != null) {
customerChatAudit.Proxy.endAgentUserService(data);
}
}
}).on('end', function (data) {
console.warn(111111, data)
if ($('#multiMediaDialogWin').length > 0) {
if (multiMediaDialogWin.document.getElementById('agentusers') != null) {
multiMediaDialogWin.Proxy.endAgentUserService(data);
}
} else {
//来电弹屏
$('#agentdesktop').attr('data-href', '/agent/index.html?userid=' + data.userid).click();
}
}).on('leave', function (data) {
top.layer.msg('当前会话已经过期,稍后将自动登出!', {icon: 1, time: 2000});
setTimeout(function () {
// 执行登出
window.location.href = "/logout.html?code=2";
}, 2000);
});
/****每分钟执行一次,与服务器交互,保持会话****/
setInterval(function () {
WebIM.ping();
}, 60000);
}); });
var WebIM = { var WebIM = {
sendMessage:function(message , userid , appid , session , touser , agentstatus, agentuserid){ sendMessage: function (message, userid, appid, session, touser, agentstatus, agentuserid) {
WebIM.sendTypeMessage(message, userid, appid, session, touser, agentstatus, null , null,agentuserid) ; WebIM.sendTypeMessage(message, userid, appid, session, touser, agentstatus, null, null, agentuserid);
}, },
sendTypeMessage:function(message , userid , appid , session , touser , agentstatus , msgtype , attachmentid,agentuserid){ sendTypeMessage: function (message, userid, appid, session, touser, agentstatus, msgtype, attachmentid, agentuserid) {
socket.emit('message', { socket.emit('message', {
appid : appid , appid: appid,
userid:userid, userid: userid,
sign:session, sign: session,
touser:touser, touser: touser,
session: session, session: session,
username:agentstatus, username: agentstatus,
nickname:agentstatus, nickname: agentstatus,
message : message, message: message,
msgtype:msgtype, msgtype: msgtype,
attachmentid:attachmentid, attachmentid: attachmentid,
agentuser:agentuserid agentuser: agentuserid
}); });
}, },
// 发送会话监控干预消息 // 发送会话监控干预消息
sendIntervention: function(supervisorid, agentuserid, session, msgtype, content, extra){ sendIntervention: function (supervisorid, agentuserid, session, msgtype, content, extra) {
socket.emit('intervention', { socket.emit('intervention', {
supervisorid: supervisorid, // 坐席监控人员ID必须 supervisorid: supervisorid, // 坐席监控人员ID必须
agentuserid: agentuserid, // 坐席访客会话ID必须 agentuserid: agentuserid, // 坐席访客会话ID必须
msgtype: msgtype, // 干预消息类型, 必须 msgtype: msgtype, // 干预消息类型, 必须
content: content, // 干预消息内容, 必须 content: content, // 干预消息内容, 必须
session: session, // 登录会话ID session: session, // 登录会话ID
extra: extra // 其它可选属性, 可选 extra: extra // 其它可选属性, 可选
}); });
}, },
ping : function(){ ping: function () {
loadURL("/message/ping.html"); loadURL("/message/ping.html");
console.log("[IM] heartbeat:" + new Date().getTime()); console.log("[IM] heartbeat:" + new Date().getTime());
}, },
audioplayer:function(id, file, loop) { audioplayer: function (id, file, loop) {
var audioplayer = document.getElementById(id); var audioplayer = document.getElementById(id);
if (audioplayer != null) { if (audioplayer != null) {
document.body.removeChild(audioplayer); document.body.removeChild(audioplayer);
} }
if (typeof(file) != 'undefined') { if (typeof (file) != 'undefined') {
if (navigator.userAgent.indexOf("MSIE") > 0) { // IE if (navigator.userAgent.indexOf("MSIE") > 0) { // IE
var player = document.createElement('bgsound'); var player = document.createElement('bgsound');
player.id = id; player.id = id;
player.src = file['mp3']; player.src = file['mp3'];
player.setAttribute('autostart', 'true'); player.setAttribute('autostart', 'true');
if (loop) { if (loop) {
player.setAttribute('loop', 'infinite'); player.setAttribute('loop', 'infinite');
} }
document.body.appendChild(player); document.body.appendChild(player);
} else { // Other FF Chome Safari Opera } else { // Other FF Chome Safari Opera
var player = document.createElement('audio'); var player = document.createElement('audio');
player.id = id; player.id = id;
player.setAttribute('autoplay', 'autoplay'); player.setAttribute('autoplay', 'autoplay');
if (loop) { if (loop) {
player.setAttribute('loop', 'loop'); player.setAttribute('loop', 'loop');
} }
document.body.appendChild(player); document.body.appendChild(player);
var mp3 = document.createElement('source'); var mp3 = document.createElement('source');
mp3.src = file['mp3']; mp3.src = file['mp3'];
mp3.type = 'audio/mpeg'; mp3.type = 'audio/mpeg';
player.appendChild(mp3); player.appendChild(mp3);
} }
} }
} }
} }

View File

@ -343,22 +343,23 @@ function newMessageScorllBottom(type, msgType) {
var Proxy = { var Proxy = {
newAgentUserService: function (data, type) { newAgentUserService: function (data, type) {
console.log("newAgentUserService data type", data, type)
if ($('#tip_message_' + data.userid).length > 0) { if ($('#tip_message_' + data.userid).length > 0) {
var channel = data.channeltype var channel = data.channeltype
if (channel) { if (channel) {
if (channel === 'phone') { if (channel === 'phone') {
$('#tip_icon_phone_' + data.userid).attr("src", "/images/phone-ico.png"); $('#tip_icon_phone_' + data.userid).attr("src", "/images/phone-ico.png");
} else { } else {
$('#tip_icon_' +channel+ '_' + data.userid).removeClass('ukefu-channel-icon-end').addClass("ukefu-channel-icon"); $('#tip_icon_' + channel + '_' + data.userid).removeClass('ukefu-channel-icon-end').addClass("ukefu-channel-icon");
} }
} }
$('#tip_message_' + data.userid).removeClass('bg-gray').addClass("bg-green").text('在线'); $('#tip_message_' + data.userid).removeClass('bg-gray').addClass("bg-green").text('在线');
} else { } else {
if ($('.chat-list-item.active').length > 0) { if ($('.chat-list-item.active').length > 0) {
var id = $('.chat-list-item.active').data('id'); var id = $('.chat-list-item.active').data('id');
type == "agent" ? loadURL('/agent/agentusers.html?newuser=true&userid=' + id, '#agentusers') : loadURL('/apps/cca/agentusers.html?newuser=true&userid=' + id, '#agentuserscca'); type == "agent" ? loadURL('/agent/agentusers.html?newuser=true&userid=' + id + '&licenseVerifiedPass=' + data.licenseVerifiedPass + '&licenseBillingMsg=' + data.licenseBillingMsg, '#agentusers') : loadURL('/apps/cca/agentusers.html?newuser=true&userid=' + id + "&licenseVerifiedPass=" + data.licenseVerifiedPass + "&licenseBillingMsg=" + data.licenseBillingMsg, '#agentuserscca');
} else { } else {
type == "agent" ? location.href = "/agent/index.html?newuser=true" : location.href = "/apps/cca/index.html?newuser=true"; type == "agent" ? location.href = "/agent/index.html?newuser=true&licenseVerifiedPass=" + data.licenseVerifiedPass + "&licenseBillingMsg=" + data.licenseBillingMsg : location.href = "/apps/cca/index.html?newuser=true&licenseVerifiedPass=" + data.licenseVerifiedPass + "&licenseBillingMsg=" + data.licenseBillingMsg;
} }
} }
if (data.userid == cursession) { if (data.userid == cursession) {
@ -485,7 +486,7 @@ var Proxy = {
if (channel === 'phone') { if (channel === 'phone') {
$('#tip_icon_phone_' + data.userid).attr("src", "/images/cde-ico-gray.png"); $('#tip_icon_phone_' + data.userid).attr("src", "/images/cde-ico-gray.png");
} else { } else {
$('#tip_icon_'+ channel +'_' + data.userid).removeClass("ukefu-channel-icon").addClass('ukefu-channel-icon-end'); $('#tip_icon_' + channel + '_' + data.userid).removeClass("ukefu-channel-icon").addClass('ukefu-channel-icon-end');
} }
} }
$('#tip_message_' + data.userid).removeClass("bg-green").addClass('bg-gray').text('离开'); $('#tip_message_' + data.userid).removeClass("bg-green").addClass('bg-gray').text('离开');
@ -504,7 +505,11 @@ var Proxy = {
} }
}, },
tipMsgForm: function (href) { tipMsgForm: function (href) {
top.layer.prompt({formType: 2, title: '请输入拉黑原因', area: ['300px', '50px']}, function (value, index, elem) { top.layer.prompt({
formType: 2,
title: '请输入拉黑原因',
area: ['300px', '50px']
}, function (value, index, elem) {
location.href = href + "&description=" + encodeURIComponent(value); location.href = href + "&description=" + encodeURIComponent(value);
top.layer.close(index); top.layer.close(index);
}); });

View File

@ -80,3 +80,11 @@
.last-msg .last-msg
small.ukefu-badge.bg-red(id="last_msg_" + agentuser.userid,style="#{(agentuser.tokenum == 0 || (curagentuser && curagentuser.id == agentuser.id)) ? 'display:none' : ''}") small.ukefu-badge.bg-red(id="last_msg_" + agentuser.userid,style="#{(agentuser.tokenum == 0 || (curagentuser && curagentuser.id == agentuser.id)) ? 'display:none' : ''}")
| #{agentuser.tokenum ? agentuser.tokenum : 0} | #{agentuser.tokenum ? agentuser.tokenum : 0}
script(language="javascript").
$(document).ready(function () {
var licenseVerifiedPass = #{licenseVerifiedPass};
var licenseBillingMsg = '#{licenseBillingMsg}';
if (licenseBillingMsg) {
handleGeneralCodeInQueryPathOrApiResp(licenseBillingMsg);
}
});