代下单功能
This commit is contained in:
@@ -90,6 +90,8 @@ export class AuthService {
|
||||
case SmsScene.REDEEM_PHONE_LOOKUP:
|
||||
case SmsScene.REDEEM_PHONE_CONFIRM:
|
||||
return ClientApp.SHOP_H5;
|
||||
case SmsScene.PARTNER_PROXY_ORDER:
|
||||
return ClientApp.PARTNER_H5;
|
||||
default:
|
||||
return ClientApp.USER_H5;
|
||||
}
|
||||
@@ -140,6 +142,13 @@ export class AuthService {
|
||||
});
|
||||
return user ? { refType: 'USER', refId: user.id } : undefined;
|
||||
}
|
||||
case SmsScene.PARTNER_PROXY_ORDER: {
|
||||
const user = await this.prisma.user.findFirst({
|
||||
where: { phone, mergedIntoUserId: null, status: 1 },
|
||||
select: { id: true },
|
||||
});
|
||||
return user ? { refType: 'USER', refId: user.id } : undefined;
|
||||
}
|
||||
default:
|
||||
return undefined;
|
||||
}
|
||||
@@ -279,6 +288,9 @@ export class AuthService {
|
||||
if (!user.phoneVerifiedAt) throw new BadRequestException('用户手机号未验证,无法核销');
|
||||
return;
|
||||
}
|
||||
if (scene === SmsScene.PARTNER_PROXY_ORDER) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
async verifySmsCode(phone: string, code: string, scene: SmsScene) {
|
||||
@@ -286,6 +298,44 @@ export class AuthService {
|
||||
await this.smsProvider.verify(normalizedPhone, code, scene);
|
||||
}
|
||||
|
||||
/** 合伙人代下单:按手机号查找或创建已验证用户 */
|
||||
async findOrCreateUserByPhone(phone: string) {
|
||||
const normalizedPhone = this.assertMobilePhone(phone);
|
||||
let user = await this.prisma.user.findUnique({
|
||||
where: { phone: normalizedPhone },
|
||||
include: { avatar: true },
|
||||
});
|
||||
|
||||
if (!user) {
|
||||
user = await this.prisma.user.create({
|
||||
data: {
|
||||
phone: normalizedPhone,
|
||||
phoneVerifiedAt: new Date(),
|
||||
userNo: generateUserNo(),
|
||||
nickname: `用户${normalizedPhone.slice(-4)}`,
|
||||
cityPreference: {
|
||||
create: {
|
||||
selectedCityCode: '410100',
|
||||
selectedDistrict: '郑州市',
|
||||
},
|
||||
},
|
||||
},
|
||||
include: { avatar: true },
|
||||
});
|
||||
} else {
|
||||
if (!user.phoneVerifiedAt) {
|
||||
user = await this.prisma.user.update({
|
||||
where: { id: user.id },
|
||||
data: { phoneVerifiedAt: new Date() },
|
||||
include: { avatar: true },
|
||||
});
|
||||
}
|
||||
await this.assertActiveUser(user.id);
|
||||
}
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
private async verifySmsForUser(
|
||||
phone: string,
|
||||
code: string,
|
||||
@@ -1261,6 +1311,21 @@ export class AuthService {
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
guest.sourceType === 'PROMO_CODE' &&
|
||||
guest.sourceRefId &&
|
||||
primary.sourceType === 'ORGANIC'
|
||||
) {
|
||||
await tx.user.update({
|
||||
where: { id: primaryId },
|
||||
data: {
|
||||
sourceType: 'PROMO_CODE',
|
||||
sourceRefId: guest.sourceRefId,
|
||||
sourceLabel: guest.sourceLabel ?? primary.sourceLabel,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
const deviceKeyToTransfer =
|
||||
guest.deviceKey && !primary.deviceKey ? guest.deviceKey : null;
|
||||
if (deviceKeyToTransfer) {
|
||||
|
||||
Reference in New Issue
Block a user