Beispiel #1
0
        public ActionResult KfNumberEdit()
        {
            string   id       = RQuery["Id"];
            KfNumber kfNumber = string.IsNullOrWhiteSpace(id) ? null : _kfNumberService.GetById(new Guid(id));

            return(AdminView(kfNumber));
        }
Beispiel #2
0
        public ActionResult Chat()
        {
            if (base.LoginAdmin.KfNumbers.Count == 0)
            {
                return(Content("请选分配工号给当前管理员,方可进入客服服务界面"));
            }

            KfNumber kfNumber = (KfNumber)base.LoginAdmin.KfNumbers.ToList()[0];

            //设置客服为上线状态
            kfNumber.IsOnline = true;
            _kfNumberService.Update(kfNumber);
            //填充页面信息
            ViewBag.Department   = base.LoginAdmin.PermissionOrganization.Name;
            ViewBag.KfNumber     = kfNumber.Number + "[" + kfNumber.NickName + "]";
            ViewBag.RoleName     = base.LoginAdmin.PermissionRole.Name;
            ViewBag.OnlineStatus = kfNumber.OnlineStatus;
            string hash = Guid.NewGuid().ToString();

            ViewBag.Hash = hash;
            //获取与当前客服还未结束的会话
            IList <KfMeeting> listKfMeeting = _kfMeetingService.Table.Where(k => k.KfNumberId == kfNumber.Id && !k.IsEnd).ToList();

            ViewBag.ListKfMeeting = listKfMeeting;
            //更新在线客服缓存
            OnlineKFModel onlineKFModel = new OnlineKFModel();

            onlineKFModel.Hash           = hash;
            onlineKFModel.KfNumberId     = kfNumber.Id;
            onlineKFModel.LastActiveDate = DateTime.Now;
            MessageManager.Instance.CacheLocalKF(onlineKFModel);
            return(View());
        }
Beispiel #3
0
        /// <summary>
        /// 设置在线状态[0:正常,1:离开]
        /// </summary>
        /// <returns></returns>
        public string SetOnlineStatus()
        {
            int      onlineStatus = int.Parse(Request["OnlineStatus"]);
            KfNumber kfNumber     = _kfNumberService.GetById(KfNumberId);

            kfNumber.OnlineStatus = onlineStatus;
            _kfNumberService.Update(kfNumber);
            return(JsonHelper.AnalysisJson <string>(onlineStatus.ToString(), "ok", null));
        }
Beispiel #4
0
        public string SendPrivateMessage()
        {
            try
            {
                KfNumber kfNumber = _kfNumberService.GetById(KfNumberId);

                if (kfNumber == null)
                {
                    return(JsonHelper.AnalysisJson <string>("KfNumber对象为null", "error", null));
                }

                KfMeeting kfMeeting = _kfMeetingService.GetById(KfMeetingId);

                if (kfMeeting.IsEnd)
                {
                    return(JsonHelper.AnalysisJson <string>(string.Format("本条消息发送失败[{0}]", "本次会话已经结束"), "error", null));
                }

                string messageText = Request["messageText"];

                if (string.IsNullOrWhiteSpace(messageText))
                {
                    return(JsonHelper.AnalysisJson <string>("消息不能为空", "error", null));
                }

                messageText = messageText.Trim();
                // 防止XSS攻击
                //messageText = Sanitizer.GetSafeHtmlFragment(messageText);
                //messageText = HttpUtility.HtmlEncode(StringHelper.StripHtml(messageText));
                messageText = HttpUtility.HtmlEncode(messageText);
                //把消息存入数据库
                //ICommunicationRepository iCommunicationRepository = new PersistedRepository();
                _kfMeetingMessageService.InsertKfMeetingMessage(KfMeetingId, 1, messageText);
                //把消息发送给微信端客户
                MpUser mpUser = _mpUserService.GetById(ReceiveUserId);

                if (mpUser != null && !string.IsNullOrWhiteSpace(mpUser.OpenID))
                {
                    _mpUserService.SendMessage(mpUser.OpenID, messageText);
                }
                //把消息发给通信线程进行中转(适用于web聊天)
                string message2 = string.Empty;

                if (new CommandManager(null).TryHandleCommand("SendPrivateMessage", new string[] { KfNumberId.ToString(), ReceiveUserId.ToString(), messageText }, ref message2) && string.IsNullOrWhiteSpace(message2))
                {
                    return(JsonHelper.AnalysisJson <string>(string.Empty, "ok", null));
                }

                this.log.Warn(string.Format("消息发送失败,{0}", message2));
                return(JsonHelper.AnalysisJson <string>(string.Format("本条消息发送失败[{0}]", message2), "error", null));
            }
            catch (Exception ex)
            {
                this.log.Warn(ex.Message);
                return(JsonHelper.AnalysisJson <string>(string.Format("本条消息发送失败[{0}]", ex.Message), "error", null));
            }
        }
