v3数据表更改
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
import type { CommonEvent } from '@prisma/client';
|
||||
|
||||
type OrderLike = {
|
||||
productName?: string;
|
||||
productSpec?: string;
|
||||
quantity?: number;
|
||||
listUnitPrice?: unknown;
|
||||
payAmount?: unknown;
|
||||
payStatus?: string;
|
||||
payExternalNo?: string | null;
|
||||
paidAt?: Date | string | null;
|
||||
imageResource?: { url?: string } | null;
|
||||
};
|
||||
|
||||
export function mapOrderItemCompat(order: OrderLike) {
|
||||
return {
|
||||
productName: order.productName ?? '',
|
||||
productSpec: order.productSpec ?? '',
|
||||
productImage: order.imageResource?.url ?? '',
|
||||
unitPrice: Number(order.listUnitPrice ?? 0),
|
||||
quantity: order.quantity ?? 1,
|
||||
};
|
||||
}
|
||||
|
||||
export function mapOrderCompat<T extends OrderLike>(order: T) {
|
||||
const payStatus = order.payStatus ?? 'UNPAID';
|
||||
return {
|
||||
...order,
|
||||
items: [mapOrderItemCompat(order)],
|
||||
payment: {
|
||||
status: payStatus === 'PAID' ? 'SUCCESS' : payStatus,
|
||||
externalNo: order.payExternalNo ?? null,
|
||||
paidAt: order.paidAt ?? null,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export function mapStoreCompat<T extends { coverResource?: { url?: string } | null }>(store: T) {
|
||||
return {
|
||||
...store,
|
||||
coverUrl: store.coverResource?.url ?? null,
|
||||
};
|
||||
}
|
||||
|
||||
export function mapStatusLogCompat(events: CommonEvent[]) {
|
||||
return events.map((e) => ({
|
||||
fromStatus: e.param1,
|
||||
toStatus: e.param2 ?? '',
|
||||
operator: e.param3,
|
||||
remark: e.remark,
|
||||
createdAt: e.createdAt,
|
||||
}));
|
||||
}
|
||||
|
||||
export function mapBenefitLedgerCompat(
|
||||
event: CommonEvent,
|
||||
user?: { userNo?: string | null } | null,
|
||||
coupon?: { couponNo?: string } | null,
|
||||
) {
|
||||
return {
|
||||
id: event.id,
|
||||
type: event.param1,
|
||||
amount: event.amount1 != null ? Number(event.amount1) : 0,
|
||||
balanceAfter: event.amount2 != null ? Number(event.amount2) : 0,
|
||||
remark: event.remark,
|
||||
createdAt: event.createdAt,
|
||||
userId: event.actorId,
|
||||
couponId: event.param2 ? BigInt(event.param2) : null,
|
||||
user: user ? { userNo: user.userNo } : undefined,
|
||||
coupon: coupon ? { couponNo: coupon.couponNo } : undefined,
|
||||
};
|
||||
}
|
||||
@@ -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,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user