/// <summary> /// 根据手机号码查询用户编号 /// </summary> /// <param name="UserID"></param> /// <returns></returns> public string GetUserIDByMobile(string Mobile, EnumUserType userType) { var GetUserIDByMobile_CacheKey = new XuHos.Common.Cache.Keys.StringCacheKey(XuHos.Common.Cache.Keys.StringCacheKeyType.MAP_GetUserIDByMobile, $"{Mobile}:{userType}"); var UserID = GetUserIDByMobile_CacheKey.FromCache <string>(); //缓存没有命中,则查询数据库获取医生编号并设置缓存(缓存不过期) if (string.IsNullOrEmpty(UserID)) { using (var db = new DBEntities()) { //TODO:这里需要优惠如果不是手机号码类型不需要这样查询 string currentUserID = ""; if (userType == EnumUserType.User) { currentUserID = db.Users.Where(p => p.IsDeleted == false && (p.Mobile == Mobile) && (p.UserType == EnumUserType.User || p.UserType == EnumUserType.Drugstore)).Select(t => t.UserID).FirstOrDefault(); //避免使用Or条件而采用次查询 if (string.IsNullOrEmpty(currentUserID)) { currentUserID = db.Users.Where(p => p.IsDeleted == false && (p.UserAccount == Mobile) && (p.UserType == EnumUserType.User || p.UserType == EnumUserType.Drugstore)).Select(t => t.UserID).FirstOrDefault(); } } else { currentUserID = db.Users.Where(p => p.IsDeleted == false && (p.Mobile == Mobile) && p.UserType == userType).Select(t => t.UserID).FirstOrDefault(); //避免使用Or条件而采用次查询 if (string.IsNullOrEmpty(currentUserID)) { currentUserID = db.Users.Where(p => p.IsDeleted == false && (p.UserAccount == Mobile) && p.UserType == userType).Select(t => t.UserID).FirstOrDefault(); } } if (!string.IsNullOrEmpty(currentUserID)) { UserID = currentUserID; } else { //避免缓存穿透问题,有新用户注册时需要更新此缓存 UserID = ""; } UserID.ToCache(GetUserIDByMobile_CacheKey, TimeSpan.FromMinutes(_GetUserInfoExpireMinutes())); } } return(UserID); }
/// <summary> /// 检查验证码是否正确 /// </summary> /// <param name="VerifyCode"></param> /// <param name="appToken"></param> /// <returns></returns> public bool CheckVerifyCode(string VerifyCode, string VerifyCodeID) { var CacheKey = new XuHos.Common.Cache.Keys.StringCacheKey(XuHos.Common.Cache.Keys.StringCacheKeyType.VerifyCode, VerifyCodeID); var value = CacheKey.FromCache <string>(); CacheKey.RemoveCache(); if (value != VerifyCode.Trim()) { return(false); } else { return(true); } }
int?_GetLoginFaildCount(string account) { var CacheKey = new XuHos.Common.Cache.Keys.StringCacheKey(XuHos.Common.Cache.Keys.StringCacheKeyType.User_AccountLoginFail, account); return(CacheKey.FromCache <int?>()); }