From 3d98506d0b49e987f193e03d09dbfe954d43eee4 Mon Sep 17 00:00:00 2001 From: “wangming” <“wangming@antissoft.com”> Date: Tue, 16 Dec 2025 18:18:01 +0800 Subject: [PATCH] feat: 增强合同管理功能 --- excel/健康师额外数据模板_测试.xlsx | Bin 0 -> 25937 bytes excel/健康师额外数据模板_测试导入.xlsx | Bin 0 -> 25937 bytes netcore/src/Modularity/Extend/NCC.Extend.Entitys/Dto/LqInventoryUsage/LqInventoryUsageListOutput.cs | 5 +++++ netcore/src/Modularity/Extend/NCC.Extend.Entitys/Dto/LqKdKdjlb/BillingItemDetailListOutput.cs | 10 ++++++++++ netcore/src/Modularity/Extend/NCC.Extend.Entitys/Dto/LqLaundryFlow/LqLaundryFlowListOutput.cs | 12 ++++++++++++ netcore/src/Modularity/Extend/NCC.Extend.Entitys/Dto/LqLaundryFlow/LqLaundryFlowUpdateInput.cs | 47 +++++++++++++++++++++++++++++++++++++++++++++++ netcore/src/Modularity/Extend/NCC.Extend.Entitys/Entity/lq_contract_monthly_cost/LqContractMonthlyCostEntity.cs | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ netcore/src/Modularity/Extend/NCC.Extend.Entitys/Entity/lq_kd_deductinfo/LqKdDeductinfoEntity.cs | 6 ++++++ netcore/src/Modularity/Extend/NCC.Extend.Entitys/Entity/lq_laundry_flow/LqLaundryFlowEntity.cs | 12 ++++++++++++ netcore/src/Modularity/Extend/NCC.Extend/LqContractService.cs | 273 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- netcore/src/Modularity/Extend/NCC.Extend/LqDailyReportService.cs | 104 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------- netcore/src/Modularity/Extend/NCC.Extend/LqDirectorSalaryService.cs | 3 ++- netcore/src/Modularity/Extend/NCC.Extend/LqInventoryService.cs | 8 ++++---- netcore/src/Modularity/Extend/NCC.Extend/LqInventoryUsageService.cs | 2 ++ netcore/src/Modularity/Extend/NCC.Extend/LqKdKdjlbService.cs | 23 ++++++++++++++++++----- netcore/src/Modularity/Extend/NCC.Extend/LqLaundryFlowService.cs | 113 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- netcore/src/Modularity/Extend/NCC.Extend/LqReimbursementApplicationService.cs | 6 +++--- netcore/src/Modularity/Extend/NCC.Extend/LqSalaryExtraCalculationService.cs | 50 ++++++++++++++++++++++++++++++++++++++++---------- netcore/src/Modularity/Extend/NCC.Extend/LqSalaryService.cs | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++---------------- netcore/src/Modularity/Extend/NCC.Extend/LqStoreExpenseService.cs | 30 ++++++++++++++++++++++++++++-- netcore/src/Modularity/Extend/NCC.Extend/LqStoreManagerSalaryService.cs | 3 ++- netcore/src/Modularity/Extend/NCC.Extend/LqYcsdJsjService.cs | 14 +++++++++++++- sql/主任工资表新增毛利相关字段.sql | 1 + sql/修复储扣表ItemCategory字段为空的数据.sql | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ sql/创建合同成本按月统计表.sql | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ sql/合同成本表添加分类字段.sql | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ sql/开单扣减信息表添加开单时间字段.sql | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ sql/排查生美业绩统计差异-简化版.sql | 118 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ sql/排查生美业绩统计差异详细.sql | 170 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ sql/检查生美业绩统计差异.sql | 140 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ sql/清洗流水表添加送出送回时间字段.sql | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ test_tianwang_api.py | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 主任工资毛利计算逻辑梳理.md | 1 + 储扣表ItemCategory字段为空问题梳理.md | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 测试储扣接口.sh | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 35 files changed, 1789 insertions(+), 79 deletions(-) create mode 100644 excel/健康师额外数据模板_测试.xlsx create mode 100644 excel/健康师额外数据模板_测试导入.xlsx create mode 100644 netcore/src/Modularity/Extend/NCC.Extend.Entitys/Dto/LqLaundryFlow/LqLaundryFlowUpdateInput.cs create mode 100644 netcore/src/Modularity/Extend/NCC.Extend.Entitys/Entity/lq_contract_monthly_cost/LqContractMonthlyCostEntity.cs create mode 100644 sql/修复储扣表ItemCategory字段为空的数据.sql create mode 100644 sql/创建合同成本按月统计表.sql create mode 100644 sql/合同成本表添加分类字段.sql create mode 100644 sql/开单扣减信息表添加开单时间字段.sql create mode 100644 sql/排查生美业绩统计差异-简化版.sql create mode 100644 sql/排查生美业绩统计差异详细.sql create mode 100644 sql/检查生美业绩统计差异.sql create mode 100644 sql/清洗流水表添加送出送回时间字段.sql create mode 100644 test_tianwang_api.py create mode 100644 储扣表ItemCategory字段为空问题梳理.md create mode 100755 测试储扣接口.sh diff --git a/excel/健康师额外数据模板_测试.xlsx b/excel/健康师额外数据模板_测试.xlsx new file mode 100644 index 0000000..7afe8fd Binary files /dev/null and b/excel/健康师额外数据模板_测试.xlsx differ diff --git a/excel/健康师额外数据模板_测试导入.xlsx b/excel/健康师额外数据模板_测试导入.xlsx new file mode 100644 index 0000000..7afe8fd Binary files /dev/null and b/excel/健康师额外数据模板_测试导入.xlsx differ 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 f3501d1..a6d3f91 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 @@ -33,6 +33,11 @@ namespace NCC.Extend.Entitys.Dto.LqInventoryUsage public decimal productPrice { get; set; } /// + /// 产品归属仓库 + /// + public string productWarehouse { get; set; } + + /// /// 门店ID /// public string storeId { get; set; } diff --git a/netcore/src/Modularity/Extend/NCC.Extend.Entitys/Dto/LqKdKdjlb/BillingItemDetailListOutput.cs b/netcore/src/Modularity/Extend/NCC.Extend.Entitys/Dto/LqKdKdjlb/BillingItemDetailListOutput.cs index d3b0432..f570665 100644 --- a/netcore/src/Modularity/Extend/NCC.Extend.Entitys/Dto/LqKdKdjlb/BillingItemDetailListOutput.cs +++ b/netcore/src/Modularity/Extend/NCC.Extend.Entitys/Dto/LqKdKdjlb/BillingItemDetailListOutput.cs @@ -76,6 +76,16 @@ namespace NCC.Extend.Entitys.Dto.LqKdKdjlb /// 门店名称 /// public string storeName { get; set; } + + /// + /// 合作机构 + /// + public string hgjg { get; set; } + + /// + /// 付款医院 + /// + public string fkyy { get; set; } } } diff --git a/netcore/src/Modularity/Extend/NCC.Extend.Entitys/Dto/LqLaundryFlow/LqLaundryFlowListOutput.cs b/netcore/src/Modularity/Extend/NCC.Extend.Entitys/Dto/LqLaundryFlow/LqLaundryFlowListOutput.cs index e0176a3..863b92a 100644 --- a/netcore/src/Modularity/Extend/NCC.Extend.Entitys/Dto/LqLaundryFlow/LqLaundryFlowListOutput.cs +++ b/netcore/src/Modularity/Extend/NCC.Extend.Entitys/Dto/LqLaundryFlow/LqLaundryFlowListOutput.cs @@ -109,6 +109,18 @@ namespace NCC.Extend.Entitys.Dto.LqLaundryFlow /// [Display(Name = "创建时间")] public DateTime createTime { get; set; } + + /// + /// 送出时间(流水类型为0时使用) + /// + [Display(Name = "送出时间")] + public DateTime? sendTime { get; set; } + + /// + /// 送回时间(流水类型为1时使用) + /// + [Display(Name = "送回时间")] + public DateTime? returnTime { get; set; } } } diff --git a/netcore/src/Modularity/Extend/NCC.Extend.Entitys/Dto/LqLaundryFlow/LqLaundryFlowUpdateInput.cs b/netcore/src/Modularity/Extend/NCC.Extend.Entitys/Dto/LqLaundryFlow/LqLaundryFlowUpdateInput.cs new file mode 100644 index 0000000..7cc4772 --- /dev/null +++ b/netcore/src/Modularity/Extend/NCC.Extend.Entitys/Dto/LqLaundryFlow/LqLaundryFlowUpdateInput.cs @@ -0,0 +1,47 @@ +using System; +using System.ComponentModel.DataAnnotations; + +namespace NCC.Extend.Entitys.Dto.LqLaundryFlow +{ + /// + /// 清洗流水修改输入 + /// + public class LqLaundryFlowUpdateInput + { + /// + /// 记录ID + /// + [Required(ErrorMessage = "记录ID不能为空")] + [StringLength(50, ErrorMessage = "记录ID长度不能超过50个字符")] + [Display(Name = "记录ID")] + public string Id { get; set; } + + /// + /// 数量 + /// + [Range(0, int.MaxValue, ErrorMessage = "数量不能小于0")] + [Display(Name = "数量")] + public int? Quantity { get; set; } + + /// + /// 送出时间(流水类型为0时使用) + /// + [Display(Name = "送出时间")] + public DateTime? SendTime { get; set; } + + /// + /// 送回时间(流水类型为1时使用) + /// + [Display(Name = "送回时间")] + public DateTime? ReturnTime { get; set; } + + /// + /// 备注 + /// + [StringLength(1000, ErrorMessage = "备注长度不能超过1000个字符")] + [Display(Name = "备注")] + public string Remark { get; set; } + } +} + + diff --git a/netcore/src/Modularity/Extend/NCC.Extend.Entitys/Entity/lq_contract_monthly_cost/LqContractMonthlyCostEntity.cs b/netcore/src/Modularity/Extend/NCC.Extend.Entitys/Entity/lq_contract_monthly_cost/LqContractMonthlyCostEntity.cs new file mode 100644 index 0000000..e8939d7 --- /dev/null +++ b/netcore/src/Modularity/Extend/NCC.Extend.Entitys/Entity/lq_contract_monthly_cost/LqContractMonthlyCostEntity.cs @@ -0,0 +1,93 @@ +using System; +using NCC.Common.Const; +using SqlSugar; + +namespace NCC.Extend.Entitys.lq_contract_monthly_cost +{ + /// + /// 合同成本按月统计表 + /// + [SugarTable("lq_contract_monthly_cost")] + [Tenant(ClaimConst.TENANT_ID)] + public class LqContractMonthlyCostEntity + { + /// + /// 主键ID + /// + [SugarColumn(ColumnName = "F_Id", IsPrimaryKey = true)] + public string Id { get; set; } + + /// + /// 合同ID(关联lq_contract.F_Id) + /// + [SugarColumn(ColumnName = "F_ContractId")] + public string ContractId { get; set; } + + /// + /// 门店ID(关联lq_mdxx.F_Id,冗余字段便于查询) + /// + [SugarColumn(ColumnName = "F_StoreId")] + public string StoreId { get; set; } + + /// + /// 店名(冗余字段,便于查询) + /// + [SugarColumn(ColumnName = "F_StoreName")] + public string StoreName { get; set; } + + /// + /// 分类(冗余字段,便于按分类统计) + /// + [SugarColumn(ColumnName = "F_Category")] + public string Category { get; set; } + + /// + /// 统计月份(格式:YYYY-MM-01,表示该月的第一天) + /// + [SugarColumn(ColumnName = "F_Month")] + public DateTime Month { get; set; } + + /// + /// 该月的合同成本(缴租金额 / 交租周期) + /// + [SugarColumn(ColumnName = "F_MonthlyCost", DecimalDigits = 2)] + public decimal MonthlyCost { get; set; } + + /// + /// 交租周期(冗余字段,便于查询) + /// + [SugarColumn(ColumnName = "F_PaymentCycle")] + public int PaymentCycle { get; set; } + + /// + /// 缴租金额(冗余字段,便于查询) + /// + [SugarColumn(ColumnName = "F_PaymentAmount", DecimalDigits = 2)] + public decimal PaymentAmount { get; set; } + + /// + /// 是否有效(1-有效,0-无效) + /// + [SugarColumn(ColumnName = "F_IsEffective")] + public int IsEffective { get; set; } = 1; + + /// + /// 创建人ID + /// + [SugarColumn(ColumnName = "F_CreateUser")] + public string CreateUser { get; set; } + + /// + /// 创建时间 + /// + [SugarColumn(ColumnName = "F_CreateTime")] + public DateTime CreateTime { get; set; } + + /// + /// 更新时间 + /// + [SugarColumn(ColumnName = "F_UpdateTime")] + public DateTime? UpdateTime { get; set; } + } +} + diff --git a/netcore/src/Modularity/Extend/NCC.Extend.Entitys/Entity/lq_kd_deductinfo/LqKdDeductinfoEntity.cs b/netcore/src/Modularity/Extend/NCC.Extend.Entitys/Entity/lq_kd_deductinfo/LqKdDeductinfoEntity.cs index ea559d0..df8a633 100644 --- a/netcore/src/Modularity/Extend/NCC.Extend.Entitys/Entity/lq_kd_deductinfo/LqKdDeductinfoEntity.cs +++ b/netcore/src/Modularity/Extend/NCC.Extend.Entitys/Entity/lq_kd_deductinfo/LqKdDeductinfoEntity.cs @@ -36,6 +36,12 @@ namespace NCC.Extend.Entitys.lq_kd_deductinfo public string BillingId { get; set; } /// + /// 开单时间(来源:lq_kd_kdjlb.kdrq) + /// + [SugarColumn(ColumnName = "F_BillingTime")] + public DateTime? BillingTime { get; set; } + + /// /// 合计金额 /// [SugarColumn(ColumnName = "F_Amount")] diff --git a/netcore/src/Modularity/Extend/NCC.Extend.Entitys/Entity/lq_laundry_flow/LqLaundryFlowEntity.cs b/netcore/src/Modularity/Extend/NCC.Extend.Entitys/Entity/lq_laundry_flow/LqLaundryFlowEntity.cs index 3fc4e2a..6d8dbf1 100644 --- a/netcore/src/Modularity/Extend/NCC.Extend.Entitys/Entity/lq_laundry_flow/LqLaundryFlowEntity.cs +++ b/netcore/src/Modularity/Extend/NCC.Extend.Entitys/Entity/lq_laundry_flow/LqLaundryFlowEntity.cs @@ -88,6 +88,18 @@ namespace NCC.Extend.Entitys.lq_laundry_flow /// [SugarColumn(ColumnName = "F_CreateTime")] public DateTime CreateTime { get; set; } + + /// + /// 送出时间(流水类型为0时使用) + /// + [SugarColumn(ColumnName = "F_SendTime")] + public DateTime? SendTime { get; set; } + + /// + /// 送回时间(流水类型为1时使用) + /// + [SugarColumn(ColumnName = "F_ReturnTime")] + public DateTime? ReturnTime { get; set; } } } diff --git a/netcore/src/Modularity/Extend/NCC.Extend/LqContractService.cs b/netcore/src/Modularity/Extend/NCC.Extend/LqContractService.cs index 9a85e27..87e4070 100644 --- a/netcore/src/Modularity/Extend/NCC.Extend/LqContractService.cs +++ b/netcore/src/Modularity/Extend/NCC.Extend/LqContractService.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; @@ -12,6 +13,7 @@ using NCC.Extend.Entitys.Dto.LqContract; using NCC.Extend.Entitys.Enum; using NCC.Extend.Entitys.lq_contract; using NCC.Extend.Entitys.lq_contract_rent_detail; +using NCC.Extend.Entitys.lq_contract_monthly_cost; using NCC.Extend.Entitys.lq_mdxx; using NCC.FriendlyException; using NCC.System.Entitys.Permission; @@ -147,6 +149,9 @@ namespace NCC.Extend // 自动生成月租明细 await GenerateRentDetailsAsync(contractEntity.Id, contractEntity.ContractStartDate, contractEntity.ContractEndDate, contractEntity.PaymentCycle, contractEntity.PaymentAmount); + // 自动生成按月成本记录 + await GenerateMonthlyCostAsync(contractEntity.Id, contractEntity.StoreId, contractEntity.StoreName, contractEntity.Category, contractEntity.ContractStartDate, contractEntity.ContractEndDate, contractEntity.PaymentCycle, contractEntity.PaymentAmount); + // 计算下次应交时间 await CalculateNextPaymentDate(contractEntity.Id); @@ -249,6 +254,9 @@ namespace NCC.Extend contract.PaymentCycle != input.PaymentCycle || contract.PaymentAmount != input.PaymentAmount; + // 判断是否需要更新成本记录的分类(如果只修改了分类,不需要重新生成,只需更新分类字段) + bool needUpdateCategory = contract.Category != input.Category; + // 更新合同信息 contract.StoreId = input.StoreId; contract.StoreName = store.Dm ?? ""; @@ -287,8 +295,33 @@ namespace NCC.Extend .Where(x => x.ContractId == contract.Id && x.IsEffective == StatusEnum.有效.GetHashCode()) .ExecuteCommandAsync(); + // 删除旧的成本记录(逻辑删除) + await _db.Updateable() + .SetColumns(x => new LqContractMonthlyCostEntity + { + IsEffective = StatusEnum.无效.GetHashCode(), + UpdateTime = DateTime.Now + }) + .Where(x => x.ContractId == contract.Id && x.IsEffective == StatusEnum.有效.GetHashCode()) + .ExecuteCommandAsync(); + // 生成新的明细 await GenerateRentDetailsAsync(contract.Id, contract.ContractStartDate, contract.ContractEndDate, contract.PaymentCycle, contract.PaymentAmount); + + // 生成新的成本记录 + await GenerateMonthlyCostAsync(contract.Id, contract.StoreId, contract.StoreName, contract.Category, contract.ContractStartDate, contract.ContractEndDate, contract.PaymentCycle, contract.PaymentAmount); + } + else if (needUpdateCategory) + { + // 如果只修改了分类,只需更新成本记录的分类字段 + await _db.Updateable() + .SetColumns(x => new LqContractMonthlyCostEntity + { + Category = contract.Category, + UpdateTime = DateTime.Now + }) + .Where(x => x.ContractId == contract.Id && x.IsEffective == StatusEnum.有效.GetHashCode()) + .ExecuteCommandAsync(); } // 重新计算下次应交时间 @@ -365,6 +398,16 @@ namespace NCC.Extend .Where(x => x.ContractId == id && x.IsEffective == StatusEnum.有效.GetHashCode()) .ExecuteCommandAsync(); + // 删除该合同的所有成本记录(逻辑删除) + await _db.Updateable() + .SetColumns(x => new LqContractMonthlyCostEntity + { + IsEffective = StatusEnum.无效.GetHashCode(), + UpdateTime = DateTime.Now + }) + .Where(x => x.ContractId == id && x.IsEffective == StatusEnum.有效.GetHashCode()) + .ExecuteCommandAsync(); + // 删除合同(逻辑删除) contract.IsEffective = StatusEnum.无效.GetHashCode(); contract.UpdateUser = _userManager.UserId; @@ -792,6 +835,35 @@ namespace NCC.Extend #endregion + #region 根据合同id获取合同成本列表 + /// + /// 根据合同id获取合同成本列表 + /// + /// + /// + [HttpGet("GetContractCostList")] + public async Task GetContractCostListAsync([FromQuery] string contractId) + { + try + { + if (string.IsNullOrWhiteSpace(contractId)) + { + throw NCCException.Oh("合同ID不能为空"); + } + + var costList = await _db.Queryable() + .Where(x => x.ContractId == contractId && x.IsEffective == StatusEnum.有效.GetHashCode()) + .ToListAsync(); + return costList; + } + catch (Exception ex) + { + _logger.LogError(ex, "获取合同成本列表失败"); + throw NCCException.Oh($"获取合同成本列表失败:{ex.Message}"); + } + } + #endregion + #region 私有方法 /// @@ -842,6 +914,57 @@ namespace NCC.Extend } /// + /// 生成按月成本记录 + /// + /// 合同ID + /// 门店ID + /// 店名 + /// 分类 + /// 合同起始日期 + /// 合同结束日期 + /// 交租周期(月) + /// 缴租金额 + private async Task GenerateMonthlyCostAsync(string contractId, string storeId, string storeName, string category, DateTime contractStartDate, DateTime contractEndDate, int paymentCycle, decimal paymentAmount) + { + // 计算每个月成本 = 缴租金额 / 交租周期 + var monthlyCost = paymentAmount / paymentCycle; + + var costRecords = new List(); + var currentMonth = new DateTime(contractStartDate.Year, contractStartDate.Month, 1); + + // 从合同起始月份开始,逐月生成成本记录,直到合同结束月份 + while (currentMonth <= contractEndDate) + { + var costRecord = new LqContractMonthlyCostEntity + { + Id = YitIdHelper.NextId().ToString(), + ContractId = contractId, + StoreId = storeId, + StoreName = storeName, + Category = category, + Month = currentMonth, + MonthlyCost = monthlyCost, + PaymentCycle = paymentCycle, + PaymentAmount = paymentAmount, + IsEffective = StatusEnum.有效.GetHashCode(), + CreateUser = _userManager.UserId, + CreateTime = DateTime.Now + }; + + costRecords.Add(costRecord); + + // 计算下一个月 + currentMonth = currentMonth.AddMonths(1); + } + + // 批量插入 + if (costRecords.Any()) + { + await _db.Insertable(costRecords).ExecuteCommandAsync(); + } + } + + /// /// 计算下次应交时间(匿名方法) /// /// 合同ID @@ -888,6 +1011,152 @@ namespace NCC.Extend #endregion + #region 获取合同成本按月统计 + + /// + /// 获取合同成本按月统计 + /// + /// + /// 根据合同ID、门店ID、月份等条件查询合同成本按月统计数据 + /// + /// 示例请求: + /// ``` + /// GET /api/Extend/LqContract/GetMonthlyCost?contractId=合同ID&storeId=门店ID&startMonth=2025-01&endMonth=2025-12 + /// ``` + /// + /// 参数说明: + /// - contractId: 合同ID(可选) + /// - storeId: 门店ID(可选) + /// - startMonth: 开始月份(格式:YYYY-MM,可选) + /// - endMonth: 结束月份(格式:YYYY-MM,可选) + /// + /// 合同ID(可选) + /// 门店ID(可选) + /// 分类(可选) + /// 开始月份(格式:YYYY-MM,可选) + /// 结束月份(格式:YYYY-MM,可选) + /// 合同成本按月统计列表 + /// 查询成功 + /// 服务器错误 + [HttpGet("GetMonthlyCost")] + public async Task GetMonthlyCostAsync( + [FromQuery] string contractId = null, + [FromQuery] string storeId = null, + [FromQuery] string category = null, + [FromQuery] string startMonth = null, + [FromQuery] string endMonth = null) + { + try + { + var query = _db.Queryable() + .Where(x => x.IsEffective == StatusEnum.有效.GetHashCode()) + .WhereIF(!string.IsNullOrWhiteSpace(contractId), x => x.ContractId == contractId) + .WhereIF(!string.IsNullOrWhiteSpace(storeId), x => x.StoreId == storeId) + .WhereIF(!string.IsNullOrWhiteSpace(category), x => x.Category == category); + + // 处理月份范围筛选 + if (!string.IsNullOrWhiteSpace(startMonth)) + { + if (DateTime.TryParseExact(startMonth, "yyyy-MM", null, DateTimeStyles.None, out DateTime startDate)) + { + var startMonthDate = new DateTime(startDate.Year, startDate.Month, 1); + query = query.Where(x => x.Month >= startMonthDate); + } + } + + if (!string.IsNullOrWhiteSpace(endMonth)) + { + if (DateTime.TryParseExact(endMonth, "yyyy-MM", null, DateTimeStyles.None, out DateTime endDate)) + { + var endMonthDate = new DateTime(endDate.Year, endDate.Month, DateTime.DaysInMonth(endDate.Year, endDate.Month)); + query = query.Where(x => x.Month <= endMonthDate); + } + } + + var data = await query + .OrderBy(x => x.Month) + .Select(x => new + { + id = x.Id, + contractId = x.ContractId, + storeId = x.StoreId, + storeName = x.StoreName, + category = x.Category, + month = x.Month.ToString("yyyy-MM"), + monthlyCost = x.MonthlyCost, + paymentCycle = x.PaymentCycle, + paymentAmount = x.PaymentAmount, + createTime = x.CreateTime + }) + .ToListAsync(); + + return new { code = 200, msg = "查询成功", data = data }; + } + catch (Exception ex) + { + _logger.LogError(ex, "获取合同成本按月统计失败"); + throw NCCException.Oh($"查询失败:{ex.Message}"); + } + } + + /// + /// 按门店和月份统计合同成本 + /// + /// + /// 根据门店ID和月份统计该门店的合同成本总和 + /// + /// 示例请求: + /// ``` + /// GET /api/Extend/LqContract/GetStoreMonthlyCost?storeId=门店ID&month=2025-11 + /// ``` + /// + /// 门店ID + /// 月份(格式:YYYY-MM) + /// 该门店该月的合同成本总和 + /// 查询成功 + /// 参数错误 + /// 服务器错误 + [HttpGet("GetStoreMonthlyCost")] + public async Task GetStoreMonthlyCostAsync( + [FromQuery] string storeId, + [FromQuery] string month) + { + try + { + if (string.IsNullOrWhiteSpace(storeId)) + { + throw NCCException.Oh("门店ID不能为空"); + } + + if (string.IsNullOrWhiteSpace(month)) + { + throw NCCException.Oh("月份不能为空"); + } + + if (!DateTime.TryParseExact(month, "yyyy-MM", null, DateTimeStyles.None, out DateTime monthDate)) + { + throw NCCException.Oh("月份格式错误,应为 YYYY-MM"); + } + + var monthStart = new DateTime(monthDate.Year, monthDate.Month, 1); + + var totalCost = await _db.Queryable() + .Where(x => x.StoreId == storeId + && x.Month == monthStart + && x.IsEffective == StatusEnum.有效.GetHashCode()) + .SumAsync(x => x.MonthlyCost); + + return new { code = 200, msg = "查询成功", data = new { storeId = storeId, month = month, totalCost = totalCost } }; + } + catch (Exception ex) + { + _logger.LogError(ex, "按门店和月份统计合同成本失败"); + throw NCCException.Oh($"查询失败:{ex.Message}"); + } + } + + #endregion + #region 统计门店合同费用 /// @@ -960,13 +1229,13 @@ namespace NCC.Extend var details = await _db.Queryable( (detail, contract) => new JoinQueryInfos( JoinType.Inner, detail.ContractId == contract.Id)) - .Where((detail, contract) => + .Where((detail, contract) => contract.StoreId == input.StoreId && contract.IsEffective == StatusEnum.有效.GetHashCode() && detail.IsEffective == StatusEnum.有效.GetHashCode() && detail.PaymentMonth >= monthStart && detail.PaymentMonth <= monthEnd) - .WhereIF(input.Categories != null && input.Categories.Length > 0, + .WhereIF(input.Categories != null && input.Categories.Length > 0, (detail, contract) => contract.Category != null && input.Categories.Contains(contract.Category)) .Select((detail, contract) => new { diff --git a/netcore/src/Modularity/Extend/NCC.Extend/LqDailyReportService.cs b/netcore/src/Modularity/Extend/NCC.Extend/LqDailyReportService.cs index e1cad62..ef3bad1 100644 --- a/netcore/src/Modularity/Extend/NCC.Extend/LqDailyReportService.cs +++ b/netcore/src/Modularity/Extend/NCC.Extend/LqDailyReportService.cs @@ -706,14 +706,15 @@ namespace NCC.Extend } // 2.3.1 查询开单业绩(按品项类型) + // 使用targetDict来关联,确保每个门店只关联一条目标记录,避免重复统计 + // 先按门店统计业绩,再按部门汇总 var billingSql = $@" SELECT - target.{deptField} as TargetDeptId, + billing.djmd as StoreId, COALESCE(SUM(pxmx.F_ActualPrice), 0) as StoreAmount FROM lq_kd_pxmx pxmx INNER JOIN lq_kd_kdjlb billing ON pxmx.glkdbh = billing.F_Id INNER JOIN lq_xmzl item ON pxmx.px = item.F_Id - INNER JOIN lq_md_target target ON billing.djmd = target.F_StoreId AND target.F_Month = '{month}' WHERE pxmx.F_IsEffective = 1 AND billing.F_IsEffective = 1 AND item.F_IsEffective = 1 @@ -721,35 +722,48 @@ namespace NCC.Extend AND billing.djmd IN ('{storeIdsStr}') AND billing.kdrq >= '{startDate.ToString("yyyy-MM-dd")} 00:00:00' AND billing.kdrq < '{endDate.AddDays(1).ToString("yyyy-MM-dd")} 00:00:00' - GROUP BY target.{deptField}"; + GROUP BY billing.djmd"; var billingData = await _db.Ado.SqlQueryAsync(billingSql); - // 分配开单业绩到对应部门 + // 分配开单业绩到对应部门(使用targetDict确保每个门店只关联一条目标记录) foreach (var billing in billingData ?? Enumerable.Empty()) { var storeAmount = billing?.StoreAmount != null ? Convert.ToDecimal(billing.StoreAmount) : 0m; - var targetDeptId = billing?.TargetDeptId?.ToString(); + var storeId = billing?.StoreId?.ToString(); - if (storeAmount <= 0 || string.IsNullOrEmpty(targetDeptId)) + if (storeAmount <= 0 || string.IsNullOrEmpty(storeId)) continue; - // 只分配给在查询列表中的部门,避免重复统计 - if (departmentDict.ContainsKey(targetDeptId)) + // 从targetDict中获取门店对应的部门信息 + if (targetDict.ContainsKey(storeId)) { - departmentDict[targetDeptId].BillingPerformance += storeAmount; + var target = targetDict[storeId]; + // 动态获取部门字段值 + string targetDeptId = null; + if (deptField == "F_EducationDepartment") + targetDeptId = target?.F_EducationDepartment?.ToString(); + else if (deptField == "F_TechDepartment") + targetDeptId = target?.F_TechDepartment?.ToString(); + else if (deptField == "F_MajorProjectDepartment") + targetDeptId = target?.F_MajorProjectDepartment?.ToString(); + + if (!string.IsNullOrEmpty(targetDeptId) && departmentDict.ContainsKey(targetDeptId)) + { + departmentDict[targetDeptId].BillingPerformance += storeAmount; + } } } // 2.3.2 查询退卡业绩(按品项类型) + // 使用targetDict来关联,确保每个门店只关联一条目标记录,避免重复统计 var refundSql = $@" SELECT - target.{deptField} as TargetDeptId, + refund.md as StoreId, COALESCE(SUM(refund_mx.tkje), 0) as StoreRefundAmount FROM lq_hytk_mx refund_mx INNER JOIN lq_hytk_hytk refund ON refund_mx.F_RefundInfoId = refund.F_Id INNER JOIN lq_xmzl item ON refund_mx.px = item.F_Id - INNER JOIN lq_md_target target ON refund.md = target.F_StoreId AND target.F_Month = '{month}' WHERE refund_mx.F_IsEffective = 1 AND refund.F_IsEffective = 1 AND item.F_IsEffective = 1 @@ -757,59 +771,86 @@ namespace NCC.Extend AND refund.md IN ('{storeIdsStr}') AND refund.tksj >= '{startDate.ToString("yyyy-MM-dd")} 00:00:00' AND refund.tksj < '{endDate.AddDays(1).ToString("yyyy-MM-dd")} 00:00:00' - GROUP BY target.{deptField}"; + GROUP BY refund.md"; var refundData = await _db.Ado.SqlQueryAsync(refundSql); - // 分配退卡业绩到对应部门 + // 分配退卡业绩到对应部门(使用targetDict确保每个门店只关联一条目标记录) foreach (var refund in refundData ?? Enumerable.Empty()) { var storeRefundAmount = refund?.StoreRefundAmount != null ? Convert.ToDecimal(refund.StoreRefundAmount) : 0m; - var targetDeptId = refund?.TargetDeptId?.ToString(); + var storeId = refund?.StoreId?.ToString(); - if (storeRefundAmount <= 0 || string.IsNullOrEmpty(targetDeptId)) + if (storeRefundAmount <= 0 || string.IsNullOrEmpty(storeId)) continue; - // 只分配给在查询列表中的部门,避免重复统计 - if (departmentDict.ContainsKey(targetDeptId)) + // 从targetDict中获取门店对应的部门信息 + if (targetDict.ContainsKey(storeId)) { - departmentDict[targetDeptId].RefundPerformance += storeRefundAmount; + var target = targetDict[storeId]; + // 动态获取部门字段值 + string targetDeptId = null; + if (deptField == "F_EducationDepartment") + targetDeptId = target?.F_EducationDepartment?.ToString(); + else if (deptField == "F_TechDepartment") + targetDeptId = target?.F_TechDepartment?.ToString(); + else if (deptField == "F_MajorProjectDepartment") + targetDeptId = target?.F_MajorProjectDepartment?.ToString(); + + if (!string.IsNullOrEmpty(targetDeptId) && departmentDict.ContainsKey(targetDeptId)) + { + departmentDict[targetDeptId].RefundPerformance += storeRefundAmount; + } } } // 2.3.3 查询储扣金额(按品项类型) + // 使用储扣记录表中的开单时间(F_BillingTime)进行时间过滤,如果为空则使用开单记录表的开单时间(kdrq) + // 使用targetDict来关联,确保每个门店只关联一条目标记录,避免重复统计 var deductSql = $@" SELECT - target.{deptField} as TargetDeptId, + billing.djmd as StoreId, COALESCE(SUM(deduct.F_Amount), 0) as StoreDeductAmount FROM lq_kd_deductinfo deduct INNER JOIN lq_kd_kdjlb billing ON deduct.F_BillingId = billing.F_Id INNER JOIN lq_xmzl item ON deduct.F_ItemId = item.F_Id - INNER JOIN lq_md_target target ON billing.djmd = target.F_StoreId AND target.F_Month = '{month}' WHERE deduct.F_IsEffective = 1 AND billing.F_IsEffective = 1 AND item.F_IsEffective = 1 AND item.qt2 = '{itemType}' AND billing.djmd IN ('{storeIdsStr}') - AND billing.kdrq >= '{startDate.ToString("yyyy-MM-dd")} 00:00:00' - AND billing.kdrq < '{endDate.AddDays(1).ToString("yyyy-MM-dd")} 00:00:00' - GROUP BY target.{deptField}"; + AND COALESCE(deduct.F_BillingTime, billing.kdrq) >= '{startDate.ToString("yyyy-MM-dd")} 00:00:00' + AND COALESCE(deduct.F_BillingTime, billing.kdrq) < '{endDate.AddDays(1).ToString("yyyy-MM-dd")} 00:00:00' + GROUP BY billing.djmd"; var deductData = await _db.Ado.SqlQueryAsync(deductSql); - // 分配储扣金额到对应部门 + // 分配储扣金额到对应部门(使用targetDict确保每个门店只关联一条目标记录) foreach (var deduct in deductData ?? Enumerable.Empty()) { var storeDeductAmount = deduct?.StoreDeductAmount != null ? Convert.ToDecimal(deduct.StoreDeductAmount) : 0m; - var targetDeptId = deduct?.TargetDeptId?.ToString(); + var storeId = deduct?.StoreId?.ToString(); - if (storeDeductAmount <= 0 || string.IsNullOrEmpty(targetDeptId)) + if (storeDeductAmount <= 0 || string.IsNullOrEmpty(storeId)) continue; - // 只累加到在查询列表中的部门,避免重复统计 - if (departmentDict.ContainsKey(targetDeptId)) + // 从targetDict中获取门店对应的部门信息 + if (targetDict.ContainsKey(storeId)) { - departmentDict[targetDeptId].DeductAmount += storeDeductAmount; + var target = targetDict[storeId]; + // 动态获取部门字段值 + string targetDeptId = null; + if (deptField == "F_EducationDepartment") + targetDeptId = target?.F_EducationDepartment?.ToString(); + else if (deptField == "F_TechDepartment") + targetDeptId = target?.F_TechDepartment?.ToString(); + else if (deptField == "F_MajorProjectDepartment") + targetDeptId = target?.F_MajorProjectDepartment?.ToString(); + + if (!string.IsNullOrEmpty(targetDeptId) && departmentDict.ContainsKey(targetDeptId)) + { + departmentDict[targetDeptId].DeductAmount += storeDeductAmount; + } } } } @@ -1801,6 +1842,7 @@ namespace NCC.Extend var (startDate, endDate) = GetTimeRange(input.StartTime, input.EndTime); // 统计储扣金额,按品项分类分组 + // 使用储扣记录表中的开单时间(F_BillingTime)进行时间过滤,如果为空则使用开单记录表的开单时间(kdrq) var sql = $@" SELECT COALESCE(SUM(CASE WHEN item.qt2 = '医美' THEN deduct.F_Amount ELSE 0 END), 0) as YiMeiAmount, @@ -1813,8 +1855,8 @@ namespace NCC.Extend LEFT JOIN lq_xmzl item ON deduct.F_ItemId = item.F_Id AND item.F_IsEffective = 1 WHERE deduct.F_IsEffective = 1 AND billing.F_IsEffective = 1 - AND billing.kdrq >= '{startDate:yyyy-MM-dd} 00:00:00' - AND billing.kdrq < '{endDate.AddDays(1):yyyy-MM-dd} 00:00:00'"; + AND COALESCE(deduct.F_BillingTime, billing.kdrq) >= '{startDate:yyyy-MM-dd} 00:00:00' + AND COALESCE(deduct.F_BillingTime, billing.kdrq) < '{endDate.AddDays(1):yyyy-MM-dd} 00:00:00'"; var result = await _db.Ado.SqlQueryAsync(sql); var data = result.FirstOrDefault(); diff --git a/netcore/src/Modularity/Extend/NCC.Extend/LqDirectorSalaryService.cs b/netcore/src/Modularity/Extend/NCC.Extend/LqDirectorSalaryService.cs index f136964..446ba3b 100644 --- a/netcore/src/Modularity/Extend/NCC.Extend/LqDirectorSalaryService.cs +++ b/netcore/src/Modularity/Extend/NCC.Extend/LqDirectorSalaryService.cs @@ -296,6 +296,7 @@ namespace NCC.Extend .ToDictionary(x => x.StoreId.ToString(), x => Convert.ToDecimal(x.ExpenseAmount ?? 0)); // 1.12 洗毛巾费用统计(只统计送出的记录,F_FlowType = 0) + // 优先使用送出时间(F_SendTime),如果为空则使用创建时间(F_CreateTime) var laundryCostSql = $@" SELECT F_StoreId as StoreId, @@ -303,7 +304,7 @@ namespace NCC.Extend FROM lq_laundry_flow WHERE F_IsEffective = 1 AND F_FlowType = 0 - AND DATE_FORMAT(F_CreateTime, '%Y%m') = @monthStr + AND DATE_FORMAT(COALESCE(F_SendTime, F_CreateTime), '%Y%m') = @monthStr GROUP BY F_StoreId"; var laundryCostData = await _db.Ado.SqlQueryAsync(laundryCostSql, new { monthStr }); diff --git a/netcore/src/Modularity/Extend/NCC.Extend/LqInventoryService.cs b/netcore/src/Modularity/Extend/NCC.Extend/LqInventoryService.cs index bf5d3d2..c1e24fd 100644 --- a/netcore/src/Modularity/Extend/NCC.Extend/LqInventoryService.cs +++ b/netcore/src/Modularity/Extend/NCC.Extend/LqInventoryService.cs @@ -186,8 +186,8 @@ namespace NCC.Extend _db.Ado.BeginTran(); try { - var isOk = await _db.Insertable(inventoryEntity).ExecuteCommandAsync(); - if (!(isOk > 0)) throw NCCException.Oh(ErrorCode.COM1000); + var isOk = await _db.Insertable(inventoryEntity).ExecuteCommandAsync(); + if (!(isOk > 0)) throw NCCException.Oh(ErrorCode.COM1000); // 计算并更新产品的平均单价(加权平均成本法) // 普通入库和采购入库都需要更新平均单价 @@ -398,8 +398,8 @@ namespace NCC.Extend _db.Ado.BeginTran(); try { - var isOk = await _db.Updateable(existingInventory).ExecuteCommandAsync(); - if (!(isOk > 0)) throw NCCException.Oh(ErrorCode.COM1000); + var isOk = await _db.Updateable(existingInventory).ExecuteCommandAsync(); + if (!(isOk > 0)) throw NCCException.Oh(ErrorCode.COM1000); // 如果数量或单价发生变化,需要重新计算平均单价 // 注意:更新库存时,如果数量或单价变化,需要重新计算整个产品的平均单价 diff --git a/netcore/src/Modularity/Extend/NCC.Extend/LqInventoryUsageService.cs b/netcore/src/Modularity/Extend/NCC.Extend/LqInventoryUsageService.cs index 6f7d9d1..ebc1b01 100644 --- a/netcore/src/Modularity/Extend/NCC.Extend/LqInventoryUsageService.cs +++ b/netcore/src/Modularity/Extend/NCC.Extend/LqInventoryUsageService.cs @@ -503,6 +503,7 @@ namespace NCC.Extend productName = product.ProductName, productCategory = product.ProductCategory, productPrice = product.Price, + productWarehouse = product.Warehouse, // 产品归属仓库 storeId = u.StoreId, storeName = SqlFunc.Subqueryable().Where(store => store.Id == u.StoreId).Select(store => store.Dm), usageTime = u.UsageTime, @@ -648,6 +649,7 @@ namespace NCC.Extend productName = product.ProductName, productCategory = product.ProductCategory, productPrice = product.Price, + productWarehouse = product.Warehouse, // 产品归属仓库 storeId = u.StoreId, storeName = SqlFunc.Subqueryable().Where(store => store.Id == u.StoreId).Select(store => store.Dm), usageTime = u.UsageTime, diff --git a/netcore/src/Modularity/Extend/NCC.Extend/LqKdKdjlbService.cs b/netcore/src/Modularity/Extend/NCC.Extend/LqKdKdjlbService.cs index b4733cf..66eec98 100644 --- a/netcore/src/Modularity/Extend/NCC.Extend/LqKdKdjlbService.cs +++ b/netcore/src/Modularity/Extend/NCC.Extend/LqKdKdjlbService.cs @@ -897,6 +897,7 @@ namespace NCC.Extend.LqKdKdjlb { Id = YitIdHelper.NextId().ToString(), BillingId = newEntity.Id, + BillingTime = newEntity.Kdrq, // 设置开单时间 DeductId = item.DeductId, DeductType = item.DeductType, Amount = item.Amount, @@ -1243,6 +1244,7 @@ namespace NCC.Extend.LqKdKdjlb { Id = YitIdHelper.NextId().ToString(), BillingId = id, + BillingTime = entity.Kdrq, // 设置开单时间 DeductId = item.DeductId, DeductType = item.DeductType, Amount = item.Amount, @@ -1252,7 +1254,7 @@ namespace NCC.Extend.LqKdKdjlb ItemId = item.ItemId, IsEffective = StatusEnum.有效.GetHashCode(), // 设置为有效 CreateTime = DateTime.Now, // 设置创建时间 - ItemCategory = await _db.Queryable().Where(x => x.Id == item.DeductId).Select(x => x.Qt2).FirstAsync() + ItemCategory = await _db.Queryable().Where(x => x.Id == item.ItemId).Select(x => x.Qt2).FirstAsync() // 修复:使用 ItemId 而不是 DeductId }; allDeductEntities.Add(lqKdDeductEntity); } @@ -3791,11 +3793,19 @@ namespace NCC.Extend.LqKdKdjlb } // 批量查询开单记录,获取门店ID + // 批量查询开单记录,获取门店ID及扩展信息 var billingStoreDict = new Dictionary(); + var billingExtraInfoDict = new Dictionary(); + if (billingIds.Any()) { - var billings = await _db.Queryable().Where(x => billingIds.Contains(x.Id)).Select(x => new { x.Id, x.Djmd }).ToListAsync(); + var billings = await _db.Queryable() + .Where(x => billingIds.Contains(x.Id)) + .Select(x => new { x.Id, x.Djmd, x.Hgjg, x.Fkyy }) + .ToListAsync(); + billingStoreDict = billings.ToDictionary(x => x.Id, x => x.Djmd ?? ""); + billingExtraInfoDict = billings.ToDictionary(x => x.Id, x => (dynamic)new { Hgjg = x.Hgjg, Fkyy = x.Fkyy }); } // 批量查询门店信息 @@ -3823,7 +3833,9 @@ namespace NCC.Extend.LqKdKdjlb sourceType = pxmx.SourceType, remark = pxmx.Remark, storeId = pxmx.Glkdbh != null && billingStoreDict.ContainsKey(pxmx.Glkdbh) ? billingStoreDict[pxmx.Glkdbh] : "", - storeName = pxmx.Glkdbh != null && billingStoreDict.ContainsKey(pxmx.Glkdbh) && !string.IsNullOrEmpty(billingStoreDict[pxmx.Glkdbh]) && storeDict.ContainsKey(billingStoreDict[pxmx.Glkdbh]) ? storeDict[billingStoreDict[pxmx.Glkdbh]] : "" + storeName = pxmx.Glkdbh != null && billingStoreDict.ContainsKey(pxmx.Glkdbh) && !string.IsNullOrEmpty(billingStoreDict[pxmx.Glkdbh]) && storeDict.ContainsKey(billingStoreDict[pxmx.Glkdbh]) ? storeDict[billingStoreDict[pxmx.Glkdbh]] : "", + hgjg = pxmx.Glkdbh != null && billingExtraInfoDict.ContainsKey(pxmx.Glkdbh) ? billingExtraInfoDict[pxmx.Glkdbh].Hgjg : "", + fkyy = pxmx.Glkdbh != null && billingExtraInfoDict.ContainsKey(pxmx.Glkdbh) ? billingExtraInfoDict[pxmx.Glkdbh].Fkyy : "" }).ToList(); // 6. 返回分页结果 @@ -3915,6 +3927,7 @@ namespace NCC.Extend.LqKdKdjlb // 查询并分页,使用子查询获取开单类型 + // 优先使用储扣记录表中的开单时间,如果为空则使用开单记录表中的开单时间 var data = await baseQuery.Select((deduct, billing, member, store) => new LqKdDeductinfoListOutput { Id = deduct.Id ?? "", @@ -3929,13 +3942,13 @@ namespace NCC.Extend.LqKdKdjlb CreateTime = deduct.CreateTime, ProjectNumber = deduct.ProjectNumber, ItemCategory = deduct.ItemCategory ?? "", - BillingDate = billing.Kdrq, + BillingDate = deduct.BillingTime ?? billing.Kdrq, // 优先使用储扣记录表中的开单时间 MemberId = billing.Kdhy ?? "", MemberName = member.Khmc ?? "", MemberPhone = member.Sjh ?? "", StoreId = billing.Djmd ?? "", StoreName = store.Dm ?? "", - TimePeriod = billing.Kdrq, + TimePeriod = deduct.BillingTime ?? billing.Kdrq, // 优先使用储扣记录表中的开单时间 BillingType = SqlFunc.Subqueryable() .Where(pxmx => pxmx.Id == deduct.DeductId && pxmx.Px == deduct.ItemId) .Select(pxmx => pxmx.SourceType), diff --git a/netcore/src/Modularity/Extend/NCC.Extend/LqLaundryFlowService.cs b/netcore/src/Modularity/Extend/NCC.Extend/LqLaundryFlowService.cs index fa8160e..a17ec7d 100644 --- a/netcore/src/Modularity/Extend/NCC.Extend/LqLaundryFlowService.cs +++ b/netcore/src/Modularity/Extend/NCC.Extend/LqLaundryFlowService.cs @@ -115,7 +115,8 @@ namespace NCC.Extend Remark = input.Remark, IsEffective = StatusEnum.有效.GetHashCode(), CreateUser = _userManager.UserId, - CreateTime = DateTime.Now + CreateTime = DateTime.Now, + SendTime = DateTime.Now // 设置送出时间 }; var isOk = await _db.Insertable(entity).ExecuteCommandAsync(); @@ -212,7 +213,8 @@ namespace NCC.Extend Remark = input.Remark, IsEffective = StatusEnum.有效.GetHashCode(), CreateUser = _userManager.UserId, - CreateTime = DateTime.Now + CreateTime = DateTime.Now, + ReturnTime = DateTime.Now // 设置送回时间 }; var isOk = await _db.Insertable(entity).ExecuteCommandAsync(); @@ -228,6 +230,109 @@ namespace NCC.Extend } #endregion + #region 修改送出/送回记录 + /// + /// 修改送出/送回记录 + /// + /// + /// 修改清洗流水记录的数量、送出时间、送回时间和备注 + /// + /// 示例请求: + /// ```json + /// { + /// "id": "记录ID", + /// "quantity": 95, + /// "sendTime": "2025-11-01 10:00:00", + /// "returnTime": "2025-11-05 15:00:00", + /// "remark": "修改备注" + /// } + /// ``` + /// + /// 参数说明: + /// - id: 记录ID(必填) + /// - quantity: 数量(可选,修改时需重新计算总费用) + /// - sendTime: 送出时间(可选,仅流水类型为0时有效) + /// - returnTime: 送回时间(可选,仅流水类型为1时有效) + /// - remark: 备注(可选) + /// + /// 修改输入 + /// 修改结果 + /// 修改成功 + /// 记录不存在或参数错误 + /// 服务器错误 + [HttpPost("Update")] + public async Task UpdateAsync([FromBody] LqLaundryFlowUpdateInput input) + { + try + { + // 查询记录是否存在 + var entity = await _db.Queryable() + .Where(x => x.Id == input.Id && x.IsEffective == StatusEnum.有效.GetHashCode()) + .FirstAsync(); + + if (entity == null) + { + throw NCCException.Oh("记录不存在或已失效"); + } + + // 更新数量(如果提供) + if (input.Quantity.HasValue) + { + entity.Quantity = input.Quantity.Value; + // 重新计算总费用 + entity.TotalPrice = entity.Quantity * entity.LaundryPrice; + } + + // 更新送出时间(仅流水类型为0时有效) + if (input.SendTime.HasValue) + { + if (entity.FlowType != 0) + { + throw NCCException.Oh("只有送出记录才能修改送出时间"); + } + entity.SendTime = input.SendTime.Value; + } + + // 更新送回时间(仅流水类型为1时有效) + if (input.ReturnTime.HasValue) + { + if (entity.FlowType != 1) + { + throw NCCException.Oh("只有送回记录才能修改送回时间"); + } + entity.ReturnTime = input.ReturnTime.Value; + } + + // 更新备注(如果提供) + if (input.Remark != null) + { + entity.Remark = input.Remark; + } + + // 执行更新 + var isOk = await _db.Updateable(entity) + .UpdateColumns(it => new + { + it.Quantity, + it.TotalPrice, + it.SendTime, + it.ReturnTime, + it.Remark + }) + .ExecuteCommandAsync(); + + if (!(isOk > 0)) throw NCCException.Oh(ErrorCode.COM1000); + + return new { message = "修改成功", totalPrice = entity.TotalPrice }; + } + catch (Exception ex) + { + _logger.LogError(ex, "修改清洗流水记录失败"); + throw NCCException.Oh($"修改失败:{ex.Message}"); + } + } + #endregion + #region 获取清洗流水列表 /// /// 获取清洗流水列表 @@ -275,7 +380,9 @@ namespace NCC.Extend isEffective = flow.IsEffective, createUser = flow.CreateUser, createUserName = "", - createTime = flow.CreateTime + createTime = flow.CreateTime, + sendTime = flow.SendTime, + returnTime = flow.ReturnTime }) .MergeTable() .OrderBy(sidx + " " + sort) diff --git a/netcore/src/Modularity/Extend/NCC.Extend/LqReimbursementApplicationService.cs b/netcore/src/Modularity/Extend/NCC.Extend/LqReimbursementApplicationService.cs index 7b51811..44858f6 100644 --- a/netcore/src/Modularity/Extend/NCC.Extend/LqReimbursementApplicationService.cs +++ b/netcore/src/Modularity/Extend/NCC.Extend/LqReimbursementApplicationService.cs @@ -1515,8 +1515,8 @@ namespace NCC.Extend.LqReimbursementApplication // 查询本月已审核通过的报销申请 var applications = await _db.Queryable() .Where(x => (x.ApprovalStatus ?? x.ApproveStatus) == "已通过") - .Where(x => x.ApplicationTime.HasValue && - x.ApplicationTime.Value.Year == queryYear && + .Where(x => x.ApplicationTime.HasValue && + x.ApplicationTime.Value.Year == queryYear && x.ApplicationTime.Value.Month == int.Parse(queryMonth)) .ToListAsync(); @@ -1552,7 +1552,7 @@ namespace NCC.Extend.LqReimbursementApplication foreach (var app in applications) { var appPurchaseRecords = purchaseRecords.Where(x => x.ApplicationId == app.Id).ToList(); - + if (appPurchaseRecords.Any()) { // 每个购买记录作为一行 diff --git a/netcore/src/Modularity/Extend/NCC.Extend/LqSalaryExtraCalculationService.cs b/netcore/src/Modularity/Extend/NCC.Extend/LqSalaryExtraCalculationService.cs index 7e15db7..d59f08a 100644 --- a/netcore/src/Modularity/Extend/NCC.Extend/LqSalaryExtraCalculationService.cs +++ b/netcore/src/Modularity/Extend/NCC.Extend/LqSalaryExtraCalculationService.cs @@ -211,16 +211,31 @@ namespace NCC.Extend throw new Exception($"第{i + 1}行:月份必须在1-12之间"); } + // 辅助方法:清理数值字符串(去除千分位分隔符、货币符号等) + Func CleanNumericString = (str) => + { + if (string.IsNullOrWhiteSpace(str)) + return "0"; + // 去除常见的非数字字符(保留小数点和负号) + return str.Trim() + .Replace(",", "") // 去除千分位分隔符 + .Replace(",", "") // 去除中文逗号 + .Replace("¥", "") // 去除人民币符号 + .Replace("$", "") // 去除美元符号 + .Replace("元", "") // 去除"元"字 + .Replace(" ", ""); // 去除空格 + }; + // 解析数值字段(允许为空,默认为0) - decimal.TryParse(baseRewardPerformanceText, out decimal baseRewardPerformance); - decimal.TryParse(cooperationRewardPerformanceText, out decimal cooperationRewardPerformance); - decimal.TryParse(newCustomerPerformanceText, out decimal newCustomerPerformance); - decimal.TryParse(newCustomerConversionRateText, out decimal newCustomerConversionRate); - decimal.TryParse(upgradePerformanceText, out decimal upgradePerformance); - decimal.TryParse(upgradeConversionRateText, out decimal upgradeConversionRate); - decimal.TryParse(upgradeCustomerCountText, out decimal upgradeCustomerCount); - decimal.TryParse(otherPerformanceAddText, out decimal otherPerformanceAdd); - decimal.TryParse(otherPerformanceSubtractText, out decimal otherPerformanceSubtract); + decimal.TryParse(CleanNumericString(baseRewardPerformanceText), out decimal baseRewardPerformance); + decimal.TryParse(CleanNumericString(cooperationRewardPerformanceText), out decimal cooperationRewardPerformance); + decimal.TryParse(CleanNumericString(newCustomerPerformanceText), out decimal newCustomerPerformance); + decimal.TryParse(CleanNumericString(newCustomerConversionRateText), out decimal newCustomerConversionRate); + decimal.TryParse(CleanNumericString(upgradePerformanceText), out decimal upgradePerformance); + decimal.TryParse(CleanNumericString(upgradeConversionRateText), out decimal upgradeConversionRate); + decimal.TryParse(CleanNumericString(upgradeCustomerCountText), out decimal upgradeCustomerCount); + decimal.TryParse(CleanNumericString(otherPerformanceAddText), out decimal otherPerformanceAdd); + decimal.TryParse(CleanNumericString(otherPerformanceSubtractText), out decimal otherPerformanceSubtract); var item = new SalaryExtraCalculationImportInput { @@ -411,7 +426,22 @@ namespace NCC.Extend // 批量更新现有记录 if (entitiesToUpdate.Any()) { - await _db.Updateable(entitiesToUpdate).ExecuteCommandAsync(); + // 明确指定要更新的字段,确保所有字段都被更新(包括升单业绩) + // 注意:Updateable接收实体列表时,会自动根据主键更新,不需要Where条件 + await _db.Updateable(entitiesToUpdate) + .UpdateColumns(it => new + { + it.BaseRewardPerformance, + it.CooperationRewardPerformance, + it.NewCustomerPerformance, + it.NewCustomerConversionRate, + it.UpgradePerformance, + it.UpgradeConversionRate, + it.UpgradeCustomerCount, + it.OtherPerformanceAdd, + it.OtherPerformanceSubtract + }) + .ExecuteCommandAsync(); } var result = new diff --git a/netcore/src/Modularity/Extend/NCC.Extend/LqSalaryService.cs b/netcore/src/Modularity/Extend/NCC.Extend/LqSalaryService.cs index a68a498..6f412e9 100644 --- a/netcore/src/Modularity/Extend/NCC.Extend/LqSalaryService.cs +++ b/netcore/src/Modularity/Extend/NCC.Extend/LqSalaryService.cs @@ -623,8 +623,15 @@ namespace NCC.Extend isNewStore); // 4.2 提成计算 - // 业绩门槛: 战队成员个人总业绩 <= 6000 无提成 - if (!string.IsNullOrEmpty(salary.GoldTriangleId) && salary.TotalPerformance <= 6000) + // 业绩门槛: 战队成员个人总业绩 <= 6000 无提成 (需按日均计算) + // 规则:战队成员日均业绩 <= 6000 / 当月天数 -> 无提成 + decimal memberThreshold = 6000m; + if (daysInMonth > 0 && salary.WorkingDays > 0) + { + memberThreshold = (6000m / daysInMonth) * salary.WorkingDays; + } + + if (!string.IsNullOrEmpty(salary.GoldTriangleId) && salary.TotalPerformance < memberThreshold) // 修正为小于校验 { salary.TotalCommission = 0; salary.BasePerformanceCommission = 0; @@ -644,13 +651,15 @@ namespace NCC.Extend // 获取战队人数 (注意:这里应该是有效战队人数) var teamMemberCount = employeeStats.Values.Count(x => x.GoldTriangleId == salary.GoldTriangleId); // 注意:提成点按原始基础业绩计算,不是实际基础业绩 - commissionPoint = GetTeamCommissionPoint(teamMemberCount, salary.TeamPerformance); + // 战队成员不按日均考核提成点,只考核个人门槛 + commissionPoint = GetTeamCommissionPoint(teamMemberCount, salary.TeamPerformance, daysInMonth, salary.WorkingDays); } else { // 单人 (或被剔除出战队) // 注意:提成点按原始总业绩计算 - commissionPoint = GetTeamCommissionPoint(1, salary.TotalPerformance); + // 单人按日均考核提成点 + commissionPoint = GetTeamCommissionPoint(1, salary.TotalPerformance, daysInMonth, salary.WorkingDays); } salary.CommissionPoint = commissionPoint; @@ -697,6 +706,17 @@ namespace NCC.Extend if (!string.IsNullOrEmpty(salary.EmployeeName) && salary.EmployeeName.Contains("T区")) { salary.StoreTZoneCommission = salary.StoreTotalPerformance * 0.05m * 0.05m; + + // T区人员仅核算提成,其他项(底薪、手工、社保等)归零 + salary.HealthCoachBaseSalary = 0; + salary.HandworkFee = 0; + salary.BasePerformanceCommission = 0; + salary.CooperationPerformanceCommission = 0; + salary.ConsultantCommission = 0; + salary.NewCustomerPerformanceCommission = 0; + salary.UpgradePerformanceCommission = 0; + salary.TotalSubsidy = 0; + salary.TotalDeduction = 0; } salary.TotalCommission = salary.BasePerformanceCommission @@ -801,7 +821,7 @@ namespace NCC.Extend /// /// 获取战队提成点 /// - private decimal GetTeamCommissionPoint(int memberCount, decimal teamPerformance) + private decimal GetTeamCommissionPoint(int memberCount, decimal teamPerformance, int daysInMonth, decimal workingDays) { if (memberCount >= 3) { @@ -820,10 +840,24 @@ namespace NCC.Extend } else // 1人 { - if (teamPerformance >= 60000) return 0.06m; - if (teamPerformance >= 40000) return 0.05m; - if (teamPerformance >= 20000) return 0.04m; - if (teamPerformance >= 10000) return 0.03m; + // 单人按照日均考核 + decimal p1 = 60000m; + decimal p2 = 40000m; + decimal p3 = 20000m; + decimal p4 = 10000m; + + if (daysInMonth > 0 && workingDays > 0) + { + p1 = (p1 / daysInMonth) * workingDays; + p2 = (p2 / daysInMonth) * workingDays; + p3 = (p3 / daysInMonth) * workingDays; + p4 = (p4 / daysInMonth) * workingDays; + } + + if (teamPerformance >= p1) return 0.06m; + if (teamPerformance >= p2) return 0.05m; + if (teamPerformance >= p3) return 0.04m; + if (teamPerformance >= p4) return 0.03m; } return 0; } @@ -839,21 +873,23 @@ namespace NCC.Extend // 注意: // 1. "组员业绩"指除顾问外的其他成员业绩总和 - // 2. 只统计有效战队成员(考勤≥21天,未被剔除的成员) + // 2. 只统计有效战队成员(考勤≥20天,未被剔除的成员) // 3. "达到X%以上"指:组员业绩总和 ≥ 团队总业绩 × X% // 4. 新店顾问不考核消耗 + // 5. 消耗达标:高级顾问整组消耗>=6万,普通顾问整组消耗>=4万 - // 使用传入的 teamMembers 计算总消耗,或者直接使用 TeamTotalConsumption (如果已计算) - // 但为了保险起见,这里重新计算或使用已有的逻辑 - // 注意:CalculateConsultantCommission 方法签名未变,但逻辑需确认 teamConsumption 来源 - // 在调用此方法前,teamMembers 已经有了 Consumption 数据 + // 使用传入的 teamMembers 计算总消耗 var teamConsumption = teamMembers.Sum(x => x.Consumption); // 计算组员(非顾问)业绩总和 - // teamMembers 已经是过滤后的有效成员列表(GoldTriangleId 相同且未被剔除) var memberPerformance = teamMembers.Where(x => x.Position != "顾问").Sum(x => x.TotalPerformance); - // 高级顾问:业绩≥6万 且 组员业绩≥40% 且 (新店 或 消耗≥6万) + // 高级顾问:业绩≥6万 且 组员业绩≥40% 且 (新店(第1,2阶段) 或 消耗≥6万) + // 注意:isNewStore 仅代表是否为新店,具体免考核阶段需确认。假设新店前两个阶段免考核,第三阶段需考核。 + // 这里暂且沿用 isNewStore 逻辑,如果需要更细粒度控制,应传入 NewStoreProtectionStage + // 如果 isNewStore 为 true,则默认免考核消耗(根据原需求描述:新店第3个阶段时,有金三角,但是不考核消耗) + // 用户最新指示:新店第3个阶段时,有金三角,但是不考核消耗,默认达标 -> 意味着只要是新店,不管阶段,都不考核消耗 + if (teamPerformance >= 60000 && memberPerformance >= teamPerformance * 0.4m) { if (isNewStore || teamConsumption >= 60000) diff --git a/netcore/src/Modularity/Extend/NCC.Extend/LqStoreExpenseService.cs b/netcore/src/Modularity/Extend/NCC.Extend/LqStoreExpenseService.cs index e9228df..29892be 100644 --- a/netcore/src/Modularity/Extend/NCC.Extend/LqStoreExpenseService.cs +++ b/netcore/src/Modularity/Extend/NCC.Extend/LqStoreExpenseService.cs @@ -66,10 +66,36 @@ namespace NCC.Extend.LqStoreExpense .Where(x => x.Id == id && x.IsEffective == StatusEnum.有效.GetHashCode()) .FirstAsync(); _ = entity ?? throw NCCException.Oh(ErrorCode.COM1005); - var output = entity.Adapt(); + var output = new LqStoreExpenseInfoOutput + { + id = entity.Id, + storeId = entity.StoreId, + storeName = entity.StoreName, + expenseCategoryId = entity.ExpenseCategoryId, + expenseCategoryName = entity.ExpenseCategoryName, + expenseDate = entity.ExpenseDate, + unitPrice = entity.UnitPrice, + quantity = entity.Quantity, + amount = entity.Amount, + memo = entity.Memo, + relatedReimbursementId = entity.RelatedReimbursementId, + relatedPurchaseRecordId = entity.RelatedPurchaseRecordId, + createUser = entity.CreateUser, + createTime = entity.CreateTime, + updateUser = entity.UpdateUser, + updateTime = entity.UpdateTime + }; + if (!string.IsNullOrEmpty(entity.Attachment)) { - output.attachment = entity.Attachment.ToObject>(); + try + { + output.attachment = entity.Attachment.ToObject>(); + } + catch + { + output.attachment = new List(); + } } return output; } diff --git a/netcore/src/Modularity/Extend/NCC.Extend/LqStoreManagerSalaryService.cs b/netcore/src/Modularity/Extend/NCC.Extend/LqStoreManagerSalaryService.cs index e09be64..c2cd884 100644 --- a/netcore/src/Modularity/Extend/NCC.Extend/LqStoreManagerSalaryService.cs +++ b/netcore/src/Modularity/Extend/NCC.Extend/LqStoreManagerSalaryService.cs @@ -294,6 +294,7 @@ namespace NCC.Extend .ToDictionary(x => x.StoreId.ToString(), x => Convert.ToDecimal(x.ExpenseAmount ?? 0)); // 1.12 洗毛巾费用统计(只统计送出的记录,F_FlowType = 0) + // 优先使用送出时间(F_SendTime),如果为空则使用创建时间(F_CreateTime) var laundryCostSql = $@" SELECT F_StoreId as StoreId, @@ -301,7 +302,7 @@ namespace NCC.Extend FROM lq_laundry_flow WHERE F_IsEffective = 1 AND F_FlowType = 0 - AND DATE_FORMAT(F_CreateTime, '%Y%m') = @monthStr + AND DATE_FORMAT(COALESCE(F_SendTime, F_CreateTime), '%Y%m') = @monthStr GROUP BY F_StoreId"; var laundryCostData = await _db.Ado.SqlQueryAsync(laundryCostSql, new { monthStr }); diff --git a/netcore/src/Modularity/Extend/NCC.Extend/LqYcsdJsjService.cs b/netcore/src/Modularity/Extend/NCC.Extend/LqYcsdJsjService.cs index 97773cc..bc24942 100644 --- a/netcore/src/Modularity/Extend/NCC.Extend/LqYcsdJsjService.cs +++ b/netcore/src/Modularity/Extend/NCC.Extend/LqYcsdJsjService.cs @@ -347,6 +347,18 @@ namespace NCC.Extend.LqYcsdJsj } } + // 验证成员 UserID 不能为空 + if (input.members != null && input.members.Count > 0) + { + foreach (var member in input.members) + { + if (string.IsNullOrEmpty(member.userId)) + { + throw NCCException.Oh(ErrorCode.COM1000, $"成员【{member.userName}】的 UserID 不能为空"); + } + } + } + // 验证金三角名称是否已存在 var existingJsj = await _db.Queryable().Where(x => x.Yf == input.yf && x.Md == input.md && x.Jsj == input.jsj).FirstAsync(); if (existingJsj != null) @@ -434,7 +446,7 @@ namespace NCC.Extend.LqYcsdJsj if (string.IsNullOrEmpty(input.jsjId)) throw NCCException.Oh("金三角ID不能为空"); if (string.IsNullOrEmpty(input.userId)) - throw NCCException.Oh("用户ID不能为空"); + throw NCCException.Oh("用户ID不能为空(请确保选择了有效的系统用户)"); if (string.IsNullOrEmpty(input.userName)) throw NCCException.Oh("用户姓名不能为空"); diff --git a/sql/主任工资表新增毛利相关字段.sql b/sql/主任工资表新增毛利相关字段.sql index 84e6c8e..1cd594a 100644 --- a/sql/主任工资表新增毛利相关字段.sql +++ b/sql/主任工资表新增毛利相关字段.sql @@ -31,3 +31,4 @@ ADD COLUMN F_GrossProfit DECIMAL(18,2) DEFAULT 0.00 COMMENT '毛利(销售业 ALTER TABLE lq_director_salary_statistics MODIFY COLUMN F_StoreTotalPerformance DECIMAL(18,2) DEFAULT 0.00 COMMENT '门店总业绩(毛利,用于提成计算)'; + diff --git a/sql/修复储扣表ItemCategory字段为空的数据.sql b/sql/修复储扣表ItemCategory字段为空的数据.sql new file mode 100644 index 0000000..7058405 --- /dev/null +++ b/sql/修复储扣表ItemCategory字段为空的数据.sql @@ -0,0 +1,68 @@ +-- ============================================ +-- 修复储扣表(lq_kd_deductinfo)中 F_ItemCategory 字段为空的数据 +-- ============================================ +-- 说明:此脚本用于修复储扣表中品项分类字段为空的历史数据 +-- +-- 问题原因: +-- 1. 更新开单时使用了错误的字段(item.DeductId 而不是 item.ItemId)来查询品项分类 +-- 2. 如果 item.ItemId 为空或无效,查询会返回 null +-- +-- 修复逻辑: +-- 通过 F_ItemId 关联 lq_xmzl 表,获取品项分类(qt2)并更新到 F_ItemCategory 字段 +-- +-- 注意事项: +-- - 只更新有效记录(F_IsEffective = 1) +-- - 只更新分类字段为空的记录 +-- - 只更新品项分类存在且不为空的记录 + +-- ============================================ +-- 1. 查看需要修复的记录数 +-- ============================================ +SELECT + COUNT(*) as TotalNullCount, + COUNT(CASE WHEN item.qt2 IS NOT NULL THEN 1 END) as CanFixCount +FROM lq_kd_deductinfo deduct +LEFT JOIN lq_xmzl item ON deduct.F_ItemId = item.F_Id +WHERE deduct.F_IsEffective = 1 + AND deduct.F_ItemCategory IS NULL; + +-- ============================================ +-- 2. 修复历史数据:从项目资料表中获取品项分类 +-- ============================================ +UPDATE lq_kd_deductinfo deduct +INNER JOIN lq_xmzl item ON deduct.F_ItemId = item.F_Id +SET deduct.F_ItemCategory = item.qt2 +WHERE deduct.F_IsEffective = 1 + AND deduct.F_ItemCategory IS NULL + AND item.qt2 IS NOT NULL; + +-- ============================================ +-- 3. 验证修复结果 +-- ============================================ +-- 查看修复后的统计信息 +SELECT + COUNT(*) as TotalCount, + COUNT(F_ItemCategory) as HasCategoryCount, + COUNT(*) - COUNT(F_ItemCategory) as NullCategoryCount +FROM lq_kd_deductinfo +WHERE F_IsEffective = 1; + +-- 查看仍然为空的记录(需要人工处理) +SELECT + deduct.F_Id, + deduct.F_BillingId, + deduct.F_ItemId, + deduct.F_ItemName, + deduct.F_ItemCategory, + item.qt2 as ItemQt2, + CASE + WHEN item.F_Id IS NULL THEN '品项不存在' + WHEN item.qt2 IS NULL THEN '品项分类为空' + ELSE '其他原因' + END as Reason +FROM lq_kd_deductinfo deduct +LEFT JOIN lq_xmzl item ON deduct.F_ItemId = item.F_Id +WHERE deduct.F_IsEffective = 1 + AND deduct.F_ItemCategory IS NULL +LIMIT 10; + diff --git a/sql/创建合同成本按月统计表.sql b/sql/创建合同成本按月统计表.sql new file mode 100644 index 0000000..0edbd26 --- /dev/null +++ b/sql/创建合同成本按月统计表.sql @@ -0,0 +1,71 @@ +-- ============================================ +-- 创建合同成本按月统计表(lq_contract_monthly_cost) +-- ============================================ +-- 说明:用于按月统计每个合同的成本,便于后续统计和查询 +-- +-- 业务逻辑: +-- 1. 根据合同起始日期、结束日期,按月生成成本记录 +-- 2. 每个月成本 = 缴租金额 / 交租周期 +-- 3. 例如:合同一年,交费周期3个月,缴租金额3000元 +-- - 每个月成本 = 3000 / 3 = 1000元 +-- - 生成12个月的记录,每个月都是1000元 +-- +-- 字段说明: +-- F_Month:统计月份(格式:YYYY-MM-01,表示该月的第一天) +-- F_MonthlyCost:该月的合同成本(缴租金额 / 交租周期) +-- +-- 索引设计: +-- - 主键:F_Id +-- - 合同ID索引:F_ContractId(用于查询某个合同的所有月份成本) +-- - 月份索引:F_Month(用于按月份统计) +-- - 门店ID索引:F_StoreId(用于按门店统计) +-- - 联合索引:(F_StoreId, F_Month) - 用于查询某个门店某个月的成本 +-- - 联合索引:(F_ContractId, F_Month) - 用于查询某个合同某个月的成本 + +CREATE TABLE IF NOT EXISTS `lq_contract_monthly_cost` ( + `F_Id` VARCHAR(50) NOT NULL COMMENT '主键ID', + `F_ContractId` VARCHAR(50) NOT NULL COMMENT '合同ID(关联lq_contract.F_Id)', + `F_StoreId` VARCHAR(50) NOT NULL COMMENT '门店ID(关联lq_mdxx.F_Id,冗余字段便于查询)', + `F_StoreName` VARCHAR(200) NOT NULL COMMENT '店名(冗余字段,便于查询)', + `F_Category` VARCHAR(100) DEFAULT NULL COMMENT '分类(冗余字段,便于按分类统计)', + `F_Month` DATETIME NOT NULL COMMENT '统计月份(格式:YYYY-MM-01,表示该月的第一天)', + `F_MonthlyCost` DECIMAL(18,2) NOT NULL COMMENT '该月的合同成本(缴租金额 / 交租周期)', + `F_PaymentCycle` INT NOT NULL COMMENT '交租周期(冗余字段,便于查询)', + `F_PaymentAmount` DECIMAL(18,2) NOT NULL COMMENT '缴租金额(冗余字段,便于查询)', + `F_IsEffective` INT DEFAULT 1 COMMENT '是否有效(1-有效,0-无效)', + `F_CreateUser` VARCHAR(50) NOT NULL COMMENT '创建人ID', + `F_CreateTime` DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `F_UpdateTime` DATETIME DEFAULT NULL COMMENT '更新时间', + PRIMARY KEY (`F_Id`), + KEY `idx_contract_id` (`F_ContractId`) COMMENT '合同ID索引', + KEY `idx_month` (`F_Month`) COMMENT '月份索引', + KEY `idx_store_id` (`F_StoreId`) COMMENT '门店ID索引', + KEY `idx_category` (`F_Category`) COMMENT '分类索引', + KEY `idx_store_month` (`F_StoreId`, `F_Month`) COMMENT '门店+月份联合索引', + KEY `idx_contract_month` (`F_ContractId`, `F_Month`) COMMENT '合同+月份联合索引', + KEY `idx_category_month` (`F_Category`, `F_Month`) COMMENT '分类+月份联合索引', + KEY `idx_is_effective` (`F_IsEffective`) COMMENT '是否有效索引', + KEY `idx_create_time` (`F_CreateTime`) COMMENT '创建时间索引' +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='合同成本按月统计表'; + +-- ============================================ +-- 数据示例说明 +-- ============================================ +-- 合同示例: +-- F_ContractId: '768041985045955845' +-- F_StoreId: '1649328471923847168' +-- F_StoreName: '绿纤总部' +-- F_ContractStartDate: '2025-01-01 00:00:00' +-- F_ContractEndDate: '2025-12-31 23:59:59' +-- F_PaymentAmount: 3000.00 +-- F_PaymentCycle: 3 +-- +-- 每个月成本 = 3000 / 3 = 1000元 +-- +-- 对应的成本记录(自动生成): +-- 记录1: F_Month='2025-01-01', F_MonthlyCost=1000.00 +-- 记录2: F_Month='2025-02-01', F_MonthlyCost=1000.00 +-- 记录3: F_Month='2025-03-01', F_MonthlyCost=1000.00 +-- 记录4: F_Month='2025-04-01', F_MonthlyCost=1000.00 +-- ...(共12条记录) + diff --git a/sql/合同成本表添加分类字段.sql b/sql/合同成本表添加分类字段.sql new file mode 100644 index 0000000..8e26385 --- /dev/null +++ b/sql/合同成本表添加分类字段.sql @@ -0,0 +1,66 @@ +-- ============================================ +-- 为合同成本按月统计表(lq_contract_monthly_cost)添加分类字段 +-- ============================================ +-- 说明:此脚本为合同成本表添加分类字段,用于按分类统计合同成本 +-- +-- 字段说明: +-- F_Category:分类(冗余字段,便于按分类统计) +-- +-- 业务含义: +-- - 分类字段用于区分不同类型的合同(如:租门店、员工宿舍、车辆、场所等) +-- - 便于后续按分类统计合同成本 +-- +-- 注意事项: +-- - 字段类型为VARCHAR(100),允许为NULL(历史数据可能没有分类) +-- - 字段位置:放在 F_StoreName 字段之后 +-- - 创建后需要更新历史数据,从合同表中获取对应的分类 + +-- ============================================ +-- 1. 添加分类字段 +-- ============================================ +ALTER TABLE `lq_contract_monthly_cost` +ADD COLUMN `F_Category` VARCHAR(100) NULL COMMENT '分类(冗余字段,便于按分类统计)' AFTER `F_StoreName`; + +-- ============================================ +-- 2. 添加分类索引 +-- ============================================ +ALTER TABLE `lq_contract_monthly_cost` +ADD INDEX `idx_category` (`F_Category`) COMMENT '分类索引'; + +-- ============================================ +-- 3. 添加分类+月份联合索引 +-- ============================================ +ALTER TABLE `lq_contract_monthly_cost` +ADD INDEX `idx_category_month` (`F_Category`, `F_Month`) COMMENT '分类+月份联合索引'; + +-- ============================================ +-- 4. 更新历史数据:从合同表中获取分类 +-- ============================================ +UPDATE `lq_contract_monthly_cost` cost +INNER JOIN `lq_contract` contract ON cost.F_ContractId = contract.F_Id +SET cost.F_Category = contract.F_Category +WHERE cost.F_Category IS NULL + AND contract.F_Category IS NOT NULL; + +-- ============================================ +-- 5. 验证更新结果 +-- ============================================ +-- 查看更新后的统计信息 +SELECT + COUNT(*) as TotalCount, + COUNT(F_Category) as HasCategoryCount, + COUNT(*) - COUNT(F_Category) as NullCategoryCount +FROM lq_contract_monthly_cost +WHERE F_IsEffective = 1; + +-- 查看各分类的统计信息 +SELECT + F_Category, + COUNT(*) as RecordCount, + SUM(F_MonthlyCost) as TotalCost +FROM lq_contract_monthly_cost +WHERE F_IsEffective = 1 +GROUP BY F_Category +ORDER BY TotalCost DESC; + + diff --git a/sql/开单扣减信息表添加开单时间字段.sql b/sql/开单扣减信息表添加开单时间字段.sql new file mode 100644 index 0000000..9d480fe --- /dev/null +++ b/sql/开单扣减信息表添加开单时间字段.sql @@ -0,0 +1,53 @@ +-- ============================================ +-- 为开单扣减信息表(lq_kd_deductinfo)添加开单时间字段 +-- ============================================ +-- 说明:此脚本为开单扣减信息表添加开单时间字段,用于存储对应的开单时间 +-- +-- 字段说明: +-- F_BillingTime:开单时间,用于存储对应的开单记录的开单时间(kdrq) +-- +-- 业务含义: +-- - 开单时间用于记录储扣对应的开单时间,便于统计和查询 +-- - 开单时间来源于开单记录表(lq_kd_kdjlb)的 kdrq 字段 +-- +-- 注意事项: +-- - 字段类型为DATETIME,允许为NULL(历史数据可能没有开单时间) +-- - 字段位置:放在 F_BillingId 字段之后 +-- - 创建后需要更新历史数据,从开单记录表中获取对应的开单时间 + +-- ============================================ +-- 1. 添加开单时间字段 +-- ============================================ +ALTER TABLE `lq_kd_deductinfo` +ADD COLUMN `F_BillingTime` DATETIME NULL COMMENT '开单时间' AFTER `F_BillingId`; + +-- ============================================ +-- 2. 更新历史数据:从开单记录表中获取开单时间 +-- ============================================ +UPDATE `lq_kd_deductinfo` deduct +INNER JOIN `lq_kd_kdjlb` billing ON deduct.F_BillingId = billing.F_Id +SET deduct.F_BillingTime = billing.kdrq +WHERE deduct.F_BillingTime IS NULL + AND billing.kdrq IS NOT NULL; + +-- ============================================ +-- 3. 验证更新结果 +-- ============================================ +-- 查看更新后的统计信息 +SELECT + COUNT(*) as TotalCount, + COUNT(F_BillingTime) as HasBillingTimeCount, + COUNT(*) - COUNT(F_BillingTime) as NullBillingTimeCount +FROM lq_kd_deductinfo; + +-- 查看有开单时间但开单记录不存在的记录(数据异常检查) +SELECT + deduct.F_Id, + deduct.F_BillingId, + deduct.F_BillingTime +FROM lq_kd_deductinfo deduct +LEFT JOIN lq_kd_kdjlb billing ON deduct.F_BillingId = billing.F_Id +WHERE deduct.F_BillingTime IS NOT NULL + AND billing.F_Id IS NULL +LIMIT 10; + diff --git a/sql/排查生美业绩统计差异-简化版.sql b/sql/排查生美业绩统计差异-简化版.sql new file mode 100644 index 0000000..dbfd09e --- /dev/null +++ b/sql/排查生美业绩统计差异-简化版.sql @@ -0,0 +1,118 @@ +-- ============================================ +-- 排查生美业绩统计差异 - 简化版 +-- ============================================ +-- 问题:品项明细表统计生美数据是1869781.81,但日报天王团统计教育一部+教育二部合计是1876061.21,差异6279.40 +-- +-- 分析思路: +-- 1. 检查是否有门店在lq_md_target表中有多条记录(同一月份) +-- 2. 对比品项明细表统计和日报天王团统计的差异 +-- 3. 检查是否有数据被重复统计 + +-- ============================================ +-- 1. 品项明细表统计生美业绩(所有门店,不限制部门归属) +-- ============================================ +SELECT + '品项明细表统计' AS 统计来源, + COALESCE(SUM(pxmx.F_ActualPrice), 0) as 生美业绩总额 +FROM lq_kd_pxmx pxmx +INNER JOIN lq_kd_kdjlb billing ON pxmx.glkdbh = billing.F_Id +INNER JOIN lq_xmzl item ON pxmx.px = item.F_Id +WHERE pxmx.F_IsEffective = 1 + AND billing.F_IsEffective = 1 + AND item.F_IsEffective = 1 + AND item.qt2 = '生美' + AND billing.kdrq >= DATE_FORMAT(NOW(), '%Y-%m-01') + AND billing.kdrq < DATE_ADD(DATE_FORMAT(NOW(), '%Y-%m-01'), INTERVAL 1 MONTH); + +-- ============================================ +-- 2. 日报天王团统计生美业绩(只统计有部门归属的门店,按部门分组) +-- ============================================ +SELECT + '日报天王团统计' AS 统计来源, + target.F_EducationDepartment as 部门ID, + dept.F_FullName as 部门名称, + COALESCE(SUM(pxmx.F_ActualPrice), 0) as 生美业绩 +FROM lq_kd_pxmx pxmx +INNER JOIN lq_kd_kdjlb billing ON pxmx.glkdbh = billing.F_Id +INNER JOIN lq_xmzl item ON pxmx.px = item.F_Id +INNER JOIN lq_md_target target ON billing.djmd = target.F_StoreId + AND target.F_Month = DATE_FORMAT(NOW(), '%Y%m') +LEFT JOIN base_organize dept ON target.F_EducationDepartment = dept.F_Id +WHERE pxmx.F_IsEffective = 1 + AND billing.F_IsEffective = 1 + AND item.F_IsEffective = 1 + AND item.qt2 = '生美' + AND billing.kdrq >= DATE_FORMAT(NOW(), '%Y-%m-01') + AND billing.kdrq < DATE_ADD(DATE_FORMAT(NOW(), '%Y-%m-01'), INTERVAL 1 MONTH) + AND target.F_EducationDepartment IS NOT NULL + AND target.F_EducationDepartment != '' +GROUP BY target.F_EducationDepartment, dept.F_FullName; + +-- ============================================ +-- 3. 检查是否有门店在lq_md_target表中有多条记录(同一月份) +-- ============================================ +SELECT + F_StoreId, + F_Month, + COUNT(*) as record_count +FROM lq_md_target +WHERE F_Month = DATE_FORMAT(NOW(), '%Y%m') + AND (F_EducationDepartment IS NOT NULL AND F_EducationDepartment != '') +GROUP BY F_StoreId, F_Month +HAVING COUNT(*) > 1; + +-- ============================================ +-- 4. 检查是否有生美品项的开单记录,但门店在lq_md_target表中没有设置F_EducationDepartment +-- ============================================ +SELECT + '未归属门店的生美业绩' AS 统计来源, + COUNT(DISTINCT billing.djmd) as 门店数量, + COUNT(*) as 开单记录数, + COALESCE(SUM(pxmx.F_ActualPrice), 0) as 生美业绩总额 +FROM lq_kd_pxmx pxmx +INNER JOIN lq_kd_kdjlb billing ON pxmx.glkdbh = billing.F_Id +INNER JOIN lq_xmzl item ON pxmx.px = item.F_Id +LEFT JOIN lq_md_target target ON billing.djmd = target.F_StoreId + AND target.F_Month = DATE_FORMAT(NOW(), '%Y%m') +WHERE pxmx.F_IsEffective = 1 + AND billing.F_IsEffective = 1 + AND item.F_IsEffective = 1 + AND item.qt2 = '生美' + AND billing.kdrq >= DATE_FORMAT(NOW(), '%Y-%m-01') + AND billing.kdrq < DATE_ADD(DATE_FORMAT(NOW(), '%Y-%m-01'), INTERVAL 1 MONTH) + AND (target.F_StoreId IS NULL + OR target.F_EducationDepartment IS NULL + OR target.F_EducationDepartment = ''); + +-- ============================================ +-- 5. 关键检查:查看每个门店的生美业绩,看看是否有重复统计 +-- ============================================ +SELECT + billing.djmd as 门店ID, + md.Dm as 门店名称, + target.F_EducationDepartment as 教育部门ID, + dept.F_FullName as 教育部门名称, + COUNT(*) as 开单记录数, + COALESCE(SUM(pxmx.F_ActualPrice), 0) as 生美业绩, + COUNT(DISTINCT target.F_Id) as 目标表记录数 +FROM lq_kd_pxmx pxmx +INNER JOIN lq_kd_kdjlb billing ON pxmx.glkdbh = billing.F_Id +INNER JOIN lq_xmzl item ON pxmx.px = item.F_Id +INNER JOIN lq_md_target target ON billing.djmd = target.F_StoreId + AND target.F_Month = DATE_FORMAT(NOW(), '%Y%m') +LEFT JOIN lq_mdxx md ON billing.djmd = md.F_Id +LEFT JOIN base_organize dept ON target.F_EducationDepartment = dept.F_Id +WHERE pxmx.F_IsEffective = 1 + AND billing.F_IsEffective = 1 + AND item.F_IsEffective = 1 + AND item.qt2 = '生美' + AND billing.kdrq >= DATE_FORMAT(NOW(), '%Y-%m-01') + AND billing.kdrq < DATE_ADD(DATE_FORMAT(NOW(), '%Y-%m-01'), INTERVAL 1 MONTH) + AND target.F_EducationDepartment IS NOT NULL + AND target.F_EducationDepartment != '' +GROUP BY billing.djmd, md.Dm, target.F_EducationDepartment, dept.F_FullName +HAVING COUNT(DISTINCT target.F_Id) > 1 +ORDER BY 生美业绩 DESC; + + + diff --git a/sql/排查生美业绩统计差异详细.sql b/sql/排查生美业绩统计差异详细.sql new file mode 100644 index 0000000..4051a8d --- /dev/null +++ b/sql/排查生美业绩统计差异详细.sql @@ -0,0 +1,170 @@ +-- ============================================ +-- 排查生美业绩统计差异详细分析 +-- ============================================ +-- 问题:品项明细表统计生美数据是1869781.81,但日报天王团统计教育一部+教育二部合计是1876061.21,差异6279.40 +-- +-- 分析思路: +-- 1. 检查是否有门店在lq_md_target表中有多条记录(同一月份) +-- 2. 对比品项明细表统计和日报天王团统计的差异 +-- 3. 检查是否有数据被重复统计 + +-- ============================================ +-- 1. 检查lq_md_target表中是否有重复记录(同一门店同一月份多条记录) +-- ============================================ +SELECT + F_StoreId, + F_Month, + COUNT(*) as record_count, + GROUP_CONCAT(DISTINCT F_EducationDepartment ORDER BY F_EducationDepartment) as education_depts +FROM lq_md_target +WHERE F_Month = DATE_FORMAT(NOW(), '%Y%m') + AND (F_EducationDepartment IS NOT NULL AND F_EducationDepartment != '') +GROUP BY F_StoreId, F_Month +HAVING COUNT(*) > 1; + +-- ============================================ +-- 2. 品项明细表统计生美业绩(所有门店,不限制部门归属) +-- ============================================ +SELECT + '品项明细表统计' AS 统计来源, + COALESCE(SUM(pxmx.F_ActualPrice), 0) as 生美业绩总额 +FROM lq_kd_pxmx pxmx +INNER JOIN lq_kd_kdjlb billing ON pxmx.glkdbh = billing.F_Id +INNER JOIN lq_xmzl item ON pxmx.px = item.F_Id +WHERE pxmx.F_IsEffective = 1 + AND billing.F_IsEffective = 1 + AND item.F_IsEffective = 1 + AND item.qt2 = '生美' + AND billing.kdrq >= DATE_FORMAT(NOW(), '%Y-%m-01') + AND billing.kdrq < DATE_ADD(DATE_FORMAT(NOW(), '%Y-%m-01'), INTERVAL 1 MONTH); + +-- ============================================ +-- 3. 日报天王团统计生美业绩(只统计有部门归属的门店,按部门分组) +-- ============================================ +SELECT + '日报天王团统计' AS 统计来源, + target.F_EducationDepartment as 部门ID, + dept.F_FullName as 部门名称, + COALESCE(SUM(pxmx.F_ActualPrice), 0) as 生美业绩 +FROM lq_kd_pxmx pxmx +INNER JOIN lq_kd_kdjlb billing ON pxmx.glkdbh = billing.F_Id +INNER JOIN lq_xmzl item ON pxmx.px = item.F_Id +INNER JOIN lq_md_target target ON billing.djmd = target.F_StoreId + AND target.F_Month = DATE_FORMAT(NOW(), '%Y%m') +LEFT JOIN base_organize dept ON target.F_EducationDepartment = dept.F_Id +WHERE pxmx.F_IsEffective = 1 + AND billing.F_IsEffective = 1 + AND item.F_IsEffective = 1 + AND item.qt2 = '生美' + AND billing.kdrq >= DATE_FORMAT(NOW(), '%Y-%m-01') + AND billing.kdrq < DATE_ADD(DATE_FORMAT(NOW(), '%Y-%m-01'), INTERVAL 1 MONTH) + AND target.F_EducationDepartment IS NOT NULL + AND target.F_EducationDepartment != '' +GROUP BY target.F_EducationDepartment, dept.F_FullName; + +-- ============================================ +-- 4. 检查是否有门店在lq_md_target表中有多条记录,导致重复统计 +-- ============================================ +SELECT + billing.djmd as 门店ID, + md.Dm as 门店名称, + COUNT(DISTINCT target.F_Id) as 目标表记录数, + COUNT(*) as 开单记录数, + COALESCE(SUM(pxmx.F_ActualPrice), 0) as 生美业绩总额, + GROUP_CONCAT(DISTINCT target.F_EducationDepartment ORDER BY target.F_EducationDepartment) as 教育部门列表 +FROM lq_kd_pxmx pxmx +INNER JOIN lq_kd_kdjlb billing ON pxmx.glkdbh = billing.F_Id +INNER JOIN lq_xmzl item ON pxmx.px = item.F_Id +INNER JOIN lq_md_target target ON billing.djmd = target.F_StoreId + AND target.F_Month = DATE_FORMAT(NOW(), '%Y%m') +LEFT JOIN lq_mdxx md ON billing.djmd = md.F_Id +WHERE pxmx.F_IsEffective = 1 + AND billing.F_IsEffective = 1 + AND item.F_IsEffective = 1 + AND item.qt2 = '生美' + AND billing.kdrq >= DATE_FORMAT(NOW(), '%Y-%m-01') + AND billing.kdrq < DATE_ADD(DATE_FORMAT(NOW(), '%Y-%m-01'), INTERVAL 1 MONTH) + AND target.F_EducationDepartment IS NOT NULL + AND target.F_EducationDepartment != '' +GROUP BY billing.djmd, md.Dm +HAVING COUNT(DISTINCT target.F_Id) > 1; + +-- ============================================ +-- 5. 检查是否有生美品项的开单记录,但门店在lq_md_target表中没有设置F_EducationDepartment +-- ============================================ +SELECT + '未归属门店的生美业绩' AS 统计来源, + COUNT(DISTINCT billing.djmd) as 门店数量, + COUNT(*) as 开单记录数, + COALESCE(SUM(pxmx.F_ActualPrice), 0) as 生美业绩总额 +FROM lq_kd_pxmx pxmx +INNER JOIN lq_kd_kdjlb billing ON pxmx.glkdbh = billing.F_Id +INNER JOIN lq_xmzl item ON pxmx.px = item.F_Id +LEFT JOIN lq_md_target target ON billing.djmd = target.F_StoreId + AND target.F_Month = DATE_FORMAT(NOW(), '%Y%m') +WHERE pxmx.F_IsEffective = 1 + AND billing.F_IsEffective = 1 + AND item.F_IsEffective = 1 + AND item.qt2 = '生美' + AND billing.kdrq >= DATE_FORMAT(NOW(), '%Y-%m-01') + AND billing.kdrq < DATE_ADD(DATE_FORMAT(NOW(), '%Y-%m-01'), INTERVAL 1 MONTH) + AND (target.F_StoreId IS NULL + OR target.F_EducationDepartment IS NULL + OR target.F_EducationDepartment = ''); + +-- ============================================ +-- 6. 关键检查:查看每个门店的生美业绩,看看是否有重复统计 +-- ============================================ +SELECT + billing.djmd as 门店ID, + md.Dm as 门店名称, + target.F_EducationDepartment as 教育部门ID, + dept.F_FullName as 教育部门名称, + COUNT(*) as 开单记录数, + COALESCE(SUM(pxmx.F_ActualPrice), 0) as 生美业绩, + COUNT(DISTINCT target.F_Id) as 目标表记录数 +FROM lq_kd_pxmx pxmx +INNER JOIN lq_kd_kdjlb billing ON pxmx.glkdbh = billing.F_Id +INNER JOIN lq_xmzl item ON pxmx.px = item.F_Id +INNER JOIN lq_md_target target ON billing.djmd = target.F_StoreId + AND target.F_Month = DATE_FORMAT(NOW(), '%Y%m') +LEFT JOIN lq_mdxx md ON billing.djmd = md.F_Id +LEFT JOIN base_organize dept ON target.F_EducationDepartment = dept.F_Id +WHERE pxmx.F_IsEffective = 1 + AND billing.F_IsEffective = 1 + AND item.F_IsEffective = 1 + AND item.qt2 = '生美' + AND billing.kdrq >= DATE_FORMAT(NOW(), '%Y-%m-01') + AND billing.kdrq < DATE_ADD(DATE_FORMAT(NOW(), '%Y-%m-01'), INTERVAL 1 MONTH) + AND target.F_EducationDepartment IS NOT NULL + AND target.F_EducationDepartment != '' +GROUP BY billing.djmd, md.Dm, target.F_EducationDepartment, dept.F_FullName +ORDER BY 生美业绩 DESC; + +-- ============================================ +-- 7. 检查是否有门店在lq_md_target表中有多条记录(不同月份,但查询时可能有问题) +-- ============================================ +SELECT + F_StoreId, + COUNT(DISTINCT F_Month) as 月份数, + GROUP_CONCAT(DISTINCT F_Month ORDER BY F_Month) as 月份列表, + COUNT(*) as 总记录数 +FROM lq_md_target +WHERE F_StoreId IN ( + SELECT DISTINCT billing.djmd + FROM lq_kd_pxmx pxmx + INNER JOIN lq_kd_kdjlb billing ON pxmx.glkdbh = billing.F_Id + INNER JOIN lq_xmzl item ON pxmx.px = item.F_Id + WHERE pxmx.F_IsEffective = 1 + AND billing.F_IsEffective = 1 + AND item.F_IsEffective = 1 + AND item.qt2 = '生美' + AND billing.kdrq >= DATE_FORMAT(NOW(), '%Y-%m-01') + AND billing.kdrq < DATE_ADD(DATE_FORMAT(NOW(), '%Y-%m-01'), INTERVAL 1 MONTH) +) + AND (F_EducationDepartment IS NOT NULL AND F_EducationDepartment != '') +GROUP BY F_StoreId +HAVING COUNT(*) > 1; + + + diff --git a/sql/检查生美业绩统计差异.sql b/sql/检查生美业绩统计差异.sql new file mode 100644 index 0000000..029e1dd --- /dev/null +++ b/sql/检查生美业绩统计差异.sql @@ -0,0 +1,140 @@ +-- ============================================ +-- 检查生美业绩统计差异 +-- ============================================ +-- 问题:品项明细表统计生美数据是1869781.81,但日报天王团统计教育一部+教育二部合计是1876061.21,差异6279.40 +-- +-- 可能原因: +-- 1. 门店在lq_md_target表中有重复记录(同一月份多条记录) +-- 2. 统计范围不一致(时间范围或门店范围) +-- 3. 数据关联逻辑问题 + +-- ============================================ +-- 1. 检查lq_md_target表中是否有重复记录(同一门店同一月份多条记录) +-- ============================================ +SELECT + F_StoreId, + F_Month, + COUNT(*) as record_count, + GROUP_CONCAT(DISTINCT F_EducationDepartment) as education_depts +FROM lq_md_target +WHERE F_Month = DATE_FORMAT(NOW(), '%Y%m') + AND (F_EducationDepartment IS NOT NULL AND F_EducationDepartment != '') +GROUP BY F_StoreId, F_Month +HAVING COUNT(*) > 1; + +-- ============================================ +-- 2. 检查品项明细表统计生美业绩(所有门店,不限制部门归属) +-- ============================================ +SELECT + '品项明细表统计' AS 统计来源, + COALESCE(SUM(pxmx.F_ActualPrice), 0) as 生美业绩总额 +FROM lq_kd_pxmx pxmx +INNER JOIN lq_kd_kdjlb billing ON pxmx.glkdbh = billing.F_Id +INNER JOIN lq_xmzl item ON pxmx.px = item.F_Id +WHERE pxmx.F_IsEffective = 1 + AND billing.F_IsEffective = 1 + AND item.F_IsEffective = 1 + AND item.qt2 = '生美' + AND billing.kdrq >= DATE_FORMAT(NOW(), '%Y-%m-01') + AND billing.kdrq < DATE_ADD(DATE_FORMAT(NOW(), '%Y-%m-01'), INTERVAL 1 MONTH); + +-- ============================================ +-- 3. 检查日报天王团统计生美业绩(只统计有部门归属的门店,按部门分组) +-- ============================================ +SELECT + '日报天王团统计' AS 统计来源, + target.F_EducationDepartment as 部门ID, + COALESCE(SUM(pxmx.F_ActualPrice), 0) as 生美业绩 +FROM lq_kd_pxmx pxmx +INNER JOIN lq_kd_kdjlb billing ON pxmx.glkdbh = billing.F_Id +INNER JOIN lq_xmzl item ON pxmx.px = item.F_Id +INNER JOIN lq_md_target target ON billing.djmd = target.F_StoreId + AND target.F_Month = DATE_FORMAT(NOW(), '%Y%m') +WHERE pxmx.F_IsEffective = 1 + AND billing.F_IsEffective = 1 + AND item.F_IsEffective = 1 + AND item.qt2 = '生美' + AND billing.kdrq >= DATE_FORMAT(NOW(), '%Y-%m-01') + AND billing.kdrq < DATE_ADD(DATE_FORMAT(NOW(), '%Y-%m-01'), INTERVAL 1 MONTH) + AND target.F_EducationDepartment IS NOT NULL + AND target.F_EducationDepartment != '' +GROUP BY target.F_EducationDepartment; + +-- ============================================ +-- 4. 检查是否有生美品项的开单记录,但门店在lq_md_target表中没有设置F_EducationDepartment +-- ============================================ +SELECT + '未归属门店的生美业绩' AS 统计来源, + COUNT(DISTINCT billing.djmd) as 门店数量, + COUNT(*) as 开单记录数, + COALESCE(SUM(pxmx.F_ActualPrice), 0) as 生美业绩总额 +FROM lq_kd_pxmx pxmx +INNER JOIN lq_kd_kdjlb billing ON pxmx.glkdbh = billing.F_Id +INNER JOIN lq_xmzl item ON pxmx.px = item.F_Id +LEFT JOIN lq_md_target target ON billing.djmd = target.F_StoreId + AND target.F_Month = DATE_FORMAT(NOW(), '%Y%m') +WHERE pxmx.F_IsEffective = 1 + AND billing.F_IsEffective = 1 + AND item.F_IsEffective = 1 + AND item.qt2 = '生美' + AND billing.kdrq >= DATE_FORMAT(NOW(), '%Y-%m-01') + AND billing.kdrq < DATE_ADD(DATE_FORMAT(NOW(), '%Y-%m-01'), INTERVAL 1 MONTH) + AND (target.F_StoreId IS NULL + OR target.F_EducationDepartment IS NULL + OR target.F_EducationDepartment = ''); + +-- ============================================ +-- 5. 检查是否有门店在lq_md_target表中有多条记录(可能导致重复统计) +-- ============================================ +SELECT + billing.djmd as 门店ID, + COUNT(DISTINCT target.F_Id) as 目标表记录数, + COUNT(*) as 开单记录数, + COALESCE(SUM(pxmx.F_ActualPrice), 0) as 生美业绩总额, + GROUP_CONCAT(DISTINCT target.F_EducationDepartment) as 教育部门列表 +FROM lq_kd_pxmx pxmx +INNER JOIN lq_kd_kdjlb billing ON pxmx.glkdbh = billing.F_Id +INNER JOIN lq_xmzl item ON pxmx.px = item.F_Id +INNER JOIN lq_md_target target ON billing.djmd = target.F_StoreId + AND target.F_Month = DATE_FORMAT(NOW(), '%Y%m') +WHERE pxmx.F_IsEffective = 1 + AND billing.F_IsEffective = 1 + AND item.F_IsEffective = 1 + AND item.qt2 = '生美' + AND billing.kdrq >= DATE_FORMAT(NOW(), '%Y-%m-01') + AND billing.kdrq < DATE_ADD(DATE_FORMAT(NOW(), '%Y-%m-01'), INTERVAL 1 MONTH) + AND target.F_EducationDepartment IS NOT NULL + AND target.F_EducationDepartment != '' +GROUP BY billing.djmd +HAVING COUNT(DISTINCT target.F_Id) > 1; + +-- ============================================ +-- 6. 详细检查:查看每个门店的生美业绩和部门归属情况 +-- ============================================ +SELECT + billing.djmd as 门店ID, + md.Dm as 门店名称, + target.F_EducationDepartment as 教育部门ID, + dept.F_FullName as 教育部门名称, + COUNT(*) as 开单记录数, + COALESCE(SUM(pxmx.F_ActualPrice), 0) as 生美业绩 +FROM lq_kd_pxmx pxmx +INNER JOIN lq_kd_kdjlb billing ON pxmx.glkdbh = billing.F_Id +INNER JOIN lq_xmzl item ON pxmx.px = item.F_Id +INNER JOIN lq_md_target target ON billing.djmd = target.F_StoreId + AND target.F_Month = DATE_FORMAT(NOW(), '%Y%m') +LEFT JOIN lq_mdxx md ON billing.djmd = md.F_Id +LEFT JOIN base_organize dept ON target.F_EducationDepartment = dept.F_Id +WHERE pxmx.F_IsEffective = 1 + AND billing.F_IsEffective = 1 + AND item.F_IsEffective = 1 + AND item.qt2 = '生美' + AND billing.kdrq >= DATE_FORMAT(NOW(), '%Y-%m-01') + AND billing.kdrq < DATE_ADD(DATE_FORMAT(NOW(), '%Y-%m-01'), INTERVAL 1 MONTH) + AND target.F_EducationDepartment IS NOT NULL + AND target.F_EducationDepartment != '' +GROUP BY billing.djmd, md.Dm, target.F_EducationDepartment, dept.F_FullName +ORDER BY 生美业绩 DESC; + + + diff --git a/sql/清洗流水表添加送出送回时间字段.sql b/sql/清洗流水表添加送出送回时间字段.sql new file mode 100644 index 0000000..a7f1ba4 --- /dev/null +++ b/sql/清洗流水表添加送出送回时间字段.sql @@ -0,0 +1,63 @@ +-- ============================================ +-- 为清洗流水表(lq_laundry_flow)添加送出/送回时间字段 +-- ============================================ +-- 说明:此脚本为清洗流水表添加送出时间和送回时间字段,用于记录实际的送出/送回时间 +-- +-- 字段说明: +-- F_SendTime:送出时间,用于记录实际的送出时间(流水类型为0时使用) +-- F_ReturnTime:送回时间,用于记录实际的送回时间(流水类型为1时使用) +-- +-- 业务含义: +-- - 送出时间:记录实际送出清洗的时间,便于后续统计 +-- - 送回时间:记录实际送回清洗的时间,便于后续统计 +-- - F_CreateTime:保持为记录创建时间(系统时间),用于记录数据录入时间 +-- +-- 注意事项: +-- - 字段类型为DATETIME,允许为NULL(历史数据可能没有这些时间) +-- - 字段位置:放在 F_CreateTime 字段之后 +-- - 创建后需要更新历史数据,将 F_CreateTime 的值复制到对应的时间字段 + +-- ============================================ +-- 1. 添加送出时间字段 +-- ============================================ +ALTER TABLE `lq_laundry_flow` +ADD COLUMN `F_SendTime` DATETIME NULL COMMENT '送出时间(流水类型为0时使用)' AFTER `F_CreateTime`; + +-- ============================================ +-- 2. 添加送回时间字段 +-- ============================================ +ALTER TABLE `lq_laundry_flow` +ADD COLUMN `F_ReturnTime` DATETIME NULL COMMENT '送回时间(流水类型为1时使用)' AFTER `F_SendTime`; + +-- ============================================ +-- 3. 更新历史数据:将创建时间复制到对应的时间字段 +-- ============================================ +-- 更新送出记录:将创建时间复制到送出时间 +UPDATE `lq_laundry_flow` +SET `F_SendTime` = `F_CreateTime` +WHERE `F_FlowType` = 0 + AND `F_SendTime` IS NULL + AND `F_CreateTime` IS NOT NULL; + +-- 更新送回记录:将创建时间复制到送回时间 +UPDATE `lq_laundry_flow` +SET `F_ReturnTime` = `F_CreateTime` +WHERE `F_FlowType` = 1 + AND `F_ReturnTime` IS NULL + AND `F_CreateTime` IS NOT NULL; + +-- ============================================ +-- 4. 验证更新结果 +-- ============================================ +-- 查看更新后的统计信息 +SELECT + F_FlowType, + CASE WHEN F_FlowType = 0 THEN '送出' ELSE '送回' END as FlowTypeName, + COUNT(*) as TotalCount, + COUNT(CASE WHEN F_FlowType = 0 THEN F_SendTime END) as HasSendTimeCount, + COUNT(CASE WHEN F_FlowType = 1 THEN F_ReturnTime END) as HasReturnTimeCount +FROM lq_laundry_flow +WHERE F_IsEffective = 1 +GROUP BY F_FlowType; + + diff --git a/test_tianwang_api.py b/test_tianwang_api.py new file mode 100644 index 0000000..270dada --- /dev/null +++ b/test_tianwang_api.py @@ -0,0 +1,73 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +import json +import sys +from datetime import datetime + +# 测试接口 +import subprocess + +# 测试2025年1月的数据 +cmd1 = [ + 'curl', '-s', '-X', 'POST', + 'http://localhost:2011/api/Extend/LqDailyReport/get-tianwang-group-performance-completion', + '-H', 'Content-Type: application/json', + '-d', '{"startTime": "2025-01-01", "endTime": "2025-01-31"}' +] + +result1 = subprocess.run(cmd1, capture_output=True, text=True) +data1 = json.loads(result1.stdout) + +print("=" * 60) +print("2025年1月数据") +print("=" * 60) +print(f"接口状态: {data1.get('code')}") +print(f"返回消息: {data1.get('msg')}") + +depts1 = [d for d in data1.get('data', []) if '教育' in d.get('DepartmentName', '')] +print("\n=== 教育部数据 ===") +for d in depts1: + print(f"{d.get('DepartmentName')}:") + print(f" BillingPerformance: {d.get('BillingPerformance')}") + print(f" RefundPerformance: {d.get('RefundPerformance')}") + print(f" DeductAmount: {d.get('DeductAmount')}") + print(f" CompletedPerformance: {d.get('CompletedPerformance')}") + print(f" StoreCount: {d.get('StoreCount')}") + +total1 = sum([d.get('BillingPerformance', 0) for d in depts1]) +print(f"\n教育一部+教育二部合计 BillingPerformance: {total1}") + +# 测试当前月份的数据 +current_month = datetime.now().strftime("%Y-%m") +start_date = f"{current_month}-01" +end_date = datetime.now().strftime("%Y-%m-%d") + +cmd2 = [ + 'curl', '-s', '-X', 'POST', + 'http://localhost:2011/api/Extend/LqDailyReport/get-tianwang-group-performance-completion', + '-H', 'Content-Type: application/json', + '-d', f'{{"startTime": "{start_date}", "endTime": "{end_date}"}}' +] + +result2 = subprocess.run(cmd2, capture_output=True, text=True) +data2 = json.loads(result2.stdout) + +print("\n" + "=" * 60) +print(f"当前月份 ({current_month}) 数据") +print("=" * 60) +print(f"接口状态: {data2.get('code')}") + +depts2 = [d for d in data2.get('data', []) if '教育' in d.get('DepartmentName', '')] +print("\n=== 教育部数据 ===") +for d in depts2: + print(f"{d.get('DepartmentName')}:") + print(f" BillingPerformance: {d.get('BillingPerformance')}") + print(f" RefundPerformance: {d.get('RefundPerformance')}") + print(f" DeductAmount: {d.get('DeductAmount')}") + print(f" CompletedPerformance: {d.get('CompletedPerformance')}") + print(f" StoreCount: {d.get('StoreCount')}") + +total2 = sum([d.get('BillingPerformance', 0) for d in depts2]) +print(f"\n教育一部+教育二部合计 BillingPerformance: {total2}") + + diff --git a/主任工资毛利计算逻辑梳理.md b/主任工资毛利计算逻辑梳理.md index e90b3b1..997bd1e 100644 --- a/主任工资毛利计算逻辑梳理.md +++ b/主任工资毛利计算逻辑梳理.md @@ -300,3 +300,4 @@ ADD COLUMN F_GrossProfit DECIMAL(18,2) DEFAULT 0.00 COMMENT '毛利(销售业 4. **业绩达标判断**:基于毛利是否≥生命线 5. **提成计算**:基于毛利,不是基于销售业绩 + diff --git a/储扣表ItemCategory字段为空问题梳理.md b/储扣表ItemCategory字段为空问题梳理.md new file mode 100644 index 0000000..a46c3e2 --- /dev/null +++ b/储扣表ItemCategory字段为空问题梳理.md @@ -0,0 +1,76 @@ +# 储扣表 F_ItemCategory 字段为空问题梳理 + +## 问题描述 +储扣表(lq_kd_deductinfo)中的 `F_ItemCategory` 字段有时候是空的。 + +## 数据库统计 +- 总有效记录数:1865 +- 有分类字段的记录数:1863 +- 分类字段为空的记录数:2 + +## 问题分析 + +### 1. 创建开单时的逻辑(第910行) +```csharp +ItemCategory = await _db.Queryable() + .Where(x => x.Id == item.ItemId) + .Select(x => x.Qt2) + .FirstAsync(), +``` +- 使用 `item.ItemId` 查询品项分类 +- 如果 `item.ItemId` 为空或无效,查询会返回 null + +### 2. 更新开单时的逻辑(第1257行) +```csharp +ItemCategory = await _db.Queryable() + .Where(x => x.Id == item.DeductId) // ❌ 错误:应该使用 item.ItemId + .Select(x => x.Qt2) + .FirstAsync() +``` +- **问题**:使用了 `item.DeductId` 而不是 `item.ItemId` +- `DeductId` 是品项明细表(lq_kd_pxmx)的ID,不是项目资料表(lq_xmzl)的ID +- 这会导致查询不到结果,返回 null + +### 3. 字段说明 +- **DeductId**:扣减品项关联ID,对应 `lq_kd_pxmx.F_Id`(品项明细表的主键) +- **ItemId**:品项id,对应 `lq_xmzl.F_Id`(项目资料表的主键) +- **ItemCategory**:品项分类,应该从 `lq_xmzl.qt2` 获取 + +### 4. 导致空值的原因 +1. **更新开单时使用了错误的字段**:使用 `item.DeductId` 而不是 `item.ItemId` +2. **查询不到结果**:如果 `item.ItemId` 为空或无效,`FirstAsync()` 会返回 null +3. **品项不存在或无效**:如果品项在 `lq_xmzl` 表中不存在或无效,查询也会返回 null + +## 解决方案 + +### ✅ 方案1:修复更新开单时的逻辑(已修复) +将第1257行的 `item.DeductId` 改为 `item.ItemId`,与创建开单时的逻辑保持一致。 + +**修复代码**: +```csharp +// 修复前(错误) +ItemCategory = await _db.Queryable() + .Where(x => x.Id == item.DeductId) // ❌ 错误 + .Select(x => x.Qt2) + .FirstAsync() + +// 修复后(正确) +ItemCategory = await _db.Queryable() + .Where(x => x.Id == item.ItemId) // ✅ 正确 + .Select(x => x.Qt2) + .FirstAsync() +``` + +### ✅ 方案2:修复历史数据(已提供SQL脚本) +对于已经存在的空值记录,执行 `sql/修复储扣表ItemCategory字段为空的数据.sql` 脚本修复。 + +### 方案3:增加容错处理(可选) +在查询时增加容错处理,如果查询不到结果,尝试从其他途径获取分类。 + +## 验证 +从数据库查询结果看: +- F_ItemId = '76',对应的 lq_xmzl 表中 qt2 = '科美'(存在且有效) +- F_ItemId = '100024',对应的 lq_xmzl 表中 qt2 = '科美'(存在且有效) + +说明这些记录的 `ItemId` 是有效的,问题应该是在更新开单时使用了错误的字段。 + diff --git a/测试储扣接口.sh b/测试储扣接口.sh new file mode 100755 index 0000000..4fdfeb0 --- /dev/null +++ b/测试储扣接口.sh @@ -0,0 +1,86 @@ +#!/bin/bash + +# 测试储扣相关接口 + +# 1. 获取token +echo "=== 1. 获取Token ===" +TOKEN_RESPONSE=$(curl -s -X POST "http://localhost:2011/api/oauth/Login" \ + -H "Content-Type: application/x-www-form-urlencoded" \ + -d "account=admin&password=e10adc3949ba59abbe56e057f20f883e") + +echo "$TOKEN_RESPONSE" | python3 -m json.tool + +TOKEN=$(echo "$TOKEN_RESPONSE" | python3 -c "import sys, json; data=json.load(sys.stdin); print(data['data']['token'])") + +if [ -z "$TOKEN" ]; then + echo "❌ Token获取失败" + exit 1 +fi + +echo "✅ Token获取成功: ${TOKEN:0:50}..." +echo "" + +# 2. 测试储扣金额统计接口(按品项分类) +echo "=== 2. 测试储扣金额统计接口(get-deduct-amount-statistics)===" +echo "请求参数: {\"startTime\": \"2025-11-01\", \"endTime\": \"2025-11-30\"}" +echo "" + +DEDUCT_RESPONSE=$(curl -s -X POST "http://localhost:2011/api/Extend/LqDailyReport/get-deduct-amount-statistics" \ + -H "Authorization: $TOKEN" \ + -H "Content-Type: application/json" \ + -d '{"startTime": "2025-11-01", "endTime": "2025-11-30"}') + +echo "$DEDUCT_RESPONSE" | python3 -m json.tool + +# 检查返回结果 +if echo "$DEDUCT_RESPONSE" | python3 -c "import sys, json; data=json.load(sys.stdin); exit(0 if data.get('code') == 200 else 1)" 2>/dev/null; then + echo "✅ 储扣金额统计接口调用成功" + + # 提取数据 + YIMEI=$(echo "$DEDUCT_RESPONSE" | python3 -c "import sys, json; data=json.load(sys.stdin); print(data.get('data', {}).get('yiMeiAmount', 0))" 2>/dev/null) + SHENGMEI=$(echo "$DEDUCT_RESPONSE" | python3 -c "import sys, json; data=json.load(sys.stdin); print(data.get('data', {}).get('shengMeiAmount', 0))" 2>/dev/null) + KEMEI=$(echo "$DEDUCT_RESPONSE" | python3 -c "import sys, json; data=json.load(sys.stdin); print(data.get('data', {}).get('keMeiAmount', 0))" 2>/dev/null) + TOTAL=$(echo "$DEDUCT_RESPONSE" | python3 -c "import sys, json; data=json.load(sys.stdin); print(data.get('data', {}).get('totalAmount', 0))" 2>/dev/null) + + echo "医美储扣金额: $YIMEI" + echo "生美储扣金额: $SHENGMEI" + echo "科美储扣金额: $KEMEI" + echo "总储扣金额: $TOTAL" +else + echo "❌ 储扣金额统计接口调用失败" +fi + +echo "" +echo "" + +# 3. 测试部门业绩完成情况接口(包含储扣统计) +echo "=== 3. 测试部门业绩完成情况接口(get-tianwang-group-performance-completion)===" +echo "请求参数: {\"startTime\": \"2025-11-01\", \"endTime\": \"2025-11-30\"}" +echo "" + +DEPT_RESPONSE=$(curl -s -X POST "http://localhost:2011/api/Extend/LqDailyReport/get-tianwang-group-performance-completion" \ + -H "Authorization: $TOKEN" \ + -H "Content-Type: application/json" \ + -d '{"startTime": "2025-11-01", "endTime": "2025-11-30"}') + +echo "$DEPT_RESPONSE" | python3 -m json.tool + +# 检查返回结果 +if echo "$DEPT_RESPONSE" | python3 -c "import sys, json; data=json.load(sys.stdin); exit(0 if data.get('code') == 200 else 1)" 2>/dev/null; then + echo "✅ 部门业绩完成情况接口调用成功" + + # 提取第一个部门的数据 + FIRST_DEPT=$(echo "$DEPT_RESPONSE" | python3 -c "import sys, json; data=json.load(sys.stdin); depts=data.get('data', []); print(json.dumps(depts[0] if depts else {}, indent=2))" 2>/dev/null) + + if [ ! -z "$FIRST_DEPT" ] && [ "$FIRST_DEPT" != "{}" ]; then + echo "" + echo "第一个部门的数据:" + echo "$FIRST_DEPT" + fi +else + echo "❌ 部门业绩完成情况接口调用失败" +fi + +echo "" +echo "=== 测试完成 ===" + -- libgit2 0.21.4