Beispiel #5
0
 public KfNumberDTO(KfNumber kfNumber)
 {
     this.Id           = kfNumber.Id;
     this.CreateDate   = kfNumber.CreateDate;
     this.Number       = kfNumber.Number;
     this.NickName     = kfNumber.NickName;
     this.IsOnline     = kfNumber.IsOnline;
     this.OnlineStatus = kfNumber.OnlineStatus;
     this.AdminName    = kfNumber.Admin.Name;
 }
Beispiel #6
0
        public ActionResult KfNumberEditProvide()
        {
            KfNumber kfNumber   = new KfNumber();
            Guid     oldAdminId = Guid.Empty;

            if (!string.IsNullOrWhiteSpace(RQuery["KfNumberId"]))
            {
                kfNumber   = _kfNumberService.GetById(new Guid(RQuery["KfNumberId"]));
                oldAdminId = kfNumber.AdminId;
            }

            UpdateModel <KfNumber>(kfNumber);

            if (kfNumber.AdminId == Guid.Empty || kfNumber.AdminId == null)
            {
                return(JsonMessage(false, "请选择分配管理员"));
            }

            if (string.IsNullOrWhiteSpace(RQuery["KfNumberId"]))
            {
                Ocean.Entity.Admin admin = _adminService.GetById(kfNumber.AdminId);

                if (admin.KfNumbers.Count != 0)
                {
                    return(JsonMessage(false, "当前所选管理员已被分配过工号"));
                }

                _kfNumberService.Insert(kfNumber);
                return(JsonMessage(true, "添加客服工号成功"));
            }
            else
            {
                if (oldAdminId != kfNumber.AdminId)
                {
                    Ocean.Entity.Admin admin = _adminService.GetById(kfNumber.AdminId);

                    if (admin.KfNumbers.Count != 0)
                    {
                        return(JsonMessage(false, "当前所选管理员已被分配过工号"));
                    }
                }

                _kfNumberService.Update(kfNumber);
                return(JsonMessage(true, "修改客服工号成功"));
            }
        }
Beispiel #7
0
        public ActionResult KfMeetingListProvide(KfMeetingDTO kfMeetingDTO)
        {
            if (!base.HasPermission("kfmeeting", PermissionOperate.view))
            {
                if (base.LoginAdmin.KfNumbers.Count == 0)
                {
                    return(null);
                }

                KfNumber kfNumber = (KfNumber)base.LoginAdmin.KfNumbers.ToList()[0];
                kfMeetingDTO.KfNumberId = kfNumber.Id;
            }

            PagedList <KfMeeting> list = _kfMeetingService.GetPageList(PageIndex, PageSize, kfMeetingDTO);

            return(SwitchJsonList <KfMeeting, KfMeetingDTO>(list, list.TotalItemCount));
        }
Beispiel #8
0
        public string OffLine()
        {
            string   message  = string.Empty;
            KfNumber kfNumber = _kfNumberService.GetById(KfNumberId);

            if (kfNumber == null)
            {
                return(JsonHelper.AnalysisJson <string>("KfNumber对象为null", "error", null));
            }

            //发送客服离线通知
            if (new CommandManager(null).TryHandleCommand("OffLine", new string[] { KfNumberId.ToString(), "1" }, ref message))
            {
                return(JsonHelper.AnalysisJson <string>(string.Empty, "ok", null));
            }
            else
            {
                this.log.Error(message);
                return(JsonHelper.AnalysisJson <string>(message, "error", null));
            }
        }
