V4.0.9版本更新合伙人H5端调整
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { BadRequestException, Body, Controller, Get, Param, Post, Put, Query, UseGuards } from '@nestjs/common';
|
||||
import { IsOptional, IsString } from 'class-validator';
|
||||
import { BadRequestException, Body, Controller, ForbiddenException, Get, Param, Post, Put, Query, UseGuards } from '@nestjs/common';
|
||||
import { IsNotEmpty, IsOptional, IsString, MaxLength } from 'class-validator';
|
||||
import { parseShanghaiYmd } from '@dukang/domain';
|
||||
import { DEFAULT_PARTNER_STORE_STAFF_PERMISSIONS } from '@dukang/shared-types';
|
||||
import { SettlementService } from './settlement.service';
|
||||
@@ -20,11 +20,38 @@ class UpdatePartnerMeDto {
|
||||
name?: string;
|
||||
}
|
||||
|
||||
class UpdatePartnerBankDto {
|
||||
@IsString()
|
||||
@IsNotEmpty({ message: '请填写收款人' })
|
||||
@MaxLength(64)
|
||||
bankAccountName!: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty({ message: '请填写银行账号' })
|
||||
@MaxLength(32)
|
||||
bankAccountNo!: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty({ message: '请填写开户行名称' })
|
||||
@MaxLength(128)
|
||||
bankBranch!: string;
|
||||
}
|
||||
|
||||
@Controller('partner/settlement')
|
||||
@UseGuards(JwtAuthGuard, PartnerPrimaryGuard)
|
||||
export class SettlementController {
|
||||
constructor(private readonly settlementService: SettlementService) {}
|
||||
|
||||
@Get('cycle')
|
||||
cycle() {
|
||||
return this.settlementService.getPartnerSettlementCycle();
|
||||
}
|
||||
|
||||
@Get('preview')
|
||||
preview(@CurrentUser() user: AuthUser) {
|
||||
return this.settlementService.getPartnerSettlementPreview(user.actorId);
|
||||
}
|
||||
|
||||
@Get('bills')
|
||||
bills(@CurrentUser() user: AuthUser) {
|
||||
return this.settlementService.listPartnerBills(user.actorId);
|
||||
@@ -325,7 +352,9 @@ export class AdminPartnerBillController {
|
||||
refIdField: 'id',
|
||||
includeBody: true,
|
||||
})
|
||||
generate(@Body() body: { partnerId: string; year: number; month: number }) {
|
||||
generate(@Body() body: { partnerId: string; weekStartYmd: string }) {
|
||||
if (!body?.weekStartYmd) throw new BadRequestException('请提供 weekStartYmd');
|
||||
if (!body?.partnerId) throw new BadRequestException('请提供 partnerId');
|
||||
return this.settlementService.generatePartnerBill(body);
|
||||
}
|
||||
|
||||
@@ -336,7 +365,8 @@ export class AdminPartnerBillController {
|
||||
batch: true,
|
||||
includeBody: true,
|
||||
})
|
||||
generateAll(@Body() body: { year: number; month: number }) {
|
||||
generateAll(@Body() body: { weekStartYmd: string }) {
|
||||
if (!body?.weekStartYmd) throw new BadRequestException('请提供 weekStartYmd');
|
||||
return this.settlementService.generateAllPartnerBills(body);
|
||||
}
|
||||
|
||||
@@ -349,6 +379,7 @@ export class AdminPartnerBillController {
|
||||
partnerId: query.partnerId,
|
||||
year: query.year ? Number(query.year) : undefined,
|
||||
month: query.month ? Number(query.month) : undefined,
|
||||
weekStartYmd: query.weekStartYmd,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -359,6 +390,7 @@ export class AdminPartnerBillController {
|
||||
status: query.status,
|
||||
year: query.year ? Number(query.year) : undefined,
|
||||
month: query.month ? Number(query.month) : undefined,
|
||||
weekStartYmd: query.weekStartYmd,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -618,6 +650,29 @@ export class PartnerMeController {
|
||||
return this.buildPartnerMe(user.actorId);
|
||||
}
|
||||
|
||||
@Put('bank')
|
||||
async updateBank(@CurrentUser() user: AuthUser, @Body() dto: UpdatePartnerBankDto) {
|
||||
const account = await this.prisma.partnerAccount.findUniqueOrThrow({
|
||||
where: { id: user.actorId },
|
||||
});
|
||||
if (account.isPrimary !== 1) {
|
||||
throw new ForbiddenException('仅主账号可修改收款账户');
|
||||
}
|
||||
const bankAccountName = dto.bankAccountName.trim();
|
||||
const bankAccountNo = dto.bankAccountNo.replace(/\s+/g, '');
|
||||
const bankBranch = dto.bankBranch.trim();
|
||||
if (!bankAccountName) throw new BadRequestException('请填写收款人');
|
||||
if (!/^\d{8,32}$/.test(bankAccountNo)) {
|
||||
throw new BadRequestException('请填写正确的银行账号');
|
||||
}
|
||||
if (!bankBranch) throw new BadRequestException('请填写开户行名称');
|
||||
await this.prisma.partnerAccount.update({
|
||||
where: { id: account.id },
|
||||
data: { bankAccountName, bankAccountNo, bankBranch },
|
||||
});
|
||||
return this.buildPartnerMe(user.actorId);
|
||||
}
|
||||
|
||||
private async buildPartnerMe(actorId: bigint) {
|
||||
let account = await this.prisma.partnerAccount.findUniqueOrThrow({
|
||||
where: { id: actorId },
|
||||
@@ -661,6 +716,14 @@ export class PartnerMeController {
|
||||
wxAvatarUrl: account.wxAvatarUrl ?? undefined,
|
||||
managedWarehouseId: primary.managedWarehouseId?.toString() ?? null,
|
||||
hasWarehouseAccess,
|
||||
bankAccount:
|
||||
account.isPrimary === 1
|
||||
? {
|
||||
bankAccountName: account.bankAccountName,
|
||||
bankAccountNo: account.bankAccountNo,
|
||||
bankBranch: account.bankBranch,
|
||||
}
|
||||
: undefined,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user