门店账户多账号

This commit is contained in:
2026-07-12 12:24:34 +08:00
parent 06b1cb22e0
commit 54a15d6da7
39 changed files with 1962 additions and 311 deletions
@@ -54,16 +54,20 @@ export class AdminRedeemDebugService {
throw new NotFoundException('用户不存在,请检查 ID、用户编号或手机号');
}
private async resolveStoreAccountId(storeId: string): Promise<bigint> {
const account = await this.prisma.storeAccount.findFirst({
where: { storeId: this.parseStoreId(storeId), status: 'ACTIVE' },
private async resolveStoreAccountId(storeId: string): Promise<{ accountId: bigint; storeId: bigint }> {
const sid = this.parseStoreId(storeId);
const binding = await this.prisma.storeAccountStore.findFirst({
where: {
storeId: sid,
storeAccount: { status: 'ACTIVE', isPrimary: 1 },
},
orderBy: { id: 'asc' },
select: { id: true, store: { select: { name: true } } },
select: { storeAccountId: true, storeId: true },
});
if (!account) {
if (!binding) {
throw new NotFoundException('该门店无可用账户,请先创建门店账户');
}
return account.id;
return { accountId: binding.storeAccountId, storeId: binding.storeId };
}
async createToken(dto: AdminRedeemDebugCreateTokenDto) {
@@ -76,32 +80,32 @@ export class AdminRedeemDebugService {
}
async preview(dto: AdminRedeemDebugStoreTokenDto) {
const storeAccountId = await this.resolveStoreAccountId(dto.storeId);
return this.redeemService.previewRedeem(storeAccountId, dto.token);
const { accountId, storeId } = await this.resolveStoreAccountId(dto.storeId);
return this.redeemService.previewRedeem(accountId, storeId, dto.token);
}
async confirm(dto: AdminRedeemDebugStoreTokenDto) {
const storeAccountId = await this.resolveStoreAccountId(dto.storeId);
return this.redeemService.confirmRedeem(storeAccountId, { token: dto.token });
const { accountId, storeId } = await this.resolveStoreAccountId(dto.storeId);
return this.redeemService.confirmRedeem(accountId, storeId, { token: dto.token });
}
async sendPhoneLookupSms(dto: AdminRedeemDebugPhoneStoreDto) {
const storeAccountId = await this.resolveStoreAccountId(dto.storeId);
return this.redeemService.sendPhoneLookupSms(storeAccountId, dto.phone);
const { accountId, storeId } = await this.resolveStoreAccountId(dto.storeId);
return this.redeemService.sendPhoneLookupSms(accountId, storeId, dto.phone);
}
async phoneBalance(dto: AdminRedeemDebugPhoneBalanceDto) {
const storeAccountId = await this.resolveStoreAccountId(dto.storeId);
return this.redeemService.verifyPhoneAndGetBalance(storeAccountId, dto.phone, dto.code);
const { accountId, storeId } = await this.resolveStoreAccountId(dto.storeId);
return this.redeemService.verifyPhoneAndGetBalance(accountId, storeId, dto.phone, dto.code);
}
async phonePrepare(dto: AdminRedeemDebugPhonePrepareDto) {
const storeAccountId = await this.resolveStoreAccountId(dto.storeId);
return this.redeemService.preparePhoneRedeem(storeAccountId, dto.sessionId, dto.amount);
const { accountId, storeId } = await this.resolveStoreAccountId(dto.storeId);
return this.redeemService.preparePhoneRedeem(accountId, storeId, dto.sessionId, dto.amount);
}
async phoneConfirm(dto: AdminRedeemDebugPhoneConfirmDto) {
const storeAccountId = await this.resolveStoreAccountId(dto.storeId);
return this.redeemService.confirmPhoneRedeem(storeAccountId, dto.sessionId, dto.code);
const { accountId, storeId } = await this.resolveStoreAccountId(dto.storeId);
return this.redeemService.confirmPhoneRedeem(accountId, storeId, dto.sessionId, dto.code);
}
}