From bf896352a30b8e27da7efe5d6f141981fcb343e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E6=A2=93=E5=BD=AD?= Date: Thu, 26 Mar 2026 00:09:20 +0800 Subject: [PATCH] =?UTF-8?q?=E5=95=86=E6=88=B7=E5=BE=AE=E4=BF=A1=E6=94=AF?= =?UTF-8?q?=E4=BB=98=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Merchant/Dtos/AddMerchantInput.cs | 5 ++ .../Merchant/Dtos/MerchantOutput.cs | 5 ++ .../Merchant/Dtos/WeChatPayConfigDto.cs | 44 ++++++++++ .../Merchant/Dtos/WeChatPayConfigInputDto.cs | 39 +++++++++ .../Merchant/MerchantService.cs | 43 +++++++++- YD_Event.Application/YD_Event.Application.xml | 80 +++++++++++++++++++ 6 files changed, 215 insertions(+), 1 deletion(-) create mode 100644 YD_Event.Application/Merchant/Dtos/WeChatPayConfigDto.cs create mode 100644 YD_Event.Application/Merchant/Dtos/WeChatPayConfigInputDto.cs diff --git a/YD_Event.Application/Merchant/Dtos/AddMerchantInput.cs b/YD_Event.Application/Merchant/Dtos/AddMerchantInput.cs index 65b3ca8..cc453b9 100644 --- a/YD_Event.Application/Merchant/Dtos/AddMerchantInput.cs +++ b/YD_Event.Application/Merchant/Dtos/AddMerchantInput.cs @@ -52,4 +52,9 @@ public class AddMerchantInput /// 审核状态 /// public AuditStatus? AuditStatus { get; set; } + + /// + /// 微信支付配置 + /// + public WeChatPayConfigInputDto? WeChatPayConfig { get; set; } } diff --git a/YD_Event.Application/Merchant/Dtos/MerchantOutput.cs b/YD_Event.Application/Merchant/Dtos/MerchantOutput.cs index 4bfeeb8..6a7cf60 100644 --- a/YD_Event.Application/Merchant/Dtos/MerchantOutput.cs +++ b/YD_Event.Application/Merchant/Dtos/MerchantOutput.cs @@ -71,4 +71,9 @@ public class MerchantOutput /// 更新时间 /// public DateTime? UpdatedTime { get; set; } + + /// + /// 微信支付配置 + /// + public WeChatPayConfigDto? WeChatPayConfig { get; set; } } \ No newline at end of file diff --git a/YD_Event.Application/Merchant/Dtos/WeChatPayConfigDto.cs b/YD_Event.Application/Merchant/Dtos/WeChatPayConfigDto.cs new file mode 100644 index 0000000..59752b8 --- /dev/null +++ b/YD_Event.Application/Merchant/Dtos/WeChatPayConfigDto.cs @@ -0,0 +1,44 @@ +using YD_Event.Core.Enum; + +namespace YD_Event.Application.Merchant.Dtos; + +/// +/// 微信支付配置DTO +/// +public class WeChatPayConfigDto +{ + /// + /// 主键Id + /// + public long Id { get; set; } + + /// + /// 商户ID(外键) + /// + public long MerchantId { get; set; } + + /// + /// 微信支付商户号 + /// + public string MerchantIdValue { get; set; } + + /// + /// 微信支付 APIv3 密钥 + /// + public string MerchantV3Secret { get; set; } + + /// + /// 微信支付商户证书序列号 + /// + public string MerchantCertificateSerialNumber { get; set; } + + /// + /// 微信支付商户私钥(PEM格式) + /// + public string MerchantCertificatePrivateKey { get; set; } + + /// + /// 可用状态 + /// + public AvailabilityStatus Status { get; set; } +} diff --git a/YD_Event.Application/Merchant/Dtos/WeChatPayConfigInputDto.cs b/YD_Event.Application/Merchant/Dtos/WeChatPayConfigInputDto.cs new file mode 100644 index 0000000..d6695e9 --- /dev/null +++ b/YD_Event.Application/Merchant/Dtos/WeChatPayConfigInputDto.cs @@ -0,0 +1,39 @@ +using System.ComponentModel.DataAnnotations; +using YD_Event.Core.Enum; + +namespace YD_Event.Application.Merchant.Dtos; + +/// +/// 微信支付配置输入DTO +/// +public class WeChatPayConfigInputDto +{ + /// + /// 微信支付商户号 + /// + [Required(ErrorMessage = "微信支付商户号不能为空")] + public string MerchantIdValue { get; set; } + + /// + /// 微信支付 APIv3 密钥 + /// + [Required(ErrorMessage = "微信支付 APIv3 密钥不能为空")] + public string MerchantV3Secret { get; set; } + + /// + /// 微信支付商户证书序列号 + /// + [Required(ErrorMessage = "微信支付商户证书序列号不能为空")] + public string MerchantCertificateSerialNumber { get; set; } + + /// + /// 微信支付商户私钥(PEM格式) + /// + [Required(ErrorMessage = "微信支付商户私钥不能为空")] + public string MerchantCertificatePrivateKey { get; set; } + + /// + /// 可用状态 + /// + public AvailabilityStatus Status { get; set; } = AvailabilityStatus.Enable; +} diff --git a/YD_Event.Application/Merchant/MerchantService.cs b/YD_Event.Application/Merchant/MerchantService.cs index 9ce12d2..353d59a 100644 --- a/YD_Event.Application/Merchant/MerchantService.cs +++ b/YD_Event.Application/Merchant/MerchantService.cs @@ -14,6 +14,7 @@ public class MerchantService : BaseService, ITr { private readonly ISqlSugarRepository _repository; private readonly ISqlSugarRepository _userCouponRepository; + private readonly ISqlSugarRepository _weChatPayConfigRepository; private readonly AuthManager _authManager; private readonly IIdGenerator _idGenerator; private readonly IMemoryCache _memoryCache; @@ -21,6 +22,7 @@ public class MerchantService : BaseService, ITr public MerchantService(ISqlSugarRepository repository, ISqlSugarRepository userCouponRepository, + ISqlSugarRepository weChatPayConfigRepository, AuthManager authManager, IIdGenerator idGenerator, IMemoryCache memoryCache, @@ -28,6 +30,7 @@ public class MerchantService : BaseService, ITr { _repository = repository; _userCouponRepository = userCouponRepository; + _weChatPayConfigRepository = weChatPayConfigRepository; _authManager = authManager; _idGenerator = idGenerator; _memoryCache = memoryCache; @@ -163,11 +166,20 @@ public class MerchantService : BaseService, ITr /// [DisplayName("添加商户")] [HttpPost("add")] + [UnitOfWork] public async Task Add(AddMerchantInput input) { var entity = input.Adapt(); entity.Id = _idGenerator.NextId(); await _repository.InsertAsync(entity); + + if (input.WeChatPayConfig != null) + { + var weChatPayConfig = input.WeChatPayConfig.Adapt(); + weChatPayConfig.Id = _idGenerator.NextId(); + weChatPayConfig.MerchantId = entity.Id; + await _weChatPayConfigRepository.InsertAsync(weChatPayConfig); + } } /// @@ -175,6 +187,7 @@ public class MerchantService : BaseService, ITr /// [DisplayName("更新商户")] [HttpPut("edit")] + [UnitOfWork] public async Task Update(UpdateMerchantInput input) { var entity = await _repository.GetByIdAsync(input.Id); @@ -182,6 +195,31 @@ public class MerchantService : BaseService, ITr input.Adapt(entity); await _repository.UpdateAsync(entity); + + var existingWeChatPayConfig = await _weChatPayConfigRepository.GetFirstAsync(c => c.MerchantId == input.Id); + + if (input.WeChatPayConfig != null) + { + if (existingWeChatPayConfig != null) + { + input.WeChatPayConfig.Adapt(existingWeChatPayConfig); + await _weChatPayConfigRepository.UpdateAsync(existingWeChatPayConfig); + } + else + { + var weChatPayConfig = input.WeChatPayConfig.Adapt(); + weChatPayConfig.Id = _idGenerator.NextId(); + weChatPayConfig.MerchantId = input.Id; + await _weChatPayConfigRepository.InsertAsync(weChatPayConfig); + } + } + else + { + if (existingWeChatPayConfig != null) + { + await _weChatPayConfigRepository.DeleteAsync(existingWeChatPayConfig); + } + } } /// @@ -204,6 +242,8 @@ public class MerchantService : BaseService, ITr var entity = await _repository.GetByIdAsync(id); if (entity == null) throw Oops.Bah("商户不存在"); + var weChatPayConfig = await _weChatPayConfigRepository.GetFirstAsync(c => c.MerchantId == id); + return new MerchantOutput { Id = entity.Id, @@ -218,7 +258,8 @@ public class MerchantService : BaseService, ITr AuditRemark = entity.AuditRemark, Status = entity.Status, CreatedTime = entity.CreatedTime, - UpdatedTime = entity.UpdatedTime + UpdatedTime = entity.UpdatedTime, + WeChatPayConfig = weChatPayConfig != null ? weChatPayConfig.Adapt() : null }; } diff --git a/YD_Event.Application/YD_Event.Application.xml b/YD_Event.Application/YD_Event.Application.xml index 05a74f8..4acf7e4 100644 --- a/YD_Event.Application/YD_Event.Application.xml +++ b/YD_Event.Application/YD_Event.Application.xml @@ -6053,6 +6053,11 @@ 审核状态 + + + 微信支付配置 + + 商户输出DTO @@ -6123,6 +6128,11 @@ 更新时间 + + + 微信支付配置 + + 商户查询输入 @@ -6268,6 +6278,76 @@ 主键Id + + + 微信支付配置DTO + + + + + 主键Id + + + + + 商户ID(外键) + + + + + 微信支付商户号 + + + + + 微信支付 APIv3 密钥 + + + + + 微信支付商户证书序列号 + + + + + 微信支付商户私钥(PEM格式) + + + + + 可用状态 + + + + + 微信支付配置输入DTO + + + + + 微信支付商户号 + + + + + 微信支付 APIv3 密钥 + + + + + 微信支付商户证书序列号 + + + + + 微信支付商户私钥(PEM格式) + + + + + 可用状态 + + 商户管理