| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- import { z } from '@hono/zod-openapi';
- import { GoodsSchema } from '@/server/modules/goods/goods.schema';
- // 随机商品列表查询参数Schema
- export const RandomGoodsQuerySchema = z.object({
- limit: z.coerce.number().int().positive().min(1).max(50).default(10).openapi({
- description: '返回商品数量限制',
- example: 10
- }),
- categoryId: z.coerce.number().int().positive().optional().openapi({
- description: '指定商品分类ID',
- example: 1
- }),
- includeImages: z.coerce.boolean().default(true).openapi({
- description: '是否包含商品图片',
- example: true
- })
- });
- // 随机商品列表响应Schema
- export const RandomGoodsResponseSchema = z.object({
- data: z.array(GoodsSchema).openapi({
- description: '随机商品列表',
- example: [{
- id: 1,
- name: 'iPhone 15',
- price: 5999.99,
- costPrice: 4999.99,
- salesNum: 100,
- clickNum: 1000,
- categoryId1: 1,
- categoryId2: 2,
- categoryId3: 3,
- goodsType: 1,
- supplierId: 1,
- imageFileId: 1,
- detail: null,
- instructions: '高品质智能手机',
- sort: 0,
- state: 1,
- stock: 100,
- spuId: 0,
- spuName: null,
- lowestBuy: 1,
- createdAt: new Date('2024-01-01T12:00:00Z'),
- updatedAt: new Date('2024-01-01T12:00:00Z'),
- createdBy: 1,
- updatedBy: 1
- }]
- }),
- total: z.number().int().nonnegative().openapi({
- description: '符合条件的商品总数',
- example: 100
- })
- });
- // 类型定义
- export type RandomGoodsQuery = z.infer<typeof RandomGoodsQuerySchema>;
- export type RandomGoodsResponse = z.infer<typeof RandomGoodsResponseSchema>;
|