发布商品,商品图片使用oss服务器地址

This commit is contained in:
2026-07-06 08:53:03 +08:00
parent a0466f023e
commit 5ba69eb935
60 changed files with 2776 additions and 157 deletions
@@ -1,10 +1,13 @@
import { Module } from '@nestjs/common';
import { IntegrationsModule } from '../integrations/integrations.module';
import { TradeModule } from '../modules/trade/trade.module';
import { PrismaModule } from '../common/prisma/prisma.module';
import { WechatPayCallbackController } from './wechat-pay.controller';
import { WechatRefundCallbackController } from './wechat-refund.controller';
import { DeliveryCallbackController } from './delivery-track.controller';
@Module({
imports: [IntegrationsModule, TradeModule],
controllers: [WechatPayCallbackController],
imports: [IntegrationsModule, TradeModule, PrismaModule],
controllers: [WechatPayCallbackController, WechatRefundCallbackController, DeliveryCallbackController],
})
export class CallbacksModule {}
@@ -0,0 +1,36 @@
import { Body, Controller, Post } from '@nestjs/common';
import { TradeService } from '../modules/trade/trade.service';
import { CourierService } from '../integrations/courier/courier.service';
import { PrismaService } from '../common/prisma/prisma.module';
@Controller('callbacks/delivery')
export class DeliveryCallbackController {
constructor(
private readonly tradeService: TradeService,
private readonly courier: CourierService,
private readonly prisma: PrismaService,
) {}
@Post('track')
async track(@Body() body: { orderNo?: string; orderId?: string; status?: string }) {
if (!body.orderId && !body.orderNo) {
return this.courier.buildTrackCallbackResponse(false);
}
const order = body.orderId
? await this.prisma.order.findUnique({ where: { id: BigInt(body.orderId) } })
: await this.prisma.order.findUnique({ where: { orderNo: body.orderNo! } });
if (!order) return this.courier.buildTrackCallbackResponse(false);
const statusMap: Record<string, string> = {
SHIPPED: 'SHIPPING',
OUT_WAREHOUSE: 'OUT_WAREHOUSE',
DELIVERED: 'COMPLETED',
COMPLETED: 'COMPLETED',
};
const target = statusMap[body.status ?? ''] ?? body.status;
if (target && target !== order.status) {
await this.tradeService.applyStatusTransition(order.id, order.status, target, 'DELIVERY_CALLBACK');
}
return this.courier.buildTrackCallbackResponse(true);
}
}
@@ -0,0 +1,44 @@
import { Controller, Headers, Post, Req, Res } from '@nestjs/common';
import type { Request, Response } from 'express';
import { PrismaService } from '../common/prisma/prisma.module';
@Controller('callbacks/wechat')
export class WechatRefundCallbackController {
constructor(private readonly prisma: PrismaService) {}
@Post('refund')
async refundNotify(
@Req() req: Request,
@Headers() _headers: Record<string, string | string[] | undefined>,
@Res() res: Response,
) {
try {
const body = typeof req.body === 'object' ? req.body : {};
const outRefundNo = String((body as Record<string, unknown>).out_refund_no ?? '');
const refundId = String((body as Record<string, unknown>).refund_id ?? outRefundNo);
const existing = await this.prisma.logThirdParty.findFirst({
where: { provider: 'WECHAT_REFUND', externalNo: refundId, status: 'SUCCESS' },
});
if (existing) {
return res.status(200).json({ code: 'SUCCESS', message: '成功' });
}
await this.prisma.logThirdParty.create({
data: {
provider: 'WECHAT_REFUND',
scene: 'ORDER_REFUND_CALLBACK',
refType: 'TICKET',
refId: BigInt(0),
externalNo: refundId,
status: 'SUCCESS',
},
});
return res.status(200).json({ code: 'SUCCESS', message: '成功' });
} catch (err) {
const message = err instanceof Error ? err.message : '处理失败';
return res.status(500).json({ code: 'FAIL', message });
}
}
}