refactor: 移除废弃的WordPress产品相关代码
清理不再使用的WordPress产品模块代码,包括实体、DTO、服务和控制器 统一使用新的产品模块接口
This commit is contained in:
parent
16cd48e503
commit
677b11c48f
|
|
@ -1,7 +1,6 @@
|
|||
import { MidwayConfig } from '@midwayjs/core';
|
||||
import { join } from 'path';
|
||||
import { Product } from '../entity/product.entity';
|
||||
import { WpProduct } from '../entity/wp_product.entity';
|
||||
import { Variation } from '../entity/variation.entity';
|
||||
import { User } from '../entity/user.entity';
|
||||
import { PurchaseOrder } from '../entity/purchase_order.entity';
|
||||
|
|
@ -53,7 +52,6 @@ export default {
|
|||
Product,
|
||||
ProductStockComponent,
|
||||
ProductSiteSku,
|
||||
WpProduct,
|
||||
Variation,
|
||||
User,
|
||||
PurchaseOrder,
|
||||
|
|
|
|||
|
|
@ -253,21 +253,6 @@ export class ProductController {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
// 获取所有 WordPress 商品
|
||||
@ApiOkResponse({ description: '获取所有 WordPress 商品' })
|
||||
@Get('/wp-products')
|
||||
async getWpProducts() {
|
||||
try {
|
||||
const data = await this.productService.getWpProducts();
|
||||
return successResponse(data);
|
||||
} catch (error) {
|
||||
return errorResponse(error?.message || error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 通用属性接口:分页列表
|
||||
@ApiOkResponse()
|
||||
@Get('/attribute')
|
||||
|
|
|
|||
|
|
@ -1,232 +0,0 @@
|
|||
import {
|
||||
Controller,
|
||||
Param,
|
||||
Post,
|
||||
Inject,
|
||||
Get,
|
||||
Query,
|
||||
Put,
|
||||
Body,
|
||||
Files,
|
||||
Del,
|
||||
} from '@midwayjs/core';
|
||||
import { WpProductService } from '../service/wp_product.service';
|
||||
import { errorResponse, successResponse } from '../utils/response.util';
|
||||
import { ApiOkResponse } from '@midwayjs/swagger';
|
||||
import { BooleanRes, WpProductListRes } from '../dto/reponse.dto';
|
||||
import {
|
||||
QueryWpProductDTO,
|
||||
UpdateVariationDTO,
|
||||
UpdateWpProductDTO,
|
||||
BatchSyncProductsDTO,
|
||||
BatchUpdateTagsDTO,
|
||||
BatchUpdateProductsDTO,
|
||||
} from '../dto/wp_product.dto';
|
||||
|
||||
import {
|
||||
ProductsRes,
|
||||
} from '../dto/reponse.dto';
|
||||
@Controller('/wp_product')
|
||||
export class WpProductController {
|
||||
// 移除控制器内的配置站点引用,统一由服务层处理站点数据
|
||||
|
||||
@Inject()
|
||||
private readonly wpProductService: WpProductService;
|
||||
|
||||
// 平台服务保留按需注入
|
||||
|
||||
@ApiOkResponse({
|
||||
type: BooleanRes,
|
||||
})
|
||||
@Del('/:id')
|
||||
async delete(@Param('id') id: number) {
|
||||
return errorResponse('接口已废弃,请改用 /site-api/:siteId/products 删除');
|
||||
}
|
||||
|
||||
@ApiOkResponse({
|
||||
type: BooleanRes,
|
||||
})
|
||||
@Post('/import/:siteId')
|
||||
async importProducts(@Param('siteId') siteId: number, @Files() files) {
|
||||
try {
|
||||
if (!files || files.length === 0) {
|
||||
throw new Error('请上传文件');
|
||||
}
|
||||
await this.wpProductService.importProducts(siteId, files[0]);
|
||||
return successResponse(true);
|
||||
} catch (error) {
|
||||
console.error('导入失败:', error);
|
||||
return errorResponse(error.message || '导入失败');
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOkResponse({
|
||||
type: BooleanRes,
|
||||
})
|
||||
@Post('/setconstitution')
|
||||
async setConstitution(@Body() body: any) {
|
||||
try {
|
||||
return successResponse(true);
|
||||
} catch (error) {
|
||||
return errorResponse(error.message || '设置失败');
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOkResponse({
|
||||
type: BooleanRes,
|
||||
})
|
||||
@Post('/batch-update')
|
||||
async batchUpdateProducts(@Body() body: BatchUpdateProductsDTO) {
|
||||
try {
|
||||
await this.wpProductService.batchUpdateProducts(body);
|
||||
return successResponse(true);
|
||||
} catch (error) {
|
||||
return errorResponse(error.message || '批量更新失败');
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOkResponse({
|
||||
type: BooleanRes,
|
||||
})
|
||||
@Post('/batch-update-tags')
|
||||
async batchUpdateTags(@Body() body: BatchUpdateTagsDTO) {
|
||||
try {
|
||||
await this.wpProductService.batchUpdateTags(body.ids, body.tags);
|
||||
return successResponse(true);
|
||||
} catch (error) {
|
||||
return errorResponse(error.message || '批量更新标签失败');
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOkResponse({
|
||||
type: BooleanRes,
|
||||
})
|
||||
@Post('/sync/:siteId')
|
||||
async syncProducts(@Param('siteId') siteId: number) {
|
||||
try {
|
||||
const result = await this.wpProductService.syncSite(siteId);
|
||||
return successResponse(result);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
return errorResponse('同步失败');
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOkResponse({
|
||||
type: BooleanRes,
|
||||
})
|
||||
@Post('/batch-sync-to-site/:siteId')
|
||||
async batchSyncToSite(
|
||||
@Param('siteId') siteId: number,
|
||||
@Body() body: BatchSyncProductsDTO
|
||||
) {
|
||||
try {
|
||||
await this.wpProductService.batchSyncToSite(siteId, body.productIds);
|
||||
return successResponse(true, '批量同步成功');
|
||||
} catch (error) {
|
||||
console.error('批量同步失败:', error);
|
||||
return errorResponse(error.message || '批量同步失败');
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOkResponse({
|
||||
type: WpProductListRes,
|
||||
})
|
||||
@Get('/list')
|
||||
async getWpProducts(@Query() query: QueryWpProductDTO) {
|
||||
return errorResponse('接口已废弃,请改用 /site-api/:siteId/products 列表');
|
||||
}
|
||||
|
||||
@ApiOkResponse({
|
||||
type: BooleanRes
|
||||
})
|
||||
@Post('/updateState/:id')
|
||||
async updateWPProductState(
|
||||
@Param('id') id: number,
|
||||
@Body() body: any, // todo
|
||||
) {
|
||||
try {
|
||||
const res = await this.wpProductService.updateProductStatus(id, body?.status, body?.stock_status);
|
||||
return successResponse(res);
|
||||
} catch (error) {
|
||||
return errorResponse(error.message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建产品接口
|
||||
* @param siteId 站点 ID
|
||||
* @param body 创建数据
|
||||
*/
|
||||
@ApiOkResponse({
|
||||
type: BooleanRes,
|
||||
})
|
||||
@Post('/siteId/:siteId/products')
|
||||
async createProduct(
|
||||
@Param('siteId') siteId: number,
|
||||
@Body() body: any
|
||||
) {
|
||||
return errorResponse('接口已废弃,请改用 /site-api/:siteId/products 创建');
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新产品接口
|
||||
* @param productId 产品 ID
|
||||
* @param body 更新数据
|
||||
*/
|
||||
@ApiOkResponse({
|
||||
type: BooleanRes,
|
||||
})
|
||||
@Put('/siteId/:siteId/products/:productId')
|
||||
async updateProduct(
|
||||
@Param('siteId') siteId: number,
|
||||
@Param('productId') productId: string,
|
||||
@Body() body: UpdateWpProductDTO
|
||||
) {
|
||||
return errorResponse('接口已废弃,请改用 /site-api/:siteId/products/:id 更新');
|
||||
}
|
||||
|
||||
@ApiOkResponse({
|
||||
type: BooleanRes,
|
||||
})
|
||||
@Post('/sync-to-product/:id')
|
||||
async syncToProduct(@Param('id') id: number) {
|
||||
try {
|
||||
await this.wpProductService.syncToProduct(id);
|
||||
return successResponse(true);
|
||||
} catch (error) {
|
||||
return errorResponse(error.message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新变体接口
|
||||
* @param productId 产品 ID
|
||||
* @param variationId 变体 ID
|
||||
* @param body 更新数据
|
||||
*/
|
||||
@Put('/siteId/:siteId/products/:productId/variations/:variationId')
|
||||
async updateVariation(
|
||||
@Param('siteId') siteId: number,
|
||||
@Param('productId') productId: string,
|
||||
@Param('variationId') variationId: string,
|
||||
@Body() body: UpdateVariationDTO
|
||||
) {
|
||||
return errorResponse('接口已废弃,请改用 /site-api/:siteId/products/:productId/variations/:variationId 更新');
|
||||
}
|
||||
|
||||
@ApiOkResponse({
|
||||
description: '通过name搜索产品/订单',
|
||||
type: ProductsRes,
|
||||
})
|
||||
@Get('/search')
|
||||
async searchProducts(@Query('name') name: string) {
|
||||
try {
|
||||
// 调用服务获取产品数据
|
||||
const products = await this.wpProductService.findProductsByName(name);
|
||||
return successResponse(products);
|
||||
} catch (error) {
|
||||
return errorResponse(error.message || '获取数据失败');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -60,3 +60,11 @@ export class CustomerDto {
|
|||
state: string;
|
||||
|
||||
}
|
||||
|
||||
export class CustomerListResponseDTO {
|
||||
@ApiProperty()
|
||||
total: number;
|
||||
|
||||
@ApiProperty({ type: [CustomerDto] })
|
||||
list: CustomerDto[];
|
||||
}
|
||||
|
|
@ -11,7 +11,6 @@ import { OrderStatusCountDTO } from './order.dto';
|
|||
import { SiteConfig } from './site.dto';
|
||||
import { PurchaseOrderDTO, StockDTO, StockRecordDTO } from './stock.dto';
|
||||
import { LoginResDTO } from './user.dto';
|
||||
import { WpProductDTO } from './wp_product.dto';
|
||||
import { OrderSale } from '../entity/order_sale.entity';
|
||||
import { Service } from '../entity/service.entity';
|
||||
import { RateDTO } from './freightcom.dto';
|
||||
|
|
@ -77,15 +76,6 @@ export class ProductSizeAllRes extends SuccessArrayWrapper(Dict) {}
|
|||
// 产品尺寸返回数据
|
||||
export class ProductSizeRes extends SuccessWrapper(Dict) {}
|
||||
|
||||
//产品分页数据
|
||||
export class WpProductPaginatedResponse extends PaginatedWrapper(
|
||||
WpProductDTO
|
||||
) {}
|
||||
//产品分页返回数据
|
||||
export class WpProductListRes extends SuccessWrapper(
|
||||
WpProductPaginatedResponse
|
||||
) {}
|
||||
|
||||
export class LoginRes extends SuccessWrapper(LoginResDTO) {}
|
||||
export class StockPaginatedRespone extends PaginatedWrapper(StockDTO) {}
|
||||
export class StockListRes extends SuccessWrapper(StockPaginatedRespone) {}
|
||||
|
|
|
|||
|
|
@ -14,9 +14,6 @@ export class UnifiedPaginationDTO<T> {
|
|||
@ApiProperty({ description: '每页数量', example: 20 })
|
||||
per_page: number;
|
||||
|
||||
@ApiProperty({ description: '每页数量别名', example: 20 })
|
||||
page_size?: number;
|
||||
|
||||
@ApiProperty({ description: '总页数', example: 5 })
|
||||
totalPages: number;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
// WooCommerce 平台原始数据类型定义
|
||||
// 仅包含当前映射逻辑所需字段以保持简洁与类型安全
|
||||
|
||||
import { Variation } from "../entity/variation.entity";
|
||||
|
||||
// 产品类型
|
||||
export interface WooProduct {
|
||||
// 产品主键
|
||||
|
|
@ -124,6 +126,9 @@ export interface WooProduct {
|
|||
// 元数据
|
||||
meta_data?: Array<{ id?: number; key: string; value: any }>;
|
||||
}
|
||||
export interface WooVariation extends Variation{
|
||||
|
||||
}
|
||||
|
||||
// 订单类型
|
||||
export interface WooOrder {
|
||||
|
|
|
|||
|
|
@ -1,136 +0,0 @@
|
|||
import { ApiProperty } from '@midwayjs/swagger';
|
||||
import { Variation } from '../entity/variation.entity';
|
||||
import { WpProduct } from '../entity/wp_product.entity';
|
||||
import { Rule, RuleType } from '@midwayjs/validate';
|
||||
import { ProductStatus } from '../enums/base.enum';
|
||||
|
||||
export class VariationDTO extends Variation {}
|
||||
|
||||
export class WpProductDTO extends WpProduct {
|
||||
@ApiProperty({ description: '变体列表', type: VariationDTO, isArray: true })
|
||||
variations?: VariationDTO[];
|
||||
}
|
||||
|
||||
export class UpdateVariationDTO {
|
||||
@ApiProperty({ description: '产品名称' })
|
||||
@Rule(RuleType.string().optional())
|
||||
name?: string;
|
||||
|
||||
@ApiProperty({ description: 'SKU' })
|
||||
@Rule(RuleType.string().allow('').optional())
|
||||
sku?: string;
|
||||
|
||||
@ApiProperty({ description: '常规价格', type: Number })
|
||||
@Rule(RuleType.number().optional())
|
||||
regular_price?: number; // 常规价格
|
||||
|
||||
@ApiProperty({ description: '销售价格', type: Number })
|
||||
@Rule(RuleType.number().optional())
|
||||
sale_price?: number; // 销售价格
|
||||
|
||||
@ApiProperty({ description: '是否促销中', type: Boolean })
|
||||
@Rule(RuleType.boolean().optional())
|
||||
on_sale?: boolean; // 是否促销中
|
||||
}
|
||||
|
||||
export class UpdateWpProductDTO {
|
||||
@ApiProperty({ description: '变体名称' })
|
||||
@Rule(RuleType.string().optional())
|
||||
name?: string;
|
||||
|
||||
@ApiProperty({ description: 'SKU' })
|
||||
@Rule(RuleType.string().allow('').optional())
|
||||
sku?: string;
|
||||
|
||||
@ApiProperty({ description: '常规价格', type: Number })
|
||||
@Rule(RuleType.number().optional())
|
||||
regular_price?: number; // 常规价格
|
||||
|
||||
@ApiProperty({ description: '销售价格', type: Number })
|
||||
@Rule(RuleType.number().optional())
|
||||
sale_price?: number; // 销售价格
|
||||
|
||||
@ApiProperty({ description: '是否促销中', type: Boolean })
|
||||
@Rule(RuleType.boolean().optional())
|
||||
on_sale?: boolean; // 是否促销中
|
||||
|
||||
@ApiProperty({ description: '分类列表', type: [String] })
|
||||
@Rule(RuleType.array().items(RuleType.string()).optional())
|
||||
categories?: string[];
|
||||
|
||||
@ApiProperty({ description: '标签列表', type: [String] })
|
||||
@Rule(RuleType.array().items(RuleType.string()).optional())
|
||||
tags?: string[];
|
||||
|
||||
@ApiProperty({ description: '站点ID', required: false })
|
||||
@Rule(RuleType.number().optional())
|
||||
siteId?: number;
|
||||
}
|
||||
|
||||
export class QueryWpProductDTO {
|
||||
@ApiProperty({ example: '1', description: '页码' })
|
||||
@Rule(RuleType.number())
|
||||
current: number;
|
||||
|
||||
@ApiProperty({ example: '10', description: '每页大小' })
|
||||
@Rule(RuleType.number())
|
||||
pageSize: number;
|
||||
|
||||
@ApiProperty({ example: 'ZYN', description: '产品名' })
|
||||
@Rule(RuleType.string())
|
||||
name?: string;
|
||||
|
||||
@ApiProperty({ example: '1', description: '站点ID' })
|
||||
@Rule(RuleType.string())
|
||||
siteId?: string;
|
||||
|
||||
@ApiProperty({ description: '产品状态', enum: ProductStatus })
|
||||
@Rule(RuleType.string().valid(...Object.values(ProductStatus)))
|
||||
status?: ProductStatus;
|
||||
|
||||
@ApiProperty({ description: 'SKU列表', type: Array })
|
||||
@Rule(RuleType.array().items(RuleType.string()).single())
|
||||
skus?: string[];
|
||||
}
|
||||
|
||||
export class BatchSyncProductsDTO {
|
||||
@ApiProperty({ description: '产品ID列表', type: [Number] })
|
||||
@Rule(RuleType.array().items(RuleType.number()).required())
|
||||
productIds: number[];
|
||||
}
|
||||
|
||||
export class BatchUpdateTagsDTO {
|
||||
@ApiProperty({ description: '产品ID列表', type: [Number] })
|
||||
@Rule(RuleType.array().items(RuleType.number()).required())
|
||||
ids: number[];
|
||||
|
||||
@ApiProperty({ description: '标签列表', type: [String] })
|
||||
@Rule(RuleType.array().items(RuleType.string()).required())
|
||||
tags: string[];
|
||||
}
|
||||
|
||||
export class BatchUpdateProductsDTO {
|
||||
@ApiProperty({ description: '产品ID列表', type: [Number] })
|
||||
@Rule(RuleType.array().items(RuleType.number()).required())
|
||||
ids: number[];
|
||||
|
||||
@ApiProperty({ description: '常规价格', type: Number })
|
||||
@Rule(RuleType.number())
|
||||
regular_price?: number;
|
||||
|
||||
@ApiProperty({ description: '销售价格', type: Number })
|
||||
@Rule(RuleType.number())
|
||||
sale_price?: number;
|
||||
|
||||
@ApiProperty({ description: '分类列表', type: [String] })
|
||||
@Rule(RuleType.array().items(RuleType.string()))
|
||||
categories?: string[];
|
||||
|
||||
@ApiProperty({ description: '标签列表', type: [String] })
|
||||
@Rule(RuleType.array().items(RuleType.string()))
|
||||
tags?: string[];
|
||||
|
||||
@ApiProperty({ description: '状态', enum: ProductStatus })
|
||||
@Rule(RuleType.string().valid(...Object.values(ProductStatus)))
|
||||
status?: ProductStatus;
|
||||
}
|
||||
|
|
@ -16,7 +16,7 @@ import { ProductStockComponent } from './product_stock_component.entity';
|
|||
import { ProductSiteSku } from './product_site_sku.entity';
|
||||
import { Category } from './category.entity';
|
||||
|
||||
@Entity()
|
||||
@Entity('product_v2')
|
||||
export class Product {
|
||||
@ApiProperty({
|
||||
example: '1',
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import { Repository } from 'typeorm';
|
|||
import { CustomerTag } from '../entity/customer_tag.entity';
|
||||
import { Customer } from '../entity/customer.entity';
|
||||
import { SiteApiService } from './site-api.service';
|
||||
import { UnifiedCustomerDTO, UnifiedSearchParamsDTO } from '../dto/site-api.dto';
|
||||
import { UnifiedCustomerDTO, UnifiedPaginationDTO, UnifiedSearchParamsDTO } from '../dto/site-api.dto';
|
||||
import { SyncOperationResult, BatchErrorItem } from '../dto/batch.dto';
|
||||
|
||||
@Provide()
|
||||
|
|
@ -332,7 +332,7 @@ export class CustomerService {
|
|||
* 支持基本的分页、搜索和排序功能
|
||||
* 使用TypeORM查询构建器实现
|
||||
*/
|
||||
async getCustomerList(param: Record<string, any>): Promise<any>{
|
||||
async getCustomerList(param: Record<string, any>): Promise<UnifiedPaginationDTO<any>>{
|
||||
const {
|
||||
current = 1,
|
||||
pageSize = 10,
|
||||
|
|
@ -427,8 +427,9 @@ export class CustomerService {
|
|||
return {
|
||||
items: processedItems,
|
||||
total,
|
||||
current,
|
||||
pageSize,
|
||||
page: current,
|
||||
per_page: pageSize,
|
||||
totalPages: Math.ceil(total / pageSize),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ import { plainToClass } from 'class-transformer';
|
|||
import { OrderItem } from '../entity/order_item.entity';
|
||||
|
||||
import { OrderSale } from '../entity/order_sale.entity';
|
||||
import { WpProduct } from '../entity/wp_product.entity';
|
||||
import { Product } from '../entity/product.entity';
|
||||
import { OrderFee } from '../entity/order_fee.entity';
|
||||
import { OrderRefund } from '../entity/order_refund.entity';
|
||||
|
|
@ -57,10 +56,6 @@ export class OrderService {
|
|||
@InjectEntityModel(OrderSale)
|
||||
orderSaleModel: Repository<OrderSale>;
|
||||
|
||||
|
||||
@InjectEntityModel(WpProduct)
|
||||
wpProductModel: Repository<WpProduct>;
|
||||
|
||||
@InjectEntityModel(Variation)
|
||||
variationModel: Repository<Variation>;
|
||||
|
||||
|
|
@ -1618,86 +1613,84 @@ export class OrderService {
|
|||
//换货确认按钮改成调用这个方法
|
||||
//换货功能更新OrderSale和Orderitem数据
|
||||
async updateExchangeOrder(orderId: number, data: any) {
|
||||
try {
|
||||
const dataSource = this.dataSourceManager.getDataSource('default');
|
||||
let transactionError = undefined;
|
||||
throw new Error('暂未实现')
|
||||
// try {
|
||||
// const dataSource = this.dataSourceManager.getDataSource('default');
|
||||
// let transactionError = undefined;
|
||||
|
||||
await dataSource.transaction(async manager => {
|
||||
const orderRepo = manager.getRepository(Order);
|
||||
const orderSaleRepo = manager.getRepository(OrderSale);
|
||||
const orderItemRepo = manager.getRepository(OrderItem);
|
||||
// await dataSource.transaction(async manager => {
|
||||
// const orderRepo = manager.getRepository(Order);
|
||||
// const orderSaleRepo = manager.getRepository(OrderSale);
|
||||
// const orderItemRepo = manager.getRepository(OrderItem);
|
||||
|
||||
|
||||
const productRepo = manager.getRepository(Product);
|
||||
const WpProductRepo = manager.getRepository(WpProduct);
|
||||
// const productRepo = manager.getRepository(ProductV2);
|
||||
|
||||
const order = await orderRepo.findOneBy({ id: orderId });
|
||||
let product: Product;
|
||||
let wpProduct: WpProduct;
|
||||
// const order = await orderRepo.findOneBy({ id: orderId });
|
||||
// let product: ProductV2;
|
||||
|
||||
await orderSaleRepo.delete({ orderId });
|
||||
await orderItemRepo.delete({ orderId });
|
||||
for (const sale of data['sales']) {
|
||||
product = await productRepo.findOneBy({ sku: sale['sku'] });
|
||||
await orderSaleRepo.save({
|
||||
orderId,
|
||||
siteId: order.siteId,
|
||||
productId: product.id,
|
||||
name: product.name,
|
||||
sku: sale['sku'],
|
||||
quantity: sale['quantity'],
|
||||
});
|
||||
};
|
||||
// await orderSaleRepo.delete({ orderId });
|
||||
// await orderItemRepo.delete({ orderId });
|
||||
// for (const sale of data['sales']) {
|
||||
// product = await productRepo.findOneBy({ sku: sale['sku'] });
|
||||
// await orderSaleRepo.save({
|
||||
// orderId,
|
||||
// siteId: order.siteId,
|
||||
// productId: product.id,
|
||||
// name: product.name,
|
||||
// sku: sale['sku'],
|
||||
// quantity: sale['quantity'],
|
||||
// });
|
||||
// };
|
||||
|
||||
for (const item of data['items']) {
|
||||
wpProduct = await WpProductRepo.findOneBy({ sku: item['sku'] });
|
||||
// for (const item of data['items']) {
|
||||
// product = await productRepo.findOneBy({ sku: item['sku'] });
|
||||
|
||||
// await orderItemRepo.save({
|
||||
// orderId,
|
||||
// siteId: order.siteId,
|
||||
// productId: product.id,
|
||||
// name: product.name,
|
||||
// externalOrderId: order.externalOrderId,
|
||||
// externalProductId: product.externalProductId,
|
||||
|
||||
await orderItemRepo.save({
|
||||
orderId,
|
||||
siteId: order.siteId,
|
||||
productId: wpProduct.id,
|
||||
name: wpProduct.name,
|
||||
externalOrderId: order.externalOrderId,
|
||||
externalProductId: wpProduct.externalProductId,
|
||||
// sku: item['sku'],
|
||||
// quantity: item['quantity'],
|
||||
// });
|
||||
|
||||
sku: item['sku'],
|
||||
quantity: item['quantity'],
|
||||
});
|
||||
// };
|
||||
|
||||
};
|
||||
// //将是否换货状态改为true
|
||||
// await orderRepo.update(
|
||||
// order.id
|
||||
// , {
|
||||
// is_exchange: true
|
||||
// });
|
||||
|
||||
//将是否换货状态改为true
|
||||
await orderRepo.update(
|
||||
order.id
|
||||
, {
|
||||
is_exchange: true
|
||||
});
|
||||
// //查询这个用户换过多少次货
|
||||
// const counts = await orderRepo.countBy({
|
||||
// is_editable: true,
|
||||
// customer_email: order.customer_email,
|
||||
// });
|
||||
|
||||
//查询这个用户换过多少次货
|
||||
const counts = await orderRepo.countBy({
|
||||
is_editable: true,
|
||||
customer_email: order.customer_email,
|
||||
});
|
||||
// //批量更新当前用户换货次数
|
||||
// await orderRepo.update({
|
||||
// customer_email: order.customer_email
|
||||
// }, {
|
||||
// exchange_frequency: counts
|
||||
// });
|
||||
|
||||
//批量更新当前用户换货次数
|
||||
await orderRepo.update({
|
||||
customer_email: order.customer_email
|
||||
}, {
|
||||
exchange_frequency: counts
|
||||
});
|
||||
// }).catch(error => {
|
||||
// transactionError = error;
|
||||
// });
|
||||
|
||||
}).catch(error => {
|
||||
transactionError = error;
|
||||
});
|
||||
|
||||
if (transactionError !== undefined) {
|
||||
throw new Error(`更新物流信息错误:${transactionError.message}`);
|
||||
}
|
||||
return true;
|
||||
} catch (error) {
|
||||
throw new Error(`更新发货产品失败:${error.message}`);
|
||||
}
|
||||
// if (transactionError !== undefined) {
|
||||
// throw new Error(`更新物流信息错误:${transactionError.message}`);
|
||||
// }
|
||||
// return true;
|
||||
// } catch (error) {
|
||||
// throw new Error(`更新发货产品失败:${error.message}`);
|
||||
// }
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ import {
|
|||
SizePaginatedResponse,
|
||||
} from '../dto/reponse.dto';
|
||||
import { InjectEntityModel } from '@midwayjs/typeorm';
|
||||
import { WpProduct } from '../entity/wp_product.entity';
|
||||
import { Variation } from '../entity/variation.entity';
|
||||
import { Dict } from '../entity/dict.entity';
|
||||
import { DictItem } from '../entity/dict_item.entity';
|
||||
|
|
@ -53,9 +52,6 @@ export class ProductService {
|
|||
@InjectEntityModel(DictItem)
|
||||
dictItemModel: Repository<DictItem>;
|
||||
|
||||
@InjectEntityModel(WpProduct)
|
||||
wpProductModel: Repository<WpProduct>;
|
||||
|
||||
@InjectEntityModel(Variation)
|
||||
variationModel: Repository<Variation>;
|
||||
|
||||
|
|
@ -74,11 +70,6 @@ export class ProductService {
|
|||
@InjectEntityModel(Category)
|
||||
categoryModel: Repository<Category>;
|
||||
|
||||
|
||||
// 获取所有 WordPress 商品
|
||||
async getWpProducts() {
|
||||
return this.wpProductModel.find();
|
||||
}
|
||||
// 获取所有分类
|
||||
async getCategoriesAll(): Promise<Category[]> {
|
||||
return this.categoryModel.find({
|
||||
|
|
|
|||
|
|
@ -5,14 +5,13 @@
|
|||
import { Inject, Provide } from '@midwayjs/core';
|
||||
import axios, { AxiosRequestConfig } from 'axios';
|
||||
import WooCommerceRestApi, { WooCommerceRestApiVersion } from '@woocommerce/woocommerce-rest-api';
|
||||
import { WpProduct } from '../entity/wp_product.entity';
|
||||
import { Variation } from '../entity/variation.entity';
|
||||
import { UpdateVariationDTO, UpdateWpProductDTO } from '../dto/wp_product.dto';
|
||||
import { SiteService } from './site.service';
|
||||
import { IPlatformService } from '../interface/platform.interface';
|
||||
import { BatchOperationDTO, BatchOperationResultDTO } from '../dto/batch.dto';
|
||||
import * as FormData from 'form-data';
|
||||
import * as fs from 'fs';
|
||||
import { WooProduct, WooVariation } from '../dto/woocommerce.dto';
|
||||
const MAX_PAGE_SIZE = 100;
|
||||
@Provide()
|
||||
export class WPService implements IPlatformService {
|
||||
|
|
@ -244,7 +243,7 @@ export class WPService implements IPlatformService {
|
|||
|
||||
async getProducts(site: any, page: number = 1, pageSize: number = 100): Promise<any> {
|
||||
const api = this.createApi(site, 'wc/v3');
|
||||
return await this.sdkGetPage<WpProduct>(api, 'products', { page, per_page: pageSize });
|
||||
return await this.sdkGetPage<WooProduct>(api, 'products', { page, per_page: pageSize });
|
||||
}
|
||||
|
||||
async getProduct(site: any, id: number): Promise<any> {
|
||||
|
|
@ -393,7 +392,7 @@ export class WPService implements IPlatformService {
|
|||
async updateProduct(
|
||||
site: any,
|
||||
productId: string,
|
||||
data: UpdateWpProductDTO
|
||||
data: WooProduct
|
||||
): Promise<any> {
|
||||
const { regular_price, sale_price, ...params } = data;
|
||||
const api = this.createApi(site, 'wc/v3');
|
||||
|
|
@ -510,7 +509,7 @@ export class WPService implements IPlatformService {
|
|||
site: any,
|
||||
productId: string,
|
||||
variationId: string,
|
||||
data: Partial<UpdateVariationDTO>
|
||||
data: Partial<WooVariation & any>
|
||||
): Promise<boolean> {
|
||||
const { regular_price, sale_price, ...params } = data;
|
||||
const api = this.createApi(site, 'wc/v3');
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -1 +1 @@
|
|||
{"root":["./src/configuration.ts","./src/interface.ts","./src/config/config.default.ts","./src/config/config.local.ts","./src/config/config.unittest.ts","./src/controller/api.controller.ts","./src/controller/area.controller.ts","./src/controller/customer.controller.ts","./src/controller/dict.controller.ts","./src/controller/locale.controller.ts","./src/controller/logistics.controller.ts","./src/controller/order.controller.ts","./src/controller/product.controller.ts","./src/controller/site.controller.ts","./src/controller/statistics.controller.ts","./src/controller/stock.controller.ts","./src/controller/subscription.controller.ts","./src/controller/template.controller.ts","./src/controller/user.controller.ts","./src/controller/webhook.controller.ts","./src/controller/wp_product.controller.ts","./src/db/datasource.ts","./src/db/migrations/1764238434984-product-dict-item-many-to-many.ts","./src/db/migrations/1764294088896-area.ts","./src/db/migrations/1764299629279-productstock.ts","./src/db/seeds/area.seeder.ts","./src/db/seeds/dict.seeder.ts","./src/db/seeds/template.seeder.ts","./src/decorator/user.decorator.ts","./src/dto/area.dto.ts","./src/dto/customer.dto.ts","./src/dto/dict.dto.ts","./src/dto/freightcom.dto.ts","./src/dto/logistics.dto.ts","./src/dto/order.dto.ts","./src/dto/product.dto.ts","./src/dto/reponse.dto.ts","./src/dto/site.dto.ts","./src/dto/statistics.dto.ts","./src/dto/stock.dto.ts","./src/dto/subscription.dto.ts","./src/dto/template.dto.ts","./src/dto/user.dto.ts","./src/dto/wp_product.dto.ts","./src/entity/area.entity.ts","./src/entity/auth_code.ts","./src/entity/customer.entity.ts","./src/entity/customer_tag.entity.ts","./src/entity/device_whitelist.ts","./src/entity/dict.entity.ts","./src/entity/dict_item.entity.ts","./src/entity/order.entity.ts","./src/entity/order_coupon.entity.ts","./src/entity/order_fee.entity.ts","./src/entity/order_item.entity.ts","./src/entity/order_item_original.entity.ts","./src/entity/order_items_original.entity.ts","./src/entity/order_note.entity.ts","./src/entity/order_refund.entity.ts","./src/entity/order_refund_item.entity.ts","./src/entity/order_sale.entity.ts","./src/entity/order_shipment.entity.ts","./src/entity/order_shipping.entity.ts","./src/entity/product.entity.ts","./src/entity/product_stock_component.entity.ts","./src/entity/purchase_order.entity.ts","./src/entity/purchase_order_item.entity.ts","./src/entity/service.entity.ts","./src/entity/shipment.entity.ts","./src/entity/shipment_item.entity.ts","./src/entity/shipping_address.entity.ts","./src/entity/site.entity.ts","./src/entity/stock.entity.ts","./src/entity/stock_point.entity.ts","./src/entity/stock_record.entity.ts","./src/entity/subscription.entity.ts","./src/entity/template.entity.ts","./src/entity/transfer.entity.ts","./src/entity/transfer_item.entity.ts","./src/entity/user.entity.ts","./src/entity/variation.entity.ts","./src/entity/wp_product.entity.ts","./src/enums/base.enum.ts","./src/filter/default.filter.ts","./src/filter/notfound.filter.ts","./src/job/sync_products.job.ts","./src/job/sync_shipment.job.ts","./src/middleware/auth.middleware.ts","./src/middleware/report.middleware.ts","./src/service/area.service.ts","./src/service/authcode.service.ts","./src/service/canadapost.service.ts","./src/service/customer.service.ts","./src/service/devicewhitelist.service.ts","./src/service/dict.service.ts","./src/service/freightcom.service.ts","./src/service/logistics.service.ts","./src/service/mail.service.ts","./src/service/order.service.ts","./src/service/product.service.ts","./src/service/site.service.ts","./src/service/statistics.service.ts","./src/service/stock.service.ts","./src/service/subscription.service.ts","./src/service/template.service.ts","./src/service/uni_express.service.ts","./src/service/user.service.ts","./src/service/wp.service.ts","./src/service/wp_product.service.ts","./src/utils/helper.util.ts","./src/utils/object-transform.util.ts","./src/utils/paginate.util.ts","./src/utils/paginated-response.util.ts","./src/utils/response-wrapper.util.ts","./src/utils/response.util.ts"],"version":"5.9.3"}
|
||||
{"root":["./src/configuration.ts","./src/interface.ts","./src/config/config.default.ts","./src/config/config.local.ts","./src/config/config.unittest.ts","./src/controller/api.controller.ts","./src/controller/area.controller.ts","./src/controller/customer.controller.ts","./src/controller/dict.controller.ts","./src/controller/locale.controller.ts","./src/controller/logistics.controller.ts","./src/controller/order.controller.ts","./src/controller/product.controller.ts","./src/controller/site.controller.ts","./src/controller/statistics.controller.ts","./src/controller/stock.controller.ts","./src/controller/subscription.controller.ts","./src/controller/template.controller.ts","./src/controller/user.controller.ts","./src/controller/webhook.controller.ts","./src/controller/wp_product.controller.ts","./src/db/datasource.ts","./src/db/migrations/1764238434984-product-dict-item-many-to-many.ts","./src/db/migrations/1764294088896-area.ts","./src/db/migrations/1764299629279-productstock.ts","./src/db/seeds/area.seeder.ts","./src/db/seeds/dict.seeder.ts","./src/db/seeds/template.seeder.ts","./src/decorator/user.decorator.ts","./src/dto/area.dto.ts","./src/dto/customer.dto.ts","./src/dto/dict.dto.ts","./src/dto/freightcom.dto.ts","./src/dto/logistics.dto.ts","./src/dto/order.dto.ts","./src/dto/product.dto.ts","./src/dto/reponse.dto.ts","./src/dto/site.dto.ts","./src/dto/statistics.dto.ts","./src/dto/stock.dto.ts","./src/dto/subscription.dto.ts","./src/dto/template.dto.ts","./src/dto/user.dto.ts","./src/dto/wp_product.dto.ts","./src/entity/area.entity.ts","./src/entity/auth_code.ts","./src/entity/customer.entity.ts","./src/entity/customer_tag.entity.ts","./src/entity/device_whitelist.ts","./src/entity/dict.entity.ts","./src/entity/dict_item.entity.ts","./src/entity/order.entity.ts","./src/entity/order_coupon.entity.ts","./src/entity/order_fee.entity.ts","./src/entity/order_item.entity.ts","./src/entity/order_item_original.entity.ts","./src/entity/order_items_original.entity.ts","./src/entity/order_note.entity.ts","./src/entity/order_refund.entity.ts","./src/entity/order_refund_item.entity.ts","./src/entity/order_sale.entity.ts","./src/entity/order_shipment.entity.ts","./src/entity/order_shipping.entity.ts","./src/entity/product.ts","./src/entity/product_stock_component.entity.ts","./src/entity/purchase_order.entity.ts","./src/entity/purchase_order_item.entity.ts","./src/entity/service.entity.ts","./src/entity/shipment.entity.ts","./src/entity/shipment_item.entity.ts","./src/entity/shipping_address.entity.ts","./src/entity/site.entity.ts","./src/entity/stock.entity.ts","./src/entity/stock_point.entity.ts","./src/entity/stock_record.entity.ts","./src/entity/subscription.entity.ts","./src/entity/template.entity.ts","./src/entity/transfer.entity.ts","./src/entity/transfer_item.entity.ts","./src/entity/user.entity.ts","./src/entity/variation.entity.ts","./src/entity/wp_product.ts","./src/enums/base.enum.ts","./src/filter/default.filter.ts","./src/filter/notfound.filter.ts","./src/job/sync_products.job.ts","./src/job/sync_shipment.job.ts","./src/middleware/auth.middleware.ts","./src/middleware/report.middleware.ts","./src/service/area.service.ts","./src/service/authcode.service.ts","./src/service/canadapost.service.ts","./src/service/customer.service.ts","./src/service/devicewhitelist.service.ts","./src/service/dict.service.ts","./src/service/freightcom.service.ts","./src/service/logistics.service.ts","./src/service/mail.service.ts","./src/service/order.service.ts","./src/service/product.service.ts","./src/service/site.service.ts","./src/service/statistics.service.ts","./src/service/stock.service.ts","./src/service/subscription.service.ts","./src/service/template.service.ts","./src/service/uni_express.service.ts","./src/service/user.service.ts","./src/service/wp.service.ts","./src/service/wp_product.service.ts","./src/utils/helper.util.ts","./src/utils/object-transform.util.ts","./src/utils/paginate.util.ts","./src/utils/paginated-response.util.ts","./src/utils/response-wrapper.util.ts","./src/utils/response.util.ts"],"version":"5.9.3"}
|
||||
Loading…
Reference in New Issue