feat(settlement): 门店账单确认打款支持上传凭证照片

财务确认打款与提现通过可附带 OSS 凭证图,详情与导出展示。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-30 15:25:56 +08:00
parent b375fab44a
commit e68eb4d38c
11 changed files with 293 additions and 114 deletions
@@ -0,0 +1,5 @@
-- 门店账单 / 手动提现:确认打款凭证照片
ALTER TABLE `store_bill`
ADD COLUMN `payment_proof_urls` JSON NULL AFTER `payment_ref`;
ALTER TABLE `store_withdraw_request`
ADD COLUMN `payment_proof_urls` JSON NULL AFTER `payment_ref`;
+9 -7
View File
@@ -1953,10 +1953,11 @@ model StoreBill {
redeemAmount Decimal @map("redeem_amount") @db.Decimal(10, 2)
settlementRate Decimal @map("settlement_rate") @db.Decimal(5, 4)
payoutAmount Decimal @map("payout_amount") @db.Decimal(10, 2)
status FinancePayStatus @default(UNPAID)
paymentRef String? @map("payment_ref") @db.VarChar(128)
paidAt DateTime? @map("paid_at") @db.DateTime(3)
createdAt DateTime @default(now()) @map("created_at") @db.DateTime(3)
status FinancePayStatus @default(UNPAID)
paymentRef String? @map("payment_ref") @db.VarChar(128)
paymentProofUrls Json? @map("payment_proof_urls")
paidAt DateTime? @map("paid_at") @db.DateTime(3)
createdAt DateTime @default(now()) @map("created_at") @db.DateTime(3)
store Store @relation(fields: [storeId], references: [id], onDelete: Restrict)
payouts StorePayout[]
@@ -2002,9 +2003,10 @@ model StoreWithdrawRequest {
appliedAt DateTime @default(now()) @map("applied_at") @db.DateTime(3)
reviewedAt DateTime? @map("reviewed_at") @db.DateTime(3)
reviewedByHqId BigInt? @map("reviewed_by_hq_id") @db.UnsignedBigInt
paidAt DateTime? @map("paid_at") @db.DateTime(3)
paymentRef String? @map("payment_ref") @db.VarChar(128)
createdAt DateTime @default(now()) @map("created_at") @db.DateTime(3)
paidAt DateTime? @map("paid_at") @db.DateTime(3)
paymentRef String? @map("payment_ref") @db.VarChar(128)
paymentProofUrls Json? @map("payment_proof_urls")
createdAt DateTime @default(now()) @map("created_at") @db.DateTime(3)
updatedAt DateTime @updatedAt @map("updated_at") @db.DateTime(3)
store Store @relation(fields: [storeId], references: [id], onDelete: Restrict)
@@ -133,7 +133,7 @@ export class AdminStoreWithdrawController {
approve(
@CurrentUser() user: AuthUser,
@Param('id') id: string,
@Body() body: { paymentRef?: string },
@Body() body: { paymentRef?: string; paymentProofUrls?: string[] },
) {
return this.settlementService.approveStoreWithdraw(BigInt(id), user.actorId, body);
}
@@ -287,8 +287,10 @@ export class AdminStoreBillController {
batch: true,
includeBody: true,
})
batchConfirm(@Body() body: { ids: string[] }) {
return this.settlementService.batchConfirmStoreBills(body.ids ?? []);
batchConfirm(
@Body() body: { ids: string[]; paymentRef?: string; paymentProofUrls?: string[] },
) {
return this.settlementService.batchConfirmStoreBills(body.ids ?? [], body);
}
@Get(':id')
@@ -302,7 +304,10 @@ export class AdminStoreBillController {
refType: 'STORE_BILL',
refIdParam: 'id',
})
confirm(@Param('id') id: string, @Body() body: { paymentRef?: string }) {
confirm(
@Param('id') id: string,
@Body() body: { paymentRef?: string; paymentProofUrls?: string[] },
) {
return this.settlementService.confirmStoreBill(BigInt(id), body);
}
}
@@ -4,6 +4,7 @@ import {
DEFAULT_STORE_WITHDRAW_DAILY_LIMIT,
DEFAULT_XFX_LOGISTICS_PRICING,
LOGISTICS_SETTLEMENT_METHOD_LABELS,
PAYMENT_PROOF_IMAGE_MAX_COUNT,
WINERY_SETTLEMENT_LAG_DAYS,
WINERY_SETTLEMENT_RATE,
} from '@dukang/shared-types';
@@ -50,6 +51,19 @@ function csvEscape(value: string) {
return value;
}
function parsePaymentProofUrls(raw: unknown): string[] {
if (!Array.isArray(raw)) return [];
return raw
.map((u) => String(u ?? '').trim())
.filter((u) => /^https?:\/\//i.test(u))
.slice(0, PAYMENT_PROOF_IMAGE_MAX_COUNT);
}
function paymentProofUrlsInput(urls?: string[]): Prisma.InputJsonValue | typeof Prisma.JsonNull {
const parsed = parsePaymentProofUrls(urls);
return parsed.length ? (parsed as Prisma.InputJsonValue) : Prisma.JsonNull;
}
/** 上海时区自然日 00:00(用本地 Date 构造;服务器需设 Asia/Shanghai 或等价) */
function startOfDay(d: Date) {
return new Date(d.getFullYear(), d.getMonth(), d.getDate(), 0, 0, 0, 0);
@@ -715,6 +729,7 @@ export class SettlementService implements OnModuleInit {
if (!row) throw new NotFoundException('提现申请不存在');
return serializeBigInt({
...row,
paymentProofUrls: parsePaymentProofUrls(row.paymentProofUrls),
overdue:
row.status === 'PENDING_REVIEW' ? isWithdrawOverdue(row.appliedAt) : false,
});
@@ -723,7 +738,7 @@ export class SettlementService implements OnModuleInit {
async approveStoreWithdraw(
id: bigint,
hqAccountId: bigint,
dto?: { paymentRef?: string },
dto?: { paymentRef?: string; paymentProofUrls?: string[] },
) {
const row = await this.prisma.storeWithdrawRequest.findUnique({
where: { id },
@@ -744,6 +759,7 @@ export class SettlementService implements OnModuleInit {
reviewedByHqId: hqAccountId,
paidAt,
paymentRef: dto?.paymentRef?.trim() || null,
paymentProofUrls: paymentProofUrlsInput(dto?.paymentProofUrls),
},
});
await tx.storePayout.updateMany({
@@ -764,6 +780,7 @@ export class SettlementService implements OnModuleInit {
extraJson: {
amount: Number(row.amount),
paymentRef: dto?.paymentRef,
paymentProofCount: parsePaymentProofUrls(dto?.paymentProofUrls).length,
},
});
@@ -1425,10 +1442,18 @@ export class SettlementService implements OnModuleInit {
});
if (!bill) throw new NotFoundException('门店对账单不存在');
const storeAccount = await loadStorePrimaryBank(this.prisma, bill.storeId);
return serializeBigInt({ ...bill, billDate: shanghaiYmd(bill.billDate), storeAccount });
return serializeBigInt({
...bill,
billDate: shanghaiYmd(bill.billDate),
storeAccount,
paymentProofUrls: parsePaymentProofUrls(bill.paymentProofUrls),
});
}
async confirmStoreBill(id: bigint, dto: { paymentRef?: string } = {}) {
async confirmStoreBill(
id: bigint,
dto: { paymentRef?: string; paymentProofUrls?: string[] } = {},
) {
const bill = await this.prisma.storeBill.findUnique({ where: { id } });
if (!bill) throw new NotFoundException('门店对账单不存在');
if (bill.status !== 'UNPAID') throw new BadRequestException('仅未打款账单可确认打款');
@@ -1441,6 +1466,7 @@ export class SettlementService implements OnModuleInit {
status: 'PAID',
paidAt,
paymentRef: dto.paymentRef?.trim() || null,
paymentProofUrls: paymentProofUrlsInput(dto.paymentProofUrls),
},
});
await tx.storePayout.updateMany({
@@ -1449,14 +1475,20 @@ export class SettlementService implements OnModuleInit {
});
return b;
});
return serializeBigInt(updated);
return serializeBigInt({
...updated,
paymentProofUrls: parsePaymentProofUrls(updated.paymentProofUrls),
});
}
async batchConfirmStoreBills(ids: string[]) {
async batchConfirmStoreBills(
ids: string[],
dto: { paymentRef?: string; paymentProofUrls?: string[] } = {},
) {
const results: Array<{ id: string; ok: boolean; message?: string }> = [];
for (const id of ids) {
try {
await this.confirmStoreBill(BigInt(id));
await this.confirmStoreBill(BigInt(id), dto);
results.push({ id, ok: true });
} catch (e) {
results.push({ id, ok: false, message: e instanceof Error ? e.message : '失败' });
@@ -1493,6 +1525,7 @@ export class SettlementService implements OnModuleInit {
'状态',
'打款时间',
'打款凭证',
'打款凭证照片',
'收款户名',
'收款账号',
'开户行',
@@ -1511,6 +1544,7 @@ export class SettlementService implements OnModuleInit {
b.status,
b.paidAt ? b.paidAt.toISOString().slice(0, 19).replace('T', ' ') : '',
csvEscape(b.paymentRef ?? ''),
csvEscape(parsePaymentProofUrls(b.paymentProofUrls).join(' ')),
csvEscape(bank?.bankAccountName ?? ''),
csvEscape(bank?.bankAccountNo ?? ''),
csvEscape(bank?.bankBranch ?? ''),