| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- import { z } from '@hono/zod-openapi';
- // 退款状态枚举
- export const RefundStatus = {
- PENDING: 0, // 未退款
- PROCESSING: 1, // 退款中
- SUCCESS: 2, // 退款成功
- FAILED: 3, // 退款失败
- } as const;
- // 订单退款基础Schema
- export const OrderRefundSchema = z.object({
- id: z.number().int().positive().openapi({
- description: '退款记录ID',
- example: 1
- }),
- orderNo: z.string().max(32, '订单号最多32个字符').nullable().optional().openapi({
- description: '订单号',
- example: 'ORD20240101123456'
- }),
- refundOrderNo: z.string().max(32, '退款订单号最多32个字符').nullable().optional().openapi({
- description: '退款订单号',
- example: 'REF20240101123456'
- }),
- refundAmount: z.coerce.number().min(0, '退款金额不能小于0').max(999999.99, '退款金额不能超过999999.99').nullable().optional().openapi({
- description: '退款金额',
- example: 99.99
- }),
- state: z.coerce.number().int().min(0, '状态最小为0').max(3, '状态最大为3').default(0).openapi({
- description: '0未退款1退款中2退款成功3退款失败',
- example: 0
- }),
- remark: z.string().max(255, '备注最多255个字符').nullable().optional().openapi({
- description: '备注',
- example: '用户申请退款'
- }),
- createdBy: z.number().int().positive().nullable().optional().openapi({
- description: '创建人ID',
- example: 1
- }),
- updatedBy: z.number().int().positive().nullable().optional().openapi({
- description: '更新人ID',
- example: 1
- }),
- createdAt: z.coerce.date().openapi({
- description: '创建时间',
- example: '2024-01-01T12:00:00Z'
- }),
- updatedAt: z.coerce.date().openapi({
- description: '更新时间',
- example: '2024-01-01T12:00:00Z'
- }),
- // 关联实体
- order: z.object({
- id: z.number().int().positive().openapi({ description: '订单ID' }),
- orderNo: z.string().openapi({ description: '订单号', example: 'ORD20240101123456' }),
- amount: z.number().openapi({ description: '订单金额', example: 99.99 })
- }).nullable().optional().openapi({
- description: '订单信息'
- })
- });
- // 创建订单退款DTO
- export const CreateOrderRefundDto = z.object({
- orderNo: z.string().max(32, '订单号最多32个字符').nullable().optional().openapi({
- description: '订单号',
- example: 'ORD20240101123456'
- }),
- refundOrderNo: z.string().max(32, '退款订单号最多32个字符').nullable().optional().openapi({
- description: '退款订单号',
- example: 'REF20240101123456'
- }),
- refundAmount: z.coerce.number().min(0, '退款金额不能小于0').max(999999.99, '退款金额不能超过999999.99').nullable().optional().openapi({
- description: '退款金额',
- example: 99.99
- }),
- state: z.coerce.number().int().min(0, '状态最小为0').max(3, '状态最大为3').default(0).optional().openapi({
- description: '0未退款1退款中2退款成功3退款失败',
- example: 0
- }),
- remark: z.string().max(255, '备注最多255个字符').nullable().optional().openapi({
- description: '备注',
- example: '用户申请退款'
- })
- });
- // 更新订单退款DTO
- export const UpdateOrderRefundDto = z.object({
- orderNo: z.string().max(32, '订单号最多32个字符').nullable().optional().openapi({
- description: '订单号',
- example: 'ORD20240101123456'
- }),
- refundOrderNo: z.string().max(32, '退款订单号最多32个字符').nullable().optional().openapi({
- description: '退款订单号',
- example: 'REF20240101123456'
- }),
- refundAmount: z.coerce.number().min(0, '退款金额不能小于0').max(999999.99, '退款金额不能超过999999.99').nullable().optional().openapi({
- description: '退款金额',
- example: 99.99
- }),
- state: z.coerce.number().int().min(0, '状态最小为0').max(3, '状态最大为3').optional().openapi({
- description: '0未退款1退款中2退款成功3退款失败',
- example: 2
- }),
- remark: z.string().max(255, '备注最多255个字符').nullable().optional().openapi({
- description: '备注',
- example: '退款已完成'
- })
- });
- // 订单退款列表响应
- export const OrderRefundListResponse = z.object({
- data: z.array(OrderRefundSchema),
- pagination: z.object({
- total: z.number().openapi({
- example: 100,
- description: '总记录数'
- }),
- current: z.number().openapi({
- example: 1,
- description: '当前页码'
- }),
- pageSize: z.number().openapi({
- example: 10,
- description: '每页数量'
- })
- })
- });
|