mirror of
https://github.com/JetSprow/J-Board-Lite.git
synced 2026-05-01 01:14:10 +05:30
feat: add subscription push transfers
This commit is contained in:
@@ -52,7 +52,7 @@ export async function creditWallet(
|
||||
input: {
|
||||
userId: string;
|
||||
amount: number | string | Prisma.Decimal;
|
||||
type: "BALANCE_RECHARGE" | "CARD_REDEEM" | "ADMIN_ADJUST" | "REFUND";
|
||||
type: "BALANCE_RECHARGE" | "CARD_REDEEM" | "ADMIN_ADJUST" | "REFUND" | "SUBSCRIPTION_TRANSFER_REFUND";
|
||||
description?: string;
|
||||
orderId?: string | null;
|
||||
rechargeOrderId?: string | null;
|
||||
@@ -86,13 +86,15 @@ export async function creditWallet(
|
||||
return wallet;
|
||||
}
|
||||
|
||||
export async function debitWalletForOrder(
|
||||
export async function debitWallet(
|
||||
db: DbClient,
|
||||
input: {
|
||||
userId: string;
|
||||
orderId: string;
|
||||
amount: number | string | Prisma.Decimal;
|
||||
type: "BALANCE_PAYMENT" | "SUBSCRIPTION_TRANSFER_FEE";
|
||||
description?: string;
|
||||
orderId?: string | null;
|
||||
metadata?: Prisma.InputJsonValue;
|
||||
},
|
||||
) {
|
||||
const amount = toMoneyDecimal(input.amount);
|
||||
@@ -107,7 +109,7 @@ export async function debitWalletForOrder(
|
||||
});
|
||||
|
||||
if (claimed.count === 0) {
|
||||
throw new Error("余额不足,请先充值后再支付");
|
||||
throw new Error("余额不足,请先充值后再操作");
|
||||
}
|
||||
|
||||
const wallet = await db.walletAccount.findUniqueOrThrow({
|
||||
@@ -118,17 +120,37 @@ export async function debitWalletForOrder(
|
||||
data: {
|
||||
walletId: wallet.id,
|
||||
userId: input.userId,
|
||||
type: "BALANCE_PAYMENT",
|
||||
type: input.type,
|
||||
amount: amount.negated(),
|
||||
balanceAfter: wallet.balance,
|
||||
description: input.description ?? "余额支付订单",
|
||||
orderId: input.orderId,
|
||||
description: input.description ?? "余额扣费",
|
||||
orderId: input.orderId ?? null,
|
||||
metadata: input.metadata ?? undefined,
|
||||
},
|
||||
});
|
||||
|
||||
return wallet;
|
||||
}
|
||||
|
||||
export async function debitWalletForOrder(
|
||||
db: DbClient,
|
||||
input: {
|
||||
userId: string;
|
||||
orderId: string;
|
||||
amount: number | string | Prisma.Decimal;
|
||||
description?: string;
|
||||
},
|
||||
) {
|
||||
const amount = toMoneyDecimal(input.amount);
|
||||
return debitWallet(db, {
|
||||
userId: input.userId,
|
||||
orderId: input.orderId,
|
||||
amount,
|
||||
type: "BALANCE_PAYMENT",
|
||||
description: input.description ?? "余额支付订单",
|
||||
});
|
||||
}
|
||||
|
||||
type PlanCardSnapshot = {
|
||||
type: "PROXY" | "STREAMING";
|
||||
nodeId: string | null;
|
||||
|
||||
Reference in New Issue
Block a user