发布商品,商品图片使用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
@@ -14,7 +14,9 @@ import {
import { loadAppConfig, WECHAT_AUTH_REQUIRED } from '@dukang/shared-types';
import { PrismaService } from '../../common/prisma/prisma.module';
import { serializeBigInt } from '../../common/decorators/current-user.decorator';
import { CatalogService } from '../catalog/catalog.service';
import { BenefitService } from '../benefit/benefit.service';
import { TicketService } from '../common/ticket.service';
import { PAY_PROVIDER, DELIVERY_PROVIDER } from '../../integrations/integrations.constants';
import { IPayProvider } from '../../integrations/pay/pay.interface';
import { IDeliveryProvider } from '../../integrations/delivery/delivery.interface';
@@ -29,16 +31,16 @@ import type { Request } from 'express';
export class TradeService {
constructor(
private readonly prisma: PrismaService,
private readonly catalogService: CatalogService,
private readonly benefitService: BenefitService,
private readonly ticketService: TicketService,
private readonly ipGeoService: IpGeoService,
@Inject(PAY_PROVIDER) private readonly payProvider: IPayProvider,
@Inject(DELIVERY_PROVIDER) private readonly deliveryProvider: IDeliveryProvider,
) {}
async preview(userId: bigint, body: { productId: string; quantity: number; addressId?: string }) {
const product = await this.prisma.commonProductItem.findUnique({
where: { id: BigInt(body.productId) },
});
const product = await this.catalogService.getProduct(BigInt(body.productId));
if (!product || product.status !== 'ON_SALE') {
throw new BadRequestException('商品不可购买');
}
@@ -73,7 +75,7 @@ export class TradeService {
const freightPayType: FreightPayType | null = deliveryType === 'CROSS_CITY' ? 'COD' : null;
return {
product: serializeBigInt(product),
product,
quantity: body.quantity,
deliveryType,
productAmount,
@@ -384,6 +386,47 @@ export class TradeService {
return this.getOrder(userId, orderId);
}
async createRefundRequest(userId: bigint, orderId: bigint, remark?: string) {
const order = await this.prisma.order.findFirst({ where: { id: orderId, userId } });
if (!order) throw new NotFoundException('订单不存在');
if (!['PENDING_SHIP', 'PENDING_RECEIVE', 'COMPLETED', 'OUT_WAREHOUSE', 'SHIPPING'].includes(order.status)) {
throw new BadRequestException('当前订单不可申请退款');
}
await this.prisma.order.update({
where: { id: orderId },
data: { status: 'REFUNDING', payStatus: 'REFUNDING' },
});
return this.ticketService.create({
ticketType: 'REFUND',
refType: 'ORDER',
refId: orderId.toString(),
remark: remark ?? '用户申请退款',
});
}
async listPartnerReshipments(partnerAccountId: bigint) {
const account = await this.prisma.partnerAccount.findUniqueOrThrow({
where: { id: partnerAccountId },
});
const cities = await this.prisma.commonCity.findMany({
where: { partnerId: account.partnerId },
select: { id: true },
});
const orders = await this.prisma.order.findMany({
where: { cityId: { in: cities.map((c) => c.id) } },
select: { id: true },
});
const tickets = await this.prisma.commonTicket.findMany({
where: {
ticketType: 'RESHIPMENT',
refType: 'ORDER',
refId: { in: orders.map((o) => o.id) },
},
orderBy: { createdAt: 'desc' },
});
return serializeBigInt(tickets);
}
async listPartnerOrders(partnerAccountId: bigint, page = 1, pageSize = 20) {
const account = await this.prisma.partnerAccount.findUniqueOrThrow({
where: { id: partnerAccountId },