using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using System.Data; namespace YTSoft.BaseCallCenter.MVCWeb.Controllers { public class OCXOptController : Controller { // // GET: /OCXOpt/ public ActionResult OCXOptAjax() { return View(); } /// /// 通话处理 /// /// /// [ActionName("OCXOptCallAjax")] [HttpGet] public string OCXOptCallAjax(string optaction,string timeno,string callid,string userid,string usercode,string username,string extnumber,string callernum,string path) { //&timeno=" + timeno+"&callid=" + callID + "&userid=" + userid + "&usercode=" + usercode //+ "&username=" + username + "&extnumber" + extnumber + "&callernum=" + callerNum string res = "error"; try { switch (optaction) { case "gethflist": //res=LoadHFList(context) break; case "getlist": //res=LoadList(context)); break; case "getcallinlist": //来电弹屏通话记录 //res=LoadCallInList(context)); break; case "getgdlist": // //res=LoadGDList(context)); break; case "deletelist": //res=Delete(context)); break; case "clear": break; case "insertCallLogs": res = InsertCallLogs(); break; case "getCallIdByPhone": //根据来电号码获取 res = getCallIdByPhone(callernum); break; case "zhenlingEvent": //振铃事件 res=zhenlingEvent(callid, userid, usercode, username, extnumber, callernum); break; case "zhaijiEvent": //摘机事件 res=zhaijiEvent(callid); break; case "guajiEvent": //挂机事件 res=guajiEvent(callid); break; case "luyinEvent": //录音开始事件 res=luyinEvent(callid,path); break; case "callout": //外呼 res = callout(callernum, userid, usercode, username, extnumber, callid); break; case "callouthf": //外呼回访 res=callouthf(callernum, userid, usercode, username, extnumber, callid); break; } } catch { } return res; } #region 外呼回访 public string callouthf(string phone, string userid, string usercode, string username, string extnumber, string hfid) { string res = "1||" + DateTime.Now.ToString("yyyyMMddHHmmssms"); try { //处理判断本地或外地 zhgjie try { if (phone.Trim() != "") { //判断号码前是否存在0 if (phone.Trim().Substring(0, 1) != "0") { //判断是否手机 if (phone.Trim().Length > 10) { BLL.T_Sys_MobileData mobile_Bll = new BLL.T_Sys_MobileData(); Model.T_Sys_MobileData mobileModel = mobile_Bll.GetModel(phone.Substring(0, 7)); if (mobileModel != null) { if (mobileModel.F_ZipCode != "0371") { phone = "0" + phone; } } } } } } catch { } Model.T_Call_CallRecords model = new Model.T_Call_CallRecords(); model.CallId = DateTime.Now.ToString("yyyyMMddHHmmssms"); model.CallNumber = phone; model.CallType = 1; if (!string.IsNullOrEmpty(userid)) { model.UserId = Convert.ToInt32(userid); } if (!string.IsNullOrEmpty(usercode)) { model.UserCode = usercode.Trim(); } if (!string.IsNullOrEmpty(username)) { model.UserName = HttpUtility.UrlDecode(username.Trim()); //model.UserName=context.Request.Form["txtAgentName"] } if (!string.IsNullOrEmpty(extnumber)) { model.ExtNumber = extnumber.Trim(); //model.UserName=context.Request.Form["txtAgentName"] } model.CallState = 0; model.DealType = 7; model.IsDeal = 1; model.OperateType = 7;//回访 model.OperateObject = ""; model.OperateTime = DateTime.Now; try { if (hfid != "") { model.OperateObject = hfid; } } catch { } string cid = model.CallId; new BLL.T_Call_CallRecords().Add(model); try { //更新回访状态 new BLL.T_Call_TaskTelNum().UpdateHC(Convert.ToInt32(hfid), 1); new BLL.T_Call_TaskTelNum().UpdateYJ(Convert.ToInt32(hfid), 0); //string workorderid = CommonRequest.GetQueryString("workorderid"); //if (workorderid != "") //{ // Model.T_Call_WorkOrder modelorder = new Model.T_Call_WorkOrder(); // modelorder.CallId = model.CallId; // modelorder.F_WORKORDERID = Convert.ToInt32(workorderid); // modelorder.F_WORKORDERSTATEID = 6; // new BLL.T_Call_WorkOrder().Add(modelorder); //} } catch { } if (phone.Length > 5) { res = "2|" + phone + "|" + cid; } else { res = "1|" + phone + "|" + cid; } } catch { } return res; } #endregion #region 话机外呼 public string callout(string phone,string userid,string usercode,string username,string extnumber,string workorderid) { string res = "1||" + DateTime.Now.ToString("yyyyMMddHHmmssms"); try { //处理判断本地或外地 zhgjie try { if (phone.Trim() != "") { //判断号码前是否存在0 if (phone.Trim().Substring(0, 1) != "0") { //判断是否手机 if (phone.Trim().Length > 10) { BLL.T_Sys_MobileData mobile_Bll = new BLL.T_Sys_MobileData(); Model.T_Sys_MobileData mobileModel = mobile_Bll.GetModel(phone.Substring(0, 7)); if (mobileModel != null) { if (mobileModel.F_ZipCode != "0371") { phone = "0" + phone; } } } } } } catch { } Model.T_Call_CallRecords model = new Model.T_Call_CallRecords(); model.CallId = DateTime.Now.ToString("yyyyMMddHHmmssms"); model.CallNumber = phone; model.CallType = 1; if (!string.IsNullOrEmpty(userid)) { model.CallId = DateTime.Now.ToString("yyyyMMddHHmmssms") + userid; model.UserId = Convert.ToInt32(userid); } if (!string.IsNullOrEmpty(usercode)) { model.UserCode = usercode.Trim(); } if (!string.IsNullOrEmpty(username)) { model.UserName = HttpUtility.UrlDecode(username.Trim()); } if (!string.IsNullOrEmpty(extnumber)) { model.ExtNumber = extnumber.Trim(); //model.UserName=context.Request.Form["txtAgentName"] } model.CallState = 0; model.DealType = 6; model.IsDeal = 1; string cid = model.CallId; new BLL.T_Call_CallRecords().Add(model); try { if (workorderid != null) { if (workorderid != "") { Model.T_Call_WorkOrder modelorder = new Model.T_Call_WorkOrder(); modelorder.CallId = model.CallId; modelorder.F_WORKORDERID = Convert.ToInt32(workorderid); modelorder.F_WORKORDERSTATEID = 6; new BLL.T_Call_WorkOrder().Add(modelorder); } } } catch { } if (phone.Length > 5) { res = "2|" + phone + "|" + cid; } else { res = "1|" + phone + "|" + cid; } } catch { } return res; } #endregion #region 电话操作日志 public string InsertCallLogs() { string res = "error"; return res; } #endregion #region 根据来电号码获取callid public string getCallIdByPhone(string telphone) { string res = ""; try { Model.T_Call_CallRecords model = new BLL.T_Call_CallRecords().GetModelByTelphone(telphone); if (model != null) { res = model.CallId.Trim(); } } catch (Exception ex) { res = ""; } return res; } #endregion #region 来电归属地查询 public string GetPhoneLocation(string phoneNumber, bool isPhone) { string location = "未知"; try { //如果是手机号码 if (isPhone) { BLL.T_Sys_MobileData mobile_Bll = new BLL.T_Sys_MobileData(); Model.T_Sys_MobileData mobileModel = mobile_Bll.GetModel(phoneNumber.Substring(0, 7)); return mobileModel != null ? (mobileModel.F_CityDes + mobileModel.F_CardDes) : location; } else//如果是电话号码 { BLL.T_Sys_TelTitleData numbBll = new BLL.T_Sys_TelTitleData(); List mobileModel = numbBll.GetModelList(" 1=1 and F_KeyPhoneNum='" + phoneNumber.Substring(0, 4) + "'"); if (mobileModel == null || mobileModel.Count <= 0) mobileModel = numbBll.GetModelList(" 1=1 and F_KeyPhoneNum='" + phoneNumber.Substring(0, 3) + "'"); return mobileModel.Count > 0 ? mobileModel[0].F_TitleName : location; } } catch (System.Exception ex) { return location; } } #endregion #region 自动添加工单 public bool SubmitOSubmit(string phone,string recordid,string callid,string locationaddress,string userid,string username,string usercode, out int workorderid) { bool bl = false; workorderid = 0; try { Model.T_Wo_WorkOrderBase model = new Model.T_Wo_WorkOrderBase(); List modellist = new BLL.T_Wo_WorkOrderBase().GetModelList(" F_RANGEID="+ recordid); if (modellist != null && modellist.Count > 0) { model = modellist[0]; #region 工单信息 if (string.IsNullOrEmpty(model.F_LINKMAN)) { //model.F_WORKORDERTYPEID = Convert.ToInt32(typeid);//类型ID model.F_WORKORDERSTATEID = 0;//状态ID model.F_REPAIRREQUEST = "未处理"; model.F_CODE = "";//工单编号 model.F_WORKORDERNAME = "";//工单名称 model.F_NUMBER = model.F_CODE; //model.F_CUSTOMERNAME = txtCustomerName.Text.Trim();//客户姓名 model.F_CUSTOMERTELEPHONE = phone.Trim();//客户电话 model.F_USERID = Convert.ToInt32(userid);//坐席id model.F_LINKMAN = usercode.Trim();//坐席工号 model.F_REPAIRMANNAME = username.Trim();//坐席名称 model.F_LINKMANTELEPHONE = phone.Trim();//联系人电话 //model.F_ADSLACCOUNT = hfCallId.Value.Trim(); model.F_BANDWIDTH = ""; model.F_STANDARDADDRESS = locationaddress.Trim(); //model.F_INSTALLADDRESS = F_INSTALLADDRESS; model.F_KSHADDRESSCODE = callid; model.F_RANGEID = Convert.ToInt32(recordid); model.F_PROVINCE = ""; model.F_CITY = ""; model.F_AREA = ""; model.F_ROAD = ""; model.F_HOUSING = ""; model.F_REPAIRMANID = 1; model.F_WORKORDERFROM = "语音工单"; //model.F_WORKORDERLEVELID = F_WORKORDERLEVELID; model.F_FILEFLAG = 0; model.F_CREATEBY = Convert.ToInt32(userid.Trim()); model.F_CREATEDATE = DateTime.Now; model.F_RETURNVISITFLAG = 0; model.F_RETURNVISITSTATE = 0; model.F_RETURNVISITRESULT = 0; model.F_RETURNVISITCONTENT = ""; model.F_DELETEFLAG = 0; model.F_ALLUSETIMES = 0; model.F_STARTTIME = DateTime.Now; model.F_OVERTIMES = 0; model.F_FORMID = 0; model.F_HASTENCOUNTS = 0; model.F_RANGEX = 0; model.F_RANGEY = 0; model.F_REPAIRCLOSEMANID = 0; model.F_REPAIRCLOSEMANNAME = ""; model.F_REPAIRCLOSEREASONS = ""; model.F_REPAIRCLOSEREPTID = 0; model.F_REPAIRCLOSEREPT = ""; new BLL.T_Wo_WorkOrderBase().Update(model); } workorderid = model.F_WORKORDERID; #endregion } else { #region 工单信息 //model.F_WORKORDERTYPEID = Convert.ToInt32(typeid);//类型ID model.F_WORKORDERSTATEID = 0;//状态ID model.F_REPAIRREQUEST = "未处理"; model.F_CODE = "";//工单编号 model.F_WORKORDERNAME = "";//工单名称 model.F_NUMBER = model.F_CODE; //model.F_CUSTOMERNAME = txtCustomerName.Text.Trim();//客户姓名 model.F_CUSTOMERTELEPHONE = phone.Trim();//客户电话 model.F_USERID = Convert.ToInt32(userid);//坐席id model.F_LINKMAN = usercode.Trim();//坐席工号 model.F_REPAIRMANNAME = username.Trim();//坐席名称 model.F_LINKMANTELEPHONE = phone.Trim();//联系人电话 //model.F_ADSLACCOUNT = hfCallId.Value.Trim(); model.F_BANDWIDTH = ""; model.F_STANDARDADDRESS = locationaddress.Trim(); //model.F_INSTALLADDRESS = F_INSTALLADDRESS; model.F_KSHADDRESSCODE = callid; model.F_RANGEID = Convert.ToInt32(recordid); model.F_PROVINCE = ""; model.F_CITY = ""; model.F_AREA = ""; model.F_ROAD = ""; model.F_HOUSING = ""; model.F_REPAIRMANID = 1; model.F_WORKORDERFROM = "语音工单"; //model.F_WORKORDERLEVELID = F_WORKORDERLEVELID; model.F_FILEFLAG = 0; model.F_CREATEBY = Convert.ToInt32(userid.Trim()); model.F_CREATEDATE = DateTime.Now; model.F_RETURNVISITFLAG = 0; model.F_RETURNVISITSTATE = 0; model.F_RETURNVISITRESULT = 0; model.F_RETURNVISITCONTENT = ""; model.F_DELETEFLAG = 0; model.F_ALLUSETIMES = 0; model.F_STARTTIME = DateTime.Now; model.F_OVERTIMES = 0; model.F_FORMID = 0; model.F_HASTENCOUNTS = 0; model.F_RANGEX = 0; model.F_RANGEY = 0; model.F_REPAIRCLOSEMANID = 0; model.F_REPAIRCLOSEMANNAME = ""; model.F_REPAIRCLOSEREASONS = ""; model.F_REPAIRCLOSEREPTID = 0; model.F_REPAIRCLOSEREPT = ""; #endregion workorderid = new BLL.T_Wo_WorkOrderBase().Add(model);//添加基本信息 } if (workorderid > 0) { bl = true; } else { bl = false; } } catch (Exception ex) { } return bl; } #endregion #region 处理振铃事件 public string zhenlingEvent(string callid, string userid, string usercode, string username, string extnumber, string callernum) { string res = "error"; try { Model.T_Call_CallRecords vmodel = new BLL.T_Call_CallRecords().GetModelByCallId(callid); if (vmodel != null) { #region 存在通话记录 Model.T_Call_CallRecords model = new Model.T_Call_CallRecords(); model.CallId = callid; if (!string.IsNullOrEmpty(userid)) { model.UserId = Convert.ToInt32(userid); } if (!string.IsNullOrEmpty(usercode)) { model.UserCode = usercode.Trim(); } if (!string.IsNullOrEmpty(username)) { model.UserName = HttpUtility.UrlDecode(username.Trim()); //model.UserName=context.Request.Form["txtAgentName"] } if (!string.IsNullOrEmpty(extnumber)) { model.ExtNumber = extnumber.Trim(); //model.UserName=context.Request.Form["txtAgentName"] } model.DealType = 5; bool bl = new BLL.T_Call_CallRecords().UpdateCallInRingTelRecord(model); if (bl) { string phone = callernum; #region 来电归属地查询 string location = ""; //来电归属地查询 if (phone.Trim().Length == 11 && phone.Substring(0, 1) != "0") { location = GetPhoneLocation(phone, true); } else { location = GetPhoneLocation(phone, false); } #endregion #region 创建工单 int workorderid = 0; bool wobl = SubmitOSubmit(phone, vmodel.CallRecordsId.ToString(), callid, location, userid, username, usercode, out workorderid); if (wobl) { try { Model.T_Call_WorkOrder modelorder = new Model.T_Call_WorkOrder(); modelorder.CallId = callid; modelorder.F_WORKORDERID = workorderid; modelorder.F_WORKORDERSTATEID = 0; new BLL.T_Call_WorkOrder().Add(modelorder); } catch { } res = workorderid.ToString(); } #endregion } #endregion } else { Model.T_Call_CallRecords model = new Model.T_Call_CallRecords(); model.CallId = callid; model.CallNumber = callernum.Trim(); model.CallType = 0; if (!string.IsNullOrEmpty(userid)) { //model.CallId = DateTime.Now.ToString("yyyyMMddHHmmssms") + CommonRequest.GetQueryString("userid"); model.UserId = Convert.ToInt32(userid); } if (!string.IsNullOrEmpty(usercode)) { model.UserCode = usercode.Trim(); } if (!string.IsNullOrEmpty(username)) { model.UserName = HttpUtility.UrlDecode(username.Trim()); //model.UserName=context.Request.Form["txtAgentName"] } if (!string.IsNullOrEmpty(extnumber)) { model.ExtNumber = extnumber.Trim(); //model.UserName=context.Request.Form["txtAgentName"] } model.CallState = 0; model.DealType = 6; model.IsDeal = 1; string cid = model.CallId; int b = new BLL.T_Call_CallRecords().Add(model); if (b > 0) { string phone = callernum; #region 来电归属地查询 string location = ""; //来电归属地查询 if (phone.Trim().Length == 11 && phone.Substring(0, 1) != "0") { location = GetPhoneLocation(phone, true); } else { location = GetPhoneLocation(phone, false); } #endregion #region 创建工单 int workorderid = 0; bool wobl = SubmitOSubmit(phone, b.ToString(), callid, location, userid, username, usercode, out workorderid); if (wobl) { try { Model.T_Call_WorkOrder modelorder = new Model.T_Call_WorkOrder(); modelorder.CallId = callid; modelorder.F_WORKORDERID = workorderid; modelorder.F_WORKORDERSTATEID = 0; new BLL.T_Call_WorkOrder().Add(modelorder); } catch { } res = workorderid.ToString(); } #endregion } } } catch (Exception ex) { //res = ex.ToString(); } return res; } #endregion #region 处理摘机事件 public string zhaijiEvent(string callid) { string res = "error"; try { Model.T_Call_CallRecords model = new Model.T_Call_CallRecords(); model.CallId = callid; model.CallState = 1; model.DealType = 6; bool bl = new BLL.T_Call_CallRecords().UpdateCallInAnswerTelRecord(model); if (bl) { res = "success"; //更新回访状态 #region /* try { Model.T_Call_CallRecords vmodel = new BLL.T_Call_CallRecords().GetModelByCallId(callid); string type = vmodel.OperateType.ToString(); if (type == "7") { new BLL.T_Call_TaskTelNum().UpdateYJ(Convert.ToInt32(vmodel.OperateObject.ToString()), 1); } } catch { } */ #endregion } } catch (Exception ex) { res = ex.ToString(); } return res; } #endregion #region 处理挂机事件 public string guajiEvent(string callid) { string res = "error"; try { bool bl = new BLL.T_Call_CallRecords().UpdateCallInHookTelRecord(callid); if (bl) { res = "success"; } } catch (Exception ex) { res = ex.ToString(); } return res; } #endregion #region 处理录音开始事件 public string luyinEvent(string callid,string path) { string res = "error"; try { Model.T_Call_CallRecords model = new Model.T_Call_CallRecords(); model.CallId = callid; model.CallState = 1; model.DealType = 6; model.FilePath = path; bool bl = new BLL.T_Call_CallRecords().UpdateCallInPathTelRecord(model); if (bl) { res = "success"; //更新回访状态 try { Model.T_Call_CallRecords vmodel = new BLL.T_Call_CallRecords().GetModelByCallId(callid); string type = vmodel.OperateType.ToString(); if (type == "7") { new BLL.T_Call_TaskTelNum().UpdateYJ(Convert.ToInt32(vmodel.OperateObject.ToString()), 1); } } catch { } } } catch (Exception ex) { res = ex.ToString(); } return res; } #endregion } }