273 lines
10 KiB
C#
273 lines
10 KiB
C#
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<Bas_Inneruser_List>()
|
|
{
|
|
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);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 编辑
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[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 获取角色下拉列表
|
|
|
|
/// <summary>
|
|
/// 获取角色下拉
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private List<SelectListItem> GetRole_List()
|
|
{
|
|
List<BAS_ROLE> retmsg = new BAS_ROLE_BL().GetList();
|
|
|
|
List<SelectListItem> list = new List<SelectListItem>();
|
|
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<int> 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);
|
|
}
|
|
/// <summary>
|
|
/// 修改密码
|
|
/// </summary>
|
|
public ActionResult changepwd()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 修改密码
|
|
/// </summary>
|
|
/// <param name="PASSWORD"></param>
|
|
/// <returns></returns>
|
|
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);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 修改sso密码
|
|
/// </summary>
|
|
/// <param name="model"></param>
|
|
public SSORequest.SsoResponse<string> 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<string, object> param = new Dictionary<string, object>();
|
|
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<string, string>();
|
|
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<SSORequest.SsoResponse<string>>(result);
|
|
return response;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new SSORequest.SsoResponse<string> { 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<string, object> dic = new Dictionary<string, object>();
|
|
string AppId = Utility.GetSettingByKey("appId");//坐席的appid
|
|
string Secret = Utility.GetSettingByKey("appSecret");//坐席的appid的密钥
|
|
ApiDockHelper dock = new ApiDockHelper(AppId, Secret);
|
|
ApiResult<bool> model = dock.GetApi<bool>(url, dic);
|
|
if (model.code != 0 || !model.data)
|
|
{
|
|
ret = new retMsg { result = false, retcode = 200, retmsg = "同步失败!" + model.msg };
|
|
}
|
|
return Json(ret, JsonRequestBehavior.AllowGet);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 计算 md5
|
|
/// </summary>
|
|
/// <param name="enCode"></param>
|
|
/// <returns></returns>
|
|
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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 计算签名
|
|
/// </summary>
|
|
/// <param name="param"></param>
|
|
/// <param name="timestamps"></param>
|
|
/// <returns></returns>
|
|
private string GetSign(Dictionary<string, object> 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);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取时间戳
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private string GetTimeStamp()
|
|
{
|
|
TimeSpan ts = DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0);
|
|
return Convert.ToInt64(ts.TotalSeconds).ToString();
|
|
}
|
|
}
|
|
} |