using Core.Web.App_Start; using Core.Web.WebHelper; using CRM.Core.BLL; using CRM.Core.BLL.Application.B; using CRM.Core.BLL.Application.Bill; using CRM.Core.BLL.BlackNumber; using CRM.Core.BLL.Res; using CRM.Core.BLL.Util; using CRM.Core.BLL.Wx; using CRM.Core.Common.Layui; using CRM.Core.Common.WebHelper; using CRM.Core.DTO; using CRM.Core.DTO.Bill; using CRM.Core.Model.Entity; using CRM.Core.Model.Enum; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using System.Web.Helpers; using System.Web.Mvc; using WX.CRM.Common; using WX.CRM.Common.Employee; using WX.CRM.Common.StockHelper; using WX.CRM.WebHelper; using static Core.Web.Controllers.InComplaintController; using static NPOI.HSSF.Util.HSSFColor; namespace Core.Web.Controllers { public class OutComplaintController : BaseController { private CACHE_BL cache_BL = new CACHE_BL(); private RES_CUSTOMER_BL res_Customer_BL = new RES_CUSTOMER_BL(); private BlackNumber_BL blackNumber_BL = new BlackNumber_BL(); private WX_SZZYORDER_BL _order = new WX_SZZYORDER_BL(); public readonly string webapi = ""; public OutComplaintController() { webapi = cache_BL.GetValue_Parameter(Parameter.Hg_Core_WebApi); //ebapi = "https://localhost:7090"; } [HttpGet] [AuthorizeRedirect(RightsConfig.CONST_外部投诉列表, ToolBarConfig.CONST_NotButton, true)] public ActionResult Index() { ViewBag.rightCode = RightsConfig.CONST_外部投诉列表; ViewBag.eid = Eid; ViewBag.userName = UserName; ViewBag.File_Server = cache_BL.GetValue_Parameter("File_Server"); var deptments = cache_BL.GetDeptments(); ViewBag.companyList = deptments; ViewBag.webapi = webapi; ViewBag.hgServiceHost = cache_BL.GetValue_Parameter("HgCrm_ServiceHost"); return View(); } [HttpGet] [AuthorizeRedirect(RightsConfig.CONST_外部投诉列表, ToolBarConfig.CONST_NotButton, false)] public JsonResult OutComplaintHtml(Laypage pager, SearchOutComplaintDto dto) { var url = $"{webapi}/api/OutComplaint/page"; var para = $"Deptid={dto.Deptid}&Orderid={dto.Orderid}&Type=1&PersonType={dto.PersonType}" + $"&Reason={dto.Reason}&Resid={dto.Resid}&UMID={dto.UMID}&CreaetOrUpdateUser={dto.CreaetOrUpdateUser}" + $"&BusinessStatus={dto.BusinessStatus}&Cname={dto.Cname}&ComplaintId={dto.ComplaintId}" + $"&DateType={dto.DateType}&DueStatus={dto.DueStatus}&Eid={dto.Eid}&RefundStatus={dto.RefundStatus}" + $"&OutComplaintChannel={dto.OutComplaintChannel}&OutComplaintStatus={dto.OutComplaintStatus}" + $"&DateFrom={dto.DateFrom}&DateTo={dto.DateTo}&Channel={dto.Channel}&PageIndex={pager.page}&PageSize={pager.limit}"; var result = Utility.GetData(url, para, Encoding.UTF8); var data = JsonConvert.DeserializeObject>>(result); return Json(data, JsonRequestBehavior.AllowGet); } [HttpGet] [AuthorizeRedirect(RightsConfig.CONST_外部投诉列表, ToolBarConfig.CONST_NotButton, true)] public ActionResult OutComplaintEdit(int? id = null, bool read = false) { var model = new OutComplaintDto(); model.outComplaintDateStr = DateTime.Now.ToString("yyyy-MM-dd"); if (id != null) { var url = $"{webapi}/api/OutComplaint"; var para = $"id={id}"; var result = Utility.GetData(url, para, Encoding.UTF8); var data = JsonConvert.DeserializeObject>(result); model = data.data; } ViewBag.id = id; ViewBag.rightCode = RightsConfig.CONST_外部投诉列表; ViewBag.eid = Eid; ViewBag.userName = UserName; ViewBag.File_Server = cache_BL.GetValue_Parameter("File_Server"); ViewBag.Readonly = read; var deptments = cache_BL.GetDeptments(); ViewBag.companyList = deptments; return View(model); } [HttpGet] [AuthorizeRedirect(RightsConfig.CONST_外部投诉列表, ToolBarConfig.CONST_NotButton, true)] public ActionResult OutComplaintFollowUp(int? id = null) { ViewBag.id = id; ViewBag.rightCode = RightsConfig.CONST_外部投诉列表; ViewBag.eid = Eid; ViewBag.userName = UserName; return View(); } [HttpGet] [AuthorizeRedirect(RightsConfig.CONST_外部投诉列表, ToolBarConfig.CONST_NotButton, true)] public ActionResult OutComplaintFollowUpEdit(int? id = null) { ViewBag.id = id; ViewBag.rightCode = RightsConfig.CONST_外部投诉列表; ViewBag.eid = Eid; ViewBag.userName = UserName; return View(); } [HttpGet] [AuthorizeRedirect(RightsConfig.CONST_外部投诉列表, ToolBarConfig.CONST_NotButton, true)] public ActionResult OutComplaintRestoreEdit(int? id = null, bool read = false) { var model = new OutComplaintRestoreDto(); if (id != null) { var url = $"{webapi}/api/OutComplaint/Restore"; var para = $"id={id}"; var result = Utility.GetData(url, para, Encoding.UTF8); var data = JsonConvert.DeserializeObject>(result); model = data.data; } ViewBag.id = id; ViewBag.rightCode = RightsConfig.CONST_外部投诉列表; ViewBag.eid = Eid; ViewBag.userName = UserName; ViewBag.File_Server = cache_BL.GetValue_Parameter("File_Server"); ViewBag.Readonly = read; return View(model); } [HttpGet] [AuthorizeRedirect(RightsConfig.CONST_外部投诉列表, ToolBarConfig.CONST_NotButton, false)] public JsonResult OutComplaintFollowUpHtml(int? id = null) { var url = $"{webapi}/api/OutComplaint/FollowUp"; var para = $"id={id}"; var result = Utility.GetData(url, para, Encoding.UTF8); var data = JsonConvert.DeserializeObject>(result); return Json(data, JsonRequestBehavior.AllowGet); } [HttpGet] [AuthorizeRedirect(RightsConfig.CONST_外部投诉列表, ToolBarConfig.CONST_NotButton, false)] public JsonResult GetComplaintCustomerInfo(string resid) { //var webapi = cache_BL.GetValue_Parameter(Parameter.Hg_Core_WebApi); // 旧地址 //var webapi = "https://localhost:7151"; // 新本地测试地址 //var //webapi = "https://localhost:7090"; // 旧本地测试地址 //var url = $"{webapi}/api/InComplaint/customerInfo"; // 旧地址拼接 //var webapi = cache_BL.GetValue_Parameter(Parameter.Hg_Internal_WebApi); //新地址 //var url = $"{webapi}/api/Customer/details"; // 新地址拼接 //var para = $"resid={resid}"; //var result = Utility.GetData(url, para, Encoding.UTF8); //var data = JsonConvert.DeserializeObject>(result); //if (data.code == 0) //{ // var orderStatus = new List { "200", "220", "205", "80", "90" }; // foreach (var dept in data.data.deptInfos) // { // var order = _order.GetList(x => x.companycode == dept.companycode && x.RESID == resid && orderStatus.Contains(x.ORDERSTATUS), x => x.CTIME); // dept.eid = order.FirstOrDefault()?.eid; // } //} var url = $"{webapi}/api/InComplaint/customerInfo"; // 旧地址拼接 var para = $"resid={resid}"; var result = Utility.GetData(url, para, Encoding.UTF8); var data = JsonConvert.DeserializeObject>(result); return Json(data, JsonRequestBehavior.AllowGet); } [HttpPost] [AuthorizeRedirect(RightsConfig.CONST_外部投诉列表, ToolBarConfig.CONST_NotButton, false)] public JsonResult Create(CreateOutComplaintDto dto) { try { var url = $"{webapi}/api/OutComplaint"; var result = Utility.PostAjaxData(url, dto.ToJson(), Encoding.UTF8); var data = JsonConvert.DeserializeObject>(result); if (data.code == 0) { //将客户添加到黑名单 //获取Resid关联的所有客户 var webapi2 = cache_BL.GetValue_Parameter(Parameter.Hg_Internal_WebApi); //webapi = "https://localhost:7090"; var url2 = $"{webapi2}/api/Customer/relation_customers"; var para = $"resid={dto.Resid}"; var customerStr = Utility.GetData(url2, para, Encoding.UTF8); var customer = JsonConvert.DeserializeObject>>(customerStr); if (customer.code == 0) { //List list = res_Customer_BL.GetList_CustomerByResid(dto.Resid); //list = list.Where(m => m.RESID == dto.Resid || m.CUSTOMERID == dto.Resid).ToList(); var list = customer.data; var blackModels = new List(); foreach (var item in list) { var blackCustomer = blackNumber_BL.GetByResId(dto.Resid, "F"); if (blackCustomer == null) { CSVR_BLACKNUMBER model = new CSVR_BLACKNUMBER(); model.RESID = item; model.BLACKTYPE = "F"; model.REASON = "系统自动添加(外诉客户)"; model.CTIME = DateTime.Now; model.CREATEUSER = UserId; model.CREATEUSERNAME = Eid + "-" + UserName; model.DeptChannel = "-1"; model.ChannelName = "全事业部"; blackModels.Add(model); } } if (blackModels.Any()) blackNumber_BL.CreateEntities(blackModels); } } return Json(data, JsonRequestBehavior.AllowGet); } catch (Exception ex) { LogHelper.Error("InComplaint_Create:" + ex.StackTrace + ";" + ex.Message); return Json(new ApiResult { code = -1, message = ex.Message }, JsonRequestBehavior.AllowGet); } } [HttpPost] [AuthorizeRedirect(RightsConfig.CONST_外部投诉列表, ToolBarConfig.CONST_NotButton, false)] public JsonResult Update(UpdateOutComplaintDto dto) { var url = $"{webapi}/api/OutComplaint/update"; var result = Utility.PostAjaxData(url, dto.ToJson(), Encoding.UTF8); var data = JsonConvert.DeserializeObject>(result); return Json(data, JsonRequestBehavior.AllowGet); } [HttpPost] [AuthorizeRedirect(RightsConfig.CONST_外部投诉列表, ToolBarConfig.CONST_NotButton, false)] public JsonResult CreateOutComplaintRestore(CreateOutComplaintRestoreDto dto) { var url = $"{webapi}/api/OutComplaint/Restore"; dto.RestoreType = 2; var result = Utility.PostAjaxData(url, dto.ToJson(), Encoding.UTF8); var data = JsonConvert.DeserializeObject>(result); return Json(data, JsonRequestBehavior.AllowGet); } [HttpPost] [AuthorizeRedirect(RightsConfig.CONST_外部投诉列表, ToolBarConfig.CONST_NotButton, false)] public JsonResult UpdateOutComplaintStatus(UpdateOutComplaintStatusDto dto) { var url = $"{webapi}/api/OutComplaint/Status"; var result = Utility.PostAjaxData(url, dto.ToJson(), Encoding.UTF8); var data = JsonConvert.DeserializeObject>(result); return Json(data, JsonRequestBehavior.AllowGet); } [HttpGet] [AuthorizeRedirect(RightsConfig.CONST_外部投诉列表, ToolBarConfig.CONST_NotButton, false)] public JsonResult GetOutComplaintRestore(int? id) { var url = $"{webapi}/api/OutComplaint/Restore"; var para = $"id={id}"; var result = Utility.GetData(url, para, Encoding.UTF8); var data = JsonConvert.DeserializeObject>(result); return Json(data, JsonRequestBehavior.AllowGet); } [HttpPost] [AuthorizeRedirect(RightsConfig.CONST_外部投诉列表, ToolBarConfig.CONST_NotButton, false)] public JsonResult CreateOutComlpaintFollowUp(CreateOutComplaintFollowUpDto dto) { var url = $"{webapi}/api/OutComplaint/FollowUp"; var result = Utility.PostAjaxData(url, dto.ToJson(), Encoding.UTF8); var data = JsonConvert.DeserializeObject>(result); return Json(data, JsonRequestBehavior.AllowGet); } [HttpPost] [AuthorizeRedirect(RightsConfig.CONST_外部投诉列表, ToolBarConfig.CONST_NotButton, false)] public JsonResult UpdateOutComlpaintFollowUp(CreateOutComplaintFollowUpDto dto) { var url = $"{webapi}/api/OutComplaint/UpdateFollowUp"; var result = Utility.PostAjaxData(url, dto.ToJson(), Encoding.UTF8); var data = JsonConvert.DeserializeObject>(result); return Json(data, JsonRequestBehavior.AllowGet); } [HttpGet] [AuthorizeRedirect(RightsConfig.CONST_外部投诉列表, ToolBarConfig.CONST_Export, false)] public FileResult ExportData(string param) { var url = $"{webapi}/api/OutComplaint/page"; var dto = Utility.ToObject(param); var para = $"Deptid={dto.Deptid}&Orderid={dto.Orderid}&PersonType={dto.PersonType}&PersonType={dto.PersonType}" + $"&Reason={dto.Reason}&Resid={dto.Resid}&CreaetOrUpdateUser={dto.CreaetOrUpdateUser}" + $"&BusinessStatus={dto.BusinessStatus}&Cname={dto.Cname}&ComplaintId={dto.ComplaintId}" + $"&DateType={dto.DateType}&DueStatus={dto.DueStatus}&Eid={dto.Eid}&RefundStatus={dto.RefundStatus}" + $"&OutComplaintChannel={dto.OutComplaintChannel}&OutComplaintStatus={dto.OutComplaintStatus}" + $"&DateFrom={dto.DateFrom}&DateTo={dto.DateTo}&Channel={dto.Channel}&PageIndex=1&PageSize=100000"; var result = Utility.GetData(url, para, Encoding.UTF8); var data = JsonConvert.DeserializeObject>>(result); string checkedFilds = Server.UrlDecode(Request.Cookies["checkedFilds"].Value); string checkedTitle = Server.UrlDecode(Request.Cookies["checkedTitles"].Value); Request.Cookies.Remove("checkedFilds");//用完后删除cookies Request.Cookies.Remove("checkedTitles");//用完后删除cookies String file = string.Format("外部投诉列表{0}.xls", DateTime.Now.ToLocalTime().ToString("yyyyMMddHHmmssfffff")); return File(ExcelHelper.ExportListModelToExcel(data.data.Data.ToList(), "sheet", 30000, checkedFilds, checkedTitle, DataFormart), "application/ms-excel", file); } public string DataFormart(string key, object value) { string formartValue = string.Empty; switch (key) { case "reasonList": case "orderList": case "priceList": case "products": case "orderIds": case "arrivalPays": case "arrivalStatus": formartValue = string.Join("\n", Utility.ToObject>(Utility.ToJson(value))); break; case "oTimes": formartValue = string.Join("\n", Utility.ToObject>(Utility.ToJson(value))); break; default: formartValue = string.Format("{0}", value); break; } return formartValue; } [HttpPost] public JsonResult Import() { var file = Request.Files[0]; var dt = new DataTable(); dt = ExcelToDataTable(file); var importDtos = new List(); foreach (DataRow item in dt.Rows) { DateTime d = DateTime.Now; if (!DateTime.TryParse(item[2].ToString(), out d)) { d = DateTime.ParseExact(item[2].ToString(), "dd-M月-yyyy", System.Globalization.CultureInfo.InvariantCulture); } var importDto = new OutComplaintImportDto() { DeptName = item[3].ToString(), OutComplaintDate = d, OutComplaintChannel = item[1].ToString(), Cname = item[4].ToString(), Resid = item[5].ToString(), Content = item[6].ToString(), Reasons = item[7].ToString(), ComplaintStatus = item[8].ToString(), Follow = item[9].ToString(), Remark = item[10].ToString(), }; importDtos.Add(importDto); } var url = $"{webapi}/api/OutComplaint/Import"; var result = Utility.PostAjaxData(url, importDtos.ToJson(), Encoding.UTF8); var data = JsonConvert.DeserializeObject>(result); return Json(data, JsonRequestBehavior.AllowGet); } #region 实体 public class SearchOutComplaintDto { /// /// 事业部 /// public int? Deptid { get; set; } /// /// 外诉渠道 /// public int? OutComplaintChannel { get; set; } /// /// 投诉原因 /// public int? Reason { get; set; } /// /// 外诉状态 /// public int? OutComplaintStatus { get; set; } /// /// 业务处理状态 /// public int? BusinessStatus { get; set; } /// /// 到期状态 /// public int? DueStatus { get; set; } /// /// 退款状态 /// public int? RefundStatus { get; set; } /// /// 投诉单号 /// public string ComplaintId { get; set; } /// /// 客户ID /// public string Resid { get; set; } /// /// 客户ID /// public string UMID { get; set; } /// /// 客户姓名 /// public string Cname { get; set; } /// /// 成交客服/工号 /// public string Eid { get; set; } /// /// 已退订单号 /// public int? Orderid { get; set; } /// /// 创建人/更新人 /// public string CreaetOrUpdateUser { get; set; } /// /// 日期搜索类型 /// public int DateType { get; set; } /// /// 日期 /// public DateTime? DateFrom { get; set; } /// /// 日期 /// public DateTime? DateTo { get; set; } /// /// 事业部渠道 /// public string Channel { get; set; } /// /// 人员类型 /// public int PersonType { get; set; } } public class OutComplaintDto { public int id { get; set; } public string complaintId { get; set; } public string resid { get; set; } public string UMID { get; set; } public string cname { get; set; } public int? deptid { get; set; } public string deptname { get; set; } public int? eid { get; set; } public string euser { get; set; } public int? outComplaintChannel { get; set; } public string outComplaintChannelStr { get; set; } public List reasons { get; set; } public List reasonList { get; set; } public int? outComplaintStatus { get; set; } public string outComplaintStatusStr { get; set; } public int? businessStatus { get; set; } public string businessStatusStr { get; set; } public string content { get; set; } public string follow { get; set; } public string remark { get; set; } public int? dueStatus { get; set; } public string dueStatusStr { get; set; } public int? refundStatus { get; set; } public string refundStatusStr { get; set; } public DateTime? businessDeadline { get; set; } public string businessDeadlineSpan { get; set; } public DateTime? complaintDeadline { get; set; } public string complaintDeadlineSpan { get; set; } public DateTime? outComplaintDate { get; set; } public string outComplaintDateStr { get; set; } public string creator { get; set; } public DateTime? createTime { get; set; } public string updater { get; set; } public DateTime? updateTime { get; set; } public ICollection orderList { get; set; } public ICollection priceList { get; set; } public int needRestoreCount { get; set; } public int restoreCount { get; set; } public int followUpCount { get; set; } public int? age { get; set; } public List products { get; set; } public List orderIds { get; set; } public List oTimes { get; set; } public List arrivalPays { get; set; } public List arrivalStatus { get; set; } public string verifyier { get; set; } public DateTime? verifyTime { get; set; } public string isInComplaint { get; set; } public string riskSituation { get; set; } public int? complaintCycle { get; set; } } public class ComplaintCustomerInfoDto { public string resid { get; set; } public string cname { get; set; } public int? eid { get; set; } public List deptInfos { get; set; } } public class ComplaintCustomerDeptInfo { public int? channel { get; set; } public int? deptid { get; set; } public string deptname { get; set; } public string companycode { get; set; } public int? eid { get; set; } } public class CreateOutComplaintDto { /// /// 资源id /// public string Resid { get; set; } /// /// 客户姓名 /// public string Cname { get; set; } /// /// 客服id /// public int? Eid { get; set; } /// /// 事业部 /// public int? Deptid { get; set; } /// /// 外诉渠道 /// public int? OutComplaintChannel { get; set; } /// /// 投诉原因 /// public string Reasons { get; set; } /// /// 客户外诉日期 /// public DateTime? OutComplaintDate { get; set; } /// /// 投诉内容 /// public string Content { get; set; } /// /// 处理跟进 /// public string Follow { get; set; } /// /// 合规核查 /// public string Remark { get; set; } /// /// 操作人 /// public string Operator { get; set; } /// /// 操作人工号 /// public string OperatorEid { get; set; } /// /// 事业部Code /// public string CompanyCode { get; set; } /// /// 风险情况 /// public string RiskSituation { get; set; } } public class UpdateOutComplaintDto { public int Id { get; set; } /// /// 投诉内容 /// public string Content { get; set; } /// /// 处理跟进 /// public string Follow { get; set; } /// /// 合规备注 /// public string Remark { get; set; } /// /// 操作人 /// public string Operator { get; set; } /// /// 操作人工号 /// public string OperatorEid { get; set; } /// /// 风险情况 /// public string RiskSituation { get; set; } } public class CreateOutComplaintRestoreDto { public int Id { get; set; } public string Content { get; set; } public string Creator { get; set; } public int? CreatorEid { get; set; } public string Attachment { get; set; } public int RestoreType { get; set; } } public class OutComplaintRestoreDto { public int Id { get; set; } public string Resid { get; set; } public string Cname { get; set; } public int? Deptid { get; set; } public string Deptname { get; set; } public string ComplaintId { get; set; } public int? OutComplaintStatus { get; set; } public string OutComplaintStatusStr { get; set; } public int? OutComplaintBusinessStatus { get; set; } public string OutComplaintBusinessStatusStr { get; set; } public List Restores { get; set; } } public class UpdateOutComplaintStatusDto { public int Id { get; set; } public int? OutComplaintStatus { get; set; } /// /// 操作人 /// public string Operator { get; set; } /// /// 操作人eid /// public int? OperatorEid { get; set; } } public class OutComlpaintFollowUpDto { public int Id { get; set; } public string ComplaintId { get; set; } public string Resid { get; set; } public string Cname { get; set; } public int? OutComplaintStatus { get; set; } public string OutComplaintStatusStr { get; set; } public List Details { get; set; } } public class OutComlpaintFollowUpDetailDto { public int Id { get; set; } public string Index { get; set; } public string Content { get; set; } public string Follow { get; set; } public string Creator { get; set; } public DateTime? CreateTime { get; set; } public string Updater { get; set; } public DateTime? UpdateTime { get; set; } } public class CreateOutComplaintFollowUpDto { /// /// 外诉id /// public int? Id { get; set; } /// /// 投诉内容 /// public string Content { get; set; } /// /// 处理进记 /// public string Follow { get; set; } /// /// 操作人 /// public string Operator { get; set; } /// /// 操作人eid /// public int? OperatorEid { get; set; } } public class OutComplaintImportDto { /// /// 资源id /// public string Resid { get; set; } /// /// 客户姓名 /// public string Cname { get; set; } public string DeptName { get; set; } /// /// 客户外诉日期 /// public DateTime? OutComplaintDate { get; set; } /// /// 外诉渠道 /// public string OutComplaintChannel { get; set; } /// /// 投诉内容 /// public string Content { get; set; } /// /// 投诉原因 /// public string Reasons { get; set; } /// /// 投诉原因 /// public string ComplaintStatus { get; set; } /// /// 处理跟进 /// public string Follow { get; set; } /// /// 合规核查 /// public string Remark { get; set; } } #endregion } }