From 65e1ea9f1c805734dfb2964db4c4a45b43d81d38 Mon Sep 17 00:00:00 2001 From: “wangming” <“wangming@antissoft.com”> Date: Tue, 28 Oct 2025 00:33:34 +0800 Subject: [PATCH] fix: 修复员工业绩统计和人次统计逻辑 --- antis-ncc-admin/.env.development | 4 ++-- netcore/src/Modularity/Extend/NCC.Extend.Entitys/Dto/LqInventoryUsage/LqInventoryUsageListOutput.cs | 36 ++++++++++++++++++------------------ netcore/src/Modularity/Extend/NCC.Extend.Entitys/Dto/LqStatistics/EmployeePerformanceStatisticsInput.cs | 22 ++++++++++++++++++++++ netcore/src/Modularity/Extend/NCC.Extend.Entitys/Dto/LqStatistics/EmployeePerformanceStatisticsOutput.cs | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ netcore/src/Modularity/Extend/NCC.Extend/LqInventoryUsageService.cs | 69 +++++++++++++++++++++++++++++++++++---------------------------------- netcore/src/Modularity/Extend/NCC.Extend/LqStatisticsService.cs | 249 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- netcore/src/Modularity/Extend/NCC.Extend/LqXmzlService.cs | 24 ++++++++++++++++-------- 7 files changed, 413 insertions(+), 64 deletions(-) create mode 100644 netcore/src/Modularity/Extend/NCC.Extend.Entitys/Dto/LqStatistics/EmployeePerformanceStatisticsInput.cs create mode 100644 netcore/src/Modularity/Extend/NCC.Extend.Entitys/Dto/LqStatistics/EmployeePerformanceStatisticsOutput.cs diff --git a/antis-ncc-admin/.env.development b/antis-ncc-admin/.env.development index 78e23e6..be31aec 100644 --- a/antis-ncc-admin/.env.development +++ b/antis-ncc-admin/.env.development @@ -2,6 +2,6 @@ VUE_CLI_BABEL_TRANSPILE_MODULES = true # VUE_APP_BASE_API = 'http://lvqian.antissoft.com' -VUE_APP_BASE_API = 'http://erp_test.lvqianmeiye.com' -# VUE_APP_BASE_API = 'http://localhost:2011' +# VUE_APP_BASE_API = 'http://erp_test.lvqianmeiye.com' +VUE_APP_BASE_API = 'http://localhost:2011' VUE_APP_BASE_WSS = 'ws://192.168.110.45:2011/websocket' diff --git a/netcore/src/Modularity/Extend/NCC.Extend.Entitys/Dto/LqInventoryUsage/LqInventoryUsageListOutput.cs b/netcore/src/Modularity/Extend/NCC.Extend.Entitys/Dto/LqInventoryUsage/LqInventoryUsageListOutput.cs index 4f30762..3891c30 100644 --- a/netcore/src/Modularity/Extend/NCC.Extend.Entitys/Dto/LqInventoryUsage/LqInventoryUsageListOutput.cs +++ b/netcore/src/Modularity/Extend/NCC.Extend.Entitys/Dto/LqInventoryUsage/LqInventoryUsageListOutput.cs @@ -10,91 +10,91 @@ namespace NCC.Extend.Entitys.Dto.LqInventoryUsage /// /// 使用记录ID /// - public string Id { get; set; } + public string id { get; set; } /// /// 产品ID /// - public string ProductId { get; set; } + public string productId { get; set; } /// /// 产品名称 /// - public string ProductName { get; set; } + public string productName { get; set; } /// /// 产品类别 /// - public string ProductCategory { get; set; } + public string productCategory { get; set; } /// /// 产品价格 /// - public decimal ProductPrice { get; set; } + public decimal productPrice { get; set; } /// /// 门店ID /// - public string StoreId { get; set; } + public string storeId { get; set; } /// /// 门店名称 /// - public string StoreName { get; set; } + public string storeName { get; set; } /// /// 使用时间 /// - public DateTime UsageTime { get; set; } + public DateTime usageTime { get; set; } /// /// 使用数量 /// - public int UsageQuantity { get; set; } + public int usageQuantity { get; set; } /// /// 关联消耗ID /// - public string RelatedConsumeId { get; set; } + public string relatedConsumeId { get; set; } /// /// 创建人ID /// - public string CreateUser { get; set; } + public string createUser { get; set; } /// /// 创建人姓名 /// - public string CreateUserName { get; set; } + public string createUserName { get; set; } /// /// 创建时间 /// - public DateTime CreateTime { get; set; } + public DateTime createTime { get; set; } /// /// 更新人ID /// - public string UpdateUser { get; set; } + public string updateUser { get; set; } /// /// 更新人姓名 /// - public string UpdateUserName { get; set; } + public string updateUserName { get; set; } /// /// 更新时间 /// - public DateTime? UpdateTime { get; set; } + public DateTime? updateTime { get; set; } /// /// 是否有效(1:有效 0:无效) /// - public int IsEffective { get; set; } + public int isEffective { get; set; } /// /// 使用总价值 /// - public decimal UsageTotalValue { get; set; } + public decimal usageTotalValue { get; set; } } } diff --git a/netcore/src/Modularity/Extend/NCC.Extend.Entitys/Dto/LqStatistics/EmployeePerformanceStatisticsInput.cs b/netcore/src/Modularity/Extend/NCC.Extend.Entitys/Dto/LqStatistics/EmployeePerformanceStatisticsInput.cs new file mode 100644 index 0000000..ebfd1b6 --- /dev/null +++ b/netcore/src/Modularity/Extend/NCC.Extend.Entitys/Dto/LqStatistics/EmployeePerformanceStatisticsInput.cs @@ -0,0 +1,22 @@ +using System.ComponentModel.DataAnnotations; + +namespace NCC.Extend.Entitys.Dto.LqStatistics +{ + /// + /// 员工业绩统计查询输入参数 + /// + public class EmployeePerformanceStatisticsInput + { + /// + /// 员工ID(必填) + /// + [Required(ErrorMessage = "员工ID不能为空")] + public string UserId { get; set; } + + /// + /// 统计月份(格式:YYYYMM,如202510) + /// + [Required(ErrorMessage = "统计月份不能为空")] + public string StatisticsMonth { get; set; } + } +} diff --git a/netcore/src/Modularity/Extend/NCC.Extend.Entitys/Dto/LqStatistics/EmployeePerformanceStatisticsOutput.cs b/netcore/src/Modularity/Extend/NCC.Extend.Entitys/Dto/LqStatistics/EmployeePerformanceStatisticsOutput.cs new file mode 100644 index 0000000..f86697b --- /dev/null +++ b/netcore/src/Modularity/Extend/NCC.Extend.Entitys/Dto/LqStatistics/EmployeePerformanceStatisticsOutput.cs @@ -0,0 +1,73 @@ +namespace NCC.Extend.Entitys.Dto.LqStatistics +{ + /// + /// 员工业绩统计数据输出 + /// + public class EmployeePerformanceStatisticsOutput + { + /// + /// 员工ID + /// + public string UserId { get; set; } + + /// + /// 统计月份 + /// + public string StatisticsMonth { get; set; } + + /// + /// 拓客人数 + /// + public int InvitationCount { get; set; } + + /// + /// 邀约人数 + /// + public int InviteCount { get; set; } + + /// + /// 预约人数 + /// + public int AppointmentCount { get; set; } + + /// + /// 开单数量 + /// + public int BillingCount { get; set; } + + /// + /// 开单金额 + /// + public decimal BillingAmount { get; set; } + + /// + /// 消耗数量 + /// + public int ConsumeCount { get; set; } + + /// + /// 消耗金额 + /// + public decimal ConsumeAmount { get; set; } + + /// + /// 退卡数量 + /// + public int RefundCount { get; set; } + + /// + /// 退卡金额 + /// + public decimal RefundAmount { get; set; } + + /// + /// 人头(月度去重客户数) + /// + public int HeadCount { get; set; } + + /// + /// 人次(日度去重客户数) + /// + public int PersonCount { get; set; } + } +} diff --git a/netcore/src/Modularity/Extend/NCC.Extend/LqInventoryUsageService.cs b/netcore/src/Modularity/Extend/NCC.Extend/LqInventoryUsageService.cs index f4a181f..531e997 100644 --- a/netcore/src/Modularity/Extend/NCC.Extend/LqInventoryUsageService.cs +++ b/netcore/src/Modularity/Extend/NCC.Extend/LqInventoryUsageService.cs @@ -12,6 +12,7 @@ using NCC.Extend.Entitys.Dto.LqInventoryUsage; using NCC.Extend.Entitys.Enum; using NCC.Extend.Entitys.lq_inventory; using NCC.Extend.Entitys.lq_inventory_usage; +using NCC.Extend.Entitys.lq_mdxx; using NCC.Extend.Interfaces.LqInventoryUsage; using NCC.FriendlyException; using NCC.System.Entitys.Permission; @@ -184,23 +185,23 @@ namespace NCC.Extend .WhereIF(input.IsEffective.HasValue, x => x.IsEffective == input.IsEffective.Value) .Select(x => new LqInventoryUsageListOutput { - Id = x.Id, - ProductId = x.ProductId, - ProductName = "", - ProductCategory = "", - ProductPrice = 0, - StoreId = x.StoreId, - StoreName = "", - UsageTime = x.UsageTime, - UsageQuantity = x.UsageQuantity, - RelatedConsumeId = x.RelatedConsumeId, - CreateUser = x.CreateUser, - CreateUserName = "", - CreateTime = x.CreateTime, - UpdateUser = x.UpdateUser, - UpdateUserName = "", - UpdateTime = x.UpdateTime, - IsEffective = x.IsEffective + id = x.Id, + productId = x.ProductId, + productName = "", + productCategory = "", + productPrice = 0, + storeId = x.StoreId, + storeName = SqlFunc.Subqueryable().Where(u => u.Id == x.StoreId).Select(u => u.Dm), + usageTime = x.UsageTime, + usageQuantity = x.UsageQuantity, + relatedConsumeId = x.RelatedConsumeId, + createUser = x.CreateUser, + createUserName = "", + createTime = x.CreateTime, + updateUser = x.UpdateUser, + updateUserName = "", + updateTime = x.UpdateTime, + isEffective = x.IsEffective }) .MergeTable() .OrderBy(sidx + " " + input.sort) @@ -209,30 +210,30 @@ namespace NCC.Extend // 补充产品信息和用户信息 foreach (var item in data.list) { - if (!string.IsNullOrEmpty(item.ProductId)) + if (!string.IsNullOrEmpty(item.productId)) { - var product = await _db.Queryable().Where(p => p.Id == item.ProductId).FirstAsync(); + var product = await _db.Queryable().Where(p => p.Id == item.productId).FirstAsync(); if (product != null) { - item.ProductName = product.ProductName; - item.ProductCategory = product.ProductCategory; - item.ProductPrice = product.Price; + item.productName = product.ProductName; + item.productCategory = product.ProductCategory; + item.productPrice = product.Price; } } - if (!string.IsNullOrEmpty(item.StoreId)) + if (!string.IsNullOrEmpty(item.storeId)) { - var store = await _db.Queryable().Where(u => u.Id == item.StoreId).FirstAsync(); - item.StoreName = store?.RealName ?? ""; + var store = await _db.Queryable().Where(u => u.Id == item.storeId).FirstAsync(); + item.storeName = store?.RealName ?? ""; } - if (!string.IsNullOrEmpty(item.CreateUser)) + if (!string.IsNullOrEmpty(item.createUser)) { - var createUser = await _db.Queryable().Where(u => u.Id == item.CreateUser).FirstAsync(); - item.CreateUserName = createUser?.RealName ?? ""; + var createUser = await _db.Queryable().Where(u => u.Id == item.createUser).FirstAsync(); + item.createUserName = createUser?.RealName ?? ""; } - if (!string.IsNullOrEmpty(item.UpdateUser)) + if (!string.IsNullOrEmpty(item.updateUser)) { - var updateUser = await _db.Queryable().Where(u => u.Id == item.UpdateUser).FirstAsync(); - item.UpdateUserName = updateUser?.RealName ?? ""; + var updateUser = await _db.Queryable().Where(u => u.Id == item.updateUser).FirstAsync(); + item.updateUserName = updateUser?.RealName ?? ""; } } @@ -240,15 +241,15 @@ namespace NCC.Extend if (!string.IsNullOrWhiteSpace(input.ProductName) || !string.IsNullOrWhiteSpace(input.ProductCategory)) { data.list = data.list.Where(x => - (string.IsNullOrWhiteSpace(input.ProductName) || x.ProductName.Contains(input.ProductName)) && - (string.IsNullOrWhiteSpace(input.ProductCategory) || x.ProductCategory.Contains(input.ProductCategory)) + (string.IsNullOrWhiteSpace(input.ProductName) || x.productName.Contains(input.ProductName)) && + (string.IsNullOrWhiteSpace(input.ProductCategory) || x.productCategory.Contains(input.ProductCategory)) ).ToList(); } // 应用门店名称的过滤条件 if (!string.IsNullOrWhiteSpace(input.StoreName)) { - data.list = data.list.Where(x => x.StoreName.Contains(input.StoreName)).ToList(); + data.list = data.list.Where(x => x.storeName.Contains(input.StoreName)).ToList(); } return PageResult.SqlSugarPageResult(data); } diff --git a/netcore/src/Modularity/Extend/NCC.Extend/LqStatisticsService.cs b/netcore/src/Modularity/Extend/NCC.Extend/LqStatisticsService.cs index a824c65..797600e 100644 --- a/netcore/src/Modularity/Extend/NCC.Extend/LqStatisticsService.cs +++ b/netcore/src/Modularity/Extend/NCC.Extend/LqStatisticsService.cs @@ -2247,11 +2247,11 @@ namespace NCC.Extend.LqStatistics GROUP BY jksyj.jkszh, hyhk.md ) headcount_stats ON jksyj.jkszh = headcount_stats.jkszh AND hyhk.md = headcount_stats.md LEFT JOIN ( - -- 人次统计:日度去重到店数 + -- 人次统计:日度去重客户数(每天同一个客户只算一次) SELECT jksyj.jkszh, hyhk.md, - COUNT(DISTINCT DATE(hyhk.hksj)) as F_PersonCount + COUNT(DISTINCT CONCAT(hyhk.hy, '-', DATE(hyhk.hksj))) as F_PersonCount FROM lq_xh_jksyj jksyj INNER JOIN lq_xh_hyhk hyhk ON jksyj.glkdbh = hyhk.F_Id AND hyhk.F_IsEffective = 1 WHERE jksyj.F_IsEffective = 1 @@ -3382,5 +3382,250 @@ namespace NCC.Extend.LqStatistics #endregion + #region 员工业绩统计 + + /// + /// 获取员工业绩统计数据 + /// + /// + /// 根据员工ID和月份统计员工的完整业绩数据 + /// 包括:拓客人数、邀约人数、预约人数、开单、消耗、退卡、人头、人次 + /// + /// 示例请求: + /// ```json + /// { + /// "userId": "员工ID", + /// "statisticsMonth": "202510" + /// } + /// ``` + /// + /// 参数说明: + /// - userId: 员工ID(必填) + /// - statisticsMonth: 统计月份,格式YYYYMM(必填) + /// + /// 返回字段说明: + /// - UserId: 员工ID + /// - StatisticsMonth: 统计月份 + /// - InvitationCount: 拓客人数 + /// - InviteCount: 邀约人数 + /// - AppointmentCount: 预约人数 + /// - BillingCount: 开单数量 + /// - BillingAmount: 开单金额 + /// - ConsumeCount: 消耗数量 + /// - ConsumeAmount: 消耗金额 + /// - RefundCount: 退卡数量 + /// - RefundAmount: 退卡金额 + /// - HeadCount: 人头(月度去重客户数) + /// - PersonCount: 人次(日度去重客户数) + /// + /// 查询参数 + /// 员工业绩统计数据 + /// 成功返回统计数据 + /// 参数错误 + /// 服务器错误 + [HttpPost("get-employee-performance-statistics")] + public async Task GetEmployeePerformanceStatistics(EmployeePerformanceStatisticsInput input) + { + try + { + if (input == null || string.IsNullOrEmpty(input.StatisticsMonth) || input.StatisticsMonth.Length != 6) + { + throw NCCException.Oh("统计月份格式错误,请使用YYYYMM格式"); + } + + var statisticsMonth = input.StatisticsMonth; + + // 分步统计,确保效率和可维护性 + + // 1. 拓客人数统计 + var invitationCount = await GetInvitationCount(input.UserId, statisticsMonth); + + // 2. 邀约人数统计 + var inviteCount = await GetInviteCount(input.UserId, statisticsMonth); + + // 3. 预约人数统计 + var appointmentCount = await GetAppointmentCount(input.UserId, statisticsMonth); + + // 4. 开单统计(数量、金额) + var billingStats = await GetBillingStats(input.UserId, statisticsMonth); + + // 5. 消耗统计(数量、金额) + var consumeStats = await GetConsumeStats(input.UserId, statisticsMonth); + + // 6. 退卡统计(数量、金额) + var refundStats = await GetRefundStats(input.UserId, statisticsMonth); + + // 7. 人头统计 + var headCount = await GetHeadCount(input.UserId, statisticsMonth); + + // 8. 人次统计 + var personCount = await GetPersonCount(input.UserId, statisticsMonth); + + return new EmployeePerformanceStatisticsOutput + { + UserId = input.UserId, + StatisticsMonth = statisticsMonth, + InvitationCount = invitationCount, + InviteCount = inviteCount, + AppointmentCount = appointmentCount, + BillingCount = billingStats.Count, + BillingAmount = billingStats.Amount, + ConsumeCount = consumeStats.Count, + ConsumeAmount = consumeStats.Amount, + RefundCount = refundStats.Count, + RefundAmount = refundStats.Amount, + HeadCount = headCount, + PersonCount = personCount + }; + } + catch (Exception ex) + { + _logger.LogError(ex, $"获取员工业绩统计数据失败 - 员工ID: {input?.UserId}, 月份: {input?.StatisticsMonth}"); + throw NCCException.Oh($"获取员工业绩统计数据失败: {ex.Message}"); + } + } + + /// + /// 统计拓客人数 + /// + private async Task GetInvitationCount(string userId, string month) + { + var sql = $@" + SELECT COUNT(*) as Count + FROM lq_tkjlb + WHERE F_ExpansionUserId = '{userId}' + AND DATE_FORMAT(F_ExpansionTime, '%Y%m') = '{month}'"; + + var result = await _db.Ado.SqlQueryAsync(sql); + return Convert.ToInt32(result.FirstOrDefault()?.Count ?? 0); + } + + /// + /// 统计邀约人数 + /// + private async Task GetInviteCount(string userId, string month) + { + var sql = $@" + SELECT COUNT(DISTINCT yykh) as Count + FROM lq_yaoyjl + WHERE yyr = '{userId}' + AND DATE_FORMAT(yysj, '%Y%m') = '{month}'"; + + var result = await _db.Ado.SqlQueryAsync(sql); + return Convert.ToInt32(result.FirstOrDefault()?.Count ?? 0); + } + + /// + /// 统计预约人数 + /// + private async Task GetAppointmentCount(string userId, string month) + { + var sql = $@" + SELECT COUNT(DISTINCT gk) as Count + FROM lq_yyjl + WHERE yyr = '{userId}' + AND DATE_FORMAT(F_CreateTime, '%Y%m') = '{month}'"; + + var result = await _db.Ado.SqlQueryAsync(sql); + return Convert.ToInt32(result.FirstOrDefault()?.Count ?? 0); + } + + /// + /// 统计开单(数量和金额) + /// + private async Task<(int Count, decimal Amount)> GetBillingStats(string userId, string month) + { + var sql = $@" + SELECT + COUNT(*) as Count, + COALESCE(SUM(jksyj), 0) as Amount + FROM lq_kd_jksyj + WHERE jkszh = '{userId}' + AND F_IsEffective = 1 + AND DATE_FORMAT(yjsj, '%Y%m') = '{month}'"; + + var result = await _db.Ado.SqlQueryAsync(sql); + var data = result.FirstOrDefault(); + return (Convert.ToInt32(data?.Count ?? 0), Convert.ToDecimal(data?.Amount ?? 0)); + } + + /// + /// 统计消耗(数量和金额) + /// + private async Task<(int Count, decimal Amount)> GetConsumeStats(string userId, string month) + { + var sql = $@" + SELECT + COUNT(*) as Count, + COALESCE(SUM(jksyj.jksyj), 0) as Amount + FROM lq_xh_jksyj jksyj + INNER JOIN lq_xh_hyhk hyhk ON jksyj.glkdbh = hyhk.F_Id + WHERE jksyj.jkszh = '{userId}' + AND jksyj.F_IsEffective = 1 + AND hyhk.F_IsEffective = 1 + AND DATE_FORMAT(hyhk.hksj, '%Y%m') = '{month}'"; + + var result = await _db.Ado.SqlQueryAsync(sql); + var data = result.FirstOrDefault(); + return (Convert.ToInt32(data?.Count ?? 0), Convert.ToDecimal(data?.Amount ?? 0)); + } + + /// + /// 统计退卡(数量和金额) + /// + private async Task<(int Count, decimal Amount)> GetRefundStats(string userId, string month) + { + var sql = $@" + SELECT + COUNT(*) as Count, + COALESCE(SUM(jksyj), 0) as Amount + FROM lq_hytk_jksyj + WHERE jkszh = '{userId}' + AND F_IsEffective = 1 + AND DATE_FORMAT(tksj, '%Y%m') = '{month}'"; + + var result = await _db.Ado.SqlQueryAsync(sql); + var data = result.FirstOrDefault(); + return (Convert.ToInt32(data?.Count ?? 0), Convert.ToDecimal(data?.Amount ?? 0)); + } + + /// + /// 统计人头(月度去重客户数) + /// + private async Task GetHeadCount(string userId, string month) + { + var sql = $@" + SELECT COUNT(DISTINCT hyhk.hy) as Count + FROM lq_xh_jksyj jksyj + INNER JOIN lq_xh_hyhk hyhk ON jksyj.glkdbh = hyhk.F_Id + WHERE jksyj.jkszh = '{userId}' + AND jksyj.F_IsEffective = 1 + AND hyhk.F_IsEffective = 1 + AND DATE_FORMAT(hyhk.hksj, '%Y%m') = '{month}'"; + + var result = await _db.Ado.SqlQueryAsync(sql); + return Convert.ToInt32(result.FirstOrDefault()?.Count ?? 0); + } + + /// + /// 统计人次(日度去重客户数) + /// + private async Task GetPersonCount(string userId, string month) + { + var sql = $@" + SELECT COUNT(DISTINCT CONCAT(hyhk.hy, '-', DATE(hyhk.hksj))) as Count + FROM lq_xh_jksyj jksyj + INNER JOIN lq_xh_hyhk hyhk ON jksyj.glkdbh = hyhk.F_Id + WHERE jksyj.jkszh = '{userId}' + AND jksyj.F_IsEffective = 1 + AND hyhk.F_IsEffective = 1 + AND DATE_FORMAT(hyhk.hksj, '%Y%m') = '{month}'"; + + var result = await _db.Ado.SqlQueryAsync(sql); + return Convert.ToInt32(result.FirstOrDefault()?.Count ?? 0); + } + + #endregion + } } diff --git a/netcore/src/Modularity/Extend/NCC.Extend/LqXmzlService.cs b/netcore/src/Modularity/Extend/NCC.Extend/LqXmzlService.cs index 3024f22..3f157f9 100644 --- a/netcore/src/Modularity/Extend/NCC.Extend/LqXmzlService.cs +++ b/netcore/src/Modularity/Extend/NCC.Extend/LqXmzlService.cs @@ -536,8 +536,10 @@ namespace NCC.Extend.LqXmzl // 门店过滤(通过开单记录关联) if (!string.IsNullOrEmpty(input.StoreId)) { - query = query.InnerJoin((px, kd) => px.Glkdbh == kd.Id) - .Where((px, kd) => kd.Djmd == input.StoreId && kd.IsEffective == 1); + // 使用子查询过滤门店 - 在SQL层面过滤,避免别名问题 + query = query.Where(x => SqlFunc.Subqueryable() + .Where(kd => kd.Id == x.Glkdbh && kd.Djmd == input.StoreId && kd.IsEffective == 1) + .Any()); } var result = await query @@ -568,8 +570,10 @@ namespace NCC.Extend.LqXmzl if (!string.IsNullOrEmpty(input.StoreId)) { - memberCountQuery = memberCountQuery.InnerJoin((px, kd) => px.Glkdbh == kd.Id) - .Where((px, kd) => kd.Djmd == input.StoreId && kd.IsEffective == 1); + // 使用子查询过滤门店 - 在SQL层面过滤,避免别名问题 + memberCountQuery = memberCountQuery.Where(x => SqlFunc.Subqueryable() + .Where(kd => kd.Id == x.Glkdbh && kd.Djmd == input.StoreId && kd.IsEffective == 1) + .Any()); } var memberStats = await memberCountQuery @@ -605,8 +609,10 @@ namespace NCC.Extend.LqXmzl // 门店过滤(通过耗卡记录关联) if (!string.IsNullOrEmpty(input.StoreId)) { - query = query.InnerJoin((px, xh) => px.ConsumeInfoId == xh.Id) - .Where((px, xh) => xh.Md == input.StoreId && xh.IsEffective == 1); + // 使用子查询过滤门店 - 在SQL层面过滤,避免别名问题 + query = query.Where(x => SqlFunc.Subqueryable() + .Where(xh => xh.Id == x.ConsumeInfoId && xh.Md == input.StoreId && xh.IsEffective == 1) + .Any()); } var result = await query @@ -645,8 +651,10 @@ namespace NCC.Extend.LqXmzl // 门店过滤(通过退卡记录关联) if (!string.IsNullOrEmpty(input.StoreId)) { - query = query.InnerJoin((mx, hytk) => mx.RefundInfoId == hytk.Id) - .Where((mx, hytk) => hytk.Md == input.StoreId && hytk.IsEffective == 1); + // 使用子查询过滤门店 - 在SQL层面过滤,避免别名问题 + query = query.Where(x => SqlFunc.Subqueryable() + .Where(hytk => hytk.Id == x.RefundInfoId && hytk.Md == input.StoreId && hytk.IsEffective == 1) + .Any()); } var result = await query -- libgit2 0.21.4