using Core.Web.App_Start; using Core.Web.WebHelper; using CRM.Core.BLL.Base; using CRM.Core.BLL.Util; 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 CRM.Core.Model.Map; using CRM.Core.Model.QueryModels; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Linq; using System.Security.Cryptography; using System.Text; using System.Web.Mvc; using WX.CRM.Common; using WX.CRM.Common.Employee; namespace Core.Web.Controllers { public class InnerUserController : BaseController { // GET: InnerUser [AuthorizeRedirect(RightsConfig.CONST_员工管理, ToolBarConfig.CONST_NotButton, true)] public ActionResult Index() { ViewBag.rightCode = RightsConfig.CONST_员工管理; ViewBag.rolelist = GetRole_List(); return View(); } [AuthorizeRedirect(RightsConfig.CONST_员工管理, ToolBarConfig.CONST_NotButton, false)] public JsonResult GetList(Laypage pager, string name, int? isdismiss, int? roleId) { var list = new BAS_INNERUSER_BL().GetList(ref pager, name, isdismiss, roleId); var data = new LayuiData() { msg = "数据加载成功!", count = pager.count, code = 0, data = list }; return Json(data, JsonRequestBehavior.AllowGet); } [AuthorizeRedirect(RightsConfig.CONST_员工管理, ToolBarConfig.CONST_Add, true)] public ActionResult Add() { return View(); } ValidationErrors errors = new ValidationErrors(); [AuthorizeRedirect(RightsConfig.CONST_员工管理, ToolBarConfig.CONST_Add, false)] public JsonResult Save(BAS_INNERUSER model) { model.ISDISMISS = 0; model.CTIME = DateTime.Now; model.CREATEUSER = Eid; model.ISHIDE = 0; decimal eid = new BAS_INNERUSER_BL().Create(ref errors, model); return JsonResult(errors); } [AuthorizeRedirect(RightsConfig.CONST_员工管理, ToolBarConfig.CONST_Delete, false)] public JsonResult Delete(int id) { bool result = new BAS_INNERUSER_BL().Delete(ref errors, id, Convert.ToInt32(UserId)); return JsonResult(errors); } /// /// 编辑 /// /// [AuthorizeRedirect(RightsConfig.CONST_员工管理, ToolBarConfig.CONST_Edit, true)] public ActionResult Edit(int id) { var model = new BAS_INNERUSER_BL().GetModel(id); ViewBag.ModelJson = JsonHelper.ObjDivertToJson(model); return View(); } [AuthorizeRedirect(RightsConfig.CONST_员工管理, ToolBarConfig.CONST_Edit, false)] public JsonResult EditSave(BAS_INNERUSER model) { model.UTIME = DateTime.Now; model.UPDATEUSER = Eid; bool eid = new BAS_INNERUSER_BL().Update(ref errors, model); return JsonResult(errors); } #region 获取角色下拉列表 /// /// 获取角色下拉 /// /// private List GetRole_List() { List retmsg = new BAS_ROLE_BL().GetList(); List list = new List(); list.Add(new SelectListItem() { Text = "--请选择--", Value = "0" }); foreach (BAS_ROLE m in retmsg) { list.Add(new SelectListItem() { Text = m.RNAME, Value = m.ROLEID.ToString() }); } return list; } #endregion //[AuthorizeRedirect(RightsConfig.CONST_员工角色管理, ToolBarConfig.CONST_Other1, true)] [AuthorizeRedirect(RightsConfig.CONST_员工管理, ToolBarConfig.CONST_Other1, true)] public ActionResult Set(int id) { List roleids = new BAS_INNERUSERROLE_BL().GetInneruserRoleByUserId(id).Select(m => m.ROLEID).ToList(); if (roleids.Count > 0) { ViewBag.roleids = "[" + string.Join("][", roleids) + "]"; } else { ViewBag.roleids = ""; } return View(); } [HttpPost] //[AuthorizeRedirect(RightsConfig.CONST_员工角色管理, ToolBarConfig.CONST_Other1, false)] [AuthorizeRedirect(RightsConfig.CONST_员工管理, ToolBarConfig.CONST_Other1, false)] public JsonResult SetSave(string roleIds, string eids) { if (string.IsNullOrEmpty(eids)) return Json(new retMsg { result = false, retmsg = "验证不通过!" }, JsonRequestBehavior.AllowGet); bool ret = new BAS_INNERUSERROLE_BL().Save(ref errors, UserId, roleIds, eids); return JsonResult(errors); } /// /// 修改密码 /// public ActionResult changepwd() { return View(); } /// /// 修改密码 /// /// /// public ActionResult ChangePwdSave(string PASSWORD) { var apiResult = ChangeThirdPassWord(Eid, PASSWORD); if (apiResult.Ret != 0) { errors.Add($"工号【{Eid}】修改密码失败,失败原因【{apiResult.Msg}】,请到员工系统进行核对"); return JsonResult(errors); } bool ret = new BAS_INNERUSER_BL().PwdUpdate(ref errors, PASSWORD, UserId, Eid); return JsonResult(errors); } /// /// 修改sso密码 /// /// public SSORequest.SsoResponse ChangeThirdPassWord(decimal eid, string passWord) { var authToken = HttpContext.Request.Cookies.Get("AuthToken")?.Value; var ssoUrl = System.Configuration.ConfigurationManager.AppSettings["SSOUrl"]; var appid = System.Configuration.ConfigurationManager.AppSettings["appid"]; // if (string.IsNullOrEmpty(ssoUrl) || string.IsNullOrEmpty(appid)) { LogHelper.Error($"请配置相关sso密钥配置【{ssoUrl}】【{appid}】"); throw new Exception("请配置相关sso密钥配置"); } Dictionary param = new Dictionary(); ssoUrl = ssoUrl + "/v1/api/open/sso/changePassword"; var md5PassWord = Utility.EncryptMD5(passWord); param.Add("employeeId", eid.ToString()); param.Add("password", md5PassWord); try { var headers = new Dictionary(); var timestamps = GetTimeStamp(); var sign = GetSign(param, timestamps); var authorization = $"{appid}:{sign}"; headers.Add("authorization", authorization); headers.Add("timestamps", timestamps); var result = Utility.PostAjaxData(ssoUrl, JsonHelper.ObjDivertToJson(param), headers, System.Text.Encoding.UTF8); var response = JsonHelper.JsonDivertToObj>(result); return response; } catch (Exception ex) { return new SSORequest.SsoResponse { Ret = -1, Msg = ex.Message }; } } [HttpGet] public JsonResult Sync() { var ret = new retMsg { result = true, retcode = 200 }; CACHE_BL cache_BL = new CACHE_BL(); var url = cache_BL.GetValue_Parameter(Parameter.Hg_Core_WebApi_SyncSsoOrganization); Dictionary dic = new Dictionary(); string AppId = Utility.GetSettingByKey("appId");//坐席的appid string Secret = Utility.GetSettingByKey("appSecret");//坐席的appid的密钥 ApiDockHelper dock = new ApiDockHelper(AppId, Secret); ApiResult model = dock.GetApi(url, dic); if (model.code != 0 || !model.data) { ret = new retMsg { result = false, retcode = 200, retmsg = "同步失败!" + model.msg }; } return Json(ret, JsonRequestBehavior.AllowGet); } /// /// 计算 md5 /// /// /// public string _md5(string enCode) { string res = ""; byte[] data = Encoding.GetEncoding("utf-8").GetBytes(enCode); MD5 md5 = new MD5CryptoServiceProvider(); byte[] bytes = md5.ComputeHash(data); for (int i = 0; i < bytes.Length; i++) { res += bytes[i].ToString("x2"); } return res; } /// /// 计算签名 /// /// /// /// private string GetSign(Dictionary param, string timestamps) { var appSecret = System.Configuration.ConfigurationManager.AppSettings["appSecret"]; var appid = System.Configuration.ConfigurationManager.AppSettings["appid"]; //一次排序 var newP = param.OrderBy(m => m.Key).ToDictionary(m => m.Key, n => n.Value); var pJosn = JsonConvert.SerializeObject(newP, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });//去除null值数据 //二次排序 var enStrList = new string[] { appid, pJosn, appSecret, timestamps }; Array.Sort(enStrList, string.CompareOrdinal); //拼接 var enStr = string.Join("", enStrList); //md5 加密 return Utility.EncryptMD5(enStr); } /// /// 获取时间戳 /// /// private string GetTimeStamp() { TimeSpan ts = DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0); return Convert.ToInt64(ts.TotalSeconds).ToString(); } } }