v3数据表更改

This commit is contained in:
2026-07-01 14:36:50 +08:00
parent 638898b71e
commit aeb4ecfc84
46 changed files with 4553 additions and 918 deletions
@@ -27,11 +27,13 @@ type UserRow = Pick<
| 'phone'
| 'phoneVerifiedAt'
| 'nickname'
| 'avatarUrl'
| 'avatarResourceId'
| 'wxOpenId'
| 'mergedIntoUserId'
| 'status'
>;
> & {
avatar?: { url: string } | null;
};
@Injectable()
export class AuthService {
@@ -57,6 +59,7 @@ export class AuthService {
status: 1,
mergedIntoUserId: null,
},
include: { avatar: true },
});
}
@@ -67,13 +70,14 @@ export class AuthService {
userNo: generateUserNo(),
deviceKey: resolvedDeviceKey,
nickname: '访客',
cityPref: {
cityPreference: {
create: {
selectedCityCode: '410100',
selectedDistrict: '郑州市',
},
},
},
include: { avatar: true },
});
}
@@ -96,7 +100,10 @@ export class AuthService {
async loginUser(phone: string, code: string, clientApp: ClientApp, guestId?: bigint) {
await this.smsProvider.verify(phone, code, SmsScene.USER_LOGIN);
let user: UserRow | null = await this.prisma.user.findUnique({ where: { phone } });
let user: UserRow | null = await this.prisma.user.findUnique({
where: { phone },
include: { avatar: true },
});
if (!user) {
if (guestId) {
@@ -110,6 +117,7 @@ export class AuthService {
phoneVerifiedAt: new Date(),
nickname: guest.nickname === '访客' ? `用户${phone.slice(-4)}` : guest.nickname,
},
include: { avatar: true },
});
}
} catch {
@@ -123,13 +131,14 @@ export class AuthService {
phoneVerifiedAt: new Date(),
userNo: generateUserNo(),
nickname: `用户${phone.slice(-4)}`,
cityPref: {
cityPreference: {
create: {
selectedCityCode: '410100',
selectedDistrict: '郑州市',
},
},
},
include: { avatar: true },
});
}
} else {
@@ -137,6 +146,7 @@ export class AuthService {
user = await this.prisma.user.update({
where: { id: user.id },
data: { phoneVerifiedAt: new Date() },
include: { avatar: true },
});
}
if (guestId && guestId !== user.id) {
@@ -173,6 +183,7 @@ export class AuthService {
phoneVerifiedAt: new Date(),
nickname: guest.nickname === '访客' ? `用户${phone.slice(-4)}` : guest.nickname,
},
include: { avatar: true },
});
} else {
await this.assertActiveUser(existing.id);
@@ -293,9 +304,12 @@ export class AuthService {
await tx.order.updateMany({ where: { userId: guestId }, data: { userId: primaryId } });
await tx.userAddress.updateMany({ where: { userId: guestId }, data: { userId: primaryId } });
await tx.benefitCoupon.updateMany({ where: { userId: guestId }, data: { userId: primaryId } });
await tx.benefitLedger.updateMany({ where: { userId: guestId }, data: { userId: primaryId } });
await tx.commonEvent.updateMany({
where: { actorType: 'USER', actorId: guestId },
data: { actorId: primaryId },
});
await tx.redeemRecord.updateMany({ where: { userId: guestId }, data: { userId: primaryId } });
await tx.eventLog.updateMany({ where: { userId: guestId }, data: { userId: primaryId } });
await tx.logUserAnalytics.updateMany({ where: { userId: guestId }, data: { userId: primaryId } });
const primaryPref = await tx.userCityPreference.findUnique({ where: { userId: primaryId } });
const guestPref = await tx.userCityPreference.findUnique({ where: { userId: guestId } });
@@ -343,7 +357,10 @@ export class AuthService {
}
private async assertActiveUser(userId: bigint): Promise<UserRow> {
const user = await this.prisma.user.findUnique({ where: { id: userId } });
const user = await this.prisma.user.findUnique({
where: { id: userId },
include: { avatar: true },
});
if (!user) throw new NotFoundException('用户不存在');
if (user.mergedIntoUserId) {
throw new UnauthorizedException('账号已合并,请重新进入');
@@ -366,7 +383,7 @@ export class AuthService {
phone: user.phone ? user.phone.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2') : null,
phoneVerified: !!user.phoneVerifiedAt,
nickname: user.nickname,
avatarUrl: user.avatarUrl,
avatarUrl: user.avatar?.url ?? null,
hasWechat: !!user.wxOpenId,
};
}