Files
dukang/server/dukang-api/src/modules/trade/trade.controller.ts
T
jacy 0418370c31
CI / verify (pull_request) Has been cancelled
小程序端核销权益券金额输入限制
现场取货功能
2026-07-23 00:03:21 +08:00

230 lines
6.8 KiB
TypeScript

import { Body, Controller, Get, Param, Post, Put, Query, Req, UseGuards } from '@nestjs/common';
import type { Request } from 'express';
import { TradeService } from './trade.service';
import { JwtAuthGuard, AuthUser } from '../../common/guards/jwt-auth.guard';
import { PartnerPrimaryGuard } from '../../common/guards/partner-primary.guard';
import { RequirePartnerPermissions } from '../../common/decorators/partner-permission.decorator';
import { PartnerPermissionGuard } from '../../common/guards/partner-permission.guard';
import { CurrentUser } from '../../common/decorators/current-user.decorator';
import {
PartnerProxyOrderCreateDto,
PartnerProxyOrderPreviewDto,
PartnerProxyOrderSendSmsDto,
} from './dto/partner-proxy-order.dto';
import { ManualShipOrderDto } from '../ops/dto/admin-mutate.dto';
import { CreateAfterSaleTicketDto, CreateInvoiceDto } from './dto/after-sale.dto';
@Controller('trade/orders')
@UseGuards(JwtAuthGuard)
export class TradeController {
constructor(private readonly tradeService: TradeService) {}
@Post('preview')
preview(@CurrentUser() user: AuthUser, @Body() body: Record<string, unknown>) {
return this.tradeService.preview(user.actorId, body as never);
}
@Post()
create(@CurrentUser() user: AuthUser, @Body() body: Record<string, unknown>, @Req() req: Request) {
return this.tradeService.createOrder(user.actorId, body as never, req);
}
@Get()
list(
@CurrentUser() user: AuthUser,
@Query('tab') tab = 'all',
@Query('page') page = '1',
@Query('pageSize') pageSize = '20',
) {
return this.tradeService.listOrders(user.actorId, tab, Number(page), Number(pageSize));
}
@Get(':id')
detail(@CurrentUser() user: AuthUser, @Param('id') id: string) {
return this.tradeService.getOrder(user.actorId, BigInt(id));
}
@Get(':id/track')
track(@CurrentUser() user: AuthUser, @Param('id') id: string) {
return this.tradeService.getOrderTrack(user.actorId, BigInt(id));
}
@Post(':id/pay')
pay(@CurrentUser() user: AuthUser, @Param('id') id: string) {
return this.tradeService.payOrder(user.actorId, BigInt(id), user.clientApp);
}
@Put(':id/address')
updateAddress(
@CurrentUser() user: AuthUser,
@Param('id') id: string,
@Body() body: Record<string, unknown>,
) {
return this.tradeService.updateAddress(user.actorId, BigInt(id), body);
}
@Post(':id/confirm-receive')
confirmReceive(
@CurrentUser() user: AuthUser,
@Param('id') id: string,
@Body() body?: { onSitePickup?: boolean },
) {
return this.tradeService.confirmReceive(user.actorId, BigInt(id), {
onSitePickup: !!body?.onSitePickup,
});
}
@Post(':id/refund-requests')
refundRequest(
@CurrentUser() user: AuthUser,
@Param('id') id: string,
@Body() body: { remark?: string },
) {
return this.tradeService.createRefundRequest(user.actorId, BigInt(id), body.remark);
}
@Post(':id/after-sale-tickets')
createAfterSale(
@CurrentUser() user: AuthUser,
@Param('id') id: string,
@Body() body: CreateAfterSaleTicketDto,
) {
return this.tradeService.createAfterSaleTicket(user.actorId, BigInt(id), body);
}
@Post(':id/invoices')
createInvoice(
@CurrentUser() user: AuthUser,
@Param('id') id: string,
@Body() body: CreateInvoiceDto,
) {
return this.tradeService.createInvoice(user.actorId, BigInt(id), body);
}
}
@Controller('trade/after-sale-tickets')
@UseGuards(JwtAuthGuard)
export class TradeAfterSaleTicketController {
constructor(private readonly tradeService: TradeService) {}
@Get()
list(
@CurrentUser() user: AuthUser,
@Query('page') page = '1',
@Query('pageSize') pageSize = '20',
) {
return this.tradeService.listAfterSaleTickets(user.actorId, Number(page), Number(pageSize));
}
@Get(':id')
detail(@CurrentUser() user: AuthUser, @Param('id') id: string) {
return this.tradeService.getAfterSaleTicket(user.actorId, BigInt(id));
}
}
@Controller('trade/invoices')
@UseGuards(JwtAuthGuard)
export class TradeInvoiceController {
constructor(private readonly tradeService: TradeService) {}
@Get()
list(
@CurrentUser() user: AuthUser,
@Query('page') page = '1',
@Query('pageSize') pageSize = '20',
) {
return this.tradeService.listInvoices(user.actorId, Number(page), Number(pageSize));
}
@Get(':id')
detail(@CurrentUser() user: AuthUser, @Param('id') id: string) {
return this.tradeService.getInvoice(user.actorId, BigInt(id));
}
}
@Controller('partner/orders')
@UseGuards(JwtAuthGuard, PartnerPermissionGuard)
@RequirePartnerPermissions('order:view', 'warehouse:manage')
export class PartnerOrderController {
constructor(private readonly tradeService: TradeService) {}
@Get()
list(
@CurrentUser() user: AuthUser,
@Query('page') page = '1',
@Query('pageSize') pageSize = '20',
) {
return this.tradeService.listPartnerOrders(user.actorId, Number(page), Number(pageSize));
}
@Get(':id')
detail(@CurrentUser() user: AuthUser, @Param('id') id: string) {
return this.tradeService.getPartnerOrder(user.actorId, BigInt(id));
}
@Get(':id/track')
track(@CurrentUser() user: AuthUser, @Param('id') id: string) {
return this.tradeService.getPartnerOrderTrack(user.actorId, BigInt(id));
}
@Post(':id/manual-ship')
@RequirePartnerPermissions('warehouse:manage')
manualShip(
@CurrentUser() user: AuthUser,
@Param('id') id: string,
@Body() body: ManualShipOrderDto,
) {
return this.tradeService.partnerManualShip(user.actorId, BigInt(id), body);
}
@Post(':id/mock-advance-delivery')
mockAdvance(
@CurrentUser() user: AuthUser,
@Param('id') id: string,
@Body() body: { targetStatus: string },
) {
return this.tradeService.advanceDelivery(user.actorId, BigInt(id), body.targetStatus);
}
}
@Controller('partner/reshipments')
@UseGuards(JwtAuthGuard, PartnerPrimaryGuard)
export class PartnerReshipmentController {
constructor(private readonly tradeService: TradeService) {}
@Get()
list(@CurrentUser() user: AuthUser) {
return this.tradeService.listPartnerReshipments(user.actorId);
}
}
@Controller('partner/proxy-orders')
@UseGuards(JwtAuthGuard, PartnerPrimaryGuard)
export class PartnerProxyOrderController {
constructor(private readonly tradeService: TradeService) {}
@Get('options')
options() {
return this.tradeService.getPartnerProxyOrderOptions();
}
@Post('preview')
preview(@Body() dto: PartnerProxyOrderPreviewDto) {
return this.tradeService.previewPartnerProxyOrder(dto);
}
@Post('send-sms')
sendSms(@Body() dto: PartnerProxyOrderSendSmsDto) {
return this.tradeService.sendPartnerProxyOrderSms(dto.phone);
}
@Post()
create(
@CurrentUser() user: AuthUser,
@Body() dto: PartnerProxyOrderCreateDto,
@Req() req: Request,
) {
return this.tradeService.createPartnerProxyOrder(user.actorId, dto, req);
}
}