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
@@ -0,0 +1,67 @@
import type { Prisma } from '@prisma/client';
type BenefitLedgerType = 'GRANT' | 'REDEEM' | 'REFUND_VOID' | 'ADJUST';
export function buildBenefitLedgerEvent(data: {
userId: bigint;
couponId: bigint;
type: BenefitLedgerType;
amount: number;
balanceAfter: number;
refType: string;
refId?: bigint;
remark?: string;
}): Prisma.CommonEventCreateInput {
return {
eventType: 'BENEFIT_LEDGER',
refType: data.refType,
refId: data.refId ?? data.couponId,
actorType: 'USER',
actorId: data.userId,
param1: data.type,
param1Desc: 'ledger_type',
param2: data.couponId.toString(),
param2Desc: 'coupon_id',
amount1: data.amount,
amount2: data.balanceAfter,
remark: data.remark,
};
}
export function buildOrderStatusEvent(data: {
orderId: bigint;
fromStatus: string;
toStatus: string;
operator: string;
remark?: string;
}): Prisma.CommonEventCreateInput {
return {
eventType: 'ORDER_STATUS',
refType: 'ORDER',
refId: data.orderId,
actorType: 'SYSTEM',
param1: data.fromStatus,
param1Desc: 'from_status',
param2: data.toStatus,
param2Desc: 'to_status',
param3: data.operator,
param3Desc: 'operator',
remark: data.remark,
};
}
export function benefitLedgerWhere(userId?: bigint, couponId?: bigint): Prisma.CommonEventWhereInput {
return {
eventType: 'BENEFIT_LEDGER',
...(userId ? { actorType: 'USER', actorId: userId } : {}),
...(couponId ? { param2: couponId.toString() } : {}),
};
}
export function orderStatusLogWhere(orderId: bigint): Prisma.CommonEventWhereInput {
return {
eventType: 'ORDER_STATUS',
refType: 'ORDER',
refId: orderId,
};
}