diff --git a/netcore/src/Modularity/Extend/NCC.Extend.Entitys/Dto/LqReport/BusinessStatisticsOutput.cs b/netcore/src/Modularity/Extend/NCC.Extend.Entitys/Dto/LqReport/BusinessStatisticsOutput.cs index 42f175c..5288ed5 100644 --- a/netcore/src/Modularity/Extend/NCC.Extend.Entitys/Dto/LqReport/BusinessStatisticsOutput.cs +++ b/netcore/src/Modularity/Extend/NCC.Extend.Entitys/Dto/LqReport/BusinessStatisticsOutput.cs @@ -44,5 +44,20 @@ namespace NCC.Extend.Entitys.Dto.LqReport /// 消耗完成率(耗卡总金额 / 消耗目标业绩 * 100) /// public decimal ConsumeCompletionRate { get; set; } + + /// + /// 开单目标业绩(所有门店xsyj字段的总和) + /// + public decimal TargetBillingAmount { get; set; } + + /// + /// 开单完成业绩(开单总金额 - 退卡总金额) + /// + public decimal CompletedBillingAmount { get; set; } + + /// + /// 开单完成率(完成业绩 / 开单目标业绩 * 100) + /// + public decimal BillingCompletionRate { get; set; } } } diff --git a/netcore/src/Modularity/Extend/NCC.Extend/LqReportService.cs b/netcore/src/Modularity/Extend/NCC.Extend/LqReportService.cs index 7156934..49aa29c 100644 --- a/netcore/src/Modularity/Extend/NCC.Extend/LqReportService.cs +++ b/netcore/src/Modularity/Extend/NCC.Extend/LqReportService.cs @@ -715,7 +715,7 @@ namespace NCC.Extend /// - storeIds: 门店ID列表(可选) /// /// 返回字段说明: - /// - TotalBillingAmount: 开单总金额 + /// - TotalBillingAmount: 开单总金额(未扣除退卡) /// - TotalConsumeAmount: 耗卡总金额 /// - TotalRefundAmount: 退卡总金额 /// - BillingCount: 开单人数(按客户去重) @@ -723,6 +723,9 @@ namespace NCC.Extend /// - RefundCount: 退卡人数(按客户去重) /// - TargetConsumeAmount: 消耗目标业绩(所有门店xhyj字段的总和) /// - ConsumeCompletionRate: 消耗完成率(百分比) + /// - TargetBillingAmount: 开单目标业绩(所有门店xsyj字段的总和) + /// - CompletedBillingAmount: 开单完成业绩(开单总金额 - 退卡总金额) + /// - BillingCompletionRate: 开单完成率(百分比) /// /// 查询参数 /// 业务统计数据 @@ -814,19 +817,35 @@ namespace NCC.Extend var refundAmount = Convert.ToDecimal(refundResult?.FirstOrDefault()?.refund_amount ?? 0m); // 第四步:获取消耗目标业绩(所有门店xhyj字段的总和) - var targetSql = "SELECT COALESCE(SUM(CAST(md.xhyj AS DECIMAL(18,2))), 0) as target_consume_amount FROM lq_mdxx md WHERE 1=1"; - object targetParameters = null; + var targetConsumeSql = "SELECT COALESCE(SUM(CAST(md.xhyj AS DECIMAL(18,2))), 0) as target_consume_amount FROM lq_mdxx md WHERE 1=1"; + object targetConsumeParameters = null; if (input.StoreIds != null && input.StoreIds.Any()) { - targetSql += " AND md.F_Id IN @storeIds"; - targetParameters = new { storeIds = input.StoreIds }; + targetConsumeSql += " AND md.F_Id IN @storeIds"; + targetConsumeParameters = new { storeIds = input.StoreIds }; } - var targetResult = await _db.Ado.SqlQueryAsync(targetSql, targetParameters); - var targetConsumeAmount = Convert.ToDecimal(targetResult?.FirstOrDefault()?.target_consume_amount ?? 0m); + var targetConsumeResult = await _db.Ado.SqlQueryAsync(targetConsumeSql, targetConsumeParameters); + var targetConsumeAmount = Convert.ToDecimal(targetConsumeResult?.FirstOrDefault()?.target_consume_amount ?? 0m); - // 计算消耗完成率 + // 第五步:获取开单目标业绩(所有门店xsyj字段的总和) + var targetBillingSql = "SELECT COALESCE(SUM(CAST(md.xsyj AS DECIMAL(18,2))), 0) as target_billing_amount FROM lq_mdxx md WHERE 1=1"; + object targetBillingParameters = null; + + if (input.StoreIds != null && input.StoreIds.Any()) + { + targetBillingSql += " AND md.F_Id IN @storeIds"; + targetBillingParameters = new { storeIds = input.StoreIds }; + } + + var targetBillingResult = await _db.Ado.SqlQueryAsync(targetBillingSql, targetBillingParameters); + var targetBillingAmount = Convert.ToDecimal(targetBillingResult?.FirstOrDefault()?.target_billing_amount ?? 0m); + + // 计算开单完成业绩(开单总金额 - 退卡总金额) + var completedBillingAmount = billingAmount - refundAmount; + + // 计算完成率 var consumeCompletionRate = 0m; if (targetConsumeAmount > 0) { @@ -834,6 +853,13 @@ namespace NCC.Extend consumeCompletionRate = decimal.Round(consumeCompletionRate, 2); } + var billingCompletionRate = 0m; + if (targetBillingAmount > 0) + { + billingCompletionRate = (completedBillingAmount / targetBillingAmount) * 100m; + billingCompletionRate = decimal.Round(billingCompletionRate, 2); + } + var result = new BusinessStatisticsOutput { TotalBillingAmount = billingAmount, @@ -843,7 +869,10 @@ namespace NCC.Extend ConsumeCount = consumeCount, RefundCount = refundCount, TargetConsumeAmount = targetConsumeAmount, - ConsumeCompletionRate = consumeCompletionRate + ConsumeCompletionRate = consumeCompletionRate, + TargetBillingAmount = targetBillingAmount, + CompletedBillingAmount = completedBillingAmount, + BillingCompletionRate = billingCompletionRate }; return result;