/// <summary> /// 登录 /// </summary> /// <param name="context"></param> /// <param name="msg"></param> /// <param name="P1">用户名</param> /// <param name="P2">密码(未解码的)</param> /// <param name="UserInfo"></param> public void LOGIN(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo) { string password = context.Request["password"] ?? ""; string username = context.Request["UserName"] ?? ""; string chkcode = context.Request["chkcode"] ?? ""; msg.ErrorMsg = ""; //取消验证码 Weiler //if (context.Session["chkcode"] != null) //{ // if (!chkcode.ToUpper().Equals(context.Session["chkcode"].ToString())) // { // msg.ErrorMsg = "验证码不正确"; // return; // } //} //else //{ // msg.ErrorMsg = "验证码已过期"; // return; //} JH_Auth_QY qyModel = new JH_Auth_QYB().GetALLEntities().First(); password = CommonHelp.GetMD5(password); JH_Auth_User userInfo = new JH_Auth_User(); List <JH_Auth_User> userList = new JH_Auth_UserB().GetEntities(d => (d.UserName == username || d.mobphone == username) && d.UserPass == password).ToList(); if (userList.Count() == 0) { msg.ErrorMsg = "用户名或密码不正确"; return; } else { userInfo = userList[0]; if (userInfo.IsUse != "Y") { msg.ErrorMsg = "用户被禁用,请联系管理员"; return; } if (string.IsNullOrEmpty(userInfo.pccode)) { userInfo.pccode = CommonHelp.CreatePCCode(userInfo); } userInfo.logindate = DateTime.Now; new JH_Auth_UserB().Update(userInfo); msg.Result = userInfo.pccode; msg.Result1 = userInfo.UserName; msg.Result4 = userInfo; } }
/// <summary> /// 注册 /// </summary> /// <param name="context"></param> /// <param name="msg"></param> /// <param name="P1"></param> /// <param name="P2"></param> /// <param name="UserInfo"></param> public void REGISTERNEW(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo) { JObject tt = (JObject)JsonConvert.DeserializeObject(P1); string qyName = tt["QYName"].ToString(); var qy = new JH_Auth_QYB().GetEntity(p => p.QYName == qyName); if (qy != null) { msg.ErrorMsg = "企业名称已存在!"; } if (tt["xm"].ToString() == "") { msg.ErrorMsg = "姓名不能为空!"; } string mobile = tt["mobphone"].ToString(); var qy2 = new JH_Auth_QYB().GetEntities(p => p.Mobile == mobile); if (qy2.Count() > 0) { msg.ErrorMsg = "此手机已注册企业,请更换手机号继续注册"; } if (string.IsNullOrEmpty(msg.ErrorMsg)) { string QyScape = CommonHelp.GetConfig("initSpace").ToString(); //公司初始控件 string password = CommonHelp.GetMD5(tt["UserPass"].ToString()); #region 判断获取不重复的qycode随机code,如果表中存在重复code,while继续获取,否则直接执行下一步 bool flag = true; string qyCode = ""; while (flag == true) { //生成code随机数 Random ran = new Random((int)DateTime.Now.Ticks); qyCode = ran.Next().ToString(); if (new JH_Auth_QYB().GetEntities(p => p.QYCode == qyCode).Count() == 0) { flag = false; continue; } } #endregion string fileUrl = new FileHelp().GetFileServerUrl(qyCode); string userName = mobile; new JH_Auth_UserB().ExsSclarSql("exec RegistCompany '" + tt["QYName"].ToString() + "','" + tt["mobphone"].ToString() + "','" + userName + "','" + password + "','" + qyCode + "','" + fileUrl + "','" + tt["xm"].ToString() + "'," + QyScape); new FileHelp().AddQycode(qyCode, tt["QYName"].ToString()); string content = "您的[" + tt["QYName"].ToString() + "]公司账号已经注册成功:\r\n登录网站: \r\n管理员账号:" + tt["mobphone"].ToString() + "\r\n管理员密码:" + tt["UserPass"].ToString() + "\r\n"; CommonHelp.SendSMS(tt["mobphone"].ToString(), content, 0); string user = context.Request["ID"] ?? ""; } }
public void REGISTERYS(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo) { string strXM = P2; string strPhone = P1; JH_Auth_User user1 = new JH_Auth_UserB().GetUserByUserName(10334, P1); if (user1 != null) { msg.ErrorMsg = "用户已存在"; return; } JH_Auth_User user = new JH_Auth_User(); user.UserName = strPhone; user.mobphone = strPhone; user.UserRealName = P2; user.UserPass = CommonHelp.GetMD5("abc123"); user.ComId = 10334; user.BranchCode = 1728; user.CRDate = DateTime.Now; user.CRUser = "******"; user.logindate = DateTime.Now; user.IsUse = "Y"; if (!new JH_Auth_UserB().Insert(user)) { msg.ErrorMsg = "添加用户失败"; } else { JH_Auth_QY QY = new JH_Auth_QYB().GetEntity(d => d.ComId == 10334); WXHelp wx = new WXHelp(QY); wx.WX_CreateUser(user); //添加默认员工角色 JH_Auth_UserRole Model = new JH_Auth_UserRole(); Model.UserName = user.UserName; Model.RoleCode = 1219; Model.ComId = user.ComId; new JH_Auth_UserRoleB().Insert(Model); } }
/// <summary> /// 从企业微信同步到系统里 /// </summary> /// <param name="context"></param> /// <param name="msg"></param> /// <param name="P1"></param> /// <param name="P2"></param> /// <param name="UserInfo"></param> public void TBTXL(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo) { try { int bmcount = 0; int rycount = 0; if (P1 == "") { msg.ErrorMsg = "请输入初始密码"; return; } WXHelp wx = new WXHelp(UserInfo.QYinfo); #region 更新部门 GetDepartmentListResult bmlist = wx.WX_GetBranchList(""); foreach (var wxbm in bmlist.department.OrderBy(d => d.parentid)) { var bm = new JH_Auth_BranchB().GetEntity(p => p.ComId == UserInfo.User.ComId && p.WXBMCode == wxbm.id); if (bm == null) { #region 新增部门 JH_Auth_Branch jab = new JH_Auth_Branch(); jab.WXBMCode = int.Parse(wxbm.id.ToString()); jab.ComId = UserInfo.User.ComId; jab.DeptName = wxbm.name; jab.DeptDesc = wxbm.name; jab.DeptShort = int.Parse(wxbm.order.ToString()); if (wxbm.parentid == 0)//如果是跟部门,设置其跟部门为-1 { jab.DeptRoot = -1; } else { var bm1 = new JH_Auth_BranchB().GetEntity(p => p.ComId == UserInfo.User.ComId && p.WXBMCode == wxbm.parentid); jab.DeptRoot = bm1.DeptCode; jab.Remark1 = new JH_Auth_BranchB().GetBranchNo(UserInfo.User.ComId.Value, jab.DeptRoot); } new JH_Auth_BranchB().Insert(jab); jab.Remark1 = new JH_Auth_BranchB().GetBranchNo(UserInfo.User.ComId.Value, jab.DeptRoot) + jab.DeptCode; new JH_Auth_BranchB().Update(jab); bmcount = bmcount + 1; #endregion } else { //同步部门时放弃更新现有部门 } } #endregion #region 更新人员 JH_Auth_Branch branchModel = new JH_Auth_BranchB().GetEntity(d => d.DeptRoot == -1 && d.ComId == UserInfo.User.ComId); GetDepartmentMemberInfoResult yg = wx.WX_GetDepartmentMemberInfo(branchModel.WXBMCode.Value); foreach (var u in yg.userlist) { var user = new JH_Auth_UserB().GetUserByUserName(UserInfo.QYinfo.ComId, u.userid); if (user == null) { #region 新增人员 JH_Auth_User jau = new JH_Auth_User(); jau.ComId = UserInfo.User.ComId; jau.UserName = u.userid; jau.UserPass = CommonHelp.GetMD5(P1); jau.UserRealName = u.name; jau.Sex = u.gender == 1 ? "男" : "女"; if (u.department.Length > 0) { int id = int.Parse(u.department[0].ToString()); var bm1 = new JH_Auth_BranchB().GetEntity(p => p.ComId == UserInfo.User.ComId && p.WXBMCode == id); jau.BranchCode = bm1.DeptCode; jau.remark = bm1.Remark1.Split('-')[0];//用户得部门路径 } jau.mailbox = u.email; jau.mobphone = u.mobile; jau.zhiwu = string.IsNullOrEmpty(u.position) ? "员工" : u.position; jau.IsUse = "Y"; if (u.status == 1 || u.status == 4) { jau.isgz = u.status.ToString(); } jau.txurl = u.avatar; new JH_Auth_UserB().Insert(jau); rycount = rycount + 1; #endregion //为所有人增加普通员工的权限 JH_Auth_Role rdefault = new JH_Auth_RoleB().GetEntity(p => p.ComId == UserInfo.User.ComId && p.isSysRole == "Y" && p.RoleName == "员工");//找到默认角色 if (rdefault != null) { JH_Auth_UserRole jaurdefault = new JH_Auth_UserRole(); jaurdefault.ComId = UserInfo.User.ComId; jaurdefault.RoleCode = rdefault.RoleCode; jaurdefault.UserName = jau.UserName; new JH_Auth_UserRoleB().Insert(jaurdefault); } } else { //同步人员时放弃更新现有人员 #region 更新人员 user.UserRealName = u.name; if (u.department.Length > 0) { int id = int.Parse(u.department[0].ToString()); var bm1 = new JH_Auth_BranchB().GetEntity(p => p.ComId == UserInfo.User.ComId && p.WXBMCode == id); user.BranchCode = bm1.DeptCode; } user.mailbox = u.email; user.mobphone = u.mobile; user.zhiwu = string.IsNullOrEmpty(u.position) ? "员工" : u.position; user.Sex = u.gender == 1 ? "男" : "女"; if (u.status == 1 || u.status == 4) { user.IsUse = "Y"; user.isgz = u.status.ToString(); } else if (u.status == 2) { user.IsUse = "N"; } user.txurl = u.avatar; new JH_Auth_UserB().Update(user); #endregion } #region 更新角色(职务) if (!string.IsNullOrEmpty(u.position)) { var r = new JH_Auth_RoleB().GetEntity(p => p.ComId == UserInfo.User.ComId && p.RoleName == u.position); if (r == null) { JH_Auth_Role jar = new JH_Auth_Role(); jar.ComId = UserInfo.User.ComId; jar.RoleName = u.position; jar.RoleDec = u.position; jar.PRoleCode = 0; jar.isSysRole = "N"; jar.IsUse = "Y"; jar.leve = 0; jar.DisplayOrder = 0; new JH_Auth_RoleB().Insert(jar); JH_Auth_UserRole jaur = new JH_Auth_UserRole(); jaur.ComId = UserInfo.User.ComId; jaur.RoleCode = jar.RoleCode; jaur.UserName = u.userid; new JH_Auth_UserRoleB().Insert(jaur); } else { } } #endregion } #endregion msg.Result1 = bmcount; msg.Result2 = rycount; } catch (Exception ex) { msg.ErrorMsg = ex.ToString(); } }
public void SAVEIMPORTUSER(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo) { string branchMsg = "", branchErrorMsg = "", userMsg = ""; int i = 0, j = 0; DataTable dt = new DataTable(); dt = JsonConvert.DeserializeObject <DataTable>(P1); dt.Columns.Add("BranchCode"); JH_Auth_Branch branchroot = new JH_Auth_BranchB().GetEntity(d => d.ComId == UserInfo.User.ComId && d.DeptRoot == -1); foreach (DataRow row in dt.Rows) { int bRootid = branchroot.DeptCode; string branchName = row[4].ToString(); if (branchName != "") { string[] branchNames = branchName.Split('/'); string strBranch = branchNames[0]; JH_Auth_Branch branchModel = new JH_Auth_BranchB().GetEntity(d => d.DeptName == strBranch && d.ComId == UserInfo.User.ComId); if (branchModel == null) { branchModel = new JH_Auth_Branch(); branchModel.DeptName = branchNames[0]; branchModel.DeptDesc = branchNames[0]; branchModel.ComId = UserInfo.User.ComId; branchModel.DeptRoot = bRootid; branchModel.CRDate = DateTime.Now; branchModel.CRUser = UserInfo.User.UserName; new JH_Auth_BranchB().Insert(branchModel); branchModel.Remark1 = new JH_Auth_BranchB().GetBranchNo(UserInfo.User.ComId.Value, branchModel.DeptRoot) + branchModel.DeptCode; new JH_Auth_BranchB().Update(branchModel); } } } int rowIndex = 0; foreach (DataRow row in dt.Rows) { rowIndex++; string branchName = row[4].ToString(); if (branchName != "") { string[] branchNames = branchName.Split('/'); string strPBranch = branchNames[0]; JH_Auth_Branch PbranchModel = new JH_Auth_BranchB().GetEntity(d => d.DeptName == strPBranch && d.ComId == UserInfo.User.ComId); int bRootid = PbranchModel.DeptCode; for (int l = 1; l < branchNames.Length; l++) { string strBranch = branchNames[1]; JH_Auth_Branch branchModel = new JH_Auth_BranchB().GetEntity(d => d.DeptName == strBranch && d.DeptRoot == PbranchModel.DeptCode && d.ComId == UserInfo.User.ComId); if (branchModel != null) { bRootid = branchModel.DeptCode; if (l == branchNames.Length - 1) { row["BranchCode"] = branchModel.DeptCode; } } else { branchModel = new JH_Auth_Branch(); branchModel.DeptName = strBranch; branchModel.DeptDesc = strBranch; branchModel.ComId = UserInfo.User.ComId; branchModel.DeptRoot = bRootid; branchModel.CRDate = DateTime.Now; branchModel.CRUser = UserInfo.User.UserName; new JH_Auth_BranchB().Insert(branchModel); branchModel.Remark1 = new JH_Auth_BranchB().GetBranchNo(UserInfo.User.ComId.Value, branchModel.DeptRoot) + branchModel.DeptCode; new JH_Auth_BranchB().Update(branchModel); try { bRootid = branchModel.DeptCode; if (l == branchNames.Length - 1) { row["BranchCode"] = branchModel.DeptCode; } i++; branchMsg += "新增部门“" + strBranch + "”成功<br/>"; } catch (Exception ex) { branchErrorMsg += "部门:" + strBranch + "失败 " + msg.ErrorMsg + "<br/>"; } } } string userName = row[2].ToString(); JH_Auth_User userModel = new JH_Auth_UserB().GetEntity(d => d.UserName == userName && d.ComId == UserInfo.User.ComId); if (userModel == null) { JH_Auth_User userNew = new JH_Auth_User(); if (row["BranchCode"].ToString() != "") { int tempcode = int.Parse(row["BranchCode"].ToString()); JH_Auth_Branch branchTemp = new JH_Auth_BranchB().GetEntity(d => d.DeptCode == tempcode && d.ComId == UserInfo.User.ComId); userNew.BranchCode = branchTemp.DeptCode; userNew.remark = branchTemp.Remark1.Split('-')[0]; } else { userNew.BranchCode = bRootid; } userNew.ComId = UserInfo.User.ComId; userNew.IsUse = "Y"; userNew.mailbox = row[3].ToString(); userNew.mobphone = row[2].ToString(); userNew.RoomCode = row[7].ToString(); userNew.Sex = row[1].ToString(); userNew.telphone = row[9].ToString(); DateTime result; if (DateTime.TryParse(row[10].ToString(), out result)) { userNew.Birthday = result; } userNew.UserGW = row[6].ToString(); userNew.UserName = row[2].ToString(); userNew.UserRealName = row[0].ToString(); userNew.zhiwu = row[5].ToString() == "" ? "员工" : row[5].ToString(); userNew.UserPass = CommonHelp.GetMD5(P2); userNew.CRDate = DateTime.Now; userNew.CRUser = UserInfo.User.UserName; if (!string.IsNullOrEmpty(row[8].ToString())) { int orderNum = 0; int.TryParse(row[8].ToString(), out orderNum); userNew.UserOrder = orderNum; } try { msg.ErrorMsg = ""; if (string.IsNullOrEmpty(userNew.UserName)) { msg.ErrorMsg = "用户名必填"; } //Regex regexPhone = new Regex("^0?1[3|4|5|8|7][0-9]\\d{8}$"); //if (!regexPhone.IsMatch(userNew.UserName)) //{ // msg.ErrorMsg = "用户名必须为手机号"; //} if (string.IsNullOrEmpty(userNew.mobphone)) { msg.ErrorMsg = "手机号必填"; } //if (!regexPhone.IsMatch(userNew.mobphone)) //{ // msg.ErrorMsg = "手机号填写不正确"; //} Regex regexOrder = new Regex("^[0-9]*$"); if (userNew.UserOrder != null && !regexOrder.IsMatch(userNew.UserOrder.ToString())) { msg.ErrorMsg = "序号必须是数字"; } if (msg.ErrorMsg != "") { userMsg += "第" + rowIndex + "行" + msg.ErrorMsg + "<br/>"; } if (msg.ErrorMsg == "") { new JH_Auth_UserB().Insert(userNew); JH_Auth_Role role = new JH_Auth_RoleB().GetEntity(d => d.RoleName == userNew.zhiwu && d.ComId == UserInfo.User.ComId); if (role == null) { role = new JH_Auth_Role(); role.PRoleCode = 0; role.RoleName = userNew.zhiwu; role.RoleDec = userNew.zhiwu; role.IsUse = "Y"; role.isSysRole = "N"; role.leve = 0; role.ComId = UserInfo.User.ComId; role.DisplayOrder = 0; new JH_Auth_RoleB().Insert(role); } string strSql = string.Format("INSERT into JH_Auth_UserRole (UserName,RoleCode,ComId) Values('{0}',{1},{2})", userNew.UserName, role.RoleCode, UserInfo.User.ComId); new JH_Auth_RoleB().ExsSql(strSql); string isFS = context.Request["issend"] ?? ""; if (isFS.ToLower() == "true") { string content = string.Format("尊敬的" + userNew.UserName + "用户您好:你已被添加到" + UserInfo.QYinfo.QYName + ",账号:" + userNew.mobphone + ",密码" + P2 + ",登录请访问" + UserInfo.QYinfo.WXUrl); new SZHL_DXGLB().SendSMS(userNew.mobphone, content, userNew.ComId.Value); } j++; } } catch (Exception ex) { userMsg += "第" + rowIndex + "行" + msg.ErrorMsg + "<br/>"; } } else { userMsg += "第" + rowIndex + "行" + "用户“" + row[2].ToString() + "”已存在<br/>"; } } else { branchErrorMsg += "第" + rowIndex + "行所在部门必填<br/>"; } } msg.Result = branchErrorMsg + "<br/>" + userMsg; msg.Result1 = "新增部门" + i + "个,新增用户" + j + "个<br/>" + branchMsg + (branchMsg == "" ? "" : "<br/>"); }
/// <summary> /// 绑定手机、姓名、身份证、专卖许可证 /// </summary> public void BINDTOMONOLICENSE(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo) { JH_Auth_User j = JsonConvert.DeserializeObject <JH_Auth_User>(P1); if (j == null) { msg.ErrorMsg = "绑定失败"; return; } if (string.IsNullOrWhiteSpace(j.UserRealName.Trim())) { msg.ErrorMsg = "姓名不能为空"; return; } if (string.IsNullOrWhiteSpace(j.mobphone.Trim())) { msg.ErrorMsg = "手机号不能为空"; return; } if (string.IsNullOrWhiteSpace(j.IDCard.Trim())) { msg.ErrorMsg = "身份证号不能为空"; return; } if (string.IsNullOrWhiteSpace(j.ToMonoLicense.Trim())) { msg.ErrorMsg = "专卖许可证号不能为空"; return; } string _openid = CommonHelp.GetCookieString("openid"); WX_User u = new WX_UserB().GetEntity(d => d.Openid == _openid); msg.Result = u; if (u != null) { JH_Auth_User localuser = new JH_Auth_UserB().GetEntity(d => d.mobphone == j.mobphone.Trim()); if (localuser == null) { new JH_Auth_UserB().ExsSql("update JH_Auth_User set WXopenid='', IsWX=0, IDCard='',ToMonoLicense='' where WXopenid='" + _openid + "'");//清除以前绑定的用户 //新用户,随机生成 localuser = new JH_Auth_User(); localuser.UserName = "******" + Guid.NewGuid().ToString().Replace("-", "").Substring(0, 16); localuser.UserRealName = j.UserRealName.Trim(); localuser.UserPass = CommonHelp.GetMD5("a123456"); localuser.pccode = EncrpytHelper.Encrypt(localuser.UserName + "@" + localuser.UserPass + "@" + DateTime.Now.ToString("yyyy-MM-dd HH:mm")); localuser.ComId = 10334; localuser.Sex = u.Sex; localuser.mobphone = j.mobphone.Trim(); localuser.BranchCode = 0; localuser.CRDate = localuser.logindate = DateTime.Now; localuser.CRUser = "******"; localuser.IsUse = "Y"; localuser.IsWX = 1; localuser.WXopenid = _openid; localuser.weixinCard = j.weixinCard.Trim(); localuser.IDCard = j.IDCard.Trim(); localuser.ToMonoLicense = j.ToMonoLicense.Trim(); new JH_Auth_UserB().Insert(localuser); WXFWHelp.UpdateCookieAfterSignIn(localuser); msg.Result = localuser; //msg.ErrorMsg = "手机号不存在,请联系管理员"; return; } else { //老用户 if (localuser.UserRealName == j.UserRealName.Trim()) { new JH_Auth_UserB().ExsSql("update JH_Auth_User set WXopenid='', IsWX=0, IDCard='',ToMonoLicense='' where WXopenid='" + _openid + "'");//清除以前绑定的用户 localuser.WXopenid = _openid; localuser.IsWX = 1; localuser.weixinCard = j.weixinCard.Trim(); //localuser.pccode = EncrpytHelper.Encrypt(localuser.UserName + "@" + localuser.UserPass + "@" + DateTime.Now.ToString("yyyy-MM-dd HH:mm")); localuser.logindate = DateTime.Now; localuser.IDCard = j.IDCard.Trim(); localuser.ToMonoLicense = j.ToMonoLicense.Trim(); new JH_Auth_UserB().Update(localuser);//更新logindate,pccode不能更新 WXFWHelp.UpdateCookieAfterSignIn(localuser); msg.Result = localuser; } else { msg.ErrorMsg = "姓名与手机号不匹配"; return; } } } else { msg.ErrorMsg = "微信登录异常"; return; } }