|
@@ -448,8 +448,20 @@ export class PaymentMtService extends GenericCrudService<PaymentMtEntity> {
|
|
|
|
|
|
|
|
// 根据订单号查找支付记录
|
|
// 根据订单号查找支付记录
|
|
|
const paymentRepository = this.dataSource.getRepository(PaymentMtEntity);
|
|
const paymentRepository = this.dataSource.getRepository(PaymentMtEntity);
|
|
|
|
|
+
|
|
|
|
|
+ // 首先通过订单号查找对应的订单ID
|
|
|
|
|
+ const orderRepository = this.dataSource.getRepository(OrderMt);
|
|
|
|
|
+ const order = await orderRepository.findOne({
|
|
|
|
|
+ where: { orderNo, tenantId }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ if (!order) {
|
|
|
|
|
+ throw new Error(`订单不存在,订单号: ${orderNo}`);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 通过订单ID查找支付记录
|
|
|
const payment = await paymentRepository.findOne({
|
|
const payment = await paymentRepository.findOne({
|
|
|
- where: { outTradeNo: orderNo, tenantId }
|
|
|
|
|
|
|
+ where: { externalOrderId: order.id, tenantId }
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
if (!payment) {
|
|
if (!payment) {
|
|
@@ -461,8 +473,9 @@ export class PaymentMtService extends GenericCrudService<PaymentMtEntity> {
|
|
|
throw new Error(`订单支付状态不正确,当前状态: ${payment.paymentStatus}`);
|
|
throw new Error(`订单支付状态不正确,当前状态: ${payment.paymentStatus}`);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 验证退款金额
|
|
|
|
|
- if (refundAmount <= 0 || refundAmount > payment.totalAmount) {
|
|
|
|
|
|
|
+ // 验证退款金额并转换为整数(分)
|
|
|
|
|
+ const refundAmountInCents = Math.round(refundAmount * 100);
|
|
|
|
|
+ if (refundAmountInCents <= 0 || refundAmountInCents > payment.totalAmount) {
|
|
|
throw new Error(`退款金额无效,退款金额: ${refundAmount}, 支付金额: ${payment.totalAmount}`);
|
|
throw new Error(`退款金额无效,退款金额: ${refundAmount}, 支付金额: ${payment.totalAmount}`);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -479,7 +492,7 @@ export class PaymentMtService extends GenericCrudService<PaymentMtEntity> {
|
|
|
out_trade_no: payment.outTradeNo,
|
|
out_trade_no: payment.outTradeNo,
|
|
|
out_refund_no: outRefundNo,
|
|
out_refund_no: outRefundNo,
|
|
|
amount: {
|
|
amount: {
|
|
|
- refund: refundAmount,
|
|
|
|
|
|
|
+ refund: refundAmountInCents,
|
|
|
total: payment.totalAmount,
|
|
total: payment.totalAmount,
|
|
|
currency: 'CNY'
|
|
currency: 'CNY'
|
|
|
},
|
|
},
|
|
@@ -491,7 +504,7 @@ export class PaymentMtService extends GenericCrudService<PaymentMtEntity> {
|
|
|
// 更新支付记录的退款状态
|
|
// 更新支付记录的退款状态
|
|
|
payment.refundStatus = PaymentStatus.REFUNDED;
|
|
payment.refundStatus = PaymentStatus.REFUNDED;
|
|
|
payment.refundTransactionId = outRefundNo; // 使用退款订单号作为临时退款流水号
|
|
payment.refundTransactionId = outRefundNo; // 使用退款订单号作为临时退款流水号
|
|
|
- payment.refundAmount = refundAmount;
|
|
|
|
|
|
|
+ payment.refundAmount = refundAmountInCents;
|
|
|
payment.refundTime = new Date();
|
|
payment.refundTime = new Date();
|
|
|
|
|
|
|
|
await paymentRepository.save(payment);
|
|
await paymentRepository.save(payment);
|