|
|
@@ -0,0 +1,117 @@
|
|
|
+import { z } from '@hono/zod-openapi';
|
|
|
+
|
|
|
+// 兑换状态枚举
|
|
|
+export enum RedemptionStatus {
|
|
|
+ UNUSED = 0,
|
|
|
+ USED = 1,
|
|
|
+ EXPIRED = 2,
|
|
|
+ DISABLED = 3
|
|
|
+}
|
|
|
+
|
|
|
+// 兑换码完整 Schema
|
|
|
+export const RedemptionCodeSchema = z.object({
|
|
|
+ id: z.number().int().positive().openapi({
|
|
|
+ description: '兑换码ID',
|
|
|
+ example: 1
|
|
|
+ }),
|
|
|
+ code: z.string().max(100).openapi({
|
|
|
+ description: '兑换码',
|
|
|
+ example: 'ABC123XYZ'
|
|
|
+ }),
|
|
|
+ status: z.number().int().min(0).max(3).openapi({
|
|
|
+ description: '兑换状态:0-未使用,1-已使用,2-已过期,3-已禁用',
|
|
|
+ example: 0
|
|
|
+ }),
|
|
|
+ batchId: z.number().int().positive().openapi({
|
|
|
+ description: '批次ID',
|
|
|
+ example: 1
|
|
|
+ }),
|
|
|
+ redemptionResult: z.string().max(500).nullable().openapi({
|
|
|
+ description: '兑换结果描述',
|
|
|
+ example: '兑换成功,获得100积分'
|
|
|
+ }),
|
|
|
+ usedAt: z.date().nullable().openapi({
|
|
|
+ description: '使用时间',
|
|
|
+ example: '2024-01-01T12:00:00Z'
|
|
|
+ }),
|
|
|
+ usedBy: z.number().int().positive().nullable().openapi({
|
|
|
+ description: '使用用户ID',
|
|
|
+ example: 123
|
|
|
+ }),
|
|
|
+ createdBy: z.number().int().positive().nullable().openapi({
|
|
|
+ description: '创建用户ID',
|
|
|
+ example: 1
|
|
|
+ }),
|
|
|
+ updatedBy: z.number().int().positive().nullable().openapi({
|
|
|
+ description: '更新用户ID',
|
|
|
+ example: 1
|
|
|
+ }),
|
|
|
+ createdAt: z.date().openapi({
|
|
|
+ description: '创建时间',
|
|
|
+ example: '2024-01-01T00:00:00Z'
|
|
|
+ }),
|
|
|
+ updatedAt: z.date().openapi({
|
|
|
+ description: '更新时间',
|
|
|
+ example: '2024-01-01T00:00:00Z'
|
|
|
+ }),
|
|
|
+ batch: z.any().optional().openapi({
|
|
|
+ description: '关联的批次信息',
|
|
|
+ example: {}
|
|
|
+ })
|
|
|
+});
|
|
|
+
|
|
|
+// 创建DTO
|
|
|
+export const CreateRedemptionCodeDto = z.object({
|
|
|
+ code: z.string().max(100).openapi({
|
|
|
+ description: '兑换码',
|
|
|
+ example: 'ABC123XYZ'
|
|
|
+ }),
|
|
|
+ batchId: z.number().int().positive().openapi({
|
|
|
+ description: '批次ID',
|
|
|
+ example: 1
|
|
|
+ }),
|
|
|
+ status: z.number().int().min(0).max(3).default(RedemptionStatus.UNUSED).openapi({
|
|
|
+ description: '兑换状态:0-未使用,1-已使用,2-已过期,3-已禁用',
|
|
|
+ example: 0
|
|
|
+ }),
|
|
|
+ redemptionResult: z.string().max(500).nullable().optional().openapi({
|
|
|
+ description: '兑换结果描述',
|
|
|
+ example: null
|
|
|
+ })
|
|
|
+});
|
|
|
+
|
|
|
+// 更新DTO
|
|
|
+export const UpdateRedemptionCodeDto = z.object({
|
|
|
+ code: z.string().max(100).optional().openapi({
|
|
|
+ description: '兑换码',
|
|
|
+ example: 'ABC123XYZ'
|
|
|
+ }),
|
|
|
+ status: z.number().int().min(0).max(3).optional().openapi({
|
|
|
+ description: '兑换状态:0-未使用,1-已使用,2-已过期,3-已禁用',
|
|
|
+ example: 0
|
|
|
+ }),
|
|
|
+ batchId: z.number().int().positive().optional().openapi({
|
|
|
+ description: '批次ID',
|
|
|
+ example: 1
|
|
|
+ }),
|
|
|
+ redemptionResult: z.string().max(500).nullable().optional().openapi({
|
|
|
+ description: '兑换结果描述',
|
|
|
+ example: '兑换成功,获得100积分'
|
|
|
+ })
|
|
|
+});
|
|
|
+
|
|
|
+// 状态枚举映射
|
|
|
+export const RedemptionStatusMap = {
|
|
|
+ [RedemptionStatus.UNUSED]: { label: '未使用', color: 'blue' },
|
|
|
+ [RedemptionStatus.USED]: { label: '已使用', color: 'green' },
|
|
|
+ [RedemptionStatus.EXPIRED]: { label: '已过期', color: 'red' },
|
|
|
+ [RedemptionStatus.DISABLED]: { label: '已禁用', color: 'gray' }
|
|
|
+} as const;
|
|
|
+
|
|
|
+// 状态选项
|
|
|
+export const RedemptionStatusOptions = [
|
|
|
+ { label: '未使用', value: RedemptionStatus.UNUSED },
|
|
|
+ { label: '已使用', value: RedemptionStatus.USED },
|
|
|
+ { label: '已过期', value: RedemptionStatus.EXPIRED },
|
|
|
+ { label: '已禁用', value: RedemptionStatus.DISABLED }
|
|
|
+] as const;
|