//using CRM.Core.DTO; //using CRM.Core.DTO.Ord; using Ninject; using System; using System.Collections.Generic; using System.Data; using System.IO; using System.Linq; using System.Text; using System.Web; using System.Web.Mvc; using WX.CRM.BLL.Util; using WX.CRM.Common; using WX.CRM.Common.Employee; using WX.CRM.IBLL.Base; using WX.CRM.IBLL.Csvr; using WX.CRM.IBLL.QH; using WX.CRM.IBLL.RedisBL; using WX.CRM.IBLL.Res; using WX.CRM.IBLL.Util; using WX.CRM.IBLL.WeWork; using WX.CRM.IBLL.Wx; using WX.CRM.Model.Entity; using WX.CRM.Model.Enum; using WX.CRM.Model.QueryMap; using WX.CRM.WebHelper; using WX.CRM.WebHelper.DoItems; using WX.CRM.WebHelper.RedisFactory; namespace WX.CRM.WEB.Controllers.Csvr { public class CustomerInfoController : BaseController { [Inject] public ICUSTOMER_REDIS customerRedisBL { get; set; } [Inject] public ISecurityHelper sHelper { get; set; } // // GET: /Customer/ private IRES_CUSTOMERDETAIL_Q customerdetailBiz_Q; private IRES_CUSTOMERUSER_Q _customerUserQ; private IRES_CUSTOMER _customer; private IRES_CUSTOMER_Q _customerQ; private IBAS_BUSINESS_Q businessBiz_Q; private ICSVR_IDMAP_Q csvr_idmap; private ICACHE_Q cacheQ; private IBAS_MOBILEAREA_Q mobileareaQ; private readonly IWX_RCONTACT _wxRcontact; private readonly IRES_CUSTOMERDETAIL _resCustomerdetail; private IQH_CUSTOMER_RESID _iqh_Customer_Resid; private ValidationErrors errors = new ValidationErrors(); [Inject] public IBAS_INNERGROUP_Q Bas_InnerGroup_BL { get; set; } [Inject] public IWW_EXTUSER ww_extuser { get; set; } public RedisFactory redisFactory = new RedisFactory(); [Inject] public IRES_CUSTOMER_LABEL _label { get; set; } public CustomerInfoController(IRES_CUSTOMERDETAIL_Q _customerdetailBiz_Q , IRES_CUSTOMERUSER_Q customerUserQ, IRES_CUSTOMER customer, IRES_CUSTOMER_Q customerQ, IBAS_BUSINESS_Q _businessBiz_Q, ICSVR_IDMAP_Q _csvr_idmap, ICACHE_Q _cacheQ, IBAS_MOBILEAREA_Q _mobileareaQ, IWX_RCONTACT wxRcontact, IRES_CUSTOMERDETAIL resCustomerdetail, IQH_CUSTOMER_RESID iQH_CUSTOMER_RESID ) { this.customerdetailBiz_Q = _customerdetailBiz_Q; this._customerUserQ = customerUserQ; this._customerQ = customerQ; this._customer = customer; this.businessBiz_Q = _businessBiz_Q; this.csvr_idmap = _csvr_idmap; this.cacheQ = _cacheQ; this.mobileareaQ = _mobileareaQ; _wxRcontact = wxRcontact; _resCustomerdetail = resCustomerdetail; this._iqh_Customer_Resid = iQH_CUSTOMER_RESID; } #region 筛选未外呼客户ID /// /// 筛选未外呼客户ID /// /// public ActionResult ResIDNoOutboundFilter() { var groupList = Bas_InnerGroup_BL.GetList(); if (groupList != null) { groupList = groupList.Where(m => m.ISHIDE == 0).ToList(); } if (groupList == null) { groupList = new List(); } ViewBag.DeptCode = cacheQ.GetValue_Parameter(WX.CRM.Model.Enum.Parameter.Sys_Environment_DeptCode); ViewBag.MemoSubTypeList = cacheQ.GetList_MemoSubType(1); ViewBag.GroupList = groupList; return View(); } [AuthorizeRedirect(Roles = InitRights.CONST_筛选未外呼客户ID)] public JsonResult ResIDUpload(DateTime? stime, DateTime? etime, decimal? t_type, string slt_Open, string slt_NotOpen) { string dname = "这批ID在这个时间段已经全部有外呼!"; if (t_type != null && t_type == 1) dname = "这批ID在这个时间段没有无效外呼!"; else if (t_type != null && t_type == 2) dname = "筛选后无数据!"; else if (t_type != null && t_type == 8) dname = "根据条件去除后无数据!"; string importId = DateTime.Now.ToString("yyyyMMddHHmmss"); HttpPostedFileBase file = Request.Files["uploadFile"]; DataTable tab = new DataTable(); DataColumn column = new DataColumn("IMPORTID"); column.Caption = "导入批次ID"; column.DataType = typeof(System.Decimal); tab.Columns.Add(column); DataColumn column2 = new DataColumn("IMPORTDATA"); column2.Caption = "客户ID"; column2.DataType = typeof(System.String); tab.Columns.Add(column2); using (StreamReader read = new StreamReader(file.InputStream, Encoding.GetEncoding("gb2312"))) { while (!read.EndOfStream) { DataRow row = tab.NewRow(); row["IMPORTID"] = importId; row["IMPORTDATA"] = read.ReadLine().Trim(); tab.Rows.Add(row); } } List list = _customerQ.ResIDNoOutboundFilter(ref errors, tab, importId, stime.Value, etime.Value, t_type.Value, slt_Open, slt_NotOpen); Stream stream = ExcelHelper.ExportListObjectToExcel(list, "客户ID", "客户ID", null); if (errors.Count > 0) { JsonResult rs = Json(new { result = false, message = "错误提示:" + errors.Error }); rs.ContentType = "text/html"; return rs; } else if (list.Count == 0) { JsonResult rs = Json(new { result = false, message = "温馨提示:" + dname }, JsonRequestBehavior.AllowGet); rs.ContentType = "text/html"; return rs; } string fileName = DateTime.Now.ToString("yyyyMMddHHmmffff") + ".xls"; byte[] buffer = new byte[stream.Length]; stream.Read(buffer, 0, buffer.Length); //将流的内容读到缓冲区 FileStream fs = new FileStream(Server.MapPath("~/UploadFile/" + fileName), FileMode.OpenOrCreate, FileAccess.Write); fs.Write(buffer, 0, buffer.Length); fs.Flush(); fs.Close(); JsonResult rb = Json(new { result = true, src = fileName }); rb.ContentType = "text/html"; return rb; } [AuthorizeRedirect(Roles = InitRights.CONST_筛选未外呼客户ID)] public JsonResult ResIDUploadNew(DateTime? stime, DateTime? etime, string checkType_hid, string subType_hid) { string dname = "赛选客户ID"; if (Request.Files["uploadFile"] == null) { JsonResult rs = null; rs = Json(new { result = false, message = "错误提示:请选择文件!" }); rs.ContentType = "text/html"; return rs; } if (string.IsNullOrEmpty(checkType_hid) && string.IsNullOrEmpty(subType_hid)) { JsonResult rs = null; rs = Json(new { result = false, message = "错误提示:请至少选择一项过滤条件!" }); rs.ContentType = "text/html"; return rs; } if (!string.IsNullOrEmpty(subType_hid) && (!stime.HasValue || !etime.HasValue)) { JsonResult rs = null; rs = Json(new { result = false, message = "错误提示:工单过滤,请选择时间!" }); rs.ContentType = "text/html"; return rs; } string importId = DateTime.Now.ToString("yyyyMMddHHmmss"); HttpPostedFileBase file = Request.Files["uploadFile"]; DataTable tab = new DataTable(); DataColumn column = new DataColumn("IMPORTID"); column.Caption = "导入批次ID"; column.DataType = typeof(System.Decimal); tab.Columns.Add(column); DataColumn column2 = new DataColumn("IMPORTDATA"); column2.Caption = "客户ID"; column2.DataType = typeof(System.String); tab.Columns.Add(column2); using (StreamReader read = new StreamReader(file.InputStream, Encoding.GetEncoding("gb2312"))) { while (!read.EndOfStream) { DataRow row = tab.NewRow(); row["IMPORTID"] = importId; row["IMPORTDATA"] = read.ReadLine().Trim(); tab.Rows.Add(row); } } List list = _customerQ.res_GetFilterImportRes(ref errors, tab, importId, stime.Value, etime.Value, checkType_hid, subType_hid); Stream stream = ExcelHelper.ExportListObjectToExcel(list, "客户ID", "客户ID", null); if (errors.Count > 0) { JsonResult rs = Json(new { result = false, message = "错误提示:" + errors.Error }); rs.ContentType = "text/html"; return rs; } else if (list.Count == 0) { JsonResult rs = Json(new { result = false, message = "温馨提示:过滤后没有数据!" }, JsonRequestBehavior.AllowGet); rs.ContentType = "text/html"; return rs; } string fileName = DateTime.Now.ToString("yyyyMMddHHmmffff") + ".xls"; byte[] buffer = new byte[stream.Length]; stream.Read(buffer, 0, buffer.Length); //将流的内容读到缓冲区 FileStream fs = new FileStream(Server.MapPath("~/UploadFile/" + fileName), FileMode.OpenOrCreate, FileAccess.Write); fs.Write(buffer, 0, buffer.Length); fs.Flush(); fs.Close(); JsonResult rb = Json(new { result = true, src = fileName }); rb.ContentType = "text/html"; return rb; } [AuthorizeRedirect(Roles = InitRights.CONST_筛选未外呼客户ID)] public JsonResult ResIDChoice(DateTime? resStime, DateTime? resEtime, bool checkWeixin, bool checkOrder, string memoSubType, DateTime? memoStime, DateTime? memoEtime) { JsonResult rs = null; var dname = "资源筛选导出"; if (!resStime.HasValue) { rs = Json(new { result = false, message = "错误提示:资源开始时间不能为空" }); rs.ContentType = "text/html"; return rs; } if (!resEtime.HasValue) { rs = Json(new { result = false, message = "错误提示:资源结束时间不能为空" }); rs.ContentType = "text/html"; return rs; } if (resEtime > DateTime.Now.AddDays(-9)) { //rs = Json(new { result = false, message = "错误提示:资源结束时间不能大于"+ DateTime.Now.AddDays(-9).ToString() }); rs = Json(new { result = false, message = "新资源不能倒出,请筛选导出10天前的资源。" }); rs.ContentType = "text/html"; return rs; } if (resStime < resEtime.Value.AddDays(-30)) { rs = Json(new { result = false, message = "错误提示:由于资源太多,资源时间跨度不能超过1个月,如若需要可以分多次导出" }); rs.ContentType = "text/html"; return rs; } if (!memoStime.HasValue) { rs = Json(new { result = false, message = "错误提示:工单开始时间不能为空" }); rs.ContentType = "text/html"; return rs; } if (!memoEtime.HasValue) { rs = Json(new { result = false, message = "错误提示:工单结束时间不能为空" }); rs.ContentType = "text/html"; return rs; } List list = _customerQ.GetResChoiceExpor(ref errors, resStime.ToString(), resEtime.ToString(), checkWeixin ? 1 : 0, checkOrder ? 1 : 0, memoSubType, memoStime.ToString(), memoEtime.ToString()); Stream stream = ExcelHelper.ExportListObjectToExcel(list, "客户ID", "客户ID", null); if (errors.Count > 0) { rs = Json(new { result = false, message = "错误提示:" + errors.Error }); rs.ContentType = "text/html"; return rs; } else if (list.Count == 0) { rs = Json(new { result = false, message = "温馨提示:" + dname }, JsonRequestBehavior.AllowGet); rs.ContentType = "text/html"; return rs; } string fileName = DateTime.Now.ToString("yyyyMMddHHmmffff") + ".xls"; byte[] buffer = new byte[stream.Length]; stream.Read(buffer, 0, buffer.Length); //将流的内容读到缓冲区 FileStream fs = new FileStream(Server.MapPath("~/UploadFile/" + fileName), FileMode.OpenOrCreate, FileAccess.Write); fs.Write(buffer, 0, buffer.Length); fs.Flush(); fs.Close(); JsonResult rb = Json(new { result = true, src = fileName }); rb.ContentType = "text/html"; return rb; } [AuthorizeRedirect(Roles = InitRights.CONST_筛选未外呼客户ID)] public JsonResult ResIdByMemoChoice(DateTime? memoStime2, DateTime? memoEtime2, decimal? memoType1, decimal? memoType2, decimal? group1, decimal? group2) { JsonResult rs = null; var dname = "没查询到符合条件的工单资源"; if (!memoStime2.HasValue) { rs = Json(new { result = false, message = "错误提示:工单开始时间不能为空" }); rs.ContentType = "text/html"; return rs; } if (!memoEtime2.HasValue) { rs = Json(new { result = false, message = "错误提示:工单结束时间不能为空" }); rs.ContentType = "text/html"; return rs; } List list = _customerQ.GetResIdByMemoChoiceExport(ref errors, memoStime2, memoEtime2, memoType1, memoType2, group1, group2); Stream stream = ExcelHelper.ExportListObjectToExcel(list, "客户ID", "客户ID", null); if (errors.Count > 0) { rs = Json(new { result = false, message = "错误提示:" + errors.Error }); rs.ContentType = "text/html"; return rs; } else if (list.Count == 0) { rs = Json(new { result = false, message = "温馨提示:" + dname }, JsonRequestBehavior.AllowGet); rs.ContentType = "text/html"; return rs; } string fileName = DateTime.Now.ToString("yyyyMMddHHmmffff") + ".xls"; byte[] buffer = new byte[stream.Length]; stream.Read(buffer, 0, buffer.Length); //将流的内容读到缓冲区 FileStream fs = new FileStream(Server.MapPath("~/UploadFile/" + fileName), FileMode.OpenOrCreate, FileAccess.Write); fs.Write(buffer, 0, buffer.Length); fs.Flush(); fs.Close(); JsonResult rb = Json(new { result = true, src = fileName }); rb.ContentType = "text/html"; return rb; } public ActionResult ResIdExcelExport(string fileName, decimal? t_type) { string dname = "筛选未外呼客户ID"; if (t_type != null && t_type == 1) dname = "筛选无效外呼客户ID"; else if (t_type != null && t_type == 2) dname = "筛选未开户客户ID"; else if (t_type != null && t_type == 8) dname = "去除连续5次无效工单"; else if (t_type != null && t_type == 9) dname = "去除绑定微信"; else if (t_type != null && t_type == 10) dname = "去除首次汇款工单"; string filepath = Server.MapPath("~/UploadFile/" + fileName); FileStream fs = new FileStream(filepath, FileMode.Open); byte[] bytes = new byte[(int)fs.Length]; fs.Read(bytes, 0, bytes.Length); fs.Close(); Response.Charset = "UTF-8"; Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8"); Response.ContentType = "application/ms-excel"; Response.AddHeader("Content-Disposition", "attachment; filename=" + PageRequest.GetDlownLoadName(dname + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls")); Response.BinaryWrite(bytes); Response.Flush(); Response.End(); if (System.IO.File.Exists(filepath)) { System.IO.File.Delete(filepath); } return new EmptyResult(); } #endregion 筛选未外呼客户ID public ActionResult Index() { return View(); } /// /// isFromHg是否来着合规 /// [Inject] public IRES_VIPCUSTOMER _RES_VIPCUSTOMER { get; set; } public ActionResult CustomerDetail(string resid, int isFromHg = 0, int hgCustomer = 0, string name = "", int isFromComplaint = 0, string umid = "") { //ControlResource.JudgeSYQ(); //var isShowFxh = cacheQ.GetValue_Parameter(WX.CRM.Model.Enum.Parameter.Sys_IsShowFXH); //if (string.IsNullOrEmpty(isShowFxh)) // isShowFxh = "true"; //ViewBag.isShowFxh = isShowFxh; //ViewBag.IsOpen_TradeCode = cacheQ.IsOpen_TradeCode(resid); //_MN_GJS_CUSTOMER.IsOpen_TradeCode(resid); //ViewBag.IsOpen_TradeCode = false; //var tgcrmUrl = cacheQ.GetValue_Parameter("TGCRMUrl"); //ViewBag.TGCRMUrl = string.IsNullOrEmpty(tgcrmUrl)?"": (tgcrmUrl + "/Csvr/CustomerInfoMn/Index?resid="+resid); RES_CUSTOMERDETAIL model = null; if (!string.IsNullOrEmpty(resid)) { model = customerdetailBiz_Q.GetModel_RES_CUSTOMERDETAIL(resid);//Old Version if (model == null && resid.Length >= 32) { model = customerdetailBiz_Q.GetModel_RES_CUSTOMERDETAIL_UMID(resid); } } else if (!string.IsNullOrEmpty(umid)) { model = customerdetailBiz_Q.GetModel_RES_CUSTOMERDETAIL_UMID(umid); } else { Response.Redirect(Url.Action("ErrorView", "Error", new { message = "缺少resid/umid!" })); } //RES_CUSTOMERDETAIL model = redisFactory.GetInfo_Rescustomerdetail(resid); if (model == null || string.IsNullOrWhiteSpace(model.CNAME))//合规坐席拉取客户信息 { //var url = cacheQ.GetValue_Parameter(Parameter.Core_ZxdService_GetCustomer); //var theModel = new ResCustomerDto //{ // resId = resid, //}; //string json = Utility.ConvertToJSON(theModel); //json = sHelper.createSignEncodingStr(json, SecurityHelper.OrderClientIdKey);//数据参数加密 //string retmsg = Utility.PostData(url + "?" + json, Encoding.UTF8);//实现中心点先入库 //retmsg = sHelper.decyptData(SecurityHelper.OrderClientIdKey, retmsg); //retMsgNew> retmessage = JsonHelper.JsonDivertToObj>>(retmsg);//返回信息 //var uname = ""; //if (retmessage.retcode == (int)NodeJsOrderEnum.调用成功)//成功 //{ // uname = retmessage.data.FirstOrDefault(n => !string.IsNullOrWhiteSpace(n.uname))?.uname; // foreach (var ord in retmessage.data) // { // _customer.ResgisterCustomer(ord.mobile, ord.resId, "isHgComplaint"); // } //} /* var url = cacheQ.GetValue_Parameter(Parameter.Core_ZxdService_GetCustomer); var para = "page=1&limit=1&aiCallType=80"; if (!string.IsNullOrEmpty(resid)) { para += "&resId=" + resid; } var retmsg = Utility.PostData(url + "?" + para, Encoding.UTF8); var retmessage = WebHelper.JsonHelper.JsonDivertToObj(retmsg); var orders = retmessage.retmsg; var uname = orders.FirstOrDefault(n => !string.IsNullOrWhiteSpace(n.cname))?.cname; foreach (var ord in orders) { #region 注册 _customer.ResgisterCustomer(ord.mobile, ord.resid, "hgorder"); #endregion 注册 }*/ //修改客户姓名 //if (string.IsNullOrWhiteSpace(model?.CNAME) && !string.IsNullOrWhiteSpace(uname)) //{ // using (var db = new crmContext()) // { // var customerDetail = db.RES_CUSTOMERDETAIL.FirstOrDefault(n => n.RESID == resid); // if (customerDetail != null) // { // customerDetail.CNAME = uname; // db.SaveChanges(); // } // } //} model = customerdetailBiz_Q.GetModel_RES_CUSTOMERDETAIL(resid);//Old Version if (model == null && resid.Length >= 32) { model = customerdetailBiz_Q.GetModel_RES_CUSTOMERDETAIL_UMID(resid); } if(model == null)//如果信息没有,那么拉取信息 { int relust = 1; string msg = ""; SeachByResId(resid, ref relust, ref msg); model = customerdetailBiz_Q.GetModel_RES_CUSTOMERDETAIL_UMID(resid); } } if (model == null) { Response.Redirect(Url.Action("ErrorView", "Error", new { message = "错误提示:没有这个客户!" })); } CustomerInfo info = new CustomerInfo(); //if (!string.IsNullOrEmpty(model.CNAME)) //{ // var roleCodes = DataCacheHelper.GetCache().Get_RoleCodes(userRoleId); // if (!(roleCodes.Contains("[SH]") || roleCodes.Contains("[GLY]"))) // { // if (model.CNAME.Length > 4) // { // model.CNAME = model.CNAME.Substring(0, 4); // } // } //} info.RequsetResId = model.RESID; //info.ResCustomerList = _customerQ.GetList_CustomerByResid(resid);//Old Version //info.CustomerId = info.ResCustomerList.Select(p => p.CUSTOMERID).FirstOrDefault();//Old Version //string[] resids = info.ResCustomerList.Select(m => m.RESID.Trim()).ToArray();//Old Version //info.GjsCustomerList = gjs_customerQ.getGjsCustomersByResIds(resids);//Old Version info.CustomerName = model.CNAME; if (string.IsNullOrEmpty(info.CustomerName) && !string.IsNullOrEmpty(name)) { info.CustomerName = name; model.CNAME = name; } info.CustomerId = _customerQ.getResCustomerByResId(model.RESID).CUSTOMERID; try { _customer.res_customerdetial_log(Utility.GetIp(), info.CustomerId, UserId, Eid); } catch (Exception ex) { LogHelper.Error("记录访问日志出错:" + ex.ToString()); } string[] resids = _customerQ.GetAllResidByCustomerId(info.CustomerId); info.ResCustomerList = redisFactory.GetList_Rescustomer(resids, info.CustomerId);// //info.ResCustomerList = customerRedisBL.GetList_Res_Customer(resids); //info.GjsCustomerList = redisFactory.GetList_Gjscustomer(resids); //customerRedisBL.GetList_Gjs_Customer(resids); //info.FxhCustomerList = _fxh_customerQ.getFxhByResIds(resids); string isShowMobileArea = cacheQ.GetValue_Parameter(WX.CRM.Model.Enum.Parameter.Is_ShowCustomerMobileArea); var isMiniCustomerInfo = cacheQ.GetValue_Parameter(Model.Enum.Parameter.Sys_IsMiniCustomerInfo); if (null != info.ResCustomerList) { var vipcustomer = _RES_VIPCUSTOMER.GetByResIds(info.ResCustomerList.Select(obj => obj.RESID).ToArray()); foreach (RES_CUSTOMER item in info.ResCustomerList) { item.IsVip = vipcustomer.Any(obj => obj.RESID == item.RESID); //LogHelper.Info("isShowMobileArea:" + isShowMobileArea); if (isShowMobileArea == "true") { item.map_MobileArea = mobileareaQ.GetMobileArea(item.RESID); } else item.map_MobileArea = ""; } } var residsArr = info.ResCustomerList.Select(obj => obj.RESID); var fxModel = _label.Get(p => residsArr.Contains(p.RESID)); var zxdurl = cacheQ.GetValue_Parameter(Parameter.Core_ZxdUrl); zxdurl = $"{zxdurl}/Api/SoftUser/GetUserCanOpenOrderByResid"; LogHelper.Info("zxdurl:" + zxdurl); try { var canopenorderResultJson = Utility.GetData(zxdurl, $"resid={model.RESID}", Encoding.UTF8); var canopenorderResult = JsonHelper.JsonDivertToObj>(canopenorderResultJson); LogHelper.Info("canopenorderResult:" + canopenorderResult.ToJson()); LogHelper.Info("canopenorderResultJson:" + canopenorderResultJson); ViewBag.IsCanopenorder = canopenorderResult.data ? 1 : 0; } catch (Exception e) { LogHelper.Error(e.ToString()); ViewBag.IsCanopenorder = 0; } //查询出公司的业务 //List companyList = DataCacheHelper.GetCache().GetList_innerCompany(); //BAS_COMPANY company = companyList.Where(m => m.COMPANYID == companyId).FirstOrDefault(); //int businessValue = 0; //if (company != null) // businessValue = Convert.ToInt32(company.BUSINESSVALUE); List customerMessage_UC = new List();//客户信息 控件集合 List memoMessage_UC = new List();//工单信息 控件集合 //List SalememoMessage_UC = new List();//投顾工单信息 控件集合 List ordeMessage_UC = new List();//订单信息 控件集合 List Level2orderMessage_UC = new List();//订单信息 控件集合 List ActivityMessage_UC = new List();//活动信息 控件集合 //List futureMessage_UC = new List();//渤海 控件集合 //List silverMessage_UC = new List();// 控件集合 //var fastmemo = cacheQ.GetValue_Parameter("fastmemo"); //if (!string.IsNullOrEmpty(fastmemo)) //{ // customerMessage_UC.Add("FastMemo");//快速创建工单 //} customerMessage_UC.Add("CustomerBaseInfoUC");//-客户基本信息 customerMessage_UC.Add("ContactUC");//联系方式 //customerMessage_UC.Add("CustomerCategoryUC");//-客户分类 if (string.IsNullOrEmpty(isMiniCustomerInfo) || isMiniCustomerInfo == "0") { //customerMessage_UC.Add("CustomerExtendUC");//客户扩展信息 //customerMessage_UC.Add("CustomerUserUC");//用户信息 //customerMessage_UC.Add("CustomerAddWWUserUC");//添加企业微信 //customerMessage_UC.Add("CustomerAddWxUserUC");//添加微信用户 //customerMessage_UC.Add("CustomerCheckUC");//客户质检信息 //customerMessage_UC.Add("CustomerLoginInfo");//客户最近信息 //customerMessage_UC.Add("CustomerOtherInfo");//客户其它基本信息 //customerMessage_UC.Add("RelationCustomerUC");//相关客户 } else { customerMessage_UC.Add("CustomerAllMemoUC"); } if (string.IsNullOrEmpty(isMiniCustomerInfo) || isMiniCustomerInfo == "0") { memoMessage_UC.Add("CustomerAllMemoUC");//客户所有工单信息 } //sSalememoMessage_UC.Add("SaleDptAllMemoUC");//投顾客户所有工单信息 ordeMessage_UC.Add("CustomerOrderUC");//客户订单 Level2orderMessage_UC.Add("CustomerLevel2OrderUC");//投顾免费订单 // ordeMessage_UC.Add("CustomerModuleUC");//模块 ActivityMessage_UC.Add("CustomerActivityUC");//活动信息 //渤海和 需要公司有这个业务才能被显示出来 //info.BusinessNames = companyBusiness; //futureMessage_UC.Add("CustomerFutureUC");//客户渤海信息 ////} ////if (info.BusinessNames.IndexOf("[]") > -1) ////{ //silverMessage_UC.Add("CustomerFutureUcSilver");//客户信息 ////} ViewBag.QHType = cacheQ.GetValue_Parameter(WX.CRM.Model.Enum.Parameter.Sys_QHData); //if (ViewBag.QHType=="1") //{ // List qH_CUSTOMER_RESID = _iqh_Customer_Resid.GetList(resids); // if (qH_CUSTOMER_RESID.Count == 0) // { // ViewBag.CustomerQH_UC = "CustomerResid"; // } // else // { // ViewBag.CustomerQH_UC = "CustomerQH"; // } //} ViewBag.WwMessage_Url = cacheQ.GetValue_Parameter("WwMessage_Url"); string[] extids = ww_extuser.ExtUserBandGetNew(model.RESID);//获取企业微信付费版本绑定的ID string myids = ""; if (extids != null && extids.Length > 0) { myids = string.Join(";", extids); } info.IsFromHg = isFromHg; ViewBag.extuserids = myids;//企业微信外部联系人关联 ViewBag.CustomerInfo = info;//--所有控件用到的数据 ViewBag.customerMessage_UC = customerMessage_UC; ViewBag.memoMessage_UC = memoMessage_UC; //ViewBag.SalememoMessage_UC = SalememoMessage_UC; ViewBag.ordeMessage_UC = ordeMessage_UC; ViewBag.Level2orderMessage_UC = Level2orderMessage_UC; ViewBag.ActivityMessage_UC = ActivityMessage_UC; //活动 ViewBag.eid = Eid; //ViewBag.futureMessage_UC = futureMessage_UC; //ViewBag.silverMessage_UC = silverMessage_UC; ViewBag.DeptCode = cacheQ.GetValue_Parameter(WX.CRM.Model.Enum.Parameter.Sys_Environment_DeptCode); ViewBag.ProjectType = cacheQ.GetValue_Parameter(WX.CRM.Model.Enum.Parameter.Sys_ProjectType); ViewBag.isMiniCustomerInfo = isMiniCustomerInfo; ViewBag.IsHg = userRoleCodes.Contains("[HGZJ]") || userRoleCodes.Contains("[GLY]"); ViewBag.IsFx = (fxModel != null && fxModel.RFMTYPE == 1) ? true : false; ViewBag.resid = resid; try { PopupMessageFactory.AllocateResMessage.SetView(UserId, resid); } catch (Exception ex) { LogHelper.Error("清除资源提示错误:" + ex.ToString()); } return View(model); } public ActionResult SearchCustomer() { ViewBag.ProjectType = cacheQ.GetValue_Parameter(WX.CRM.Model.Enum.Parameter.Sys_ProjectType); ViewBag.roleCodes = DataCacheHelper.GetCache().Get_RoleCodes(userRoleId); return View(); } /// /// 查询出Resid,方便查找 /// /// /// [HttpPost] public JsonResult GetResData(string type) { int relust = 1; string msg = ""; string resid = Request.Form["txt_resid"].GetString(); string username = Request.Form["txt_username"].GetString(); string oldUsername = Request.Form["txt_Oldusername"].GetString(); string userno = Request.Form["txt_userno"].GetString(); string mobile = Request.Form["txt_mobile"].GetString(); string customerId = Request.Form["txt_customerid"].GetString(); string tradeCode = Request.Form["txt_tradeCode"].GetString(); string OldId = Request.Form["txt_OldId"].GetString(); string customerName = Request.Form["txt_customerName"].GetString(); switch (type) { case "username": resid = SeachByuserName(username, ref relust, ref msg); break; case "OlduserName": resid = SeachByOlduserName(oldUsername, ref relust, ref msg); break; case "userno": resid = SeachByuserNo(userno, ref relust, ref msg); break; case "mobile": resid = SeachByMobile(mobile, ref relust, ref msg); break; case "tradeCode": resid = SeachByTradeCode(tradeCode, ref relust, ref msg); break; case "resid": resid = SeachByResId(resid, ref relust, ref msg); break;//空置·不需要做处理 case "OldId": resid = SeachByOldId(OldId, ref relust, ref msg); break; case "customerName": resid = SeachByCustomerName(customerName, ref relust, ref msg); break; } try { switch (type) { case "username": LogHelper.Info(string.Format("IP:{3}工号{0}在{1}查询用户名——{2}", Eid, DateTime.Now.ToString(), username, WX.CRM.Common.Utility.GetIp())); break; case "mobile": LogHelper.Info(string.Format("IP:{3}工号{0}在{1}查询手机号——{2}", Eid, DateTime.Now.ToString(), mobile, WX.CRM.Common.Utility.GetIp())); break; } } catch (Exception) { } //if (!string.IsNullOrEmpty(resid)) //{ // RES_CUSTOMER res = _customerQ.getResCustomerByResId(resid); // if (res == null) // { // msg = "不存在此用户"; relust = 0; // } //} //else { msg = "请填写查询条件"; relust = 0; } ViewBag.ResID = resid; return Json(new { reslust = relust, message = msg, ResId = resid }); } public string SeachByOlduserName(string username, ref int relust, ref string msg) { try { if (string.IsNullOrWhiteSpace(username)) { msg = "请填写查询条件"; relust = 0; return ""; } List list = new List(); list = redisFactory.GetList_Rescustomeruser_Username(username); if (list == null || list.Count() <= 0) { msg = "不存在此用户名"; relust = 0; return ""; } if (list != null && list.Count() == 1) { return list.FirstOrDefault().RESID; } else { msg = "存在多个客户ID"; List strList = new List(); list = list.OrderBy(m => m.PKID).ToList(); foreach (var model in list) { strList.Add(model.RESID + "-" + (model.PKID == 0 ? "注册" : "活动")); } return string.Join(";", strList); } } catch (Exception ex) { LogHelper.Error("根据用户名查询:" + username + ":" + ex.Message + ex.StackTrace); msg = "系统查询出错,请联系管理员"; relust = 0; return ""; } } public string SeachByOldId(string OldCustomerId, ref int relust, ref string msg) { //string resid = string.Empty; List list = new List(); try { if (string.IsNullOrWhiteSpace(OldCustomerId)) { msg = "请填写查询条件"; relust = 0; return ""; } //resid = csvr_idmap.GetResId(OldCustomerId); //if (string.IsNullOrEmpty(resid)) //{ // msg = "找不到这个旧客户ID"; relust = 0; // return ""; //} list = csvr_idmap.GetResId(OldCustomerId); if (list == null || list.Count <= 0) { msg = "找不到这个旧客户ID"; relust = 0; return ""; } if (list != null && list.Count == 1) { return list[0]; } else { msg = "存在多个客户ID"; return string.Join(";", list); } //return resid; } catch (Exception ex) { LogHelper.Error(ex.Message + ex.StackTrace); msg = "系统查询出错,请联系管理员"; relust = 0; return ""; } } public string SeachByResId(string resid, ref int relust, ref string msg) { try { if (string.IsNullOrWhiteSpace(resid)) { msg = "请填写查询条件"; relust = 0; return ""; } else if (_customerQ.getResCustomerByResId(resid) == null) { var host = cacheQ.GetValue_Parameter(Parameter.Hg_Internal_WebApi); var url = host + "/api/Customer/moblies"; var res = Utility.GetData(url, "resid=" + resid, Encoding.UTF8); var result = JsonHelper.JsonDivertToObj>>(res); if (result.Code == 0) { CreateCustomerMoblie(resid, result.Data); } var model = customerdetailBiz_Q.GetModel_RES_CUSTOMERDETAIL(resid); if (model == null) { //url = cacheQ.GetValue_Parameter(Parameter.Core_ZxdService_HgList); //var para = "page=1&limit=1&aiCallType=80"; //if (!string.IsNullOrEmpty(resid)) //{ // para += "&resId=" + resid; //} //var retmsg = Utility.PostData(url + "?" + para, Encoding.UTF8); //var retmessage = WebHelper.JsonHelper.JsonDivertToObj(retmsg); //var orders = retmessage.retmsg; //foreach (var ord in orders) //{ // #region 注册 // _customer.ResgisterCustomer(ord.mobile, ord.resid, "hgorder"); // #endregion 注册 //} //model = customerdetailBiz_Q.GetModel_RES_CUSTOMERDETAIL(resid); //if (model == null) //{ // msg = "请填写正确的ResId"; relust = 0; // return ""; //} var mobile = cacheQ.GetPhone(resid); var rid = ResUtil.CreateResId(mobile); if (mobile != null) { _customer.ResgisterCustomer(mobile, rid, "hgorder"); var newCustomer = _customerQ.getResCustomerByResId(rid); newCustomer.CUSTOMERID = rid; _customer.Update(ref errors, newCustomer); } } } //else if(redisFactory.GetInfo_Rescustomer(resid)==null) //{ // msg = "请填写正确的ResId"; relust = 0; // return ""; //} return resid; } catch (Exception ex) { LogHelper.Error("根据resid查询客户:" + resid + ";" + ex.Message + ex.StackTrace); msg = "系统查询出错,请联系管理员"; relust = 0; return ""; } } private void CreateCustomerMoblie(string resid, List customers) { if (!customers.Any()) return; foreach (var customer in customers) { string clientid = Utility.GetSettingByKey("CRMClientKey"); var mobile = sHelper.decyptData(clientid, customer.Mobile); _customer.ResgisterCustomer(mobile, customer.Resid, "hglookup"); var newCustomer = _customerQ.getResCustomerByResId(customer.Resid); newCustomer.CUSTOMERID = customer.CustomerId; _customer.Update(ref errors, newCustomer); } } public string SeachByMobile(string mobile, ref int relust, ref string msg) { try { if (string.IsNullOrWhiteSpace(mobile)) { msg = "请填写查询条件"; relust = 0; return ""; } if (!Utility.ChekMobile(mobile) && !Utility.ValidateTelCode2(mobile))//判断是否为手机号码或者电话号码 { msg = "请填写正确的号码"; relust = 0; return ""; } return ResUtil.CreateResId(mobile); } catch (Exception ex) { LogHelper.Error(ex.Message + ex.StackTrace); msg = "系统查询出错,请联系管理员"; relust = 0; return ""; } } public string SeachByuserName(string username, ref int relust, ref string msg) { try { if (string.IsNullOrWhiteSpace(username)) { msg = "请填写查询条件"; relust = 0; return string.Empty; } var model = _wxRcontact.Get(p => p.USERNAME == username || p.ALIAS == username); if (model == null) { msg = "不存在此用户名"; relust = 0; return string.Empty; } return model.RESID; } catch (Exception ex) { LogHelper.Error("根据用户名查询:" + username + ":" + ex.Message + ex.StackTrace); msg = "系统查询出错,请联系管理员"; relust = 0; return string.Empty; } } public string SeachByuserNo(string userNo, ref int relust, ref string msg) { try { if (string.IsNullOrWhiteSpace(userNo)) { msg = "请填写用户号!"; relust = 0; return ""; } var model = _resCustomerdetail.Get(p => p.ZX_USERID == userNo); if (model == null) { msg = "不存在此用户号"; relust = 0; return string.Empty; } return model.RESID; } catch (Exception ex) { LogHelper.Error(ex.Message + ex.StackTrace); msg = "系统查询出错,请联系管理员"; relust = 0; return ""; } } public string SeachByTradeCode(string tradeCode, ref int relust, ref string msg) { string resid = string.Empty; try { if (string.IsNullOrWhiteSpace(tradeCode)) { msg = "请填写查询条件"; relust = 0; return ""; } return resid; } catch (Exception ex) { LogHelper.Error("根据tradecode查询客户:" + tradeCode + ":" + ex.Message + ex.StackTrace); msg = "系统查询出错,请联系管理员"; relust = 0; return ""; } } public string SeachByCustomerName(string customerName, ref int relust, ref string msg) { try { if (string.IsNullOrWhiteSpace(customerName)) { msg = "请填写查询条件"; relust = 0; return ""; } var list = customerdetailBiz_Q.GetList(p => p.CNAME.Contains(customerName)); if (list == null || list.Count() <= 0) { msg = "不存在此用户名"; relust = 0; return ""; } if (list != null && list.Count() == 1) { return list.FirstOrDefault().RESID; } else { msg = "存在多个客户ID"; List strList = new List(); foreach (var model in list) { strList.Add(model.RESID + "-" + model.CNAME); } return string.Join(";", strList); } } catch (Exception ex) { LogHelper.Error("根据用户名查询:" + customerName + ":" + ex.Message + ex.StackTrace); msg = "系统查询出错,请联系管理员"; relust = 0; return ""; } } public string GetResId(T model) { string resid = string.Empty; if (model != null) { var tt = model.GetType().GetProperty("RESID").GetValue(model, null); resid = tt.ToString(); } return resid; } #region 号码转换 [HttpGet] public ActionResult getResIdsByCustomerIds() { return View(); } // [HttpPost] public string getCustomerIdsAndResIds() { HttpContext.Response.ContentType = "text/html;characset=utf-8"; // Response.ContentType = "text/html;characset=utf-8"; bool result = false; string msg = "未找到客户ID"; string type = ""; string resids = ""; string path = ""; List mbs = new List(); string t = string.Format("{0}", Request.Form["FileType"]); string selecttype = string.Format("{0}", Request.Form["TrunType"]); if (t == "批量转换") { string customerids = string.Format("{0}", Request.Form["txtoldId"]); type = "批量"; if (!string.IsNullOrWhiteSpace(customerids)) { string[] _ids = customerids.Replace("\r\n", ",").Replace("\r", ",").Replace("\n", ",").Split(','); if (selecttype == "1" || selecttype == "2") { List customerturn = new List(); foreach (var model in _ids) { temp_customerturn temp = new temp_customerturn(); temp.CUSTOMERID = model.Trim(); customerturn.Add(temp); } if (customerturn.Count > 0) { DataTable tb = Utility.ToOracleDataTable(customerturn); List idmaps = csvr_idmap.GetResIdList(tb, selecttype); if (idmaps != null && idmaps.Count > 0) { foreach (var model in idmaps) { if (selecttype == "1") { resids += model.RESID + "\r\n"; } else { resids += model.CUSTOMERID + "\r\n"; } } } } } else if (selecttype == "6") { foreach (var id in _ids) { var resid = ResUtil.CreateResId(id); resids += resid.Trim() + "\r\n"; } } else { List resimportid = new List(); string importId = DateTime.Now.ToString("yyyyMMddHHmmss"); foreach (var model in _ids) { temp_resimportid temp = new temp_resimportid(); temp.IMPORTID = Convert.ToDecimal(importId); temp.IMPORTDATA = model.Trim(); resimportid.Add(temp); } DataTable tb = Utility.ToOracleDataTable(resimportid); List list = _customerQ.ResIDNoOutboundFilter(ref errors, tb, importId, DateTime.Now, DateTime.Now, selecttype.GetDecimal(0), "", ""); if (list != null && list.Count > 0) { foreach (var model in list) { resids += model + "\r\n"; } } } if (string.IsNullOrEmpty(resids)) { result = false; msg = "数据为空"; } else { result = true; msg = ""; } } // return Json(new { result = result, type = type, message = msg, ResIds = resids }, JsonRequestBehavior.AllowGet); } else if (t == "文件上传导入") { type = "文件"; // mbs = GetByTxtFile(); path = GetByTxtFile(); if (path != null) { result = true; msg = ""; } // return Json(new { result = result, type = type, path = path, selecttype = selecttype, message = msg }, JsonRequestBehavior.AllowGet); } Getresult getresult = new Getresult(); getresult.result = result; getresult.type = type; getresult.ResIds = resids; getresult.path = path; getresult.selecttype = selecttype; getresult.message = msg; string json = JsonHelper.ObjDivertToJson(getresult); return json; } private string GetByTxtFile() { string vPath = System.Configuration.ConfigurationManager.AppSettings["UploadTemFileDic"]; List lis = new List(); HttpFileCollectionBase files = Request.Files; HttpPostedFileBase file = files["FileMobile"]; string fileName = ""; if (file != null && file.ContentLength > 0) { fileName = file.FileName; //判断文件名字是否包含路径名,如果有则提取文件名 if (fileName.LastIndexOf("\\") > -1) { fileName = fileName.Substring(fileName.LastIndexOf("\\") + 1); } if (fileName.ToLower().IndexOf(".txt") > -1) { if (!System.IO.Directory.Exists(Server.MapPath(vPath))) { System.IO.Directory.CreateDirectory(Server.MapPath(vPath)); } string path = Server.MapPath((vPath + "/") + fileName); file.SaveAs(path); // System.IO.File.Delete(path); } else { throw new Exception("文件格式不正确!"); } } else { throw new Exception("文件不存在!"); } return fileName; } public FileResult CustomerIdOrResId(string path, string selecttype) { HttpContext.Response.ContentType = "text/html;characset=utf-8"; string vPath = System.Configuration.ConfigurationManager.AppSettings["UploadTemFileDic"]; if (path.LastIndexOf("\\") > -1) { path = path.Substring(path.LastIndexOf("\\") + 1); } if (path.ToLower().IndexOf(".txt") > -1) { if (!System.IO.Directory.Exists(Server.MapPath(vPath))) { System.IO.Directory.CreateDirectory(Server.MapPath(vPath)); } path = Server.MapPath((vPath + "/") + path); } List lis = new List(); FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read); StreamReader sr = new StreamReader(fs, System.Text.Encoding.Default); while (!sr.EndOfStream) { string number = sr.ReadLine(); lis.Add(number); } sr.Close(); fs.Close(); System.IO.File.Delete(path); if (selecttype == "1" || selecttype == "2") { List customerturn = new List(); List customerturn2 = new List(); foreach (var model in lis) { temp_customerturn temp = new temp_customerturn(); temp.CUSTOMERID = model; customerturn.Add(temp); } if (customerturn.Count > 0) { DataTable tb = Utility.ToOracleDataTable(customerturn); List idmaps = csvr_idmap.GetResIdList(tb, selecttype); if (idmaps != null && idmaps.Count > 0) { foreach (var model in idmaps) { temp_customerturn turn = new temp_customerturn(); if (selecttype == "1") { turn.CUSTOMERID = model.RESID; } else { turn.CUSTOMERID = model.CUSTOMERID; } customerturn2.Add(turn); } } } return File(ExcelHelper.ExportListModelToExcel(customerturn2, "Id转换", 60000, null), "application/ms-excel", PageRequest.GetDlownLoadName("Id转换.xls")); } else if (selecttype == "6") { //手机号码批量生成resid //ResUtil.CreateResId var list = new List(); foreach (var model in lis) { try { var resid = ResUtil.CreateResId(model); list.Add(resid); } catch (Exception ex) { LogHelper.Info("错误的号码:" + model); } } return File(ExcelHelper.ExportListObjectToExcel(list, "结果", "数据转换", null), "application/ms-excel", PageRequest.GetDlownLoadName("数据转换.xls")); } else { List resimportid = new List(); string importId = DateTime.Now.ToString("yyyyMMddHHmmss"); foreach (var model in lis) { temp_resimportid temp = new temp_resimportid(); temp.IMPORTID = Convert.ToDecimal(importId); temp.IMPORTDATA = model.Trim(); resimportid.Add(temp); } DataTable tb = Utility.ToOracleDataTable(resimportid); List list = _customerQ.ResIDNoOutboundFilter(ref errors, tb, importId, DateTime.Now, DateTime.Now, selecttype.GetDecimal(0), "", ""); return File(ExcelHelper.ExportListObjectToExcel(list, "结果", "数据转换", null), "application/ms-excel", PageRequest.GetDlownLoadName("数据转换.xls")); } } public class temp_customerturn { public string CUSTOMERID { get; set; } } public class temp_resimportid { public decimal IMPORTID { get; set; } public string IMPORTDATA { get; set; } } public class Getresult { public bool result { get; set; } public string type { get; set; } public string message { get; set; } public string ResIds { get; set; } public string path { get; set; } public string selecttype { get; set; } } #endregion 号码转换 } public class retMsgOrderDto { public bool result { get; set; } public int retcode { get; set; } public List retmsg { get; set; } } public class OrderDto { public string resid { get; set; } public string cname { get; set; } public decimal? inneruserid { get; set; } public string uname { get; set; } public decimal subproductid { get; set; } public string subproductname { get; set; } public decimal? needpay { get; set; } public decimal? finalpay { get; set; } public decimal? arrivalpay { get; set; } public string arrivaltime { get; set; } public decimal orderid { get; set; } public decimal? ordertype { get; set; } public string orderstatusname { get; set; } public string ctime { get; set; } public string otime { get; set; } public string source { get; set; } public string softusername { get; set; } public decimal opendays { get; set; } public decimal? giftdays { get; set; } public string contractcode { get; set; } public int riskctrlstatus { get; set; } public int? hashgrecord { get; set; } public string szzyorderid { get; set; } public string companycode { get; set; } public string mobile { get; set; } public string rejectremark { get; set; } public int channel { get; set; } public string companyName { get; set; } public decimal price { get; set; } public decimal productLevel { get; set; } public decimal productInvestTime { get; set; } public decimal productInvestType { get; set; } public long? CpConfirmOrderId { get; set; } public decimal? Ret { get; set; } public string ai_hgrecord_time { get; set; } public int? ai_hgrecord_status { get; set; } = -1; /// /// 外呼状态 /// public string ai_hgrecord_statusname { get; set; } public int hasaiaudio { get; set; } public int hasbtn { get; set; } } }