Beispiel #9
0
        public ActionResult KfMeetingMessageListProvide(KfMeetingMessageDTO kfMeetingMessageDTO)
        {
            if (!base.HasPermission("kfmeetingmessage", PermissionOperate.view))
            {
                if (base.LoginAdmin.KfNumbers.Count == 0)
                {
                    return(null);
                }

                KfNumber kfNumber = (KfNumber)base.LoginAdmin.KfNumbers.ToList()[0];
                kfMeetingMessageDTO.KfNumberId = kfNumber.Id;
            }

            if (kfMeetingMessageDTO.MpUserId != null && kfMeetingMessageDTO.MpUserId != Guid.Empty)
            {
                KfNumber kfNumber = (KfNumber)base.LoginAdmin.KfNumbers.ToList()[0];
                kfMeetingMessageDTO.KfNumberId = kfNumber.Id;
            }

            PagedList <KfMeetingMessage> list  = _kfMeetingMessageService.GetPageList(PageIndex, PageSize, kfMeetingMessageDTO);
            IList <KfMeetingMessage>     list2 = list.OrderBy(m => m.CreateDate).ToList();

            return(SwitchJsonList <KfMeetingMessage, KfMeetingMessageDTO>(list2, list.TotalItemCount));
        }
Beispiel #10
0
        public override void ExecuteNotice(CallerContext callerContext, string[] args, ref string message)
        {
            int type = int.Parse(args[1]);

            //客服离线
            if (type == 1)
            {
                Guid kfNumberId = new Guid(args[0]);
                //移除缓存中的客服
                MessageManager.Instance.RemoveCacheKF(kfNumberId);
                //离线时清理线程中的客服端(防止第一条离线信息丢失)
                CometThreadPool.DequeueCometWaitRequest(kfNumberId);
                //断开与所有访客的会话
                IKfNumberService         kfNumberService         = EngineContext.Current.Resolve <IKfNumberService>();
                IKfMeetingService        kfMeetingService        = EngineContext.Current.Resolve <IKfMeetingService>();
                IKfMeetingMessageService kfMeetingMessageService = EngineContext.Current.Resolve <IKfMeetingMessageService>();
                IMpUserService           mpUserService           = EngineContext.Current.Resolve <IMpUserService>();
                IList <KfMeeting>        listMeeting             = kfMeetingService.GetALL().Where(m => m.KfNumberId == kfNumberId && m.IsEnd == false).ToList();

                foreach (KfMeeting kfMeeting in listMeeting)
                {
                    kfMeeting.RecordCount = kfMeetingMessageService.GetCount(" where KfMeetingId='" + kfMeeting.Id + "'");
                    kfMeeting.EndDate     = DateTime.Now;
                    kfMeeting.IsEnd       = true;
                    kfMeetingService.Update(kfMeeting);
                    base.SendPrivateMessage(kfNumberId, kfMeeting.MpUserId, "本次会话已被断开,您可以重新发起会话请求");
                    //发送给微信
                    MpUser mpUser = mpUserService.GetById(kfMeeting.MpUserId);

                    if (mpUser != null && !string.IsNullOrWhiteSpace(mpUser.OpenID))
                    {
                        mpUserService.SendMessage(mpUser.OpenID, "本次会话已被断开,您可以重新发起会话请求");
                    }
                    //更新用户状态
                    mpUserService.ChangeMpUserState(kfMeeting.MpUserId, 0);
                }
                //把客服设置成离线
                KfNumber kfNumber = kfNumberService.GetById(kfNumberId);
                kfNumber.IsOnline = false;
                kfNumberService.Update(kfNumber);
            }

            //访客离线
            if (type == 2)
            {
                Guid mpUserId = new Guid(args[0]);
                //离线时清理线程中的访客端(防止第一条离线信息丢失)
                CometThreadPool.DequeueCometWaitRequest(mpUserId);
                //断开与客服的会话
                IKfMeetingService        kfMeetingService        = EngineContext.Current.Resolve <IKfMeetingService>();
                IKfMeetingMessageService kfMeetingMessageService = EngineContext.Current.Resolve <IKfMeetingMessageService>();
                IList <KfMeeting>        listMeeting             = kfMeetingService.GetALL().Where(m => m.MpUserId == mpUserId && m.IsEnd == false).ToList();

                foreach (KfMeeting kfMeeting in listMeeting)
                {
                    kfMeeting.RecordCount = kfMeetingMessageService.GetCount(" where KfMeetingId='" + kfMeeting.Id + "'");
                    kfMeeting.EndDate     = DateTime.Now;
                    kfMeeting.IsEnd       = true;
                    kfMeetingService.Update(kfMeeting);
                    base.SendNotice(mpUserId, "访客_" + new Random().Next(100), kfMeeting.KfNumberId, 3, 0, mpUserId.ToString());
                }
            }
        }