public static JsonModel<string> AccountVerifyOnly(AccountSingleParam parameter) { JsonModel<string> jsonModel = new JsonModel<string>() { Success = false, ErrMsg = "", SuccessMsg = "验证成功" }; //验证登录名 if (!BllUtility.AccountHandler.VerifyOnly(new AccountSingleParam() { LoginName = parameter.LoginName })) { jsonModel.ErrMsg = "用户名已经存在"; return jsonModel; }; if (!string.IsNullOrEmpty(parameter.Mobile)) { if (!DotNet.Utils.Untility.RegexValidate.IsMobileNumber(parameter.Mobile)) { jsonModel.ErrMsg = "手机号码格式不正确"; return jsonModel; } if (!BllUtility.AccountHandler.VerifyOnly(new AccountSingleParam() { Mobile = parameter.Mobile })) { jsonModel.ErrMsg = "手机号码已经存在"; return jsonModel; }; } if (!string.IsNullOrEmpty(parameter.Email)) { if (!DotNet.Utils.Untility.RegexValidate.IsEmailAddress(parameter.Email)) { jsonModel.ErrMsg = "Email格式不正确"; return jsonModel; } if (!BllUtility.AccountHandler.VerifyOnly(new AccountSingleParam() { Email = parameter.Email })) { jsonModel.ErrMsg = "邮箱已经存在"; return jsonModel; }; } jsonModel.Success = true; return jsonModel; }
/// <summary> /// 根据帐号的类型和帐号的输入内容,获取帐号的查询参数 /// </summary> /// <param name="loginType"></param> /// <param name="loginStr"></param> /// <returns></returns> public static AccountSingleParam GetLoginTypeParam(int loginType, string loginStr) { //过滤 loginStr = DotNet.Utils.Untility.StringHelper.FilterHtml(loginStr); AccountSingleParam param = new AccountSingleParam() { AccountId = 0 }; switch (loginType) { case (int)LoginTypeEnum.LoginName: param = new AccountSingleParam() { LoginName = loginStr }; break; case (int)LoginTypeEnum.LoginMobile: param = new AccountSingleParam() { Mobile = loginStr }; break; case (int)LoginTypeEnum.LoginEmail: param = new AccountSingleParam() { Email = loginStr }; break; } return param; }
/// <summary> /// 根据唯一参数,判断是否存在帐号 /// </summary> /// <param name="parameter"></param> /// <returns></returns> public Account CheckExist(AccountSingleParam parameter) { using (var connection = ConnectionFactory.GetMasterSql()) { StringBuilder sb = new StringBuilder(); sb.AppendFormat(" 1>2 "); DynamicParameters param = new DynamicParameters(); param.Add("@DelFlag", (int)DelFlagEnum.Noraml); //OpenId if (!string.IsNullOrEmpty(parameter.OpenId)) { sb.AppendFormat(" or OpenId=@OpenId"); param.Add("@OpenId", parameter.OpenId); } //登录名检测 if (!string.IsNullOrEmpty(parameter.LoginName)) { sb.AppendFormat(" or LoginName=@LoginName"); param.Add("@LoginName", parameter.LoginName); } //手机号码检测 if (!string.IsNullOrEmpty(parameter.Mobile)) { sb.AppendFormat(" or (Mobile=@Mobile and MobileBinding=@MobileBinding)"); param.Add("@Mobile", parameter.Mobile); param.Add("@MobileBinding", (int)BindingEnum.Binded); } //Email邮箱 if (!string.IsNullOrEmpty(parameter.Email)) { sb.AppendFormat(" or (Email=@Email and EmailBinding=@EmailBinding)"); param.Add("@Email", parameter.Email); param.Add("@EmailBinding", (int)BindingEnum.Binded); } string sql = string.Format(@"Select * from B_Account where DelFlag=@DelFlag and ( {0} )", sb.ToString()); var query = connection.Query<Account>(sql, param); return query.FirstOrDefault(); } }
/// <summary> /// 添加帐户 /// </summary> /// <param name="entity"></param> /// <returns></returns> public Account AddEntity(Account entity) { try { using (var connection = ConnectionFactory.GetMasterSql()) { AccountSingleParam singleParam = new AccountSingleParam() { OpenId=entity.OpenId, LoginName=entity.LoginName }; string sql = @"Insert into B_Account values(@OpenId,@LoginName,@EncryptKey,@Password,@SafePassword,@SafeBinding,@Mobile,@MobileBinding,@Email,@EmailBinding,@DelFlag,@ReMark,@CreateDate,@SubmitDomainId);select @@identity;"; var id = connection.ExecuteScalar<int>(sql, new { OpenId = entity.OpenId, LoginName = entity.LoginName, EncryptKey = entity.EncryptKey, Password = entity.Password, SafePassword = entity.SafePassword, SafeBinding = entity.SafeBinding, Mobile = entity.Mobile, MobileBinding = entity.MobileBinding, Email = entity.Email, EmailBinding = entity.EmailBinding, DelFlag = entity.DelFlag, ReMark = entity.ReMark, CreateDate = entity.CreateDate, SubmitDomainId = entity.SubmitDomainId }); var account = connection.Query<Account>(@"Select * from B_Account where AccountId=@AccountId", new { AccountId = id }).FirstOrDefault(); return account; } } catch { return null; } }
/// <summary> /// 检测是否唯一 /// </summary> /// <param name="parameter"></param> /// <returns></returns> public static bool VerifyOnly(AccountSingleParam parameter) { IAccountDal accountDal = new AccountDal(); var account = accountDal.GetEntity(parameter); if (account == null || account.AccountId <= 0) { return true; } return false; }
/// <summary> /// 根据唯一条件查询帐号 /// </summary> /// <param name="parameter"></param> /// <returns></returns> public Account GetAccount(AccountSingleParam parameter) { //过滤 parameter.OpenId = DotNet.Utils.Untility.StringHelper.FilterHtml(parameter.OpenId); parameter.LoginName = DotNet.Utils.Untility.StringHelper.FilterHtml(parameter.LoginName); parameter.Mobile = DotNet.Utils.Untility.StringHelper.FilterHtml(parameter.Mobile); parameter.Email = DotNet.Utils.Untility.StringHelper.FilterHtml(parameter.Email); IAccountDal accountDal = new AccountDal(); var account = accountDal.GetEntity(parameter); return account; }
/// <summary> /// 查询唯一的帐号实体 /// </summary> /// <param name="parameter"></param> /// <returns></returns> public Account GetEntity(AccountSingleParam parameter) { using (var connection = ConnectionFactory.GetMasterSql()) { StringBuilder sb = new StringBuilder(); DynamicParameters param = new DynamicParameters(); param.Add("@DelFlag", (int)DelFlagEnum.Noraml); //根据Id查询 if (parameter.AccountId > 0) { sb.AppendFormat(" and AccountId=@AccountId "); param.Add("@AccountId", parameter.AccountId); } //根据OpenId查询 if (!string.IsNullOrEmpty(parameter.OpenId)) { sb.AppendFormat(" and OpenId=@OpenId "); param.Add("@OpenId", parameter.OpenId); } //登录帐号进行查询 if (!string.IsNullOrEmpty(parameter.LoginName)) { sb.AppendFormat(" and LoginName=@LoginName "); param.Add("@LoginName", parameter.LoginName); } //手机号码查询 if (!string.IsNullOrEmpty(parameter.Mobile)) { sb.AppendFormat(" and Mobile=@Mobile and MobileBinding=@MobileBinding"); param.Add("@Mobile", parameter.Mobile); param.Add("@MobileBinding", (int)BindingEnum.Binded); } //Email邮箱查询 if (!string.IsNullOrEmpty(parameter.Email)) { sb.AppendFormat(" and Email=@Email and EmailBinding=@EmailBinding"); param.Add("@Email", parameter.Email); param.Add("@EmailBinding", (int)BindingEnum.Binded); } string sql = string.Format(@"Select * from B_Account where DelFlag=@DelFlag {0}", sb.ToString()); var query = connection.Query<Account>(sql, param); return query.FirstOrDefault(); } }