fix: update GetUserByPhone API

This commit is contained in:
AnonymousDotNet 2024-11-11 13:40:21 +08:00
parent d3053d3fec
commit e2e8f23df1

View file

@ -15,21 +15,15 @@ public partial class MongoRepository
public User? GetUserByPhone(string phone, string regionCode = "CN")
{
string phoneSecond = string.Empty;
// 如果电话号码长度小于 4直接返回 null
if (phone?.Length < 4)
if (phone == null || phone.Length < 4)
{
return null;
}
if (phone.Substring(0, 3) != "+86")
{
phoneSecond = $"+86{phone}";
}
else
{
phoneSecond = phone.Replace("+86", "");
}
var user = _dc.Users.AsQueryable().FirstOrDefault(x => (x.Phone == phone || x.Phone == phoneSecond) && x.Type != UserType.Affiliate && x.RegionCode == regionCode);
string phoneSecond = phone.StartsWith("+86") ? phone.Replace("+86", "") : $"+86{phone}";
//var user = _dc.Users.AsQueryable().FirstOrDefault(x => (x.Phone == phone || x.Phone == phoneSecond) && x.Type != UserType.Affiliate && x.RegionCode == regionCode);
var user = _dc.Users.AsQueryable().FirstOrDefault(x => (x.Phone == phone || x.Phone == phoneSecond) && x.Type != UserType.Affiliate && (x.RegionCode == regionCode || x.RegionCode == null));
return user != null ? user.ToUser() : null;
}