From c6478e8dab3c83d91faf488f60af0c17881ac245 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B5=87=E6=96=87=E9=BE=99?= Date: Fri, 8 Nov 2024 18:25:19 +0800 Subject: [PATCH] =?UTF-8?q?=E5=86=B2=E7=BA=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DS.WMS.Core/Invoice/Dtos/InvoiceDto.cs | 20 +++++ .../Invoice/Method/InvoiceApiFox.cs | 46 ----------- .../Invoice/Method/InvoiceIssuanceService.cs | 79 ++++++++++++++----- .../Invoice/Method/InvoiceService`1.cs | 11 ++- .../Controllers/FeeRecordController.cs | 4 +- 5 files changed, 89 insertions(+), 71 deletions(-) delete mode 100644 ds-wms-service/DS.WMS.Core/Invoice/Method/InvoiceApiFox.cs diff --git a/ds-wms-service/DS.WMS.Core/Invoice/Dtos/InvoiceDto.cs b/ds-wms-service/DS.WMS.Core/Invoice/Dtos/InvoiceDto.cs index c15c923e..76728ac9 100644 --- a/ds-wms-service/DS.WMS.Core/Invoice/Dtos/InvoiceDto.cs +++ b/ds-wms-service/DS.WMS.Core/Invoice/Dtos/InvoiceDto.cs @@ -283,12 +283,29 @@ namespace DS.WMS.Core.Invoice.Dtos public string? Checker { get; set; } + /// + /// 是否被冲红 + /// public bool IsSetRed { get; set; } + /// + /// 红票发票号 + /// + public string? RedNO { get; set; } + + /// + /// 红票代码 + /// public string? RedCode { get; set; } + /// + /// 冲红原因 + /// public string? RedReason { get; set; } + /// + /// 红票ID + /// public long? RedId { get; set; } /// @@ -306,6 +323,9 @@ namespace DS.WMS.Core.Invoice.Dtos public string? Email { get; set; } + /// + /// 备注 + /// public string? Note { get; set; } /// diff --git a/ds-wms-service/DS.WMS.Core/Invoice/Method/InvoiceApiFox.cs b/ds-wms-service/DS.WMS.Core/Invoice/Method/InvoiceApiFox.cs deleted file mode 100644 index 10def636..00000000 --- a/ds-wms-service/DS.WMS.Core/Invoice/Method/InvoiceApiFox.cs +++ /dev/null @@ -1,46 +0,0 @@ -using System.Security; -using DS.Module.Core; -using DS.Module.Core.Extensions; -using Microsoft.Extensions.Configuration; - -namespace DS.WMS.Core.Invoice.Method -{ - /// - /// 提供对HTTP请求的低级别访问 - /// - internal sealed class InvoiceApiFox : ApiFox - { - /// - /// 用户Key - /// - public string? UserKey { get; set; } - - /// - /// 用户密钥 - /// - public SecureString? UserSecret { get; private set; } - - - public InvoiceApiFox(IConfiguration config) - { - BaseUri = new Uri(config.GetValue("InvoiceApi:BaseUrl")); - UserKey = config.GetValue("InvoiceApi:UserKey"); - - var us = config.GetValue("InvoiceApi:UserSecret"); - if (!us.IsNullOrEmpty()) - { - UserSecret = new SecureString(); - for (int i = 0; i < us.Length; i++) - UserSecret.AppendChar(us[i]); - - UserSecret.MakeReadOnly(); - } - us = null; - - DefaultHeaders.Add("USER_KEY", UserKey ?? string.Empty); - DefaultHeaders.Add("USER_SECRET", UserSecret?.ToString()); - } - - - } -} diff --git a/ds-wms-service/DS.WMS.Core/Invoice/Method/InvoiceIssuanceService.cs b/ds-wms-service/DS.WMS.Core/Invoice/Method/InvoiceIssuanceService.cs index 186abe55..f467ed9d 100644 --- a/ds-wms-service/DS.WMS.Core/Invoice/Method/InvoiceIssuanceService.cs +++ b/ds-wms-service/DS.WMS.Core/Invoice/Method/InvoiceIssuanceService.cs @@ -28,7 +28,7 @@ namespace DS.WMS.Core.Invoice.Method } readonly Lazy CommonService; - IGeneralInvoiceService InvoiceService; + readonly Lazy InvoiceService; /// /// 初始化并加载配置 @@ -38,7 +38,7 @@ namespace DS.WMS.Core.Invoice.Method { var config = provider.GetRequiredService(); CommonService = new Lazy(provider.GetRequiredService()); - InvoiceService = provider.GetRequiredService(); + InvoiceService = new Lazy(provider.GetRequiredService()); } /// @@ -247,12 +247,12 @@ namespace DS.WMS.Core.Invoice.Method //获取发票费用明细ID var ids = await TenantDb.Queryable() .InnerJoin((i, d) => i.Id == d.ApplicationId) - .Where((i, d) => billNumbers.Contains(i.BillNO) && i.Type == InvoiceType.Red) + .Where((i, d) => billNumbers.Contains(i.BillNO) && i.Type == InvoiceType.Blue) .Select((i, d) => d.Id).ToArrayAsync(); if (ids.Length > 0) { //删除蓝票费用明细 - await InvoiceService.DeleteDetailAsync(ids); + await InvoiceService.Value.DeleteDetailAsync(ids); } await TenantDb.Updateable(invoices).WhereColumns(x => x.BillNO) @@ -300,12 +300,12 @@ namespace DS.WMS.Core.Invoice.Method /// public async Task ReverseAsync(InvoiceReversalRequest request) { - var blueInvoice = await TenantDb.Queryable().Includes(x => x.Details) + var blueInvoice = await TenantDb.Queryable() .WhereIF(request.InvoiceId.HasValue, x => x.Id == request.InvoiceId) .WhereIF(!request.orderNo.IsNullOrEmpty(), x => x.BillNO == request.orderNo) .FirstAsync(); if (blueInvoice == null) - return DataResult.FailedWithDesc("发票ID或业务编号无效"); + return DataResult.FailedWithDesc("传入的发票ID或编号无效"); if (blueInvoice.Type == InvoiceType.Red) return DataResult.FailedWithDesc("红票无法被冲红"); if (blueInvoice.IsSettled) @@ -313,23 +313,69 @@ namespace DS.WMS.Core.Invoice.Method var redInvoice = blueInvoice.DeepClone(); var sequence = CommonService.Value.GetSequenceNext(); + redInvoice.Id = 0; redInvoice.BillNO = sequence.Data; redInvoice.SN = request.senid; redInvoice.Type = InvoiceType.Red; - - - redInvoice.Details ??= []; - if (redInvoice.Details.Count == 0) - redInvoice.Details.AddRange(blueInvoice.Details); - + redInvoice.InvoiceAmount = 0 - redInvoice.InvoiceAmount; + redInvoice.ApiCode = redInvoice.ApiStatus = redInvoice.PDFUrl = null; + redInvoice.CreateBy = long.Parse(User.UserId); + redInvoice.CreateTime = DateTime.Now; + redInvoice.UpdateBy = null; + redInvoice.UpdateTime = null; + + redInvoice.Details = await TenantDb.Queryable().Where(x => x.ApplicationId == blueInvoice.Id).ToListAsync(); foreach (var detail in redInvoice.Details) { + detail.Id = detail.ApplicationId = 0; detail.ApplyAmount = 0 - detail.ApplyAmount; detail.OriginalAmount = 0 - detail.OriginalAmount; + detail.OriginalProcessedAmount = detail.ProcessedAmount = 0; + } + + redInvoice.InvoiceDetails = await TenantDb.Queryable().Where(x => x.ApplicationId == blueInvoice.Id).ToListAsync(); + if (redInvoice.InvoiceDetails.Count == 0) + redInvoice.InvoiceDetails.AddRange(blueInvoice.InvoiceDetails); + + foreach (var detail in redInvoice.InvoiceDetails) + { + detail.Id = detail.ApplicationId = 0; + detail.Amount = 0 - detail.Amount; + detail.TaxUnitPrice = 0 - detail.TaxUnitPrice; + detail.UnitPrice = 0 - detail.UnitPrice; } + await TenantDb.Ado.BeginTranAsync(); try { + await TenantDb.InsertNav(redInvoice).Include(x => x.Details).Include(x => x.InvoiceDetails).ExecuteCommandAsync(); + blueInvoice.RedId = redInvoice.Id; + blueInvoice.IsSetRed = true; + blueInvoice.RedCode = request.chyyDm; + if (string.IsNullOrEmpty(request.Reason)) + { + switch (request.chyyDm) + { + case "01": + request.Reason = "开票有误"; + break; + case "02": + request.Reason = "销货退回"; + break; + case "03": + request.Reason = "服务中止"; + break; + case "04": + request.Reason = "销售折让"; + break; + default: + request.Reason = "直接冲红"; + break; + } + } + blueInvoice.RedReason = request.Reason; + await TenantDb.Updateable(blueInvoice).UpdateColumns(x => new { x.IsSetRed, x.RedId, x.RedCode, x.RedReason }).ExecuteCommandAsync(); + //如果开票中所属机构为空,则取用户的orgId var userOrgId = (blueInvoice.SaleDeptId != null && blueInvoice.SaleDeptId > 0) ? blueInvoice.SaleDeptId : User.OrgId; //接口请求key密钥 @@ -347,14 +393,7 @@ namespace DS.WMS.Core.Invoice.Method if (result.Data == null || !result.Data.success) return DataResult.Failed(result.Data == null ? "请求失败" : result.Data.msg); - - await TenantDb.Insertable(redInvoice).ExecuteCommandAsync(); - blueInvoice.RedCode = redInvoice.SN; - blueInvoice.RedId = redInvoice.Id; - blueInvoice.IsSetRed = true; - blueInvoice.RedReason = request.Reason; - await TenantDb.Updateable(blueInvoice).UpdateColumns(x => new { x.IsSetRed, x.RedId, x.RedReason }).ExecuteCommandAsync(); - + await TenantDb.Ado.CommitTranAsync(); var result2 = DataResult.Success; result2.Data = redInvoice; return result2; diff --git a/ds-wms-service/DS.WMS.Core/Invoice/Method/InvoiceService`1.cs b/ds-wms-service/DS.WMS.Core/Invoice/Method/InvoiceService`1.cs index 1ed3c9e3..d07ad95d 100644 --- a/ds-wms-service/DS.WMS.Core/Invoice/Method/InvoiceService`1.cs +++ b/ds-wms-service/DS.WMS.Core/Invoice/Method/InvoiceService`1.cs @@ -109,7 +109,12 @@ namespace DS.WMS.Core.Invoice.Method /// public async Task> GetAsync(long id) { - var invoice = await TenantDb.Queryable().Select().FirstAsync(x => x.Id == id); + var invoice = await TenantDb.Queryable() + .LeftJoin((x, y) => x.RedId == y.Id) + .Select((x, y) => new InvoiceDto + { + RedNO = y.InvoiceNO + }, true).FirstAsync(x => x.Id == id); if (invoice != null) { if (!string.IsNullOrEmpty(invoice.PushMode)) @@ -476,7 +481,7 @@ namespace DS.WMS.Core.Invoice.Method invoice.Note += Environment.NewLine + invRemark; invoice.InvoiceRemark += Environment.NewLine + invRemark; } - + } //筛选出新增的费用明细 @@ -625,7 +630,7 @@ namespace DS.WMS.Core.Invoice.Method } else { - foreach (var detail in details) + foreach (var detail in details) { if (detail.Currency == FeeCurrency.RMB_CODE) detail.ApplyAmount = detail.OriginalAmount; diff --git a/ds-wms-service/DS.WMS.FeeApi/Controllers/FeeRecordController.cs b/ds-wms-service/DS.WMS.FeeApi/Controllers/FeeRecordController.cs index 2ec6c9e8..99ab188b 100644 --- a/ds-wms-service/DS.WMS.FeeApi/Controllers/FeeRecordController.cs +++ b/ds-wms-service/DS.WMS.FeeApi/Controllers/FeeRecordController.cs @@ -103,8 +103,8 @@ namespace DS.WMS.FeeApi.Controllers if (recordSubmit.Items == null) return DataResult.Failed("参数无效", MultiLanguageConst.IllegalRequest); - if (recordSubmit.Items.Any(x => x.FeeStatus != FeeStatus.Entering && x.FeeStatus != FeeStatus.RejectSubmission)) - return DataResult.Failed("只能提交状态为‘录入’或‘驳回提交’的费用", MultiLanguageConst.IllegalRequest); + //if (recordSubmit.Items.Any(x => x.FeeStatus != FeeStatus.Entering && x.FeeStatus != FeeStatus.RejectSubmission)) + // return DataResult.Failed("只能提交状态为‘录入’或‘驳回提交’的费用", MultiLanguageConst.IllegalRequest); foreach (var item in recordSubmit.Items) {