2026-03-08 15:46:19 +08:00
|
|
|
|
using YD_Event.Application.Event.Dtos;
|
2026-04-09 09:09:50 +08:00
|
|
|
|
using YD_Event.Application.Auth;
|
2026-02-08 18:09:05 +08:00
|
|
|
|
using YD_Event.Core.Entities;
|
|
|
|
|
|
using MiniExcelLibs;
|
|
|
|
|
|
|
2026-03-08 15:46:19 +08:00
|
|
|
|
namespace YD_Event.Application.Event;
|
2026-02-08 18:09:05 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 报名管理服务
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public class EventRegistrationService : BaseService<EventRegistration>, ITransient
|
|
|
|
|
|
{
|
|
|
|
|
|
private readonly ISqlSugarRepository<EventRegistration> _repository;
|
|
|
|
|
|
private readonly ISqlSugarRepository<EventRegistrationItem> _itemRepository;
|
|
|
|
|
|
private readonly ISqlSugarRepository<EventRegistrationPerson> _personRepository;
|
|
|
|
|
|
private readonly ISqlSugarRepository<EventRegistrationPayment> _paymentRepository;
|
2026-04-13 06:58:21 +08:00
|
|
|
|
private readonly ISqlSugarRepository<YD_Event.Core.Entities.Order> _orderRepository;
|
2026-04-14 17:30:20 +08:00
|
|
|
|
private readonly ISqlSugarRepository<TeamMember> _teamMemberRepository;
|
|
|
|
|
|
private readonly ISqlSugarRepository<YD_Event.Core.Entities.AppUser> _appUserRepository;
|
2026-04-09 09:09:50 +08:00
|
|
|
|
private readonly AuthManager _authManager;
|
2026-02-08 18:09:05 +08:00
|
|
|
|
|
|
|
|
|
|
public EventRegistrationService(
|
|
|
|
|
|
ISqlSugarRepository<EventRegistration> repository,
|
|
|
|
|
|
ISqlSugarRepository<EventRegistrationItem> itemRepository,
|
|
|
|
|
|
ISqlSugarRepository<EventRegistrationPerson> personRepository,
|
2026-04-09 09:09:50 +08:00
|
|
|
|
ISqlSugarRepository<EventRegistrationPayment> paymentRepository,
|
2026-04-13 06:58:21 +08:00
|
|
|
|
ISqlSugarRepository<YD_Event.Core.Entities.Order> orderRepository,
|
2026-04-14 17:30:20 +08:00
|
|
|
|
ISqlSugarRepository<TeamMember> teamMemberRepository,
|
|
|
|
|
|
ISqlSugarRepository<YD_Event.Core.Entities.AppUser> appUserRepository,
|
2026-04-09 09:09:50 +08:00
|
|
|
|
AuthManager authManager) : base(repository)
|
2026-02-08 18:09:05 +08:00
|
|
|
|
{
|
|
|
|
|
|
_repository = repository;
|
|
|
|
|
|
_itemRepository = itemRepository;
|
|
|
|
|
|
_personRepository = personRepository;
|
|
|
|
|
|
_paymentRepository = paymentRepository;
|
2026-04-13 06:58:21 +08:00
|
|
|
|
_orderRepository = orderRepository;
|
2026-04-14 17:30:20 +08:00
|
|
|
|
_teamMemberRepository = teamMemberRepository;
|
|
|
|
|
|
_appUserRepository = appUserRepository;
|
2026-04-09 09:09:50 +08:00
|
|
|
|
_authManager = authManager;
|
2026-02-08 18:09:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 分页查询报名
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[DisplayName("分页查询报名")]
|
|
|
|
|
|
public async Task<PageResult<RegistrationListOutput>> Page(RegistrationQueryInput input)
|
|
|
|
|
|
{
|
|
|
|
|
|
var query = _repository.AsQueryable()
|
|
|
|
|
|
.WhereIF(input.EventId.HasValue, x => x.EventId == input.EventId)
|
|
|
|
|
|
.WhereIF(input.RegistrationMode.HasValue, x => x.RegistrationMode == input.RegistrationMode)
|
|
|
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.UnitName), x => x.TeamName.Contains(input.UnitName))
|
|
|
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.UserName), x => x.ContactName.Contains(input.UserName))
|
|
|
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.ContactPhone), x => x.ContactPhone.Contains(input.ContactPhone))
|
|
|
|
|
|
.WhereIF(input.IsUploadMaterial.HasValue, x => (input.IsUploadMaterial.Value ? !string.IsNullOrEmpty(x.MaterialUrl) : string.IsNullOrEmpty(x.MaterialUrl)))
|
|
|
|
|
|
.WhereIF(input.PaymentMethod.HasValue, x => x.PaymentMethod == input.PaymentMethod)
|
|
|
|
|
|
.WhereIF(input.PaymentStatus.HasValue, x => x.PaymentStatus == input.PaymentStatus)
|
|
|
|
|
|
.WhereIF(input.RegistrationTimeStart.HasValue, x => x.RegistrationTime >= input.RegistrationTimeStart)
|
|
|
|
|
|
.WhereIF(input.RegistrationTimeEnd.HasValue, x => x.RegistrationTime <= input.RegistrationTimeEnd)
|
|
|
|
|
|
.OrderByDescending(x => x.RegistrationTime)
|
|
|
|
|
|
.Select(x => new RegistrationListOutput
|
|
|
|
|
|
{
|
|
|
|
|
|
Id = x.Id,
|
|
|
|
|
|
RegistrationMode = x.RegistrationMode,
|
|
|
|
|
|
UnitName = x.TeamName,
|
|
|
|
|
|
ContactName = x.ContactName,
|
|
|
|
|
|
ContactPhone = x.ContactPhone,
|
|
|
|
|
|
TotalPersonCount = x.TotalPersonCount,
|
|
|
|
|
|
IsUploadMaterial = !string.IsNullOrEmpty(x.MaterialUrl),
|
|
|
|
|
|
PaymentMethod = x.PaymentMethod,
|
2026-04-13 13:23:00 +08:00
|
|
|
|
PaymentMethodType = x.PaymentMethodType,
|
2026-02-08 18:09:05 +08:00
|
|
|
|
OrderNo = x.OrderNo,
|
|
|
|
|
|
TotalAmount = x.TotalAmount,
|
|
|
|
|
|
PaymentStatus = x.PaymentStatus,
|
|
|
|
|
|
PaymentProofUrl = x.PaymentProofUrl,
|
2026-04-09 23:12:51 +08:00
|
|
|
|
RegistrationTime = x.RegistrationTime
|
2026-02-08 18:09:05 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
var result = await query.ToPagedListAsync(input);
|
|
|
|
|
|
|
|
|
|
|
|
// 填充下拉详情
|
|
|
|
|
|
if (result.Rows.Any())
|
|
|
|
|
|
{
|
|
|
|
|
|
var regIds = result.Rows.Select(x => x.Id).ToList();
|
|
|
|
|
|
var items = await _itemRepository.GetListAsync(x => regIds.Contains(x.RegistrationId));
|
2026-04-13 05:20:09 +08:00
|
|
|
|
// 使用关联查询获取报名人员及其关联的用户信息
|
|
|
|
|
|
var persons = await _personRepository.AsQueryable()
|
|
|
|
|
|
.Includes(p => p.User) // 关联查询用户信息
|
|
|
|
|
|
.Where(x => regIds.Contains(x.RegistrationId))
|
|
|
|
|
|
.ToListAsync();
|
2026-02-08 18:09:05 +08:00
|
|
|
|
|
2026-04-14 17:30:20 +08:00
|
|
|
|
// 获取所有报名人员的 UserId
|
|
|
|
|
|
var allAthleteUserIds = persons
|
|
|
|
|
|
.Where(p => p.PersonType == YD_Event.Core.Enum.PersonType.Athlete && p.UserId > 0)
|
|
|
|
|
|
.Select(p => p.UserId)
|
|
|
|
|
|
.Distinct()
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
|
|
// 步骤1:通过运动员的 UserId 找到对应的 TeamId
|
|
|
|
|
|
var teamIds = new List<long>();
|
|
|
|
|
|
if (allAthleteUserIds.Any())
|
|
|
|
|
|
{
|
|
|
|
|
|
teamIds = await _teamMemberRepository.AsQueryable()
|
|
|
|
|
|
.Where(tm => allAthleteUserIds.Contains(tm.UserId) && !tm.DeleteMark)
|
|
|
|
|
|
.Select(tm => tm.TeamId)
|
|
|
|
|
|
.Distinct()
|
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 步骤2:通过 TeamId 获取同团队的教练/领队的 UserId,并获取用户详情
|
|
|
|
|
|
Dictionary<long, List<YD_Event.Core.Entities.AppUser>> teamLeadersDict = new();
|
|
|
|
|
|
Dictionary<long, List<YD_Event.Core.Entities.AppUser>> teamCoachesDict = new();
|
|
|
|
|
|
|
|
|
|
|
|
if (teamIds.Any())
|
|
|
|
|
|
{
|
|
|
|
|
|
var teamMembers = await _teamMemberRepository.AsQueryable()
|
|
|
|
|
|
.Where(tm => teamIds.Contains(tm.TeamId) && !tm.DeleteMark)
|
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
|
|
|
|
|
|
|
var coachLeaderUserIds = teamMembers
|
|
|
|
|
|
.Where(tm => tm.PersonType == YD_Event.Core.Enum.PersonType.Leader ||
|
|
|
|
|
|
tm.PersonType == YD_Event.Core.Enum.PersonType.Coach)
|
|
|
|
|
|
.Select(tm => tm.UserId)
|
|
|
|
|
|
.Distinct()
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
|
|
if (coachLeaderUserIds.Any())
|
|
|
|
|
|
{
|
|
|
|
|
|
var coachLeaderUsers = await _appUserRepository.AsQueryable()
|
|
|
|
|
|
.Where(u => coachLeaderUserIds.Contains(u.Id) && !u.DeleteMark)
|
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
|
|
|
|
|
|
|
var userDict = coachLeaderUsers.ToDictionary(u => u.Id);
|
|
|
|
|
|
|
|
|
|
|
|
// 按团队分组
|
|
|
|
|
|
foreach (var teamId in teamIds)
|
|
|
|
|
|
{
|
|
|
|
|
|
var teamLeaders = teamMembers
|
|
|
|
|
|
.Where(tm => tm.TeamId == teamId && tm.PersonType == YD_Event.Core.Enum.PersonType.Leader)
|
|
|
|
|
|
.Select(tm => userDict.TryGetValue(tm.UserId, out var user) ? user : null)
|
|
|
|
|
|
.Where(u => u != null)
|
|
|
|
|
|
.Cast<YD_Event.Core.Entities.AppUser>()
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
|
|
var teamCoaches = teamMembers
|
|
|
|
|
|
.Where(tm => tm.TeamId == teamId && tm.PersonType == YD_Event.Core.Enum.PersonType.Coach)
|
|
|
|
|
|
.Select(tm => userDict.TryGetValue(tm.UserId, out var user) ? user : null)
|
|
|
|
|
|
.Where(u => u != null)
|
|
|
|
|
|
.Cast<YD_Event.Core.Entities.AppUser>()
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
|
|
if (teamLeaders.Any())
|
|
|
|
|
|
teamLeadersDict[teamId] = teamLeaders;
|
|
|
|
|
|
|
|
|
|
|
|
if (teamCoaches.Any())
|
|
|
|
|
|
teamCoachesDict[teamId] = teamCoaches;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-08 18:09:05 +08:00
|
|
|
|
foreach (var dto in result.Rows)
|
|
|
|
|
|
{
|
|
|
|
|
|
var myItems = items.Where(x => x.RegistrationId == dto.Id).ToList();
|
|
|
|
|
|
dto.Items = new List<RegistrationItemDetailDto>();
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var item in myItems)
|
|
|
|
|
|
{
|
|
|
|
|
|
var myPersons = persons.Where(p => p.RegistrationItemId == item.Id).ToList();
|
|
|
|
|
|
|
2026-04-15 14:28:22 +08:00
|
|
|
|
// 构造参与人信息字符串,统一格式为:姓名/性别/年龄/手机号
|
2026-04-13 05:20:09 +08:00
|
|
|
|
var personInfo = string.Join(";", myPersons.Select(p =>
|
|
|
|
|
|
{
|
2026-04-13 13:23:00 +08:00
|
|
|
|
// 将性别转换为中文显示
|
|
|
|
|
|
var genderText = p.Gender switch
|
|
|
|
|
|
{
|
|
|
|
|
|
YD_Event.Core.Enum.Gender.Male => "男",
|
|
|
|
|
|
YD_Event.Core.Enum.Gender.Female => "女",
|
|
|
|
|
|
_ => "未知"
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2026-04-15 14:28:22 +08:00
|
|
|
|
// 获取手机号,优先使用关联用户信息,否则使用自身的 Phone 字段
|
|
|
|
|
|
var mobile = p.User?.Mobile ?? p.Phone ?? "";
|
|
|
|
|
|
|
|
|
|
|
|
// 统一格式:姓名/性别/年龄/手机号
|
|
|
|
|
|
return $"{p.Name}/{genderText}/{p.Age}/{mobile}";
|
2026-04-13 05:20:09 +08:00
|
|
|
|
}));
|
2026-02-08 18:09:05 +08:00
|
|
|
|
if (personInfo.Length > 100) personInfo = personInfo.Substring(0, 97) + "..."; // 截断
|
|
|
|
|
|
|
|
|
|
|
|
var detail = new RegistrationItemDetailDto
|
|
|
|
|
|
{
|
|
|
|
|
|
ProjectName = item.ProjectName,
|
|
|
|
|
|
GroupName = item.GroupName,
|
|
|
|
|
|
ParticipantInfo = personInfo
|
|
|
|
|
|
};
|
|
|
|
|
|
dto.Items.Add(detail);
|
|
|
|
|
|
}
|
2026-04-13 13:23:00 +08:00
|
|
|
|
|
2026-04-14 17:30:20 +08:00
|
|
|
|
// 设置领队信息和教练信息 - 从团队中获取
|
2026-04-13 13:23:00 +08:00
|
|
|
|
var regPersons = persons.Where(p => p.RegistrationId == dto.Id).ToList();
|
2026-04-14 17:30:20 +08:00
|
|
|
|
var regAthleteUserIds = regPersons
|
|
|
|
|
|
.Where(p => p.PersonType == YD_Event.Core.Enum.PersonType.Athlete && p.UserId > 0)
|
|
|
|
|
|
.Select(p => p.UserId)
|
|
|
|
|
|
.Distinct()
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
|
|
// 获取这些运动员所属的团队
|
|
|
|
|
|
var regTeamIds = new List<long>();
|
|
|
|
|
|
if (regAthleteUserIds.Any())
|
|
|
|
|
|
{
|
|
|
|
|
|
regTeamIds = await _teamMemberRepository.AsQueryable()
|
|
|
|
|
|
.Where(tm => regAthleteUserIds.Contains(tm.UserId) && !tm.DeleteMark)
|
|
|
|
|
|
.Select(tm => tm.TeamId)
|
|
|
|
|
|
.Distinct()
|
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 收集所有相关团队的领队和教练
|
|
|
|
|
|
var allLeaders = new List<YD_Event.Core.Entities.AppUser>();
|
|
|
|
|
|
var allCoaches = new List<YD_Event.Core.Entities.AppUser>();
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var teamId in regTeamIds)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (teamLeadersDict.TryGetValue(teamId, out var leaders))
|
|
|
|
|
|
allLeaders.AddRange(leaders);
|
|
|
|
|
|
if (teamCoachesDict.TryGetValue(teamId, out var coaches))
|
|
|
|
|
|
allCoaches.AddRange(coaches);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 去重
|
|
|
|
|
|
allLeaders = allLeaders.GroupBy(l => l.Id).Select(g => g.First()).ToList();
|
|
|
|
|
|
allCoaches = allCoaches.GroupBy(c => c.Id).Select(g => g.First()).ToList();
|
|
|
|
|
|
|
|
|
|
|
|
// 如果从团队中没有找到,再回退到从报名人员中查找
|
|
|
|
|
|
if (!allLeaders.Any())
|
|
|
|
|
|
{
|
|
|
|
|
|
var regLeaders = regPersons.Where(p => p.PersonType == YD_Event.Core.Enum.PersonType.Leader).ToList();
|
|
|
|
|
|
allLeaders = regLeaders.Select(l => new YD_Event.Core.Entities.AppUser
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = l.Name,
|
|
|
|
|
|
Mobile = l.Phone,
|
|
|
|
|
|
Gender = l.Gender
|
|
|
|
|
|
}).ToList();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!allCoaches.Any())
|
|
|
|
|
|
{
|
|
|
|
|
|
var regCoaches = regPersons.Where(p => p.PersonType == YD_Event.Core.Enum.PersonType.Coach).ToList();
|
|
|
|
|
|
allCoaches = regCoaches.Select(c => new YD_Event.Core.Entities.AppUser
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = c.Name,
|
|
|
|
|
|
Mobile = c.Phone,
|
|
|
|
|
|
Gender = c.Gender
|
|
|
|
|
|
}).ToList();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 辅助函数:获取性别文本
|
|
|
|
|
|
Func<YD_Event.Core.Enum.Gender, string> getGenderText = (gender) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
return gender switch
|
|
|
|
|
|
{
|
|
|
|
|
|
YD_Event.Core.Enum.Gender.Male => "男",
|
|
|
|
|
|
YD_Event.Core.Enum.Gender.Female => "女",
|
|
|
|
|
|
_ => "未知"
|
|
|
|
|
|
};
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
dto.TeamLeaderInfo = allLeaders.Any()
|
2026-04-14 23:34:16 +08:00
|
|
|
|
? string.Join(",", allLeaders.Select(l => $"{l.Name}/{getGenderText(l.Gender)}/{l.Mobile}"))
|
2026-04-13 13:23:00 +08:00
|
|
|
|
: null;
|
|
|
|
|
|
|
2026-04-14 17:30:20 +08:00
|
|
|
|
dto.CoachInfo = allCoaches.Any()
|
2026-04-14 23:34:16 +08:00
|
|
|
|
? string.Join(",", allCoaches.Select(c => $"{c.Name}/{getGenderText(c.Gender)}/{c.Mobile}"))
|
2026-04-13 13:23:00 +08:00
|
|
|
|
: null;
|
2026-02-08 18:09:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 批量审核
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[UnitOfWork]
|
|
|
|
|
|
[DisplayName("批量审核")]
|
|
|
|
|
|
public async Task BatchAudit(BatchAuditInput input)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (input.Ids == null || !input.Ids.Any()) return;
|
|
|
|
|
|
|
2026-04-13 06:58:21 +08:00
|
|
|
|
// 更新报名记录的支付状态
|
2026-02-08 18:09:05 +08:00
|
|
|
|
await _repository.UpdateAsync(x => new EventRegistration
|
|
|
|
|
|
{
|
2026-04-09 23:12:51 +08:00
|
|
|
|
PaymentStatus = input.PaymentStatus,
|
2026-02-08 18:09:05 +08:00
|
|
|
|
ReviewRemark = input.ReviewRemark,
|
|
|
|
|
|
ReviewTime = DateTime.Now
|
|
|
|
|
|
}, x => input.Ids.Contains(x.Id));
|
2026-04-13 06:58:21 +08:00
|
|
|
|
|
|
|
|
|
|
// 如果审核通过(PaymentStatus = 1),同步更新相关订单的状态为已支付
|
|
|
|
|
|
if (input.PaymentStatus == 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
// 获取需要更新的报名记录
|
|
|
|
|
|
var registrations = await _repository.GetListAsync(x => input.Ids.Contains(x.Id));
|
|
|
|
|
|
|
|
|
|
|
|
// 提取所有订单号
|
|
|
|
|
|
var orderNos = registrations
|
|
|
|
|
|
.Where(r => !string.IsNullOrEmpty(r.OrderNo))
|
|
|
|
|
|
.Select(r => r.OrderNo)
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
|
|
if (orderNos.Any())
|
|
|
|
|
|
{
|
|
|
|
|
|
var now = DateTime.Now;
|
|
|
|
|
|
// 更新相关订单的状态为已支付
|
|
|
|
|
|
await _orderRepository.UpdateAsync(x => new YD_Event.Core.Entities.Order
|
|
|
|
|
|
{
|
|
|
|
|
|
OrderStatus = YD_Event.Core.Enum.OrderStatus.Paid,
|
|
|
|
|
|
PaymentTime = now,
|
|
|
|
|
|
UpdatedTime = now,
|
|
|
|
|
|
UpdatedUserId = _authManager.UserId
|
|
|
|
|
|
}, x => orderNos.Contains(x.OrderNo));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-02-08 18:09:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 导出报名
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[DisplayName("导出报名")]
|
|
|
|
|
|
public async Task<byte[]> Export(RegistrationQueryInput input)
|
|
|
|
|
|
{
|
|
|
|
|
|
var list = await _repository.AsQueryable()
|
|
|
|
|
|
.WhereIF(input.EventId.HasValue, x => x.EventId == input.EventId)
|
|
|
|
|
|
.WhereIF(input.RegistrationMode.HasValue, x => x.RegistrationMode == input.RegistrationMode)
|
|
|
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.UnitName), x => x.TeamName.Contains(input.UnitName))
|
|
|
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.UserName), x => x.ContactName.Contains(input.UserName))
|
|
|
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.ContactPhone), x => x.ContactPhone.Contains(input.ContactPhone))
|
|
|
|
|
|
.WhereIF(input.PaymentStatus.HasValue, x => x.PaymentStatus == input.PaymentStatus)
|
|
|
|
|
|
.Select(x => new
|
|
|
|
|
|
{
|
|
|
|
|
|
x.RegistrationMode,
|
|
|
|
|
|
x.TeamName,
|
|
|
|
|
|
x.ContactName,
|
|
|
|
|
|
x.ContactPhone,
|
|
|
|
|
|
x.TotalPersonCount,
|
|
|
|
|
|
x.PaymentMethod,
|
|
|
|
|
|
x.TotalAmount,
|
|
|
|
|
|
x.PaymentStatus,
|
2026-04-09 23:12:51 +08:00
|
|
|
|
x.RegistrationTime
|
2026-02-08 18:09:05 +08:00
|
|
|
|
})
|
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
|
|
|
|
|
|
|
using var stream = new MemoryStream();
|
|
|
|
|
|
stream.SaveAs(list);
|
|
|
|
|
|
return stream.ToArray();
|
|
|
|
|
|
}
|
2026-03-08 15:46:19 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取素材下载链接
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[DisplayName("获取素材下载链接")]
|
2026-03-19 23:36:06 +08:00
|
|
|
|
public async Task<List<string>> MaterialUrls(List<long> ids)
|
2026-03-08 15:46:19 +08:00
|
|
|
|
{
|
|
|
|
|
|
if (ids == null || !ids.Any()) return new List<string>();
|
|
|
|
|
|
|
|
|
|
|
|
return await _repository.AsQueryable()
|
|
|
|
|
|
.Where(x => ids.Contains(x.Id) && !string.IsNullOrEmpty(x.MaterialUrl))
|
|
|
|
|
|
.Select(x => x.MaterialUrl)
|
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
|
}
|
2026-04-09 09:09:50 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 单条支付审核
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[UnitOfWork]
|
|
|
|
|
|
[DisplayName("单条支付审核")]
|
|
|
|
|
|
public async Task PaymentAudit(PaymentAuditInput input)
|
|
|
|
|
|
{
|
|
|
|
|
|
var registration = await _repository.GetByIdAsync(input.RegistrationId);
|
|
|
|
|
|
if (registration == null) throw Oops.Bah("报名记录不存在");
|
|
|
|
|
|
|
|
|
|
|
|
if (registration.PaymentStatus != 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw Oops.Bah("该记录已完成支付审核,无需重复操作");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-13 06:58:21 +08:00
|
|
|
|
var now = DateTime.Now;
|
2026-04-09 09:09:50 +08:00
|
|
|
|
registration.PaymentStatus = input.PaymentStatus;
|
|
|
|
|
|
registration.ReviewRemark = input.ReviewRemark;
|
2026-04-13 06:58:21 +08:00
|
|
|
|
registration.ReviewTime = now;
|
2026-04-09 09:09:50 +08:00
|
|
|
|
registration.Reviewer = _authManager.Account;
|
2026-04-13 06:58:21 +08:00
|
|
|
|
registration.UpdatedTime = now;
|
2026-04-09 09:09:50 +08:00
|
|
|
|
registration.UpdatedUserId = _authManager.UserId;
|
|
|
|
|
|
|
|
|
|
|
|
if (input.PaymentStatus == 1)
|
|
|
|
|
|
{
|
2026-04-13 06:58:21 +08:00
|
|
|
|
registration.PaymentTime = now;
|
2026-04-09 09:09:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
await _repository.UpdateAsync(registration);
|
2026-04-13 06:58:21 +08:00
|
|
|
|
|
|
|
|
|
|
// 如果审核通过(PaymentStatus = 1),同步更新相关订单的状态为已支付
|
|
|
|
|
|
if (input.PaymentStatus == 1 && !string.IsNullOrEmpty(registration.OrderNo))
|
|
|
|
|
|
{
|
|
|
|
|
|
// 更新相关订单的状态为已支付
|
|
|
|
|
|
await _orderRepository.UpdateAsync(x => new YD_Event.Core.Entities.Order
|
|
|
|
|
|
{
|
|
|
|
|
|
OrderStatus = YD_Event.Core.Enum.OrderStatus.Paid,
|
|
|
|
|
|
PaymentTime = now,
|
|
|
|
|
|
UpdatedTime = now,
|
|
|
|
|
|
UpdatedUserId = _authManager.UserId
|
|
|
|
|
|
}, x => x.OrderNo == registration.OrderNo);
|
|
|
|
|
|
}
|
2026-04-09 09:09:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 批量支付审核
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[UnitOfWork]
|
|
|
|
|
|
[DisplayName("批量支付审核")]
|
|
|
|
|
|
public async Task BatchPaymentAudit(BatchPaymentAuditInput input)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (input.Ids == null || !input.Ids.Any()) return;
|
|
|
|
|
|
|
|
|
|
|
|
var registrations = await _repository.GetListAsync(x => input.Ids.Contains(x.Id));
|
|
|
|
|
|
if (!registrations.Any()) throw Oops.Bah("未找到有效的报名记录");
|
|
|
|
|
|
|
|
|
|
|
|
var invalidRegistrations = registrations
|
2026-04-09 23:12:51 +08:00
|
|
|
|
.Where(r => r.PaymentStatus != 0)
|
2026-04-09 09:09:50 +08:00
|
|
|
|
.ToList();
|
|
|
|
|
|
if (invalidRegistrations.Any())
|
|
|
|
|
|
{
|
2026-04-09 23:12:51 +08:00
|
|
|
|
throw Oops.Bah("存在非待审核状态的记录,无法进行支付审核");
|
2026-04-09 09:09:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var now = DateTime.Now;
|
|
|
|
|
|
await _repository.UpdateAsync(x => new EventRegistration
|
|
|
|
|
|
{
|
|
|
|
|
|
PaymentStatus = input.PaymentStatus,
|
|
|
|
|
|
ReviewRemark = input.ReviewRemark,
|
|
|
|
|
|
ReviewTime = now,
|
|
|
|
|
|
Reviewer = _authManager.Account,
|
|
|
|
|
|
UpdatedTime = now,
|
|
|
|
|
|
UpdatedUserId = _authManager.UserId,
|
|
|
|
|
|
PaymentTime = input.PaymentStatus == 1 ? now : x.PaymentTime
|
|
|
|
|
|
}, x => input.Ids.Contains(x.Id));
|
2026-04-13 06:58:21 +08:00
|
|
|
|
|
|
|
|
|
|
// 如果审核通过(PaymentStatus = 1),同步更新相关订单的状态为已支付
|
|
|
|
|
|
if (input.PaymentStatus == 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
// 提取所有订单号
|
|
|
|
|
|
var orderNos = registrations
|
|
|
|
|
|
.Where(r => !string.IsNullOrEmpty(r.OrderNo))
|
|
|
|
|
|
.Select(r => r.OrderNo)
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
|
|
if (orderNos.Any())
|
|
|
|
|
|
{
|
|
|
|
|
|
// 更新相关订单的状态为已支付
|
|
|
|
|
|
await _orderRepository.UpdateAsync(x => new YD_Event.Core.Entities.Order
|
|
|
|
|
|
{
|
|
|
|
|
|
OrderStatus = YD_Event.Core.Enum.OrderStatus.Paid,
|
|
|
|
|
|
PaymentTime = now,
|
|
|
|
|
|
UpdatedTime = now,
|
|
|
|
|
|
UpdatedUserId = _authManager.UserId
|
|
|
|
|
|
}, x => orderNos.Contains(x.OrderNo));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-04-09 09:09:50 +08:00
|
|
|
|
}
|
2026-02-08 18:09:05 +08:00
|
|
|
|
}
|