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; using System.Web.Helpers; using System.Web.Mvc; using WX.CRM.Common; using WX.CRM.Common.Employee; using WX.CRM.WebHelper; using static NPOI.HSSF.Util.HSSFColor; namespace Core.Web.Controllers { public class InComplaintController : 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 InComplaintController() { webapi = cache_BL.GetValue_Parameter(Parameter.Hg_Core_WebApi); //webapi = "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 InComplaintHtml(Laypage pager, SearchInComplaintDto dto) { var url = $"{webapi}/api/InComplaint/page"; var para = $"Deptid={dto.Deptid}&Orderid={dto.Orderid}&Channel={dto.Channel}&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}" + $"&InComplaintChannel={dto.InComplaintChannel}&InComplaintStatus={dto.InComplaintStatus}" + $"&DateFrom={dto.DateFrom}&DateTo={dto.DateTo}&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 InComplaintEdit(int? id = null, bool read = false) { var model = new InComplaintDto(); model.inComplaintDateStr = DateTime.Now.ToString("yyyy-MM-dd"); if (id != null) { var url = $"{webapi}/api/InComplaint"; 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 InComplaintFollowUp(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 InComplaintFollowUpEdit(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 InComplaintRestoreEdit(int? id = null, bool read = false) { var model = new InComplaintRestoreDto(); if (id != null) { var url = $"{webapi}/api/InComplaint/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 InComplaintFollowUpHtml(int? id = null) { var url = $"{webapi}/api/InComplaint/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); // 旧地址 //webapi = "https://localhost:7090"; // 旧本地测试地址 //var webapi = "https://localhost:7151"; // 新本地测试地址 //var webapi = cache_BL.GetValue_Parameter(Parameter.Hg_Internal_WebApi); //新地址 //var url = $"{webapi}/api/Customer/details"; // 新地址拼接 var url = $"{webapi}/api/InComplaint/customerInfo"; // 旧地址拼接 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; // } //} return Json(data, JsonRequestBehavior.AllowGet); } [HttpPost] [AuthorizeRedirect(RightsConfig.CONST_内部投诉列表, ToolBarConfig.CONST_NotButton, false)] public JsonResult Create(CreateInComplaintDto dto) { try { var url = $"{webapi}/api/InComplaint"; var result = Utility.PostAjaxData(url, dto.ToJson(), Encoding.UTF8); var data = JsonConvert.DeserializeObject>(result); //if (data.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 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.RESID; // 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(UpdateInComplaintDto dto) { var url = $"{webapi}/api/InComplaint/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 CreateInComplaintRestore(CreateInComplaintRestoreDto dto) { var url = $"{webapi}/api/InComplaint/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 UpdateInComplaintStatus(UpdateInComplaintStatusDto dto) { var url = $"{webapi}/api/InComplaint/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 GetInComplaintRestore(int? id) { var url = $"{webapi}/api/InComplaint/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(CreateInComplaintFollowUpDto dto) { var url = $"{webapi}/api/InComplaint/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(CreateInComplaintFollowUpDto dto) { var url = $"{webapi}/api/InComplaint/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/InComplaint/page"; var dto = Utility.ToObject(param); var para = $"Deptid={dto.Deptid}&Orderid={dto.Orderid}" + $"&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}" + $"&InComplaintChannel={dto.InComplaintChannel}&InComplaintStatus={dto.InComplaintStatus}" + $"&DateFrom={dto.DateFrom}&DateTo={dto.DateTo}&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 "inComplaintChannelList": 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(",", 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 InComplaintImportDto() { DeptName = item[1].ToString(), ComplaintDate = d, ComplaintChannel = item[3].ToString(), Cname = item[4].ToString(), Resid = item[5].ToString(), Content = item[6].ToString(), Reasons = item[7].ToString(), DueResult = item[8].ToString(), ComplaintStatus = item[9].ToString(), Remark = item[11].ToString(), }; importDtos.Add(importDto); } var url = $"{webapi}/api/InComplaint/Import"; var result = Utility.PostAjaxData(url, importDtos.ToJson(), Encoding.UTF8); var data = JsonConvert.DeserializeObject>(result); return Json(data, JsonRequestBehavior.AllowGet); } [HttpPost] public JsonResult GetSalesLeadUrl(string appid, string appuserid) { var sHelper = new SecurityHelper(); var ext_flag = DateTimeTool.ConvertDateTimeLong(DateTime.Now); var model = JsonConvert.SerializeObject(new { appid = appid, appuserid = appuserid, eid = Eid.ToString(), ext_flag = ext_flag }); var content = sHelper.encyptData("WX_EXT", model); var url = "http://sc.soft.dn8188.com/dev.html?content=" + content + "&clientid=WK_EXT"; return Json(new { result = true, message = "succed", retmsg = url }, JsonRequestBehavior.AllowGet); } public JsonResult GetExt_flag() { var startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1)); var ext_flag = (long)(DateTime.Now - startTime).TotalSeconds * 1000; var sourceString = Utility.Encrypt(ext_flag.ToString()); var retmsg = HttpUtility.UrlEncode(sourceString, Encoding.UTF8); return Json(new { result = true, message = "succed", retmsg = retmsg }, JsonRequestBehavior.AllowGet); } #region 实体 public class SearchInComplaintDto { /// /// 事业部 /// public int? Deptid { get; set; } public string Channel { get; set; } /// /// 内诉渠道 /// public int? InComplaintChannel { get; set; } /// /// 投诉原因 /// public int? Reason { get; set; } /// /// 内诉状态 /// public int? InComplaintStatus { 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 int PersonType { get; set; } } public class InComplaintDto { 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? inComplaintChannel { get; set; } public List inComplaintChannels { get; set; } public List inComplaintChannelList { get; set; } public List reasons { get; set; } public List reasonList { get; set; } public int? inComplaintStatus { get; set; } public string inComplaintStatusStr { 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? InComplaintDate { get; set; } public string inComplaintDateStr { 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 isOutComplaint { 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 CreateInComplaintDto { /// /// 资源id /// public string Resid { get; set; } /// /// 客户姓名 /// public string Cname { get; set; } /// /// 客服id /// public int? Eid { get; set; } /// /// 事业部 /// public int? Deptid { get; set; } /// /// 内诉渠道 /// public string InComplaintChannels { get; set; } /// /// 投诉原因 /// public string Reasons { get; set; } /// /// 客户内诉日期 /// public DateTime? InComplaintDate { get; set; } /// /// 投诉内容 /// public string Content { get; set; } /// /// 处理跟进 /// public string Follow { get; set; } /// /// 合规备注 /// public string Remark { get; set; } /// /// 操作人 /// public string Operator { get; set; } /// /// 事业部Code /// public string CompanyCode { get; set; } public string OperatorEid { get; set; } public string RiskSituation { get; set; } } public class UpdateInComplaintDto { 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 RiskSituation { get; set; } } public class CreateInComplaintRestoreDto { 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 InComplaintRestoreDto { 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? InComplaintStatus { get; set; } public string InComplaintStatusStr { get; set; } public List Restores { get; set; } } public class UpdateInComplaintStatusDto { public int Id { get; set; } public int? InComplaintStatus { 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? InComplaintStatus { get; set; } public string InComplaintStatusStr { 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 CreateInComplaintFollowUpDto { /// /// 内诉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 RestoreDto { public int Id { get; set; } public string ComplaintId { get; set; } public string Content { get; set; } public string Creator { get; set; } public DateTime? CreateTime { get; set; } public int? CreatorEid { get; set; } public string Attachment { get; set; } public int? RestoreType { get; set; } } public class InComplaintImportDto { public string DeptName { get; set; } /// /// 客户内诉日期 /// public DateTime? ComplaintDate { get; set; } /// /// 内诉渠道 /// public string ComplaintChannel { get; set; } /// /// 客户姓名 /// public string Cname { get; set; } /// /// 资源id /// public string Resid { get; set; } /// /// 第一次投诉 /// public string Content { get; set; } /// /// 投诉原因 /// public string Reasons { get; set; } public string DueResult { get; set; } public string ComplaintStatus { get; set; } public string Remark { get; set; } } #endregion 实体 } }