f6d97b4ee8
CI / verify (pull_request) Has been cancelled
同城有仓按仓库绑定承运商自动推单或自管填单,无仓/跨城走总部快递;新增仓配注册表、FulfillmentService 及三端运单追踪。 Co-authored-by: Cursor <cursoragent@cursor.com>
165 lines
5.0 KiB
TypeScript
165 lines
5.0 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';
|
|
|
|
@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) {
|
|
return this.tradeService.confirmReceive(user.actorId, BigInt(id));
|
|
}
|
|
|
|
@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);
|
|
}
|
|
}
|
|
|
|
@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);
|
|
}
|
|
}
|