11
This commit is contained in:
parent
e06422ab06
commit
a5df8efa17
@ -174,14 +174,21 @@ public class AppUserService : BaseService<AppUserEntity>, ITransient
|
|||||||
throw Oops.Bah("当前用户未关联单位,无法进行操作");
|
throw Oops.Bah("当前用户未关联单位,无法进行操作");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 手机号为空时,跳过基于手机号的重复检测(单位添加运动员时,联系电话非必填)
|
||||||
|
var mobileIsEmpty = string.IsNullOrWhiteSpace(input.Mobile);
|
||||||
|
|
||||||
// 先检查是否存在相同手机号且相同类型的运动员在其他单位
|
// 先检查是否存在相同手机号且相同类型的运动员在其他单位
|
||||||
var existingInOtherUnit = await _appUserRep.AsQueryable()
|
AppUserEntity? existingInOtherUnit = null;
|
||||||
|
if (!mobileIsEmpty)
|
||||||
|
{
|
||||||
|
existingInOtherUnit = await _appUserRep.AsQueryable()
|
||||||
.Where(x => x.Mobile == input.Mobile
|
.Where(x => x.Mobile == input.Mobile
|
||||||
&& x.PersonType == input.PersonType
|
&& x.PersonType == input.PersonType
|
||||||
&& x.MerchantCertificationId != merchantCertificationId
|
&& x.MerchantCertificationId != merchantCertificationId
|
||||||
&& x.MerchantCertificationId != null
|
&& x.MerchantCertificationId != null
|
||||||
&& !x.DeleteMark)
|
&& !x.DeleteMark)
|
||||||
.FirstAsync();
|
.FirstAsync();
|
||||||
|
}
|
||||||
|
|
||||||
AppUserEntity? entity = null;
|
AppUserEntity? entity = null;
|
||||||
bool isUnitTransfer = false;
|
bool isUnitTransfer = false;
|
||||||
@ -198,12 +205,16 @@ public class AppUserService : BaseService<AppUserEntity>, ITransient
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// 检查是否存在相同手机号但还未加入任何单位的记录(小程序注册的用户)
|
// 检查是否存在相同手机号但还未加入任何单位的记录(小程序注册的用户)
|
||||||
var existingWithoutUnit = await _appUserRep.AsQueryable()
|
AppUserEntity? existingWithoutUnit = null;
|
||||||
|
if (!mobileIsEmpty)
|
||||||
|
{
|
||||||
|
existingWithoutUnit = await _appUserRep.AsQueryable()
|
||||||
.Where(x => x.Mobile == input.Mobile
|
.Where(x => x.Mobile == input.Mobile
|
||||||
&& x.PersonType == input.PersonType
|
&& x.PersonType == input.PersonType
|
||||||
&& x.MerchantCertificationId == null
|
&& x.MerchantCertificationId == null
|
||||||
&& !x.DeleteMark)
|
&& !x.DeleteMark)
|
||||||
.FirstAsync();
|
.FirstAsync();
|
||||||
|
}
|
||||||
|
|
||||||
if (existingWithoutUnit != null)
|
if (existingWithoutUnit != null)
|
||||||
{
|
{
|
||||||
@ -225,6 +236,9 @@ public class AppUserService : BaseService<AppUserEntity>, ITransient
|
|||||||
entity = await _appUserRep.GetByIdAsync(input.Id.Value);
|
entity = await _appUserRep.GetByIdAsync(input.Id.Value);
|
||||||
if (entity == null || entity.DeleteMark) throw Oops.Bah("成员不存在");
|
if (entity == null || entity.DeleteMark) throw Oops.Bah("成员不存在");
|
||||||
|
|
||||||
|
// 手机号为空时,不进行手机号重复检测
|
||||||
|
if (!mobileIsEmpty)
|
||||||
|
{
|
||||||
// 检查手机号是否被本单位内同类型的其他记录占用
|
// 检查手机号是否被本单位内同类型的其他记录占用
|
||||||
var duplicateInSameUnit = await _appUserRep.AsQueryable()
|
var duplicateInSameUnit = await _appUserRep.AsQueryable()
|
||||||
.Where(x => x.Mobile == input.Mobile
|
.Where(x => x.Mobile == input.Mobile
|
||||||
@ -238,13 +252,16 @@ public class AppUserService : BaseService<AppUserEntity>, ITransient
|
|||||||
{
|
{
|
||||||
throw Oops.Bah($"该手机号在本单位已存在相同类型的成员");
|
throw Oops.Bah($"该手机号在本单位已存在相同类型的成员");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
entity.UpdatedUserId = _authManager.UserId;
|
entity.UpdatedUserId = _authManager.UserId;
|
||||||
entity.UpdatedTime = DateTime.Now;
|
entity.UpdatedTime = DateTime.Now;
|
||||||
}
|
}
|
||||||
else if (isNewRecord)
|
else if (isNewRecord)
|
||||||
{
|
{
|
||||||
// 新增模式:检查本单位内是否有相同手机号且相同类型的记录
|
// 新增模式:手机号不为空时,检查本单位内是否有相同手机号且相同类型的记录
|
||||||
|
if (!mobileIsEmpty)
|
||||||
|
{
|
||||||
var existingInSameUnit = await _appUserRep.AsQueryable()
|
var existingInSameUnit = await _appUserRep.AsQueryable()
|
||||||
.Where(x => x.Mobile == input.Mobile
|
.Where(x => x.Mobile == input.Mobile
|
||||||
&& x.PersonType == input.PersonType
|
&& x.PersonType == input.PersonType
|
||||||
@ -257,6 +274,7 @@ public class AppUserService : BaseService<AppUserEntity>, ITransient
|
|||||||
// 本单位内已有相同手机号且相同类型的记录,不允许重复添加
|
// 本单位内已有相同手机号且相同类型的记录,不允许重复添加
|
||||||
throw Oops.Bah($"该手机号在本单位已存在相同类型的成员");
|
throw Oops.Bah($"该手机号在本单位已存在相同类型的成员");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 新增记录
|
// 新增记录
|
||||||
entity = new AppUserEntity
|
entity = new AppUserEntity
|
||||||
@ -270,14 +288,9 @@ public class AppUserService : BaseService<AppUserEntity>, ITransient
|
|||||||
AuditStatus = AuditStatus.PendingSubmission
|
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 cacheKey = $"sms:code:{input.Mobile}";
|
||||||
var cachedCodeResult = _cachingProvider.Get<string>(cacheKey);
|
var cachedCodeResult = _cachingProvider.Get<string>(cacheKey);
|
||||||
string? cachedCode = cachedCodeResult.Value;
|
string? cachedCode = cachedCodeResult.Value;
|
||||||
|
|||||||
@ -198,11 +198,10 @@ public class CreateOrUpdateMemberInput
|
|||||||
public int? Age { get; set; }
|
public int? Age { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 联系电话
|
/// 联系电话(非必填,有值时校验手机号格式)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Required(ErrorMessage = "联系电话不能为空")]
|
|
||||||
[RegularExpression(@"^1[3456789]\d{9}$", ErrorMessage = "手机号格式不正确")]
|
[RegularExpression(@"^1[3456789]\d{9}$", ErrorMessage = "手机号格式不正确")]
|
||||||
public string Mobile { get; set; }
|
public string? Mobile { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 技能等级(教练特有)
|
/// 技能等级(教练特有)
|
||||||
|
|||||||
@ -82,9 +82,6 @@ public class ProjectService : BaseService<YD_Event.Core.Entities.Project>, ITran
|
|||||||
[UnitOfWork]
|
[UnitOfWork]
|
||||||
public async Task Add(AddProjectInput input)
|
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>();
|
var entity = input.Adapt<YD_Event.Core.Entities.Project>();
|
||||||
entity.Id = _idGenerator.NewLong();
|
entity.Id = _idGenerator.NewLong();
|
||||||
entity.CreatedTime = DateTime.Now;
|
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);
|
var entity = await _repository.GetByIdAsync(input.Id);
|
||||||
if (entity == null) throw new InvalidOperationException("项目不存在");
|
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);
|
input.Adapt(entity);
|
||||||
entity.UpdatedTime = DateTime.Now;
|
entity.UpdatedTime = DateTime.Now;
|
||||||
await _repository.UpdateAsync(entity);
|
await _repository.UpdateAsync(entity);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user