From d573fb73c4e2e49694f926a539d901d769b8a8bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E6=A2=93=E5=BD=AD?= Date: Fri, 8 May 2026 09:25:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E8=AF=AD=E5=8F=A5=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- YD_Event.Application/Client/MyController.cs | 21 ++++++------ .../Event/EventScoreService.cs | 13 ++++---- .../Event/UnifiedRegistrationService.cs | 20 +++++++++--- .../Points/PointsRecordService.cs | 32 ++++++++++--------- 4 files changed, 51 insertions(+), 35 deletions(-) diff --git a/YD_Event.Application/Client/MyController.cs b/YD_Event.Application/Client/MyController.cs index d5dc870..146c198 100644 --- a/YD_Event.Application/Client/MyController.cs +++ b/YD_Event.Application/Client/MyController.cs @@ -370,10 +370,10 @@ public class MyController : IDynamicApiController // 先查询原始数据,然后在内存中转换证书名称 var query = _certificateRepository.AsQueryable() .LeftJoin((c, e) => c.EventId == e.Id) - .LeftJoin((c, e, p) => c.ProjectId == p.Id) - .Where((c, e, p) => c.UserId == userId && c.CertificateStatus == 2 && !c.DeleteMark) - .Select((c, e, p) => new - { + .LeftJoin((c, e, ep) => c.ProjectId == ep.Id) + .LeftJoin((c, e, ep, p) => ep.ProjectId == p.Id) + .Where((c, e, ep, p) => c.UserId == userId && c.CertificateStatus == 2 && !c.DeleteMark) + .Select((c, e, ep, p) => new { Id = c.Id, EventName = e.EventName, ProjectName = p.Name, @@ -451,24 +451,25 @@ public class MyController : IDynamicApiController var userId = GetCurrentUserId(); var query = _pointsRecordRepository.AsQueryable() .LeftJoin((p, e) => p.EventId == e.Id) - .LeftJoin((p, e, pr) => p.ProjectId == pr.Id) - .LeftJoin((p, e, pr, pg) => p.ProjectGroupId == pg.Id) + .LeftJoin((p, e, ep) => p.ProjectId == ep.Id) + .LeftJoin((p, e, ep, pr) => ep.ProjectId == pr.Id) + .LeftJoin((p, e, ep, pr, pg) => p.ProjectGroupId == pg.Id) // 小程序端只查看个人积分:UserId = 当前用户且 MerchantCertificationId = null - .Where((p, e, pr, pg) => p.UserId == userId && p.MerchantCertificationId == null && !p.DeleteMark); + .Where((p, e, ep, pr, pg) => p.UserId == userId && p.MerchantCertificationId == null && !p.DeleteMark); if (input.Type.HasValue) { var typeFilter = (PointsOperationType)input.Type.Value; - query = query.Where((p, e, pr, pg) => p.Type == typeFilter); + query = query.Where((p, e, ep, pr, pg) => p.Type == typeFilter); } // 如果前端指定了 MerchantCertificationId,优先使用前端的(保持向后兼容) if (input.MerchantCertificationId.HasValue) { - query = query.Where((p, e, pr, pg) => p.MerchantCertificationId == input.MerchantCertificationId.Value); + query = query.Where((p, e, ep, pr, pg) => p.MerchantCertificationId == input.MerchantCertificationId.Value); } - var resultQuery = query.Select((p, e, pr, pg) => new MyPointsRecordDto + var resultQuery = query.Select((p, e, ep, pr, pg) => new MyPointsRecordDto { Id = p.Id, Title = p.Remark ?? (p.Type == PointsOperationType.Acquire ? "获取积分" : "消耗积分"), diff --git a/YD_Event.Application/Event/EventScoreService.cs b/YD_Event.Application/Event/EventScoreService.cs index 87834de..93ff1f1 100644 --- a/YD_Event.Application/Event/EventScoreService.cs +++ b/YD_Event.Application/Event/EventScoreService.cs @@ -1511,12 +1511,13 @@ public class EventScoreService : BaseService, ITransient var list = await _certificateRepository.AsQueryable() .LeftJoin((c, r) => c.ResultId == r.Id) .LeftJoin((c, r, reg) => c.RegistrationId == reg.Id) - .LeftJoin((c, r, reg, p) => c.ProjectId == p.Id) - .Where((c, r, reg, p) => c.EventId == input.EventId) - .WhereIF(input.ProjectId.HasValue, (c, r, reg, p) => c.ProjectId == input.ProjectId) - .WhereIF(!string.IsNullOrWhiteSpace(input.GroupName), (c, r, reg, p) => c.GroupName == input.GroupName) - .WhereIF(!string.IsNullOrWhiteSpace(input.Name), (c, r, reg, p) => c.ParticipantName.Contains(input.Name)) - .Select((c, r, reg, p) => new CertificateExportDto + .LeftJoin((c, r, reg, ep) => c.ProjectId == ep.Id) + .LeftJoin((c, r, reg, ep, p) => ep.ProjectId == p.Id) + .Where((c, r, reg, ep, p) => c.EventId == input.EventId) + .WhereIF(input.ProjectId.HasValue, (c, r, reg, ep, p) => c.ProjectId == input.ProjectId) + .WhereIF(!string.IsNullOrWhiteSpace(input.GroupName), (c, r, reg, ep, p) => c.GroupName == input.GroupName) + .WhereIF(!string.IsNullOrWhiteSpace(input.Name), (c, r, reg, ep, p) => c.ParticipantName.Contains(input.Name)) + .Select((c, r, reg, ep, p) => new CertificateExportDto { CertificateNo = c.CertificateNo, ParticipantName = c.ParticipantName, diff --git a/YD_Event.Application/Event/UnifiedRegistrationService.cs b/YD_Event.Application/Event/UnifiedRegistrationService.cs index c6d7cdb..c284fd3 100644 --- a/YD_Event.Application/Event/UnifiedRegistrationService.cs +++ b/YD_Event.Application/Event/UnifiedRegistrationService.cs @@ -749,7 +749,7 @@ public class UnifiedRegistrationService : ITransient var regItems = new List(); var persons = new List(); - var uniqueUserIds = new HashSet(); // 用于去重的用户ID集合 + var uniqueUserIds = new HashSet(); // 用于去重的用户ID集合(仅用于单价赛事模式) foreach (var item in input.Items) { @@ -817,10 +817,22 @@ public class UnifiedRegistrationService : ITransient await _registrationItemRepository.InsertRangeAsync(regItems); await _registrationPersonRepository.InsertRangeAsync(persons); - // 使用去重后的用户数量计算金额 - var totalAmount = CalculateTotalAmount(feeConfig, eventProjects, input.Items, uniqueUserIds.Count); + // 根据收费模式决定使用哪种人数计算金额 + int countForCalculation; + if (feeConfig != null && feeConfig.ChargeMode == ChargeMode.UnitPriceEvent) + { + // 单价(赛事)模式:使用去重后的人数 + countForCalculation = uniqueUserIds.Count; + } + else + { + // 其他模式(包括单价项目):使用实际人数 + countForCalculation = persons.Count; + } - return (totalAmount, uniqueUserIds.Count); + var totalAmount = CalculateTotalAmount(feeConfig, eventProjects, input.Items, countForCalculation); + + return (totalAmount, countForCalculation); } /// diff --git a/YD_Event.Application/Points/PointsRecordService.cs b/YD_Event.Application/Points/PointsRecordService.cs index 00decf8..f60b135 100644 --- a/YD_Event.Application/Points/PointsRecordService.cs +++ b/YD_Event.Application/Points/PointsRecordService.cs @@ -238,15 +238,16 @@ public class PointsRecordService : BaseService, ITransient { var query = _repository.AsQueryable() .LeftJoin((p, e) => p.EventId == e.Id) - .LeftJoin((p, e, pr) => p.ProjectId == pr.Id) - .LeftJoin((p, e, pr, pg) => p.ProjectGroupId == pg.Id) - .Where((p, e, pr, pg) => !p.DeleteMark) - .Where((p, e, pr, pg) => p.UserId == input.UserId) - .WhereIF(input.Type.HasValue, (p, e, pr, pg) => p.Type == input.Type) - .OrderByDescending((p, e, pr, pg) => p.CreatedTime); + .LeftJoin((p, e, ep) => p.ProjectId == ep.Id) + .LeftJoin((p, e, ep, pr) => ep.ProjectId == pr.Id) + .LeftJoin((p, e, ep, pr, pg) => p.ProjectGroupId == pg.Id) + .Where((p, e, ep, pr, pg) => !p.DeleteMark) + .Where((p, e, ep, pr, pg) => p.UserId == input.UserId) + .WhereIF(input.Type.HasValue, (p, e, ep, pr, pg) => p.Type == input.Type) + .OrderByDescending((p, e, ep, pr, pg) => p.CreatedTime); return await query - .Select((p, e, pr, pg) => new PointsDetailOutput + .Select((p, e, ep, pr, pg) => new PointsDetailOutput { CreatedTime = p.CreatedTime, Type = p.Type, @@ -264,16 +265,17 @@ public class PointsRecordService : BaseService, ITransient // input.UserId 在这里是 MerchantCertificationId var query = _repository.AsQueryable() .LeftJoin((p, e) => p.EventId == e.Id) - .LeftJoin((p, e, pr) => p.ProjectId == pr.Id) - .LeftJoin((p, e, pr, pg) => p.ProjectGroupId == pg.Id) - .LeftJoin((p, e, pr, pg, u) => p.UserId == u.Id && !u.DeleteMark) - .Where((p, e, pr, pg, u) => !p.DeleteMark) - .Where((p, e, pr, pg, u) => p.MerchantCertificationId == input.UserId) - .WhereIF(input.Type.HasValue, (p, e, pr, pg, u) => p.Type == input.Type) - .OrderByDescending((p, e, pr, pg, u) => p.CreatedTime); + .LeftJoin((p, e, ep) => p.ProjectId == ep.Id) + .LeftJoin((p, e, ep, pr) => ep.ProjectId == pr.Id) + .LeftJoin((p, e, ep, pr, pg) => p.ProjectGroupId == pg.Id) + .LeftJoin((p, e, ep, pr, pg, u) => p.UserId == u.Id && !u.DeleteMark) + .Where((p, e, ep, pr, pg, u) => !p.DeleteMark) + .Where((p, e, ep, pr, pg, u) => p.MerchantCertificationId == input.UserId) + .WhereIF(input.Type.HasValue, (p, e, ep, pr, pg, u) => p.Type == input.Type) + .OrderByDescending((p, e, ep, pr, pg, u) => p.CreatedTime); return await query - .Select((p, e, pr, pg, u) => new PointsDetailOutput + .Select((p, e, ep, pr, pg, u) => new PointsDetailOutput { CreatedTime = p.CreatedTime, Type = p.Type,