using Core.Web.App_Start; using Core.Web.WebHelper; using CRM.Core.BLL; using CRM.Core.BLL.Base; using CRM.Core.BLL.Cms; using CRM.Core.BLL.EventBus.Events; using CRM.Core.BLL.Util; using CRM.Core.Common.EventBus; using CRM.Core.Common.Layui; using CRM.Core.Common.WebHelper; using CRM.Core.DTO; using CRM.Core.Model.Entity; using CRM.Core.Model.Enum; using Newtonsoft.Json; using NPOI.POIFS.FileSystem; using System; using System.Collections.Generic; using System.Data.SqlClient; using System.IO; using System.Linq; using System.Linq.Expressions; using System.Security.Policy; using System.Text; using System.Web.Mvc; using System.Web.UI.WebControls.WebParts; using WX.CRM.Common; using WX.CRM.Common.StockHelper; using static CRM.Core.Model.ConStringHelper; namespace Core.Web.Controllers { public class NewsController : BaseController { private CMS_News_BL _news = new CMS_News_BL(); private CMS_News_Log_BL _newslog = new CMS_News_Log_BL(); private CACHE_BL _cache = new CACHE_BL(); private BAS_ROLE_BL role_bl = new BAS_ROLE_BL(); private Bas_CompanyVirtual_BL _companyvirtual = new Bas_CompanyVirtual_BL(); private BAS_PARAMETER_BL _paramter = new BAS_PARAMETER_BL(); [AuthorizeRedirect(RightsConfig.CONST_广告策划审核, ToolBarConfig.CONST_NotButton, true)] public ActionResult Index() { ViewBag.Eid = Eid; ViewBag.rightCode = RightsConfig.CONST_广告策划审核; //List vurtual = _cache.GetCompanyVirtual(); var deptments = GetDeptments(); List deptList = new List(); ViewBag.hgServiceHost = _cache.GetValue_Parameter("HgCrm_ServiceHost"); ViewBag.File_Server = _cache.GetValue_Parameter("File_Server"); string[] comcodelist = role_bl.GetRoleComLists(userRoleId).Select(m => m.companycode).ToArray(); if (userRoleCodes.Contains("[GLY]"))//管理员看全部 { //vurtual.Insert(0, new Bas_CompanyVirtual() { CompanyName = "--请选择--", CompanyCode = "" }); deptList = deptments; } else { //vurtual = var cc = deptments.Where(m => comcodelist.Contains(m.CompanyCode)).ToList(); deptList = cc; } var deptMentlist = new List>(); foreach (var item in deptList) { var channel = new Dictionary { { "name", item.Title }, { "value", item.DepartmentId.ToString() } }; deptMentlist.Add(channel); } ViewBag.companyList = deptMentlist.ToJson(); var reasons = GetReasonForRejection(); ViewBag.reasons = reasons; var list = new List>(); foreach (var item in reasons) { var channel = new Dictionary { { "name", item.Value }, { "value", item.Key.ToString() } }; list.Add(channel); } ViewBag.AllReasons = JsonHelper.ToJson(list); BAS_PARAMETER model = _paramter.GetModel(CRM.Core.Model.Enum.Parameter.WeiXin_IllegalKewords.ToString()); if (model == null) ViewBag.KeyWords = ""; else ViewBag.KeyWords = model.PARAVALUE; return View(); } private List GetDeptments() { var data = new List(); var cacheKey = "cache_deptment_list"; if (CacheHelper.Exists(cacheKey)) { data = CacheHelper.Get>(cacheKey); } else { var webapi = _cache.GetValue_Parameter(Parameter.Hg_Core_WebApi); var url = $"{webapi}/api/Department/List"; var result = Utility.GetData(url, "", Encoding.UTF8); var response = JsonConvert.DeserializeObject>>(result); if (response.Code == 0) { data = response.Data; CacheHelper.Set(cacheKey, data); } } return data; } private Dictionary GetReasonForRejection() { var data = new Dictionary(); var cacheKey = "cache_new_reason_list"; if (CacheHelper.Exists(cacheKey)) { data = CacheHelper.Get>(cacheKey); } else { var webapi = _cache.GetValue_Parameter(Parameter.Hg_Core_WebApi); var url = $"{webapi}/api/CmsNews/reason"; var result = Utility.GetData(url, "", Encoding.UTF8); var response = JsonConvert.DeserializeObject>>(result); if (response.Code == 0) { data = response.Data; CacheHelper.Set(cacheKey, data); } } return data; } [HttpPost] [AuthorizeRedirect(RightsConfig.CONST_广告策划审核, ToolBarConfig.CONST_NotButton, false)] public JsonResult GetListHtml(Laypage pager, NewsQueryDto dto) { var webapi = _cache.GetValue_Parameter(Parameter.Hg_Core_WebApi); var url = $"{webapi}/api/CmsNews/Page"; var appid = System.Configuration.ConfigurationManager.AppSettings["appid"]; ViewBag.appid = appid; dto.appid = appid; dto.PageIndex = pager.page; dto.PageSize = pager.limit; var para = Utility.GetParamToString(dto); var result = Utility.GetData(url, para, Encoding.UTF8); var page = JsonConvert.DeserializeObject>>(result); var list = new List(); if (page.Code == 0) { list = page.Data.Data.ToList(); } var data = new LayuiData() { msg = "数据加载成功!", count = page.Data.Total, code = 0, data = list }; return Json(data, JsonRequestBehavior.AllowGet); } public JsonResult Add(CMS_News dto) { if (string.IsNullOrWhiteSpace(dto.Title) || string.IsNullOrWhiteSpace(dto.Content) || string.IsNullOrWhiteSpace(dto.NewsType)) { return Json(new { result = false, code = -1, msg = "参数错误!" }, JsonRequestBehavior.AllowGet); } var model = new CMS_News(dto.NewsType, dto.Title, dto.Content, Convert.ToInt32(Eid), UserName, dto.Att, dto.Remark, 0); _news.Add(model); return Json(new { result = true, code = 0, msg = "提交成功!" }, JsonRequestBehavior.AllowGet); } public JsonResult Edit(CMS_News dto) { if (dto.Id <= 0) { return Json(new { result = false, code = -1, msg = "参数错误!" }, JsonRequestBehavior.AllowGet); } var model = _news.Get(p => p.Id == dto.Id); if (model != null) { model.NewsType = dto.NewsType; model.Title = dto.Title; model.Content = dto.Content; model.Status = 0; model.CreateUser = Convert.ToInt32(Eid); model.CreateUserName = UserName; model.Att = dto.Att; model.Remark = dto.Remark; model.Author = dto.Author; model.Channels = dto.Channels; _news.Update(model); } else { return Json(new { result = false, code = -1, msg = "参数错误!" }, JsonRequestBehavior.AllowGet); } return Json(new { result = true, code = 0, msg = "提交成功!" }, JsonRequestBehavior.AllowGet); } public JsonResult Del(int Id) { retMsg ret = new retMsg(); var webapi = _cache.GetValue_Parameter(Parameter.Hg_Core_WebApi); var url = $"{webapi}/api/CmsNews/Delete"; var data = new { DelUsername=UserName, Id=Id }; var result = Utility.PostAjaxData(url, data.ToJson(), Encoding.UTF8); var resultData = JsonConvert.DeserializeObject>(result); if (resultData.code == 0) { ret = new retMsg() { result = true, retcode = 200, retmsg = "提交成功!" }; } else { ret = new retMsg() { result = false, retcode = 200, retmsg = "提交失败!Error:" + resultData.msg }; } return Json(ret); } public JsonResult Set(CMS_News model, string ImgListValue) { retMsg ret = new retMsg(); var webapi = _cache.GetValue_Parameter(Parameter.Hg_Core_WebApi); var url = $"{webapi}/api/CmsNews/Audit"; model.Auditer = Eid; model.AuditerName = UserName; var result = Utility.PostAjaxData(url, model.ToJson(), Encoding.UTF8); var data = JsonConvert.DeserializeObject>(result); if (data.code == 0) { ret = new retMsg() { result = true, retcode = 200, retmsg = "提交成功!" }; } else { ret = new retMsg() { result = false, retcode = 200, retmsg = "提交失败!Error:" + data.msg }; } model = _news.Get(x => x.Id == model.Id); // 首华处理 if (model.deptcode == "TNBD") { CMS_News_Log log = new CMS_News_Log() { CTime = DateTime.Now, Att = model.Att, Content = model.Content, deptcode = model.deptcode, newid = model.Id, NewsType = model.NewsType, OpEvent = model.Status == 1 ? "通过审核" : "驳回", OpName = model.AuditerName, OpUser = model.Auditer.Value, Remark = model.Remark, Status = model.Status, Title = model.Title, AuditImg1 = model.AuditImg1, AuditImg2 = model.AuditImg2, AuditImg3 = model.AuditImg3, AuditImg4 = model.AuditImg4, AuditImg5 = model.AuditImg5, AuditImg6 = model.AuditImg6, CheckRemark = model.AuditRemark, Channel = model.Channel, Reason = model.Reason, Channels = model.Channels, Author = model.Author }; string snedCode = ""; var companyCode = _cache.GetCompanyCode(); var company = companyCode.FirstOrDefault(p => p.Min <= model.Channel && p.Max >= model.Channel); if (company != null) { snedCode = company.CompanyCode; } else { Bas_CompanyVirtual bas_company = _cache.GetCompanyVirtual().FirstOrDefault(m => m.deptcode == model.deptcode); if (bas_company == null) { bas_company = _cache.GetCompanyVirtual().FirstOrDefault(m => m.CompanyCode == model.deptcode); snedCode = bas_company.CompanyCode; } } EventBus.Instance.Publish(new CmsNewsEvent(log, snedCode)); } return Json(ret); } [HttpPost] public JsonResult UploadAtt() { var file = Request.Files[0]; var vPath = System.Configuration.ConfigurationManager.AppSettings["UploadTemFileDic"] + "/att"; var rootPath = Server.MapPath(vPath); if (!System.IO.Directory.Exists(rootPath)) { System.IO.Directory.CreateDirectory(rootPath); } var saveFileName = Guid.NewGuid().ToString() + Path.GetExtension(file.FileName); var urlPath = vPath + "/" + saveFileName; var fileName = Path.Combine(rootPath, saveFileName); file.SaveAs(fileName); return Json(new { result = true, retcode = 1, retmsg = urlPath }, JsonRequestBehavior.AllowGet); } [AuthorizeRedirect(RightsConfig.CONST_广告策划审核, ToolBarConfig.CONST_NotButton, true)] public ActionResult Log(int Id) { ViewBag.Id = Id; return View(); } [HttpPost] [AuthorizeRedirect(RightsConfig.CONST_广告策划审核, ToolBarConfig.CONST_NotButton, false)] public JsonResult NewsLog(Laypage pager, int Id) { var webapi = _cache.GetValue_Parameter(Parameter.Hg_Core_WebApi); var url = $"{webapi}/api/CmsNews/Log"; var para = $"id={Id}"; var result = Utility.GetData(url, para, Encoding.UTF8); var data = JsonConvert.DeserializeObject>>(result); var model = new LayuiData() { msg = "数据加载成功!", count = data.Data.Count(), code = 0, data = data.Data }; return Json(model, JsonRequestBehavior.AllowGet); } public ActionResult Test() { return View(); } [AuthorizeRedirect(RightsConfig.CONST_广告策划审核, ToolBarConfig.CONST_NotButton, true)] public ActionResult Check(int id) { ViewBag.Id = id; ViewBag.Eid = Eid; ViewBag.UserName = UserName; ViewBag.File_Server = _cache.GetValue_Parameter("File_Server"); var reasons = GetReasonForRejection(); ViewBag.reasons = reasons; var model = _news.Get(x => x.Id == id); if (model.Reason != null && model.Reason > 0) { var reasonList = new Dictionary(); foreach (var reason in reasons) { if ((reason.Key & (int)model.Reason) > 0) { reasonList.Add(reason.Key, reason.Value); } } model.ReasonStr = string.Join(",", reasonList.Values); model.SelectReason = string.Join(",", reasonList.Keys); } ViewBag.Model = model.ToJson(); var list = new List>(); foreach (var item in reasons) { var channel = new Dictionary { { "name", item.Value }, { "value", item.Key.ToString() } }; list.Add(channel); } ViewBag.AllReasons = JsonHelper.ToJson(list); BAS_PARAMETER kewrods = _paramter.GetModel(CRM.Core.Model.Enum.Parameter.WeiXin_IllegalKewords.ToString()); if (model == null) ViewBag.KeyWords = ""; else ViewBag.KeyWords = kewrods.PARAVALUE; return View(); } public class NewsQueryDto { public string newstype { get; set; } public string title { get; set; } public DateTime? newsStartTime { get; set; } public DateTime? newsEndTime { get; set; } public int? status { get; set; } public DateTime? auditStartTime { get; set; } public DateTime? auditEndTime { get; set; } public string channel { get; set; } public int? reason { get; set; } public string createUserName { get; set; } public string auditerName { get; set; } public string remark { get; set; } public bool? IsUpload { get; set; } public int? PageIndex { get; set; } public int? PageSize { get; set; } public string appid { get; set; } public string DepartmentId { get; set; } } public class CmsNewsDto : CMS_News { public string DeptName { get; set; } public string RejectedReason { get; set; } } public class CmsNewsLogDto : CMS_News_Log { public string DeptName { get; set; } public string RejectedReason { get; set; } } public class DeptmentDto { public int Id { get; set; } public string Title { get; set; } public string Code { get; set; } public string Appid { get; set; } public int DepartmentId { get; set; } public bool? IsDept { get; set; } public string CompanyCode { get; set; } public List DeptmentCampains { get; set; } } public class DeptmentCampainDto { public int StartCampainId { get; set; } public int EndCampainId { get; set; } } } }