From 24296764bd9caffbac6ee3b3a4b52caacbb95d89 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 14:50:01 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B5=9B=E4=BA=8B=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Event/UnifiedRegistrationService.cs | 56 ++++++++++++++++--- .../Event/UserEventRecordService.cs | 2 + .../Domain/Pricing/EventPricingService.cs | 28 +++------- .../Pricing/Models/ProjectPricingInfo.cs | 5 ++ YD_Event.Core/YD_Event.Core.xml | 7 ++- 5 files changed, 70 insertions(+), 28 deletions(-) diff --git a/YD_Event.Application/Event/UnifiedRegistrationService.cs b/YD_Event.Application/Event/UnifiedRegistrationService.cs index 3770638..73d64c2 100644 --- a/YD_Event.Application/Event/UnifiedRegistrationService.cs +++ b/YD_Event.Application/Event/UnifiedRegistrationService.cs @@ -913,6 +913,7 @@ public class UnifiedRegistrationService : ITransient } registration.PaymentStatus = 1; + registration.PaymentMethod = 1; // 免费赛事设置为线下支付方式(但实际不产生费用) registration.PaymentTime = DateTime.Now; registration.UpdatedTime = DateTime.Now; registration.UpdatedUserId = operatorUserId; @@ -1923,11 +1924,26 @@ public class UnifiedRegistrationService : ITransient { if (eventProjectsDict.TryGetValue(item.ProjectId, out var ep)) { - pricingInput.Projects.Add(new ProjectPricingInfo + var projectInfo = new ProjectPricingInfo { ProjectId = ep.Id, UnitPrice = ep.Price - }); + }; + + // 仅在单价项目模式时设置项目人数 + if (feeConfig.ChargeMode == ChargeMode.UnitPriceProject) + { + if (item.Teams != null && item.Teams.Any()) + { + projectInfo.Quantity = item.Teams.Sum(t => t.Persons?.Count ?? 0); + } + else if (item.Persons != null && item.Persons.Any()) + { + projectInfo.Quantity = item.Persons.Count; + } + } + + pricingInput.Projects.Add(projectInfo); } } @@ -1973,15 +1989,39 @@ public class UnifiedRegistrationService : ITransient countForCalculation = items.Sum(i => i.PersonCount); } - var unifiedItems = items.Select(i => new UnifiedRegistrationItemInput + // 构建专门用于金额计算的 PricingInput,直接使用 CalculateAmountInputItem 的信息 + var pricingInput = new PricingInput { - ProjectId = i.ProjectId, - Persons = new List(new UnifiedPersonInput[i.PersonCount]) - }).ToList(); - - var totalAmount = CalculateTotalAmount(feeConfig, eventProjects, unifiedItems, countForCalculation); + ChargeMode = feeConfig.ChargeMode, + ParticipantCount = countForCalculation, + EventPrice = feeConfig.Price + }; var eventProjectsDict = eventProjects.ToDictionary(p => p.Id); + + foreach (var item in items) + { + if (eventProjectsDict.TryGetValue(item.ProjectId, out var ep)) + { + var projectInfo = new ProjectPricingInfo + { + ProjectId = ep.Id, + UnitPrice = ep.Price + }; + + // 仅在单价项目模式时设置项目人数 + if (feeConfig.ChargeMode == ChargeMode.UnitPriceProject) + { + projectInfo.Quantity = item.PersonCount; + } + + pricingInput.Projects.Add(projectInfo); + } + } + + var pricingResult = EventPricingService.Calculate(pricingInput); + var totalAmount = pricingResult.TotalAmount; + var baseProjectsDict = baseProjects.ToDictionary(p => p.Id); foreach (var item in items) diff --git a/YD_Event.Application/Event/UserEventRecordService.cs b/YD_Event.Application/Event/UserEventRecordService.cs index cd64d04..69c51e6 100644 --- a/YD_Event.Application/Event/UserEventRecordService.cs +++ b/YD_Event.Application/Event/UserEventRecordService.cs @@ -103,9 +103,11 @@ public class UserEventRecordService : IDynamicApiController, ITransient .LeftJoin((r, e, fc) => e.Id == fc.EventId) .Where((r, e, fc) => r.CreatedUserId == userId && !r.DeleteMark) // 支付状态筛选: + // - 免费赛事:直接显示 // - 线下支付时:显示未支付(0)和已支付(1)状态的数据 // - 线上支付时:仅显示已支付(1)状态的数据 .Where((r, e, fc) => + (e.ChargeMode == ChargeMode.Free) || (r.PaymentMethod == 1 && (r.PaymentStatus == 0 || r.PaymentStatus == 1)) || (r.PaymentMethod == 2 && r.PaymentStatus == 1)) .WhereIF(input.EventId.HasValue, (r, e, fc) => r.EventId == input.EventId) diff --git a/YD_Event.Core/Domain/Pricing/EventPricingService.cs b/YD_Event.Core/Domain/Pricing/EventPricingService.cs index c98bdbc..45e11b2 100644 --- a/YD_Event.Core/Domain/Pricing/EventPricingService.cs +++ b/YD_Event.Core/Domain/Pricing/EventPricingService.cs @@ -103,39 +103,29 @@ public static class EventPricingService /// /// 单价(项目)模式:根据每个项目的单独定价和报名人数进行计算。 - /// 将每个报名项目的单价相加得到单人总费用,再乘以报名人数得出最终金额 + /// 每个项目独立计算:项目单价 × 对应人数,然后累加所有项目的金额 /// private static void CalculateUnitPriceProjectMode(PricingResult result, PricingInput input) { - decimal totalProjectPrice = 0; + decimal totalAmount = 0; foreach (var project in input.Projects) { - totalProjectPrice += project.UnitPrice; + var subtotal = project.UnitPrice * project.Quantity; + totalAmount += subtotal; + result.Details.Add(new PricingDetailItem { ItemName = project.ProjectName, UnitPrice = project.UnitPrice, - Quantity = 1, - Subtotal = project.UnitPrice, + Quantity = project.Quantity, + Subtotal = subtotal, Remark = "项目单价" }); - result.CalculationLogs.Add($"[{DateTime.Now:yyyy-MM-dd HH:mm:ss}] 项目: {project.ProjectName}, 单价: {project.UnitPrice:F2} 元"); + result.CalculationLogs.Add($"[{DateTime.Now:yyyy-MM-dd HH:mm:ss}] 项目: {project.ProjectName}, 单价: {project.UnitPrice:F2} 元, 人数: {project.Quantity}, 小计: {subtotal:F2} 元"); } - var totalAmount = totalProjectPrice * input.ParticipantCount; result.TotalAmount = totalAmount; - - result.Details.Add(new PricingDetailItem - { - ItemName = input.ParticipantCount == 1 ? "项目总价" : "项目总价 × 人数", - UnitPrice = totalProjectPrice, - Quantity = input.ParticipantCount, - Subtotal = totalAmount, - Remark = input.ParticipantCount == 1 - ? $"个人参赛,项目总价 {totalProjectPrice:F2} 元" - : $"团队参赛,({totalProjectPrice:F2} 元) × {input.ParticipantCount} 人" - }); - result.CalculationLogs.Add($"[{DateTime.Now:yyyy-MM-dd HH:mm:ss}] 单价(项目)模式: 项目总价 {totalProjectPrice:F2} 元 × {input.ParticipantCount} 人 = {totalAmount:F2} 元"); + result.CalculationLogs.Add($"[{DateTime.Now:yyyy-MM-dd HH:mm:ss}] 单价(项目)模式: 总金额 {totalAmount:F2} 元"); } } diff --git a/YD_Event.Core/Domain/Pricing/Models/ProjectPricingInfo.cs b/YD_Event.Core/Domain/Pricing/Models/ProjectPricingInfo.cs index cd1a6a7..e057ac8 100644 --- a/YD_Event.Core/Domain/Pricing/Models/ProjectPricingInfo.cs +++ b/YD_Event.Core/Domain/Pricing/Models/ProjectPricingInfo.cs @@ -19,4 +19,9 @@ public class ProjectPricingInfo /// 项目单价(元) /// public decimal UnitPrice { get; set; } + + /// + /// 项目报名人数 + /// + public int Quantity { get; set; } } diff --git a/YD_Event.Core/YD_Event.Core.xml b/YD_Event.Core/YD_Event.Core.xml index 1fc3ebf..cc95228 100644 --- a/YD_Event.Core/YD_Event.Core.xml +++ b/YD_Event.Core/YD_Event.Core.xml @@ -443,7 +443,7 @@ 单价(项目)模式:根据每个项目的单独定价和报名人数进行计算。 - 将每个报名项目的单价相加得到单人总费用,再乘以报名人数得出最终金额 + 每个项目独立计算:项目单价 × 对应人数,然后累加所有项目的金额 @@ -546,6 +546,11 @@ 项目单价(元) + + + 项目报名人数 + + 表实体继承