|
|
@@ -0,0 +1,267 @@
|
|
|
+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
|
|
|
+ }),
|
|
|
+ tenantId: 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().nullable().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' }),
|
|
|
+ userId: z.number().int().positive().openapi({ description: '用户ID' })
|
|
|
+ }).nullable().optional().openapi({
|
|
|
+ description: '订单信息'
|
|
|
+ }),
|
|
|
+ goods: z.object({
|
|
|
+ id: z.number().int().positive().openapi({ description: '商品ID' }),
|
|
|
+ name: z.string().openapi({ description: '商品名称', example: '苹果手机' }),
|
|
|
+ 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: '商品图片文件信息'
|
|
|
+ })
|
|
|
+ }).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({
|
|
|
+ tenantId: z.number().int().positive('租户ID必须是正整数').openapi({
|
|
|
+ description: '租户ID',
|
|
|
+ example: 1
|
|
|
+ }),
|
|
|
+ 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().nullable().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({
|
|
|
+ tenantId: z.number().int().positive('租户ID必须是正整数').optional().openapi({
|
|
|
+ description: '租户ID',
|
|
|
+ example: 1
|
|
|
+ }),
|
|
|
+ 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().nullable().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];
|