feat: 完成尊享服务
This commit is contained in:
@@ -28,18 +28,22 @@ public class PayService : ApplicationService, IPayService
|
||||
private readonly ILogger<PayService> _logger;
|
||||
private readonly ISqlSugarRepository<PayOrderAggregateRoot, Guid> _payOrderRepository;
|
||||
private readonly IRechargeService _rechargeService;
|
||||
private readonly PremiumPackageManager _premiumPackageManager;
|
||||
|
||||
public PayService(
|
||||
AlipayManager alipayManager,
|
||||
PayManager payManager,
|
||||
ILogger<PayService> logger, ISqlSugarRepository<PayOrderAggregateRoot, Guid> payOrderRepository,
|
||||
IRechargeService rechargeService)
|
||||
ILogger<PayService> logger,
|
||||
ISqlSugarRepository<PayOrderAggregateRoot, Guid> payOrderRepository,
|
||||
IRechargeService rechargeService,
|
||||
PremiumPackageManager premiumPackageManager)
|
||||
{
|
||||
_alipayManager = alipayManager;
|
||||
_payManager = payManager;
|
||||
_logger = logger;
|
||||
_payOrderRepository = payOrderRepository;
|
||||
_rechargeService = rechargeService;
|
||||
_premiumPackageManager = premiumPackageManager;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -51,7 +55,7 @@ public class PayService : ApplicationService, IPayService
|
||||
[HttpPost("pay/Order")]
|
||||
public async Task<CreateOrderOutput> CreateOrderAsync(CreateOrderInput input)
|
||||
{
|
||||
// 1. 通过PayManager创建订单
|
||||
// 1. 通过PayManager创建订单(内部会验证VIP资格)
|
||||
var order = await _payManager.CreateOrderAsync(input.GoodsType);
|
||||
|
||||
// 2. 通过AlipayManager发起页面支付
|
||||
@@ -92,7 +96,6 @@ public class PayService : ApplicationService, IPayService
|
||||
// 2. 验证签名
|
||||
await _alipayManager.VerifyNotifyAsync(notifyData);
|
||||
|
||||
|
||||
// 3. 记录支付通知
|
||||
await _payManager.RecordPayNoticeAsync(notifyData, signStr);
|
||||
|
||||
@@ -108,16 +111,40 @@ public class PayService : ApplicationService, IPayService
|
||||
|
||||
_logger.LogInformation("订单状态更新成功,订单号:{OutTradeNo},状态:{TradeStatus}", outTradeNo, tradeStatus);
|
||||
|
||||
//5.充值Vip
|
||||
await _rechargeService.RechargeVipAsync(new RechargeCreateInput
|
||||
// 5. 根据商品类型进行不同的处理
|
||||
if (order.GoodsType.IsPremiumPackage())
|
||||
{
|
||||
UserId = order.UserId,
|
||||
RechargeAmount = order.TotalAmount,
|
||||
Content = order.GoodsName,
|
||||
Months = order.GoodsType.GetValidMonths(),
|
||||
Remark = "自助充值",
|
||||
ContactInfo = null
|
||||
});
|
||||
// 处理尊享包商品:创建尊享包记录
|
||||
await _premiumPackageManager.CreatePremiumPackageAsync(
|
||||
order.UserId,
|
||||
order.GoodsType,
|
||||
order.TotalAmount,
|
||||
expireMonths: null // 尊享包不设置过期时间,或者可以根据需求设置
|
||||
);
|
||||
|
||||
_logger.LogInformation(
|
||||
$"用户 {order.UserId} 购买尊享包成功,订单号:{outTradeNo},商品:{order.GoodsName}");
|
||||
}
|
||||
else if (order.GoodsType.IsVipService())
|
||||
{
|
||||
// 处理VIP服务商品:充值VIP
|
||||
await _rechargeService.RechargeVipAsync(new RechargeCreateInput
|
||||
{
|
||||
UserId = order.UserId,
|
||||
RechargeAmount = order.TotalAmount,
|
||||
Content = order.GoodsName,
|
||||
Months = order.GoodsType.GetValidMonths(),
|
||||
Remark = "自助充值",
|
||||
ContactInfo = null
|
||||
});
|
||||
|
||||
_logger.LogInformation(
|
||||
$"用户 {order.UserId} 充值VIP成功,订单号:{outTradeNo},月数:{order.GoodsType.GetValidMonths()}");
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogWarning($"未知的商品类型:{order.GoodsType},订单号:{outTradeNo}");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -183,4 +210,4 @@ public class PayService : ApplicationService, IPayService
|
||||
}
|
||||
return TradeStatusEnum.WAIT_TRADE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user