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格式)
+
+
+
+
+ 可用状态
+
+
商户管理