feat(partner): require WeChat OAuth before store photo upload

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-07-03 15:44:46 +08:00
parent 81413e4d08
commit cabc9e6ebb
11 changed files with 231 additions and 13 deletions
@@ -498,6 +498,51 @@ export class AuthService {
});
}
async bindPartnerWechat(
partnerAccountId: 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.partnerAccount.findUnique({
where: { id: partnerAccountId },
include: { partner: true },
});
if (!account) throw new BadRequestException('合伙人账号不存在');
const conflict = await this.prisma.partnerAccount.findFirst({
where: { wxOpenId: session.openId, id: { not: partnerAccountId } },
});
if (conflict) {
throw new BadRequestException('该微信已绑定其他合伙人账号');
}
const updated = await this.prisma.partnerAccount.update({
where: { id: partnerAccountId },
data: {
wxOpenId: session.openId,
wxUnionId: session.unionId ?? account.wxUnionId,
lastLoginAt: new Date(),
},
include: { partner: true },
});
return this.issueToken('PARTNER', updated.id, clientApp, false, undefined, undefined, {
id: updated.id.toString(),
partnerId: updated.partnerId.toString(),
name: updated.name,
phone: updated.phone,
isPrimary: updated.isPrimary === 1,
companyName: updated.partner.companyName,
});
}
async loginPartnerWechat(code: string, clientApp: ClientApp, platform: 'h5' | 'mini' = 'h5') {
this.assertWechatEnabled();
const session =