135 lines
4.0 KiB
TypeScript
135 lines
4.0 KiB
TypeScript
import { Body, Controller, Get, Param, Post, Query, UseGuards } from '@nestjs/common';
|
|
import { SettlementService } from './settlement.service';
|
|
import { JwtAuthGuard, AuthUser } from '../../common/guards/jwt-auth.guard';
|
|
import { CurrentUser } from '../../common/decorators/current-user.decorator';
|
|
import { HqAuthGuard } from '../../common/guards/hq-auth.guard';
|
|
import { PrismaService } from '../../common/prisma/prisma.module';
|
|
|
|
@Controller('partner/settlement')
|
|
@UseGuards(JwtAuthGuard)
|
|
export class SettlementController {
|
|
constructor(private readonly settlementService: SettlementService) {}
|
|
|
|
@Get('bills')
|
|
bills(@CurrentUser() user: AuthUser) {
|
|
return this.settlementService.listPartnerBills(user.actorId);
|
|
}
|
|
}
|
|
|
|
@Controller('shop/payouts')
|
|
@UseGuards(JwtAuthGuard)
|
|
export class ShopPayoutController {
|
|
constructor(private readonly settlementService: SettlementService) {}
|
|
|
|
@Get()
|
|
list(
|
|
@CurrentUser() user: AuthUser,
|
|
@Query('page') page = '1',
|
|
@Query('pageSize') pageSize = '20',
|
|
) {
|
|
return this.settlementService.listShopPayouts(user.actorId, Number(page), Number(pageSize));
|
|
}
|
|
}
|
|
|
|
@Controller('admin/store-payouts')
|
|
@UseGuards(HqAuthGuard)
|
|
export class AdminStorePayoutController {
|
|
constructor(private readonly settlementService: SettlementService) {}
|
|
|
|
@Get()
|
|
list(@Query() query: Record<string, string>) {
|
|
return this.settlementService.listAdminStorePayouts({
|
|
page: query.page ? Number(query.page) : 1,
|
|
pageSize: query.pageSize ? Number(query.pageSize) : 20,
|
|
status: query.status,
|
|
storeId: query.storeId,
|
|
});
|
|
}
|
|
|
|
@Get(':id')
|
|
detail(@Param('id') id: string) {
|
|
return this.settlementService.getAdminStorePayout(BigInt(id));
|
|
}
|
|
|
|
@Post(':id/confirm')
|
|
confirm(@Param('id') id: string, @Body() body: { paymentRef?: string; batchNo?: string; remark?: string }) {
|
|
return this.settlementService.confirmStorePayout(BigInt(id), body);
|
|
}
|
|
|
|
@Post('batch-confirm')
|
|
batchConfirm(@Body() body: { ids: string[]; batchNo?: string }) {
|
|
return this.settlementService.batchConfirmStorePayouts(body.ids ?? [], body);
|
|
}
|
|
|
|
@Post('scan-due')
|
|
scanDue() {
|
|
return this.settlementService.scanDueStorePayouts();
|
|
}
|
|
}
|
|
|
|
@Controller('admin/partner-bills')
|
|
@UseGuards(HqAuthGuard)
|
|
export class AdminPartnerBillController {
|
|
constructor(private readonly settlementService: SettlementService) {}
|
|
|
|
@Post('generate')
|
|
generate(@Body() body: { partnerId: string; year: number; month: number }) {
|
|
return this.settlementService.generatePartnerBill(body);
|
|
}
|
|
|
|
@Get()
|
|
list(@Query() query: Record<string, string>) {
|
|
return this.settlementService.listAdminPartnerBills({
|
|
page: query.page ? Number(query.page) : 1,
|
|
pageSize: query.pageSize ? Number(query.pageSize) : 20,
|
|
status: query.status,
|
|
partnerId: query.partnerId,
|
|
});
|
|
}
|
|
|
|
@Get('export')
|
|
export(@Query() query: Record<string, string>) {
|
|
return this.settlementService.exportPartnerBills({
|
|
partnerId: query.partnerId,
|
|
status: query.status,
|
|
});
|
|
}
|
|
|
|
@Get(':id')
|
|
detail(@Param('id') id: string) {
|
|
return this.settlementService.getAdminPartnerBill(BigInt(id));
|
|
}
|
|
|
|
@Post(':id/confirm')
|
|
confirm(@Param('id') id: string) {
|
|
return this.settlementService.confirmPartnerBill(BigInt(id));
|
|
}
|
|
|
|
@Post(':id/mark-paid')
|
|
markPaid(@Param('id') id: string, @Body() body: { paymentRef?: string }) {
|
|
return this.settlementService.markPartnerBillPaid(BigInt(id), body);
|
|
}
|
|
}
|
|
|
|
@Controller('partner/me')
|
|
@UseGuards(JwtAuthGuard)
|
|
export class PartnerMeController {
|
|
constructor(private readonly prisma: PrismaService) {}
|
|
|
|
@Get()
|
|
async me(@CurrentUser() user: AuthUser) {
|
|
const account = await this.prisma.partnerAccount.findUniqueOrThrow({
|
|
where: { id: user.actorId },
|
|
include: { partner: true },
|
|
});
|
|
return {
|
|
id: account.id.toString(),
|
|
name: account.name,
|
|
phone: account.phone,
|
|
isPrimary: account.isPrimary === 1,
|
|
companyName: account.partner.companyName,
|
|
hasWechat: !!account.wxOpenId,
|
|
};
|
|
}
|
|
}
|