main #22

Merged
longbot merged 2 commits from zhuotianyuan/API:main into main 2025-10-10 07:33:31 +00:00
3 changed files with 53 additions and 3 deletions
Showing only changes of commit 9df0ea233a - Show all commits

View File

@ -249,6 +249,16 @@ export class Order {
@Expose() @Expose()
utm_source: string; utm_source: string;
@ApiProperty()
@Column({ default: '' })
@Expose()
is_exchange: string;
@ApiProperty()
@Column({ default: '' })
@Expose()
exchange_frequency: string;
@ApiProperty({ @ApiProperty({
example: '2022-12-12 11:11:11', example: '2022-12-12 11:11:11',
description: '创建时间', description: '创建时间',

View File

@ -77,3 +77,6 @@ export class OrderSaleOriginal {
@Expose() @Expose()
updatedAt?: Date; updatedAt?: Date;
} }

View File

@ -5,6 +5,7 @@ import { In, Like, Repository } from 'typeorm';
import { InjectEntityModel, TypeORMDataSourceManager } from '@midwayjs/typeorm'; import { InjectEntityModel, TypeORMDataSourceManager } from '@midwayjs/typeorm';
import { plainToClass } from 'class-transformer'; import { plainToClass } from 'class-transformer';
import { OrderItem } from '../entity/order_item.entity'; import { OrderItem } from '../entity/order_item.entity';
import { OrderItemOriginal } from '../entity/order_items_original.entity';
import { OrderSale } from '../entity/order_sale.entity'; import { OrderSale } from '../entity/order_sale.entity';
import { WpProduct } from '../entity/wp_product.entity'; import { WpProduct } from '../entity/wp_product.entity';
import { Product } from '../entity/product.entty'; import { Product } from '../entity/product.entty';
@ -51,6 +52,9 @@ export class OrderService {
@InjectEntityModel(OrderItem) @InjectEntityModel(OrderItem)
orderItemModel: Repository<OrderItem>; orderItemModel: Repository<OrderItem>;
@InjectEntityModel(OrderItem)
orderItemOriginalModel: Repository<OrderItemOriginal>;
@InjectEntityModel(OrderSale) @InjectEntityModel(OrderSale)
orderSaleModel: Repository<OrderSale>; orderSaleModel: Repository<OrderSale>;
@ -209,7 +213,7 @@ export class OrderService {
el => el.key === '_wc_order_attribution_utm_source' el => el.key === '_wc_order_attribution_utm_source'
)?.value || ''; )?.value || '';
order.customer_email = order?.billing?.email || order?.shipping?.email; order.customer_email = order?.billing?.email || order?.shipping?.email;
order.billing_phone = order?.billing?.phone || order?.shipping?.phone; order.billing_phone = order?.billing?.phone || order?.shipping?.phone;
const entity = plainToClass(Order, order); const entity = plainToClass(Order, order);
const existingOrder = await this.orderModel.findOne({ const existingOrder = await this.orderModel.findOne({
where: { externalOrderId: order.externalOrderId, siteId: siteId }, where: { externalOrderId: order.externalOrderId, siteId: siteId },
@ -323,6 +327,28 @@ export class OrderService {
} }
} }
async saveOrderItemsG(orderItem: OrderItem) {
const existingOrderItem = await this.orderItemModel.findOne({
where: {
externalOrderId: orderItem.externalOrderId,
siteId: orderItem.siteId,
externalOrderItemId: orderItem.externalOrderItemId,
},
});
if (
existingOrderItem &&
existingOrderItem.quantity === orderItem.quantity
) {
return;
}
if (existingOrderItem) {
await this.orderItemModel.update(existingOrderItem.id, orderItem);
} else {
await this.orderItemModel.save(orderItem);
}
}
async saveOrderSale(orderItem: OrderItem) { async saveOrderSale(orderItem: OrderItem) {
const currentOrderSale = await this.orderSaleModel.find({ const currentOrderSale = await this.orderSaleModel.find({
where: { where: {
@ -565,7 +591,7 @@ export class OrderService {
o.total as total, o.total as total,
o.date_created as date_created, o.date_created as date_created,
o.customer_email as customer_email, o.customer_email as customer_email,
o.billing_phone as billing_phone,
o.transaction_id as transaction_id, o.transaction_id as transaction_id,
o.orderStatus as orderStatus, o.orderStatus as orderStatus,
o.customer_ip_address as customer_ip_address, o.customer_ip_address as customer_ip_address,
@ -1116,7 +1142,6 @@ export class OrderService {
} }
// update order_sale_origin if not exist // update order_sale_origin if not exist
try { try {
const order_sale_origin_count = await this.orderSaleOriginalModel.countBy({ orderId: id }); const order_sale_origin_count = await this.orderSaleOriginalModel.countBy({ orderId: id });
if (order_sale_origin_count === 0) { if (order_sale_origin_count === 0) {
@ -1126,6 +1151,15 @@ export class OrderService {
}); });
} }
// update order_item_origin if not exist
const order_item_origin_count = await this.orderItemOriginalModel.countBy({ orderId: id });
if (order_item_origin_count === 0 && items.length!=0) {
items.forEach(async sale => {
const { id: saleId, ...saleData } = sale;
await this.orderItemOriginalModel.save(saleData);
});
}
} catch (error) { } catch (error) {
console.log('create order sale origin error: ', error.message); console.log('create order sale origin error: ', error.message);
} }
@ -1342,6 +1376,9 @@ export class OrderService {
// externalOrderItemId: // externalOrderItemId:
}); });
}; };
//await orderRepo.save();
}).catch(error => { }).catch(error => {
transactionError = error; transactionError = error;
}); });