using Core.Web.Models; using Core.Web.WebHelper; using Core.Web.WebHelper.UserRight; using CRM.Core.BLL.Base; using CRM.Core.BLL.Csvr; using CRM.Core.BLL.Util; using CRM.Core.Model.Entity; using CRM.Core.Model.Enum; using CRM.Core.Model.Map; using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using WX.CRM.Common; namespace Core.Web.Controllers { public class HomeController : BaseController { private Csvr_Message_Type_BL _msgtype = new Csvr_Message_Type_BL(); private Csvr_Message_BL _msg = new Csvr_Message_BL(); private CACHE_BL cache_BL = new CACHE_BL(); // GET: Home public ActionResult Index() { HttpCookie cookie = Request.Cookies["AuthToken"]; //var AuthToken = HttpContext.Response.Cookies.Get("AuthToken"); //if (cookie == null) //{ // return Redirect("/Account/LogOff");//跳转回登录界面 //} ViewBag.AuthToken = cookie==null?"": cookie.Value;//token接收 string[] rights = UserRightsHelper.getUserRightsCodes(); var alllist = new BAS_PERMISSION_BL().Get_BasPerMissionList(); List modelist = alllist.Where(m => m.PRENTID == 0 && m.ISFORBIDDEN == 0 && m.ISHIDDEN == 0 && rights.Contains(m.CODE)).OrderBy(m => m.SORT).ToList();//主要菜单 //List modelist = new List(); List leftModelist = alllist.Where(m => m.PRENTID > 0 && m.ISFORBIDDEN == 0 && m.ISHIDDEN == 0 && rights.Contains(m.CODE)).ToList(); string[] rightid = userRightId; decimal modulId = 0; string title = ""; if (rightid != null) { if (modelist.Count > 0) { modulId = modelist[0].ID; title = modelist[0].NAME; } //leftModelist = new BAS_LEFTMEMU_BL().GetBas_LeftMenuList();//----------先不要缓存 } List menu = leftModelist.Where(m => m.TYPE == 2).ToList();//二级菜单 foreach (Bas_Permisson item in menu) { if (item.CODE == "LYJL")//如果是聊天室 { item.URL = GenerateCmsLiaoTianShiUrl(); } item.childList = GetChildMenu(leftModelist, item); } ViewBag.MainMenu = modelist; ViewBag.LeftMenu = menu; ViewBag.ChooseID = modulId; ViewBag.Title = title; ViewBag.Eid = Eid; ViewBag.Name = UserName; ViewBag.MessageType = _msgtype.GetList(m => m.status == 1).OrderBy(m => m.sort).ToList(); ViewBag.hgServiceHost = cache_BL.GetValue_Parameter("HgCrm_ServiceHost"); ViewBag.HgCoreWebApi = cache_BL.GetValue_Parameter(Parameter.Hg_Core_WebApi); ViewBag.Fjh = Fjh; ViewBag.User = new { Eid, UserId, UserName, url = ViewBag.HgCoreWebApi + "/hub" }.ToJson(); LogHelper.Info($"登录成功, {UserName}({Eid})"); return View(); } private SecurityHelper sHelper = new SecurityHelper(); /// /// 生成聊天室地址 /// /// public string GenerateCmsLiaoTianShiUrl() { string clientid = cache_BL.GetValue_Parameter(Parameter.Sys_OrderClientIdKey); if (string.IsNullOrWhiteSpace(clientid)) { clientid = "UPWEBSITE"; } var moGo2Url = new MoGo2Url { eid = Eid, url = "/admin/systems/exchangesystem/list.aspx", time = DateTime.Now }; string content = sHelper.encyptData(clientid, Utility.ConvertToJSON(moGo2Url)); string sign = sHelper.signData(clientid, content); string url = cache_BL.GetValue_Parameter(Parameter.CMSLiuYanConfig); return $"{url}?clientid={clientid}&content={HttpUtility.UrlEncode(content)}&sign={HttpUtility.UrlEncode(sign)}"; //ViewBag.Url = $"http://admin.test.dn8188.com:188/tools/go2url.html?clientid={clientid}&content={HttpUtility.UrlEncode(content)}&sign={HttpUtility.UrlEncode(sign)}"; } /// /// 获取子菜单 /// /// public List GetChildMenu(List alllist, Bas_Permisson nowmodel) { List menu = alllist.Where(m => m.PRENTID == nowmodel.ID).ToList();//二级菜单 if (menu == null) return null; foreach (var item in menu) { if (item.CODE == "LYJL")//如果是聊天室 { item.URL = GenerateCmsLiaoTianShiUrl(); } item.childList = GetChildMenu(alllist, item); } return menu; } public ActionResult LeftMenu(Bas_Permisson menu) { ViewBag.MenuInfo = menu; return View(); } public ActionResult WelCome() { return View(); } public ActionResult FengKun() { return View(); } public ActionResult Cache() { var list = new List() { "cache_Parameter_getList", "cache_Company_getList", "cache_Company_Code", "cache_comapny_virtual", "cache_comapny_wework", "cache_LeftMemu_getList", "cache_wx_szzyproduct", "cache_wx_szzysubproduct", "cache_smsSubTypeList", "cache_smsClientList" }; foreach (var item in list) { CacheHelper.Remove(item); } return View(); } /// /// 界面的按钮界面 /// /// 权限Code /// 其他按钮参数集合 色彩集合: /// layui-btn-warm:黄色 /// layui-btn-danger:红色 /// layui-btn-disabled:禁用 /// layui-btn-primary:原始白色 /// layui-btn-normal:蓝色 /// /// public ActionResult ToolBar(string rightcode, ToolBar[] otherToolBars) { //这里可以将Tool进行数据过滤 ViewBag.rightcode = rightcode; ViewBag.buttonId = UserRightsHelper.getRightButtonId(rightcode); ViewBag.toolBars = otherToolBars; return View(); } /// /// 获取消息 /// /// public JsonResult GetNewMessage(int maxid) { try { var list = new List(); if (maxid == 0) { //首次查找, //最近两天数据 DateTime nowtime = DateTime.Now; DateTime time = new DateTime(nowtime.Year, nowtime.Month, nowtime.Day).AddDays(-3);//未读所有数据,已读3天数据 DateTime time2 = new DateTime(nowtime.Year, nowtime.Month, nowtime.Day).AddDays(-5);//已读的保留5天数据 list = _msg.GetList(m => m.eid == Eid && m.id > maxid && ((m.islook == 1 && m.ctime > time) || (m.islook == 0 && m.ctime >= time2))).OrderBy(M => M.id).ToList(); } else { list = _msg.GetList(m => m.eid == Eid && m.id > maxid).OrderBy(M => M.id).ToList(); } return Json(new { result = true, data = list }); } catch (Exception e) { return Json(new { result = false, msg = "错误:" + e.Message }); } } public JsonResult LookMsg(int id) { try { var entry = _msg.Get(m => m.eid == Eid && m.id == id); if (entry == null) { return Json(new { result = false, msg = "参数错误!" }); } if (entry.islook == 1) return Json(new { result = false, msg = "已经读了!" }); entry.islook = 1; entry.looktime = DateTime.Now; _msg.Update(entry); return Json(new { result = true, msg = "查看成功!" }); } catch (Exception e) { return Json(new { result = false, msg = "错误:" + e.Message }); } } //public JsonResult qd(string s,int t = 0) //{ // return Json(new BAS_ROLERIGHTRESOURCE_BL().QueryData(s, t), JsonRequestBehavior.AllowGet); //} } }