门店页面修改

This commit is contained in:
2026-07-07 00:18:29 +08:00
parent 1fcafac2a7
commit 5d19089f91
11 changed files with 432 additions and 39 deletions
@@ -112,7 +112,17 @@ export class ShopAuthController {
}
@Post('login/wechat')
wechatLogin(@Body() dto: LoginWechatDto) {
@UseGuards(OptionalJwtAuthGuard)
wechatLogin(@Req() req: Request, @Body() dto: LoginWechatDto) {
const user = (req as Request & { user?: AuthUser }).user;
if (user?.actorType === 'STORE') {
return this.authService.bindStoreWechat(
user.actorId,
dto.code,
ClientApp.SHOP_H5,
dto.platform ?? 'h5',
);
}
return this.authService.loginStoreWechat(dto.code, ClientApp.SHOP_H5, dto.platform ?? 'h5');
}
@@ -837,6 +837,50 @@ export class AuthService {
});
}
async bindStoreWechat(
storeAccountId: bigint,
code: string,
clientApp: ClientApp,
platform: 'h5' | 'mini' = 'h5',
) {
this.assertWechatEnabled();
const session =
platform === 'mini'
? await this.wechatProvider.code2Session(code)
: await this.wechatProvider.oauth2AccessToken(code);
const account = await this.prisma.storeAccount.findUnique({
where: { id: storeAccountId },
include: { store: true },
});
if (!account) throw new BadRequestException('门店账号不存在');
const conflict = await this.prisma.storeAccount.findFirst({
where: { wxOpenId: session.openId, id: { not: storeAccountId } },
});
if (conflict) {
throw new BadRequestException('该微信已绑定其他门店账号');
}
const updated = await this.prisma.storeAccount.update({
where: { id: storeAccountId },
data: {
wxOpenId: session.openId,
wxUnionId: session.unionId ?? account.wxUnionId,
lastLoginAt: new Date(),
},
include: { store: true },
});
return this.issueToken('STORE', updated.id, clientApp, false, undefined, {
id: updated.id.toString(),
storeId: updated.storeId.toString(),
name: updated.name,
phone: updated.phone,
storeName: updated.store.name,
});
}
async bindPartnerWechat(
partnerAccountId: bigint,
code: string,