核销代码

This commit is contained in:
2026-07-06 22:10:45 +08:00
parent 047cf879f8
commit 386ee9e754
6 changed files with 191 additions and 16 deletions
@@ -1,4 +1,4 @@
import { Injectable, NotFoundException } from '@nestjs/common';
import { BadRequestException, Injectable, NotFoundException } from '@nestjs/common';
import { PrismaService } from '../../common/prisma/prisma.module';
import { RedeemService } from '../redeem/redeem.service';
import type {
@@ -13,9 +13,17 @@ export class AdminRedeemDebugService {
private readonly redeemService: RedeemService,
) {}
private parseId(value: string, label: string): bigint {
const normalized = value?.trim();
if (!normalized || !/^\d+$/.test(normalized)) {
throw new BadRequestException(`${label}格式无效`);
}
return BigInt(normalized);
}
private async resolveStoreAccountId(storeId: string): Promise<bigint> {
const account = await this.prisma.storeAccount.findFirst({
where: { storeId: BigInt(storeId), status: 'ACTIVE' },
where: { storeId: this.parseId(storeId, '门店 ID'), status: 'ACTIVE' },
orderBy: { id: 'asc' },
select: { id: true, store: { select: { name: true } } },
});
@@ -26,7 +34,7 @@ export class AdminRedeemDebugService {
}
async createToken(dto: AdminRedeemDebugCreateTokenDto) {
return this.redeemService.createToken(BigInt(dto.userId), {
return this.redeemService.createToken(this.parseId(dto.userId, '用户 ID'), {
amount: dto.amount,
couponId: dto.couponId,
storeId: dto.storeId,