This commit is contained in:
马梓彭 2026-06-04 14:23:50 +08:00
parent e06422ab06
commit a5df8efa17
3 changed files with 57 additions and 54 deletions

View File

@ -174,14 +174,21 @@ public class AppUserService : BaseService<AppUserEntity>, ITransient
throw Oops.Bah("当前用户未关联单位,无法进行操作");
}
// 手机号为空时,跳过基于手机号的重复检测(单位添加运动员时,联系电话非必填)
var mobileIsEmpty = string.IsNullOrWhiteSpace(input.Mobile);
// 先检查是否存在相同手机号且相同类型的运动员在其他单位
var existingInOtherUnit = await _appUserRep.AsQueryable()
.Where(x => x.Mobile == input.Mobile
&& x.PersonType == input.PersonType
&& x.MerchantCertificationId != merchantCertificationId
&& x.MerchantCertificationId != null
&& !x.DeleteMark)
.FirstAsync();
AppUserEntity? existingInOtherUnit = null;
if (!mobileIsEmpty)
{
existingInOtherUnit = await _appUserRep.AsQueryable()
.Where(x => x.Mobile == input.Mobile
&& x.PersonType == input.PersonType
&& x.MerchantCertificationId != merchantCertificationId
&& x.MerchantCertificationId != null
&& !x.DeleteMark)
.FirstAsync();
}
AppUserEntity? entity = null;
bool isUnitTransfer = false;
@ -198,12 +205,16 @@ public class AppUserService : BaseService<AppUserEntity>, ITransient
else
{
// 检查是否存在相同手机号但还未加入任何单位的记录(小程序注册的用户)
var existingWithoutUnit = await _appUserRep.AsQueryable()
.Where(x => x.Mobile == input.Mobile
&& x.PersonType == input.PersonType
&& x.MerchantCertificationId == null
&& !x.DeleteMark)
.FirstAsync();
AppUserEntity? existingWithoutUnit = null;
if (!mobileIsEmpty)
{
existingWithoutUnit = await _appUserRep.AsQueryable()
.Where(x => x.Mobile == input.Mobile
&& x.PersonType == input.PersonType
&& x.MerchantCertificationId == null
&& !x.DeleteMark)
.FirstAsync();
}
if (existingWithoutUnit != null)
{
@ -225,18 +236,22 @@ public class AppUserService : BaseService<AppUserEntity>, ITransient
entity = await _appUserRep.GetByIdAsync(input.Id.Value);
if (entity == null || entity.DeleteMark) throw Oops.Bah("成员不存在");
// 检查手机号是否被本单位内同类型的其他记录占用
var duplicateInSameUnit = await _appUserRep.AsQueryable()
.Where(x => x.Mobile == input.Mobile
&& x.PersonType == input.PersonType
&& x.MerchantCertificationId == merchantCertificationId
&& !x.DeleteMark
&& x.Id != input.Id.Value)
.FirstAsync();
if (duplicateInSameUnit != null)
// 手机号为空时,不进行手机号重复检测
if (!mobileIsEmpty)
{
throw Oops.Bah($"该手机号在本单位已存在相同类型的成员");
// 检查手机号是否被本单位内同类型的其他记录占用
var duplicateInSameUnit = await _appUserRep.AsQueryable()
.Where(x => x.Mobile == input.Mobile
&& x.PersonType == input.PersonType
&& x.MerchantCertificationId == merchantCertificationId
&& !x.DeleteMark
&& x.Id != input.Id.Value)
.FirstAsync();
if (duplicateInSameUnit != null)
{
throw Oops.Bah($"该手机号在本单位已存在相同类型的成员");
}
}
entity.UpdatedUserId = _authManager.UserId;
@ -244,18 +259,21 @@ public class AppUserService : BaseService<AppUserEntity>, ITransient
}
else if (isNewRecord)
{
// 新增模式:检查本单位内是否有相同手机号且相同类型的记录
var existingInSameUnit = await _appUserRep.AsQueryable()
.Where(x => x.Mobile == input.Mobile
&& x.PersonType == input.PersonType
&& x.MerchantCertificationId == merchantCertificationId
&& !x.DeleteMark)
.FirstAsync();
if (existingInSameUnit != null)
// 新增模式:手机号不为空时,检查本单位内是否有相同手机号且相同类型的记录
if (!mobileIsEmpty)
{
// 本单位内已有相同手机号且相同类型的记录,不允许重复添加
throw Oops.Bah($"该手机号在本单位已存在相同类型的成员");
var existingInSameUnit = await _appUserRep.AsQueryable()
.Where(x => x.Mobile == input.Mobile
&& x.PersonType == input.PersonType
&& x.MerchantCertificationId == merchantCertificationId
&& !x.DeleteMark)
.FirstAsync();
if (existingInSameUnit != null)
{
// 本单位内已有相同手机号且相同类型的记录,不允许重复添加
throw Oops.Bah($"该手机号在本单位已存在相同类型的成员");
}
}
// 新增记录
@ -270,14 +288,9 @@ public class AppUserService : BaseService<AppUserEntity>, ITransient
AuditStatus = AuditStatus.PendingSubmission
};
// 仅在真正新增运动员时验证验证码
if (input.PersonType == PersonType.Athlete)
// 单位添加运动员时,验证码改为非必填;仅在手机号+验证码均存在时才校验
if (input.PersonType == PersonType.Athlete && !mobileIsEmpty && !string.IsNullOrWhiteSpace(input.VerificationCode))
{
if (string.IsNullOrWhiteSpace(input.VerificationCode))
{
throw Oops.Bah("验证码不能为空");
}
var cacheKey = $"sms:code:{input.Mobile}";
var cachedCodeResult = _cachingProvider.Get<string>(cacheKey);
string? cachedCode = cachedCodeResult.Value;

View File

@ -198,11 +198,10 @@ public class CreateOrUpdateMemberInput
public int? Age { get; set; }
/// <summary>
/// 联系电话
/// 联系电话(非必填,有值时校验手机号格式)
/// </summary>
[Required(ErrorMessage = "联系电话不能为空")]
[RegularExpression(@"^1[3456789]\d{9}$", ErrorMessage = "手机号格式不正确")]
public string Mobile { get; set; }
public string? Mobile { get; set; }
/// <summary>
/// 技能等级(教练特有)

View File

@ -82,9 +82,6 @@ public class ProjectService : BaseService<YD_Event.Core.Entities.Project>, ITran
[UnitOfWork]
public async Task Add(AddProjectInput input)
{
var isExist = await _repository.IsAnyAsync(x => x.Name == input.Name);
if (isExist) throw new InvalidOperationException("该项目名称已存在");
var entity = input.Adapt<YD_Event.Core.Entities.Project>();
entity.Id = _idGenerator.NewLong();
entity.CreatedTime = DateTime.Now;
@ -115,12 +112,6 @@ public class ProjectService : BaseService<YD_Event.Core.Entities.Project>, ITran
var entity = await _repository.GetByIdAsync(input.Id);
if (entity == null) throw new InvalidOperationException("项目不存在");
if (entity.Name != input.Name)
{
var isExist = await _repository.IsAnyAsync(x => x.Name == input.Name && x.Id != input.Id);
if (isExist) throw new InvalidOperationException("该项目名称已存在");
}
input.Adapt(entity);
entity.UpdatedTime = DateTime.Now;
await _repository.UpdateAsync(entity);