feat: 支持邀请好友功能
This commit is contained in:
@@ -55,6 +55,8 @@ export class PaymentService {
|
||||
await this.inviteService.validateInviterForTrialOrder(userId, inviterId)
|
||||
}
|
||||
|
||||
const referral = await this.prisma.inviteReferral.findUnique({ where: { inviteeId: userId } })
|
||||
const amount = referral ? Math.round(Number(cardType.price) * 95 / 100) : Number(cardType.price)
|
||||
const orderNo = `${Date.now()}${Math.random().toString(36).substring(2, 8)}`
|
||||
|
||||
const order = await this.prisma.order.create({
|
||||
@@ -62,14 +64,16 @@ export class PaymentService {
|
||||
userId,
|
||||
cardTypeId,
|
||||
orderNo,
|
||||
amount: cardType.price,
|
||||
amount,
|
||||
inviteInviterId: referral?.inviterId,
|
||||
purchasedCategory: cardType.type,
|
||||
status: OrderStatus.PENDING,
|
||||
},
|
||||
})
|
||||
|
||||
const paymentParams = await this.wechatPayService.createUnifiedOrder({
|
||||
orderNo,
|
||||
amount: Number(cardType.price),
|
||||
amount,
|
||||
openid: user.openid,
|
||||
description: cardType.name,
|
||||
})
|
||||
@@ -122,6 +126,11 @@ export class PaymentService {
|
||||
const now = new Date()
|
||||
|
||||
await this.prisma.$transaction(async (tx) => {
|
||||
const claimed = await tx.order.updateMany({
|
||||
where: { id: existingOrder.id, status: OrderStatus.PENDING },
|
||||
data: { status: OrderStatus.PAID },
|
||||
})
|
||||
if (!claimed.count) return
|
||||
const membership = await this.membershipService.grantPurchasedCard(
|
||||
tx,
|
||||
existingOrder.userId,
|
||||
@@ -138,6 +147,7 @@ export class PaymentService {
|
||||
membershipId: membership.id,
|
||||
},
|
||||
})
|
||||
await this.inviteService.rewardPaidOrder(tx, existingOrder, now)
|
||||
})
|
||||
|
||||
await this.inviteService.recordTrialOrderPaid(existingOrder.id)
|
||||
|
||||
Reference in New Issue
Block a user