diff --git a/YD_Event.Application/Event/Dtos/UnifiedRegistrationDtos.cs b/YD_Event.Application/Event/Dtos/UnifiedRegistrationDtos.cs index c39ccb0..660ee64 100644 --- a/YD_Event.Application/Event/Dtos/UnifiedRegistrationDtos.cs +++ b/YD_Event.Application/Event/Dtos/UnifiedRegistrationDtos.cs @@ -314,6 +314,49 @@ public class UnifiedPaymentOutput public string? TradeType { get; set; } } +/// +/// 确认银行转账输入DTO +/// +public class ConfirmBankTransferInput +{ + /// + /// 报名ID + /// + [Required(ErrorMessage = "报名ID不能为空")] + public long RegistrationId { get; set; } + + /// + /// 支付凭证URL (可选) + /// + public string? PaymentProofUrl { get; set; } +} + +/// +/// 确认银行转账输出DTO +/// +public class ConfirmBankTransferOutput +{ + /// + /// 报名ID + /// + public long RegistrationId { get; set; } + + /// + /// 支付状态 + /// + public int PaymentStatus { get; set; } + + /// + /// 是否成功 + /// + public bool Success { get; set; } + + /// + /// 消息 + /// + public string? Message { get; set; } +} + /// /// 报名验证结果DTO /// diff --git a/YD_Event.Application/Event/UnifiedRegistrationService.cs b/YD_Event.Application/Event/UnifiedRegistrationService.cs index 505d47e..2d41fe1 100644 --- a/YD_Event.Application/Event/UnifiedRegistrationService.cs +++ b/YD_Event.Application/Event/UnifiedRegistrationService.cs @@ -1103,6 +1103,29 @@ public class UnifiedRegistrationService : ITransient /// private async Task HandleOfflinePaymentAsync(EventRegistration registration, UnifiedPaymentInput input) { + // 如果是银行转账,先不设置支付状态,等用户确认转账后再处理 + if (input.PaymentMethodType == PaymentMethodType.BankTransfer) + { + registration.PaymentProofUrl = input.PaymentProofUrl; + // 保持支付状态为未支付,等用户确认转账后再更新 + registration.PaymentStatus = 4; // 临时状态:待确认转账 + registration.UpdatedTime = DateTime.Now; + registration.UpdatedUserId = input.OperatorUserId; + await _registrationRepository.UpdateAsync(registration); + + _logger.LogInformation("银行转账方式,等待用户确认,报名ID:{RegistrationId},凭证URL:{ProofUrl}", + registration.Id, input.PaymentProofUrl); + + return new UnifiedPaymentOutput + { + RegistrationId = registration.Id, + OrderNo = registration.OrderNo, + PaymentStatus = 4, // 待确认转账 + IsFree = false + }; + } + + // 其他线下支付方式,保持原有逻辑 registration.PaymentProofUrl = input.PaymentProofUrl; registration.PaymentStatus = 0; // 待审核 registration.UpdatedTime = DateTime.Now; @@ -1121,6 +1144,58 @@ public class UnifiedRegistrationService : ITransient }; } + /// + /// 确认银行转账 + /// + public async Task ConfirmBankTransferAsync(ConfirmBankTransferInput input, long operatorUserId) + { + _logger.LogInformation("开始确认银行转账,报名ID:{RegistrationId}", input.RegistrationId); + + var registration = await _registrationRepository.GetByIdAsync(input.RegistrationId); + if (registration == null) + { + _logger.LogWarning("未找到报名记录,报名ID:{RegistrationId}", input.RegistrationId); + return new ConfirmBankTransferOutput + { + RegistrationId = input.RegistrationId, + PaymentStatus = -1, + Success = false, + Message = "报名记录不存在" + }; + } + + // 检查是否为银行转账方式 + if (registration.PaymentMethodType != PaymentMethodType.BankTransfer) + { + _logger.LogWarning("该报名不是银行转账方式,报名ID:{RegistrationId},支付方式:{PaymentMethodType}", + input.RegistrationId, registration.PaymentMethodType); + return new ConfirmBankTransferOutput + { + RegistrationId = input.RegistrationId, + PaymentStatus = registration.PaymentStatus, + Success = false, + Message = "该报名不是银行转账方式" + }; + } + + // 更新报名记录状态为待审核 + registration.PaymentProofUrl = input.PaymentProofUrl ?? registration.PaymentProofUrl; + registration.PaymentStatus = 0; // 待审核 + registration.UpdatedTime = DateTime.Now; + registration.UpdatedUserId = operatorUserId; + await _registrationRepository.UpdateAsync(registration); + + _logger.LogInformation("银行转账确认成功,报名ID:{RegistrationId},状态已更新为待审核", input.RegistrationId); + + return new ConfirmBankTransferOutput + { + RegistrationId = input.RegistrationId, + PaymentStatus = 0, + Success = true, + Message = "转账确认成功,订单已提交审核" + }; + } + /// /// 检查报名限制 /// @@ -1142,14 +1217,26 @@ public class UnifiedRegistrationService : ITransient // 先获取所有报名信息,供后续检查使用 // 线上支付类型的报名记录,仅统计PaymentStatus == 1(已支付)的记录 - // 线下支付类型的报名记录,同时统计PaymentStatus == 1(已支付)和PaymentStatus == 0(未支付)的记录 + // 线下支付类型的报名记录: + // - 银行转账方式:仅统计PaymentStatus == 1(已支付)和PaymentStatus == 0(待审核)的记录, + // 不统计PaymentStatus == 4(待确认转账)的记录 + // - 其他线下方式:统计PaymentStatus == 1(已支付)和PaymentStatus == 0(待审核)的记录 var eventRegistrationsQuery = _registrationRepository.AsQueryable().Where(x => x.EventId == input.EventId && !x.DeleteMark && ( + // 线上支付:仅已支付 (x.PaymentMethod == 2 && x.PaymentStatus == 1) || - (x.PaymentMethod == 1 && x.PaymentStatus == 1) || - (x.PaymentMethod == 1 && x.PaymentStatus == 0) - )); + // 线下支付: + (x.PaymentMethod == 1 && ( + // 已支付的都统计 + x.PaymentStatus == 1 || + // 待审核的,且不是银行转账方式中待确认转账状态的 + (x.PaymentStatus == 0 && !(x.PaymentMethodType == PaymentMethodType.BankTransfer && x.PaymentStatus == 4)) + )) + ) && + // 排除银行转账方式中待确认转账状态的记录 + !(x.PaymentMethodType == PaymentMethodType.BankTransfer && x.PaymentStatus == 4) + ); // 如果指定了要排除的报名ID,则排除该记录 if (excludeRegistrationId.HasValue) diff --git a/YD_Event.Application/Event/UserEventRegistrationService.cs b/YD_Event.Application/Event/UserEventRegistrationService.cs index 5eb537c..f1d7534 100644 --- a/YD_Event.Application/Event/UserEventRegistrationService.cs +++ b/YD_Event.Application/Event/UserEventRegistrationService.cs @@ -751,6 +751,24 @@ public class UserEventRegistrationService : IDynamicApiController, ITransient return result; } + /// + /// 确认银行转账 + /// + [DisplayName("确认银行转账")] + [HttpPost("bank-transfer/confirm")] + [UnitOfWork] + public async Task ConfirmBankTransfer([FromBody] ConfirmBankTransferInput input) + { + var userId = _authManager.UserId; + + _logger.LogInformation("用户确认银行转账,报名ID:{RegistrationId},用户ID:{UserId}", input.RegistrationId, userId); + + // 调用统一报名服务处理确认转账 + var result = await _unifiedRegistrationService.ConfirmBankTransferAsync(input, userId); + + return result; + } + /// /// 微信支付回调 /// diff --git a/YD_Event.Application/YD_Event.Application.xml b/YD_Event.Application/YD_Event.Application.xml index 2a507fc..2d037f4 100644 --- a/YD_Event.Application/YD_Event.Application.xml +++ b/YD_Event.Application/YD_Event.Application.xml @@ -6983,6 +6983,46 @@ 交易类型 + + + 确认银行转账输入DTO + + + + + 报名ID + + + + + 支付凭证URL (可选) + + + + + 确认银行转账输出DTO + + + + + 报名ID + + + + + 支付状态 + + + + + 是否成功 + + + + + 消息 + + 报名验证结果DTO @@ -8855,6 +8895,11 @@ 处理线下支付 + + + 确认银行转账 + + 检查报名限制 @@ -9193,6 +9238,11 @@ 创建支付订单 + + + 确认银行转账 + + 微信支付回调