feat(trade): connect WeChat refund API and callback flow

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-03 21:45:33 +08:00
parent e93e4b8f84
commit ab10431001
20 changed files with 455 additions and 61 deletions
@@ -1,7 +1,6 @@
import { BadRequestException, Injectable, NotFoundException } from '@nestjs/common';
import { Prisma } from '@prisma/client';
import { PrismaService } from '../../common/prisma/prisma.module';
import { BenefitService } from '../benefit/benefit.service';
import { TradeService } from '../trade/trade.service';
import { TicketService } from '../common/ticket.service';
import { serializeBigInt } from '../../common/decorators/current-user.decorator';
@@ -28,7 +27,6 @@ export class AdminTicketsService {
private readonly prisma: PrismaService,
private readonly ticketService: TicketService,
private readonly tradeService: TradeService,
private readonly benefitService: BenefitService,
private readonly partnerCityService: PartnerCityService,
) {}
@@ -123,32 +121,8 @@ export class AdminTicketsService {
return { order, warehouse };
}
private async executeRefund(orderId: bigint, remark: string) {
await this.prisma.order.update({
where: { id: orderId },
data: { status: 'REFUNDED', payStatus: 'REFUNDED' },
});
await this.benefitService.voidCouponsOnRefund(orderId);
await this.prisma.logThirdParty.create({
data: {
provider: 'WECHAT_REFUND',
scene: 'ORDER_REFUND',
refType: 'ORDER',
refId: orderId,
status: 'SUCCESS',
amount: 0,
},
});
await this.prisma.commonEvent.create({
data: {
eventType: 'ORDER_STATUS',
refType: 'ORDER',
refId: orderId,
actorType: 'HQ',
status: 'REFUNDED',
remark,
},
});
private async executeRefund(orderId: bigint, ticketId: bigint, remark: string) {
await this.tradeService.initiateRefund(orderId, ticketId, remark, 'HQ');
}
private async executeReship(orderId: bigint) {
@@ -169,7 +143,7 @@ export class AdminTicketsService {
// 仅退款:立即退款
if (ticket.ticketType === 'REFUND') {
await this.executeRefund(ticket.refId, remark ?? '仅退款工单审批通过');
await this.executeRefund(ticket.refId, ticket.id, remark ?? '仅退款工单审批通过');
return this.ticketService.updateExtraJson(
id,
this.appendLog(existingExtra, 'HQ', actorId, 'APPROVE_REFUND'),
@@ -285,7 +259,7 @@ export class AdminTicketsService {
await this.executeReship(ticket.refId);
extra = this.appendLog(extra, opts.actorType, opts.actorId, 'CONFIRM_RESHIP');
} else if (ticket.ticketType === 'DAMAGE_RETURN' || ticket.ticketType === 'RETURN_REFUND') {
await this.executeRefund(ticket.refId, `${ticket.ticketType} 协同取回后完成退款`);
await this.executeRefund(ticket.refId, ticket.id, `${ticket.ticketType} 协同取回后完成退款`);
extra = this.appendLog(extra, opts.actorType, opts.actorId, 'CONFIRM_PICKUP_REFUND');
} else {
throw new BadRequestException('工单类型不支持协同完成');