| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246 |
- import { z } from '@hono/zod-openapi';
- // 订单商品状态枚举
- export const OrderGoodsStatus = {
- UN_SHIPPED: 0, // 未发货
- SHIPPED: 1, // 已发货
- } as const;
- // 商品类型枚举
- export const GoodsType = {
- PHYSICAL: 1, // 实物产品
- VIRTUAL: 2, // 虚拟订单
- } as const;
- // 订单商品基础Schema
- export const OrderGoodsSchema = z.object({
- id: z.number().int().positive().openapi({
- description: '订单商品ID',
- example: 1
- }),
- orderId: z.number().int().positive().openapi({
- description: '订单ID',
- example: 1
- }),
- orderNo: z.string().max(50, '订单号最多50个字符').nullable().optional().openapi({
- description: '订单号',
- example: 'ORD20240101123456'
- }),
- goodsId: z.number().int().positive().openapi({
- description: '商品ID',
- example: 1
- }),
- goodsName: z.string().max(255, '商品名称最多255个字符').nullable().optional().openapi({
- description: '商品名称',
- example: '苹果手机'
- }),
- goodsType: z.coerce.number().int().min(1, '商品类型最小为1').max(2, '商品类型最大为2').default(1).openapi({
- description: '1实物产品2虚拟订单',
- example: 1
- }),
- supplierId: z.coerce.number().int().positive().default(0).openapi({
- description: '供货商ID',
- example: 1
- }),
- costPrice: z.coerce.number().min(0, '成本价不能小于0').max(999999.99, '成本价不能超过999999.99').default(0).openapi({
- description: '成本价',
- example: 50.00
- }),
- price: z.coerce.number().min(0, '售价不能小于0').max(999999.99, '售价不能超过999999.99').default(0).openapi({
- description: '售价',
- example: 99.99
- }),
- num: z.coerce.number().int().min(0, '数量不能小于0').max(99999, '数量不能超过99999').default(0).openapi({
- description: '数量',
- example: 2
- }),
- freightAmount: z.coerce.number().min(0, '运费不能小于0').max(999999.99, '运费不能超过999999.99').default(0).optional().openapi({
- description: '运费',
- example: 10.00
- }),
- state: z.coerce.number().int().min(0, '状态最小为0').max(1, '状态最大为1').default(0).openapi({
- description: '状态(0未发货、1已发货)',
- example: 0
- }),
- expressName: z.string().max(255, '快递名称最多255个字符').nullable().optional().openapi({
- description: '快递名称',
- example: '顺丰快递'
- }),
- expressNo: z.coerce.number().int().positive().nullable().optional().openapi({
- description: '快递单号',
- example: 1234567890
- }),
- 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'
- }),
- imageFileId: z.number().int().positive().nullable().openapi({
- example: 1,
- description: '商品图片文件ID'
- }),
- imageFile: z.object({
- id: z.number().int().positive().openapi({ description: '文件ID' }),
- name: z.string().max(255).openapi({ description: '文件名', example: 'goods.jpg' }),
- fullUrl: z.string().openapi({ description: '文件完整URL', example: 'https://example.com/goods.jpg' }),
- type: z.string().nullable().openapi({ description: '文件类型', example: 'image/jpeg' }),
- size: z.number().nullable().openapi({ description: '文件大小(字节)', example: 102400 })
- }).nullable().optional().openapi({
- description: '商品图片文件信息'
- }),
- // 关联实体
- order: z.object({
- id: z.number().int().positive().openapi({ description: '订单ID' }),
- orderNo: z.string().openapi({ description: '订单号', example: 'ORD20240101123456' })
- }).nullable().optional().openapi({
- description: '订单信息'
- }),
- goods: z.object({
- id: z.number().int().positive().openapi({ description: '商品ID' }),
- name: z.string().openapi({ description: '商品名称', example: '苹果手机' }),
- image: z.string().nullable().openapi({ description: '商品图片', example: 'https://example.com/goods.jpg' })
- }).nullable().optional().openapi({
- description: '商品信息'
- }),
- supplier: z.object({
- id: z.number().int().positive().openapi({ description: '供货商ID' }),
- name: z.string().openapi({ description: '供货商名称', example: '供货商A' })
- }).nullable().optional().openapi({
- description: '供货商信息'
- })
- });
- // 创建订单商品DTO
- export const CreateOrderGoodsDto = z.object({
- orderId: z.number().int().positive('订单ID必须是正整数').openapi({
- description: '订单ID',
- example: 1
- }),
- orderNo: z.string().max(50, '订单号最多50个字符').nullable().optional().openapi({
- description: '订单号',
- example: 'ORD20240101123456'
- }),
- goodsId: z.number().int().positive('商品ID必须是正整数').openapi({
- description: '商品ID',
- example: 1
- }),
- goodsName: z.string().max(255, '商品名称最多255个字符').nullable().optional().openapi({
- description: '商品名称',
- example: '苹果手机'
- }),
- goodsType: z.coerce.number().int().min(1, '商品类型最小为1').max(2, '商品类型最大为2').default(1).optional().openapi({
- description: '1实物产品2虚拟订单',
- example: 1
- }),
- supplierId: z.coerce.number().int().positive().default(0).optional().openapi({
- description: '供货商ID',
- example: 1
- }),
- costPrice: z.coerce.number().min(0, '成本价不能小于0').max(999999.99, '成本价不能超过999999.99').default(0).optional().openapi({
- description: '成本价',
- example: 50.00
- }),
- price: z.coerce.number().min(0, '售价不能小于0').max(999999.99, '售价不能超过999999.99').default(0).optional().openapi({
- description: '售价',
- example: 99.99
- }),
- num: z.coerce.number().int().min(0, '数量不能小于0').max(99999, '数量不能超过99999').default(0).optional().openapi({
- description: '数量',
- example: 2
- }),
- freightAmount: z.coerce.number().min(0, '运费不能小于0').max(999999.99, '运费不能超过999999.99').default(0).optional().openapi({
- description: '运费',
- example: 10.00
- }),
- state: z.coerce.number().int().min(0, '状态最小为0').max(1, '状态最大为1').default(0).optional().openapi({
- description: '状态(0未发货、1已发货)',
- example: 0
- }),
- expressName: z.string().max(255, '快递名称最多255个字符').nullable().optional().openapi({
- description: '快递名称',
- example: '顺丰快递'
- }),
- expressNo: z.coerce.number().int().positive().nullable().optional().openapi({
- description: '快递单号',
- example: 1234567890
- }),
- imageFileId: z.number().int().positive().nullable().optional().openapi({
- description: '商品图片文件ID',
- example: 1
- })
- });
- // 更新订单商品DTO
- export const UpdateOrderGoodsDto = z.object({
- orderId: z.number().int().positive('订单ID必须是正整数').optional().openapi({
- description: '订单ID',
- example: 1
- }),
- orderNo: z.string().max(50, '订单号最多50个字符').nullable().optional().openapi({
- description: '订单号',
- example: 'ORD20240101123456'
- }),
- goodsId: z.number().int().positive('商品ID必须是正整数').optional().openapi({
- description: '商品ID',
- example: 1
- }),
- goodsName: z.string().max(255, '商品名称最多255个字符').nullable().optional().openapi({
- description: '商品名称',
- example: '苹果手机'
- }),
- goodsType: z.coerce.number().int().min(1, '商品类型最小为1').max(2, '商品类型最大为2').optional().openapi({
- description: '1实物产品2虚拟订单',
- example: 1
- }),
- supplierId: z.coerce.number().int().positive().optional().openapi({
- description: '供货商ID',
- example: 1
- }),
- costPrice: z.coerce.number().min(0, '成本价不能小于0').max(999999.99, '成本价不能超过999999.99').optional().openapi({
- description: '成本价',
- example: 50.00
- }),
- price: z.coerce.number().min(0, '售价不能小于0').max(999999.99, '售价不能超过999999.99').optional().openapi({
- description: '售价',
- example: 99.99
- }),
- num: z.coerce.number().int().min(0, '数量不能小于0').max(99999, '数量不能超过99999').optional().openapi({
- description: '数量',
- example: 2
- }),
- freightAmount: z.coerce.number().min(0, '运费不能小于0').max(999999.99, '运费不能超过999999.99').optional().openapi({
- description: '运费',
- example: 10.00
- }),
- state: z.coerce.number().int().min(0, '状态最小为0').max(1, '状态最大为1').optional().openapi({
- description: '状态(0未发货、1已发货)',
- example: 0
- }),
- expressName: z.string().max(255, '快递名称最多255个字符').nullable().optional().openapi({
- description: '快递名称',
- example: '顺丰快递'
- }),
- expressNo: z.coerce.number().int().positive().nullable().optional().openapi({
- description: '快递单号',
- example: 1234567890
- }),
- imageFileId: z.number().int().positive().nullable().optional().openapi({
- description: '商品图片文件ID',
- example: 1
- })
- });
- // 订单商品状态类型
- export type OrderGoodsStatusType = typeof OrderGoodsStatus[keyof typeof OrderGoodsStatus];
- export type GoodsTypeType = typeof GoodsType[keyof typeof GoodsType];
|