From 910e21a04974e54a6f54c777b4957f6db31e1bf3 Mon Sep 17 00:00:00 2001
From: “wangming” <“wangming@antissoft.com”>
Date: Tue, 2 Dec 2025 22:03:30 +0800
Subject: [PATCH] 修复开单记录汇总筛选逻辑:当传入筛选条件但无匹配数据时返回空结果,而不是所有记录
---
netcore/src/Modularity/Extend/NCC.Extend.Entitys/Dto/LqKdDeductinfo/LqKdDeductinfoListOutput.cs | 15 +++++++++++++++
netcore/src/Modularity/Extend/NCC.Extend/LqKdKdjlbService.cs | 630 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
netcore/src/Modularity/Extend/NCC.Extend/LqStatisticsService.cs | 2 +-
netcore/src/Modularity/Extend/NCC.Extend/LqXhHyhkService.cs | 80 ++++++++++++++++++++++++++++++++++++++++++--------------------------------------
sql/修复人次记录HasBilling字段.sql | 47 +++++++++++++++++++++++++++++++++++++++++++++++
项目信息-薪酬规则与名词解释.md | 4 ++--
6 files changed, 164 insertions(+), 614 deletions(-)
create mode 100644 sql/修复人次记录HasBilling字段.sql
diff --git a/netcore/src/Modularity/Extend/NCC.Extend.Entitys/Dto/LqKdDeductinfo/LqKdDeductinfoListOutput.cs b/netcore/src/Modularity/Extend/NCC.Extend.Entitys/Dto/LqKdDeductinfo/LqKdDeductinfoListOutput.cs
index 27b9c2b..f1de2ac 100644
--- a/netcore/src/Modularity/Extend/NCC.Extend.Entitys/Dto/LqKdDeductinfo/LqKdDeductinfoListOutput.cs
+++ b/netcore/src/Modularity/Extend/NCC.Extend.Entitys/Dto/LqKdDeductinfo/LqKdDeductinfoListOutput.cs
@@ -95,5 +95,20 @@ namespace NCC.Extend.Entitys.Dto.LqKdDeductinfo
/// 门店名称
///
public string StoreName { get; set; }
+
+ ///
+ /// 时间期间(开单日期,用于时间范围筛选)
+ ///
+ public DateTime? TimePeriod { get; set; }
+
+ ///
+ /// 开单类型(购买、赠送、体验等)
+ ///
+ public string BillingType { get; set; }
+
+ ///
+ /// 合作机构
+ ///
+ public string CooperationInstitution { get; set; }
}
}
diff --git a/netcore/src/Modularity/Extend/NCC.Extend/LqKdKdjlbService.cs b/netcore/src/Modularity/Extend/NCC.Extend/LqKdKdjlbService.cs
index d36e815..69a0287 100644
--- a/netcore/src/Modularity/Extend/NCC.Extend/LqKdKdjlbService.cs
+++ b/netcore/src/Modularity/Extend/NCC.Extend/LqKdKdjlbService.cs
@@ -47,6 +47,7 @@ using NCC.Extend.Entitys.lq_mdxx;
using NCC.Extend.Entitys.lq_card_transfer_log;
using NCC.Extend.Entitys.Dto.LqDailyReport;
using NCC.Extend.Entitys.lq_yyjl;
+using NCC.Extend.Entitys.lq_hzf;
namespace NCC.Extend.LqKdKdjlb
{
@@ -2322,9 +2323,9 @@ namespace NCC.Extend.LqKdKdjlb
}
#endregion
- #region 获取门店某个时间段的开单记录汇总信息
+ #region 获取门店某个时间段的开单记录汇总信息(台账)
///
- /// 获取门店某个时间段的开单记录汇总信息
+ /// 获取门店某个时间段的开单记录汇总信息(台账)
///
/// 查询参数
/// 开单记录汇总信息
@@ -2368,12 +2369,15 @@ namespace NCC.Extend.LqKdKdjlb
zdyj = it.Zdyj,
sfyj = it.Sfyj,
qk = it.Qk,
+ hgjg = it.Hgjg,
+ hgjgName = SqlFunc.Subqueryable().Where(x => x.Id == it.Hgjg).Select(x => x.Hzmc),
kdhyc = SqlFunc.Subqueryable().Where(x => x.Id == it.Kdhy).Select(x => x.Khmc),
kdhysjh = SqlFunc.Subqueryable().Where(x => x.Id == it.Kdhy).Select(x => x.Sjh),
fkfs = it.Fkfs, // 付款方式
khly = it.Khly, // 客户来源
bz = it.Bz, // 备注
createTime = it.CreateTime
+
})
.ToListAsync();
@@ -2491,240 +2495,55 @@ namespace NCC.Extend.LqKdKdjlb
})
.ToListAsync();
- // 构建按开单记录分组的详细数据
- var detailedRecords = billingRecords.Select(billing => new
- {
- // 基本信息
- date = billing.kdrq?.ToString("yyyy-MM-dd"),
- customerName = billing.kdhyc,
- customerPhone = billing.kdhysjh,
- storeId = billing.djmd,
- goldTriangle = billing.jsj,
- customerType = billing.gjlx,
-
- // 品项分类
- purchasedItems = itemDetails.Where(x => x.glkdbh == billing.id && x.sourceType == "购买").Select(x => new
- {
- id = x.id,
- itemName = x.pxmc,
- itemCode = x.px,
- price = x.pxjg,
- totalPrice = x.totalPrice,
- actualPrice = x.actualPrice,
- projectNumber = x.projectNumber,
- remark = x.remark,
- itemCategory = x.itemCategory,
- }).ToList(),
-
- giftedItems = itemDetails.Where(x => x.glkdbh == billing.id && x.sourceType == "赠送").Select(x => new
- {
- id = x.id,
- itemName = x.pxmc,
- itemCode = x.px,
- price = x.pxjg,
- totalPrice = x.totalPrice,
- actualPrice = x.actualPrice,
- projectNumber = x.projectNumber,
- remark = x.remark,
- itemCategory = x.itemCategory,
- }).ToList(),
-
- experienceItems = itemDetails.Where(x => x.glkdbh == billing.id && x.sourceType == "体验").Select(x => new
- {
- id = x.id,
- itemName = x.pxmc,
- itemCode = x.px,
- price = x.pxjg,
- totalPrice = x.totalPrice,
- actualPrice = x.actualPrice,
- projectNumber = x.projectNumber,
- remark = x.remark,
- itemCategory = x.itemCategory,
- }).ToList(),
-
- // 金额信息
- paidAmount = billing.sfyj,
- debtAmount = billing.qk,
- totalAmount = billing.zdyj,
-
- // 健康师信息
- healthTeachers = healthTeacherData.Where(x => x.glkdbh == billing.id).Select(x => new
- {
- teacherId = x.jks,
- teacherName = x.jksxm,
- teacherAccount = x.jkszh,
- performance = x.jksyj,
- performanceTime = x.yjsj,
- itemDetailId = x.kdpxid,
- goldTriangleId = x.jsj_id,
- itemCategory = x.itemCategory,
- itemId = x.itemId,
- storeId = x.storeId,
- itemName = x.itemName
- }).ToList(),
-
- // 其他信息
- source = billing.khly, // 客户来源
- paymentMethod = billing.fkfs, // 支付方式
- remark = billing.bz, // 备注
- createTime = billing.createTime
- }).OrderByDescending(x => x.date).ToList();
+ // 根据筛选条件过滤开单记录
+ // 收集所有需要匹配的开单ID(取交集)
+ var matchedBillingIds = new List();
+ var hasFilterCondition = false; // 标记是否传入了筛选条件
- // 构建返回结果
- var result = new
+ // 如果传入了品项分类或品项筛选条件,收集匹配的开单ID
+ if (!string.IsNullOrEmpty(input.ItemCategory) || !string.IsNullOrEmpty(input.ItemId))
{
- success = true,
- data = new
+ hasFilterCondition = true;
+ var itemMatchedIds = itemDetails.Select(x => x.glkdbh).Distinct().ToList();
+ if (matchedBillingIds.Any())
{
- // 汇总统计
- summary = new
- {
- totalCount = billingRecords.Count,
- totalAmount = billingRecords.Sum(x => x.zdyj),
- totalPaidAmount = billingRecords.Sum(x => x.sfyj),
- totalDebt = billingRecords.Sum(x => x.qk),
- totalPurchasedItems = purchasedItems.Count,
- totalGiftedItems = giftedItems.Count,
- totalExperienceItems = experienceItems.Count,
- totalHealthTeachers = healthTeacherData.GroupBy(x => x.jks).Count()
- },
- // 详细记录列表
- records = detailedRecords
- },
- message = "获取开单记录汇总信息成功"
- };
- return result;
- }
- catch (Exception ex)
- {
- throw NCCException.Oh($"获取开单记录汇总信息失败:{ex.Message}");
- }
- }
- #endregion
-
- #region 获取门店某个时间段的开单记录汇总信息(备份)
- ///
- /// 获取门店某个时间段的开单记录汇总信息(备份)
- ///
- /// 查询参数
- /// 开单记录汇总信息
- [HttpGet("GetBillingRecordSummaryByStoreId_bak")]
- public async Task GetBillingRecordSummaryByStoreId_bak([FromQuery] BillingRecordSummaryQueryInput input)
- {
- try
- {
- // 验证参数
- if (string.IsNullOrEmpty(input.StoreId))
- {
- throw NCCException.Oh("门店ID不能为空");
+ matchedBillingIds = matchedBillingIds.Intersect(itemMatchedIds).ToList();
+ }
+ else
+ {
+ matchedBillingIds = itemMatchedIds;
+ }
}
- // 如果开始时间和结束时间为空,就默认是当月
- if (input.StartTime == null || input.EndTime == null)
+ // 如果传入了健康师筛选条件,收集匹配的开单ID
+ if (!string.IsNullOrEmpty(input.HealthCoachId))
{
- input.StartTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
- input.EndTime = DateTime.Now.AddDays(DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month));
- }
-
- // 查询开单记录
- var billingRecords = await _db.Queryable()
- .Where(w => w.Djmd == input.StoreId && w.Kdrq >= input.StartTime && w.Kdrq <= input.EndTime && w.IsEffective == StatusEnum.有效.GetHashCode())
- .Select(it => new
+ hasFilterCondition = true;
+ var healthTeacherMatchedIds = healthTeacherData.Select(x => x.glkdbh).Distinct().ToList();
+ if (matchedBillingIds.Any())
{
- id = it.Id,
- djmd = it.Djmd,
- jsj = it.Jsj,
- kdrq = it.Kdrq,
- gjlx = it.Gjlx,
- zdyj = it.Zdyj,
- sfyj = it.Sfyj,
- qk = it.Qk,
- kdhyc = SqlFunc.Subqueryable().Where(x => x.Id == it.Kdhy).Select(x => x.Khmc),
- kdhysjh = SqlFunc.Subqueryable().Where(x => x.Id == it.Kdhy).Select(x => x.Sjh),
- fkfs = it.Fkfs, // 付款方式
- khly = it.Khly, // 客户来源
- bz = it.Bz, // 备注
- createTime = it.CreateTime
- })
- .ToListAsync();
-
- if (!billingRecords.Any())
- {
- return new
+ matchedBillingIds = matchedBillingIds.Intersect(healthTeacherMatchedIds).ToList();
+ }
+ else
{
- success = true,
- data = new
- {
- billingSummary = new
- {
- totalCount = 0,
- totalAmount = 0,
- totalPaidAmount = 0,
- totalDebt = 0,
- billingRecords = new List