51 lines
1.5 KiB
TypeScript
51 lines
1.5 KiB
TypeScript
/**
|
|
* 支付套餐
|
|
*/
|
|
import { z } from "zod";
|
|
|
|
const PaymentPlanWireSchema = z.object({
|
|
plan_id: z.string(),
|
|
plan_name: z.string(),
|
|
order_type: z.string(),
|
|
amount_cents: z.number(),
|
|
original_amount_cents: z.number().nullable().default(null),
|
|
daily_price_cents: z.number().nullable().default(null),
|
|
currency: z.string(),
|
|
vip_days: z.number().nullable(),
|
|
dol_amount: z.number().nullable(),
|
|
});
|
|
|
|
export const PaymentPlanSchema = z
|
|
.preprocess((value) => {
|
|
if (!value || typeof value !== "object") return value;
|
|
const data = value as Record<string, unknown>;
|
|
if ("planId" in data) {
|
|
return {
|
|
plan_id: data.planId,
|
|
plan_name: data.planName,
|
|
order_type: data.orderType,
|
|
amount_cents: data.amountCents,
|
|
original_amount_cents: data.originalAmountCents,
|
|
daily_price_cents: data.dailyPriceCents,
|
|
currency: data.currency,
|
|
vip_days: data.vipDays,
|
|
dol_amount: data.dolAmount,
|
|
};
|
|
}
|
|
return value;
|
|
}, PaymentPlanWireSchema)
|
|
.transform((data) => ({
|
|
planId: data.plan_id,
|
|
planName: data.plan_name,
|
|
orderType: data.order_type,
|
|
amountCents: data.amount_cents,
|
|
originalAmountCents: data.original_amount_cents,
|
|
dailyPriceCents: data.daily_price_cents,
|
|
currency: data.currency,
|
|
vipDays: data.vip_days,
|
|
dolAmount: data.dol_amount,
|
|
}));
|
|
|
|
export type PaymentPlanInput = z.input<typeof PaymentPlanSchema>;
|
|
export type PaymentPlanData = z.output<typeof PaymentPlanSchema>;
|