Compare commits
2 Commits
907228297d
...
817f368522
| Author | SHA1 | Date |
|---|---|---|
|
|
817f368522 | |
|
|
a22e302c4e |
|
|
@ -119,6 +119,15 @@ export default {
|
||||||
description: 'Bearer Auth',
|
description: 'Bearer Auth',
|
||||||
addSecurityRequirements: true,
|
addSecurityRequirements: true,
|
||||||
},
|
},
|
||||||
|
// 配置 Swagger 支持嵌套查询参数
|
||||||
|
options: {
|
||||||
|
// 设置查询参数风格为 deepObject
|
||||||
|
// 这会告诉 Swagger 使用 JSON 格式来序列化嵌套的查询参数
|
||||||
|
query: {
|
||||||
|
style: 'deepObject',
|
||||||
|
explode: false
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
mailer: {
|
mailer: {
|
||||||
host: 'smtphz.qiye.163.com',
|
host: 'smtphz.qiye.163.com',
|
||||||
|
|
|
||||||
|
|
@ -37,12 +37,16 @@ export class UnifiedSearchParamsDTO<Where=Record<string, any>> {
|
||||||
@ApiProperty({ description: '搜索关键词', required: false })
|
@ApiProperty({ description: '搜索关键词', required: false })
|
||||||
search?: string;
|
search?: string;
|
||||||
|
|
||||||
@ApiProperty({ description: '过滤条件对象', type: 'object', required: false })
|
@ApiProperty({
|
||||||
|
description: '过滤条件对象',
|
||||||
|
type: 'any', // FIXME 这里是因为 openapit2ts 会将 where 变成 undefined 所以有嵌套对象时先不指定类型
|
||||||
|
required: false,
|
||||||
|
})
|
||||||
where?: Where;
|
where?: Where;
|
||||||
|
|
||||||
@ApiProperty({
|
@ApiProperty({
|
||||||
description: '排序对象,例如 { "sku": "desc" }',
|
description: '排序对象,例如 { "sku": "desc" }',
|
||||||
type: 'object',
|
type: 'any', // FIXME 这里是因为 openapit2ts 会将 where 变成 undefined 所以有嵌套对象时先不指定类型
|
||||||
required: false,
|
required: false,
|
||||||
})
|
})
|
||||||
orderBy?: Record<string, 'asc' | 'desc'> | string;
|
orderBy?: Record<string, 'asc' | 'desc'> | string;
|
||||||
|
|
|
||||||
|
|
@ -303,6 +303,68 @@ export interface ProductWhereFilter {
|
||||||
updatedAtEnd?: string;
|
updatedAtEnd?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 产品查询过滤条件DTO
|
||||||
|
*/
|
||||||
|
export class ProductWhereFilterDTO {
|
||||||
|
@ApiProperty({ description: '产品ID', example: 1 })
|
||||||
|
id?: number;
|
||||||
|
|
||||||
|
@ApiProperty({ description: '产品ID列表', example: [1, 2, 3] })
|
||||||
|
ids?: number[];
|
||||||
|
|
||||||
|
@ApiProperty({ description: 'SKU', example: 'ZYN-6MG-WINTERGREEN' })
|
||||||
|
sku?: string;
|
||||||
|
|
||||||
|
@ApiProperty({ description: 'SKU列表', example: ['ZYN-6MG-WINTERGREEN', 'ZYN-3MG-WINTERGREEN'] })
|
||||||
|
skus?: string[];
|
||||||
|
|
||||||
|
@ApiProperty({ description: '产品名称', example: 'ZYN 6MG WINTERGREEN' })
|
||||||
|
name?: string;
|
||||||
|
|
||||||
|
@ApiProperty({ description: '产品中文名称', example: 'ZYN 6毫克 冬清味' })
|
||||||
|
nameCn?: string;
|
||||||
|
|
||||||
|
@ApiProperty({ description: '分类ID', example: 1 })
|
||||||
|
categoryId?: number;
|
||||||
|
|
||||||
|
@ApiProperty({ description: '分类ID列表', example: [1, 2, 3] })
|
||||||
|
categoryIds?: number[];
|
||||||
|
|
||||||
|
@ApiProperty({ description: '品牌ID', example: 1 })
|
||||||
|
brandId?: number;
|
||||||
|
|
||||||
|
@ApiProperty({ description: '品牌ID列表', example: [1, 2, 3] })
|
||||||
|
brandIds?: number[];
|
||||||
|
|
||||||
|
@ApiProperty({ description: '产品类型', example: 'single', enum: ['single', 'bundle'] })
|
||||||
|
type?: string;
|
||||||
|
|
||||||
|
@ApiProperty({ description: '价格最小值', example: 99.99 })
|
||||||
|
minPrice?: number;
|
||||||
|
|
||||||
|
@ApiProperty({ description: '价格最大值', example: 199.99 })
|
||||||
|
maxPrice?: number;
|
||||||
|
|
||||||
|
@ApiProperty({ description: '促销价格最小值', example: 89.99 })
|
||||||
|
minPromotionPrice?: number;
|
||||||
|
|
||||||
|
@ApiProperty({ description: '促销价格最大值', example: 179.99 })
|
||||||
|
maxPromotionPrice?: number;
|
||||||
|
|
||||||
|
@ApiProperty({ description: '创建时间范围开始', example: '2023-01-01 00:00:00' })
|
||||||
|
createdAtStart?: string;
|
||||||
|
|
||||||
|
@ApiProperty({ description: '创建时间范围结束', example: '2023-12-31 23:59:59' })
|
||||||
|
createdAtEnd?: string;
|
||||||
|
|
||||||
|
@ApiProperty({ description: '更新时间范围开始', example: '2023-01-01 00:00:00' })
|
||||||
|
updatedAtStart?: string;
|
||||||
|
|
||||||
|
@ApiProperty({ description: '更新时间范围结束', example: '2023-12-31 23:59:59' })
|
||||||
|
updatedAtEnd?: string;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DTO 用于分页查询产品
|
* DTO 用于分页查询产品
|
||||||
* 支持灵活的where条件、分页和排序
|
* 支持灵活的where条件、分页和排序
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ export class Product {
|
||||||
@ApiProperty({
|
@ApiProperty({
|
||||||
example: 'ZYN 6MG WINTERGREEN',
|
example: 'ZYN 6MG WINTERGREEN',
|
||||||
description: '产品名称',
|
description: '产品名称',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
required: true,
|
required: true,
|
||||||
})
|
})
|
||||||
@Column()
|
@Column()
|
||||||
|
|
|
||||||
|
|
@ -2461,17 +2461,9 @@ export class OrderService {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 空值检查和数据清理
|
|
||||||
if (!ids || !Array.isArray(ids)) {
|
|
||||||
throw new Error('订单ID列表不能为空');
|
|
||||||
}
|
|
||||||
|
|
||||||
// 过滤掉NaN和非数字值,只保留有效的数字ID
|
// 过滤掉NaN和非数字值,只保留有效的数字ID
|
||||||
const validIds = ids.filter(id => Number.isFinite(id) && id > 0);
|
const validIds = ids?.filter?.(id => Number.isFinite(id) && id > 0);
|
||||||
|
|
||||||
if (validIds.length === 0) {
|
|
||||||
throw new Error('未提供有效的订单ID');
|
|
||||||
}
|
|
||||||
|
|
||||||
const dataSource = this.dataSourceManager.getDataSource('default');
|
const dataSource = this.dataSourceManager.getDataSource('default');
|
||||||
|
|
||||||
|
|
@ -2479,7 +2471,9 @@ export class OrderService {
|
||||||
return await dataSource.transaction(async manager => {
|
return await dataSource.transaction(async manager => {
|
||||||
// 准备查询条件
|
// 准备查询条件
|
||||||
const whereCondition: any = {};
|
const whereCondition: any = {};
|
||||||
whereCondition.id = In(validIds);
|
if(validIds.length > 0){
|
||||||
|
whereCondition.id = In(validIds);
|
||||||
|
}
|
||||||
|
|
||||||
// 获取订单、订单项和物流信息
|
// 获取订单、订单项和物流信息
|
||||||
const orders = await manager.getRepository(Order).find({
|
const orders = await manager.getRepository(Order).find({
|
||||||
|
|
|
||||||
|
|
@ -235,7 +235,6 @@ export class ProductService {
|
||||||
.leftJoinAndSelect('product.attributes', 'attribute')
|
.leftJoinAndSelect('product.attributes', 'attribute')
|
||||||
.leftJoinAndSelect('attribute.dict', 'dict')
|
.leftJoinAndSelect('attribute.dict', 'dict')
|
||||||
.leftJoinAndSelect('product.category', 'category');
|
.leftJoinAndSelect('product.category', 'category');
|
||||||
|
|
||||||
// 处理分页参数(支持新旧两种格式)
|
// 处理分页参数(支持新旧两种格式)
|
||||||
const page = query.page || 1;
|
const page = query.page || 1;
|
||||||
const pageSize = query.per_page || 10;
|
const pageSize = query.per_page || 10;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue