Commit 3b7c4f3ba2aec4212d87dab42a9bb52c0515b81c
1 parent
1f96867e
feat: 新增开单目标业绩和完成率统计
- 在GetBusinessStatistics中新增开单目标业绩统计 - 目标业绩来自门店信息表的xsyj字段 - 完成业绩 = 开单总金额 - 退卡总金额 - 计算开单完成率(完成业绩 / 开单目标业绩 * 100) - 支持门店ID过滤 - 更新输出DTO和相关接口文档
Showing
2 changed files
with
53 additions
and
9 deletions
netcore/src/Modularity/Extend/NCC.Extend.Entitys/Dto/LqReport/BusinessStatisticsOutput.cs
| ... | ... | @@ -44,5 +44,20 @@ namespace NCC.Extend.Entitys.Dto.LqReport |
| 44 | 44 | /// 消耗完成率(耗卡总金额 / 消耗目标业绩 * 100) |
| 45 | 45 | /// </summary> |
| 46 | 46 | public decimal ConsumeCompletionRate { get; set; } |
| 47 | + | |
| 48 | + /// <summary> | |
| 49 | + /// 开单目标业绩(所有门店xsyj字段的总和) | |
| 50 | + /// </summary> | |
| 51 | + public decimal TargetBillingAmount { get; set; } | |
| 52 | + | |
| 53 | + /// <summary> | |
| 54 | + /// 开单完成业绩(开单总金额 - 退卡总金额) | |
| 55 | + /// </summary> | |
| 56 | + public decimal CompletedBillingAmount { get; set; } | |
| 57 | + | |
| 58 | + /// <summary> | |
| 59 | + /// 开单完成率(完成业绩 / 开单目标业绩 * 100) | |
| 60 | + /// </summary> | |
| 61 | + public decimal BillingCompletionRate { get; set; } | |
| 47 | 62 | } |
| 48 | 63 | } | ... | ... |
netcore/src/Modularity/Extend/NCC.Extend/LqReportService.cs
| ... | ... | @@ -715,7 +715,7 @@ namespace NCC.Extend |
| 715 | 715 | /// - storeIds: 门店ID列表(可选) |
| 716 | 716 | /// |
| 717 | 717 | /// 返回字段说明: |
| 718 | - /// - TotalBillingAmount: 开单总金额 | |
| 718 | + /// - TotalBillingAmount: 开单总金额(未扣除退卡) | |
| 719 | 719 | /// - TotalConsumeAmount: 耗卡总金额 |
| 720 | 720 | /// - TotalRefundAmount: 退卡总金额 |
| 721 | 721 | /// - BillingCount: 开单人数(按客户去重) |
| ... | ... | @@ -723,6 +723,9 @@ namespace NCC.Extend |
| 723 | 723 | /// - RefundCount: 退卡人数(按客户去重) |
| 724 | 724 | /// - TargetConsumeAmount: 消耗目标业绩(所有门店xhyj字段的总和) |
| 725 | 725 | /// - ConsumeCompletionRate: 消耗完成率(百分比) |
| 726 | + /// - TargetBillingAmount: 开单目标业绩(所有门店xsyj字段的总和) | |
| 727 | + /// - CompletedBillingAmount: 开单完成业绩(开单总金额 - 退卡总金额) | |
| 728 | + /// - BillingCompletionRate: 开单完成率(百分比) | |
| 726 | 729 | /// </remarks> |
| 727 | 730 | /// <param name="input">查询参数</param> |
| 728 | 731 | /// <returns>业务统计数据</returns> |
| ... | ... | @@ -814,19 +817,35 @@ namespace NCC.Extend |
| 814 | 817 | var refundAmount = Convert.ToDecimal(refundResult?.FirstOrDefault()?.refund_amount ?? 0m); |
| 815 | 818 | |
| 816 | 819 | // 第四步:获取消耗目标业绩(所有门店xhyj字段的总和) |
| 817 | - var targetSql = "SELECT COALESCE(SUM(CAST(md.xhyj AS DECIMAL(18,2))), 0) as target_consume_amount FROM lq_mdxx md WHERE 1=1"; | |
| 818 | - object targetParameters = null; | |
| 820 | + var targetConsumeSql = "SELECT COALESCE(SUM(CAST(md.xhyj AS DECIMAL(18,2))), 0) as target_consume_amount FROM lq_mdxx md WHERE 1=1"; | |
| 821 | + object targetConsumeParameters = null; | |
| 819 | 822 | |
| 820 | 823 | if (input.StoreIds != null && input.StoreIds.Any()) |
| 821 | 824 | { |
| 822 | - targetSql += " AND md.F_Id IN @storeIds"; | |
| 823 | - targetParameters = new { storeIds = input.StoreIds }; | |
| 825 | + targetConsumeSql += " AND md.F_Id IN @storeIds"; | |
| 826 | + targetConsumeParameters = new { storeIds = input.StoreIds }; | |
| 824 | 827 | } |
| 825 | 828 | |
| 826 | - var targetResult = await _db.Ado.SqlQueryAsync<dynamic>(targetSql, targetParameters); | |
| 827 | - var targetConsumeAmount = Convert.ToDecimal(targetResult?.FirstOrDefault()?.target_consume_amount ?? 0m); | |
| 829 | + var targetConsumeResult = await _db.Ado.SqlQueryAsync<dynamic>(targetConsumeSql, targetConsumeParameters); | |
| 830 | + var targetConsumeAmount = Convert.ToDecimal(targetConsumeResult?.FirstOrDefault()?.target_consume_amount ?? 0m); | |
| 828 | 831 | |
| 829 | - // 计算消耗完成率 | |
| 832 | + // 第五步:获取开单目标业绩(所有门店xsyj字段的总和) | |
| 833 | + var targetBillingSql = "SELECT COALESCE(SUM(CAST(md.xsyj AS DECIMAL(18,2))), 0) as target_billing_amount FROM lq_mdxx md WHERE 1=1"; | |
| 834 | + object targetBillingParameters = null; | |
| 835 | + | |
| 836 | + if (input.StoreIds != null && input.StoreIds.Any()) | |
| 837 | + { | |
| 838 | + targetBillingSql += " AND md.F_Id IN @storeIds"; | |
| 839 | + targetBillingParameters = new { storeIds = input.StoreIds }; | |
| 840 | + } | |
| 841 | + | |
| 842 | + var targetBillingResult = await _db.Ado.SqlQueryAsync<dynamic>(targetBillingSql, targetBillingParameters); | |
| 843 | + var targetBillingAmount = Convert.ToDecimal(targetBillingResult?.FirstOrDefault()?.target_billing_amount ?? 0m); | |
| 844 | + | |
| 845 | + // 计算开单完成业绩(开单总金额 - 退卡总金额) | |
| 846 | + var completedBillingAmount = billingAmount - refundAmount; | |
| 847 | + | |
| 848 | + // 计算完成率 | |
| 830 | 849 | var consumeCompletionRate = 0m; |
| 831 | 850 | if (targetConsumeAmount > 0) |
| 832 | 851 | { |
| ... | ... | @@ -834,6 +853,13 @@ namespace NCC.Extend |
| 834 | 853 | consumeCompletionRate = decimal.Round(consumeCompletionRate, 2); |
| 835 | 854 | } |
| 836 | 855 | |
| 856 | + var billingCompletionRate = 0m; | |
| 857 | + if (targetBillingAmount > 0) | |
| 858 | + { | |
| 859 | + billingCompletionRate = (completedBillingAmount / targetBillingAmount) * 100m; | |
| 860 | + billingCompletionRate = decimal.Round(billingCompletionRate, 2); | |
| 861 | + } | |
| 862 | + | |
| 837 | 863 | var result = new BusinessStatisticsOutput |
| 838 | 864 | { |
| 839 | 865 | TotalBillingAmount = billingAmount, |
| ... | ... | @@ -843,7 +869,10 @@ namespace NCC.Extend |
| 843 | 869 | ConsumeCount = consumeCount, |
| 844 | 870 | RefundCount = refundCount, |
| 845 | 871 | TargetConsumeAmount = targetConsumeAmount, |
| 846 | - ConsumeCompletionRate = consumeCompletionRate | |
| 872 | + ConsumeCompletionRate = consumeCompletionRate, | |
| 873 | + TargetBillingAmount = targetBillingAmount, | |
| 874 | + CompletedBillingAmount = completedBillingAmount, | |
| 875 | + BillingCompletionRate = billingCompletionRate | |
| 847 | 876 | }; |
| 848 | 877 | |
| 849 | 878 | return result; | ... | ... |