280 lines
5.3 KiB
TypeScript
280 lines
5.3 KiB
TypeScript
import { ApiProperty } from '@midwayjs/swagger';
|
|
import {
|
|
BeforeInsert,
|
|
BeforeUpdate,
|
|
Column,
|
|
CreateDateColumn,
|
|
Entity,
|
|
PrimaryGeneratedColumn,
|
|
UpdateDateColumn,
|
|
OneToOne,
|
|
JoinColumn
|
|
} from 'typeorm';
|
|
import { ErpOrderStatus, OrderStatus } from '../enums/base.enum';
|
|
import { OrderAddress } from '../dto/order.dto';
|
|
import { Exclude, Expose } from 'class-transformer';
|
|
import { Shipment } from './shipment.entity';
|
|
|
|
@Entity('order')
|
|
@Exclude()
|
|
export class Order {
|
|
@ApiProperty()
|
|
@PrimaryGeneratedColumn()
|
|
@Expose()
|
|
id: number;
|
|
|
|
@ApiProperty()
|
|
@Column()
|
|
@Expose()
|
|
siteId: string; // 来源站点唯一标识
|
|
|
|
@ApiProperty()
|
|
@Column()
|
|
@Expose()
|
|
externalOrderId: string; // WooCommerce 订单 ID
|
|
|
|
@ApiProperty({ type: OrderStatus })
|
|
@Column({ type: 'enum', enum: OrderStatus })
|
|
@Expose()
|
|
status: OrderStatus; // WooCommerce 订单 状态
|
|
|
|
@ApiProperty({ type: ErpOrderStatus })
|
|
@Column({
|
|
type: 'enum',
|
|
enum: ErpOrderStatus,
|
|
default: ErpOrderStatus.PENDING,
|
|
})
|
|
@Expose()
|
|
orderStatus: ErpOrderStatus; // 订单状态
|
|
|
|
@ApiProperty()
|
|
@Column({ name: 'shipment_id', nullable: true })
|
|
@Expose()
|
|
shipmentId: number;
|
|
|
|
@OneToOne(() => Shipment)
|
|
@JoinColumn({ name: 'shipment_id' })
|
|
shipment: Shipment;
|
|
|
|
@ApiProperty()
|
|
@Column()
|
|
@Expose()
|
|
currency: string;
|
|
|
|
@ApiProperty()
|
|
@Column()
|
|
@Expose()
|
|
currency_symbol: string;
|
|
|
|
@ApiProperty()
|
|
@Column({ default: false })
|
|
@Expose()
|
|
prices_include_tax: boolean;
|
|
|
|
@ApiProperty()
|
|
@Column({ type: 'timestamp', nullable: true })
|
|
@Expose()
|
|
date_created: Date;
|
|
|
|
@ApiProperty()
|
|
@Column({ type: 'timestamp', nullable: true })
|
|
@Expose()
|
|
date_modified: Date;
|
|
|
|
@ApiProperty()
|
|
@Column('decimal', { precision: 10, scale: 2, default: 0 })
|
|
@Expose()
|
|
discount_total: number;
|
|
|
|
@ApiProperty()
|
|
@Column('decimal', { precision: 10, scale: 2, default: 0 })
|
|
@Expose()
|
|
discount_tax: number;
|
|
|
|
@ApiProperty()
|
|
@Column('decimal', { precision: 10, scale: 2, default: 0 })
|
|
@Expose()
|
|
shipping_total: number;
|
|
|
|
@ApiProperty()
|
|
@Column('decimal', { precision: 10, scale: 2, default: 0 })
|
|
@Expose()
|
|
shipping_tax: number;
|
|
|
|
@ApiProperty()
|
|
@Column('decimal', { precision: 10, scale: 2, default: 0 })
|
|
@Expose()
|
|
cart_tax: number;
|
|
|
|
@ApiProperty()
|
|
@Column('decimal', { precision: 10, scale: 2, default: 0 })
|
|
@Expose()
|
|
total: number;
|
|
|
|
@ApiProperty()
|
|
@Column('decimal', { precision: 10, scale: 2, default: 0 })
|
|
@Expose()
|
|
total_tax: number;
|
|
|
|
@ApiProperty()
|
|
@Column({ default: 0 })
|
|
@Expose()
|
|
customer_id: number;
|
|
|
|
@ApiProperty()
|
|
@Column()
|
|
@Expose()
|
|
customer_email: string;
|
|
|
|
@ApiProperty()
|
|
@Column({ default: '' })
|
|
@Expose()
|
|
order_key: string;
|
|
|
|
@ApiProperty({ type: OrderAddress })
|
|
@Column({ type: 'json', nullable: true })
|
|
@Expose()
|
|
billing: OrderAddress;
|
|
|
|
@ApiProperty({ type: OrderAddress })
|
|
@Column({ type: 'json', nullable: true })
|
|
@Expose()
|
|
shipping: OrderAddress;
|
|
|
|
@ApiProperty()
|
|
@Column({ default: '' })
|
|
@Expose()
|
|
payment_method: string;
|
|
|
|
@ApiProperty()
|
|
@Column({ default: '' })
|
|
@Expose()
|
|
payment_method_title: string;
|
|
|
|
@ApiProperty()
|
|
@Column({ default: '' })
|
|
@Expose()
|
|
transaction_id: string;
|
|
|
|
@ApiProperty()
|
|
@Column({ default: '' })
|
|
@Expose()
|
|
customer_ip_address: string;
|
|
|
|
@ApiProperty()
|
|
@Column({
|
|
type: 'varchar',
|
|
length: 1024,
|
|
nullable: true,
|
|
})
|
|
@Expose()
|
|
customer_user_agent: string;
|
|
|
|
@ApiProperty()
|
|
@Column({ default: '' })
|
|
@Expose()
|
|
created_via: string;
|
|
|
|
@ApiProperty()
|
|
@Column({
|
|
type: 'mediumtext', // 设置字段类型为 MEDIUMTEXT
|
|
nullable: true, // 可选:是否允许为 NULL
|
|
})
|
|
@Expose()
|
|
customer_note: string;
|
|
|
|
@ApiProperty()
|
|
@Column({ type: 'timestamp', nullable: true })
|
|
@Expose()
|
|
date_completed: Date;
|
|
|
|
@ApiProperty()
|
|
@Column({ type: 'timestamp', nullable: true })
|
|
@Expose()
|
|
date_paid: Date;
|
|
|
|
@ApiProperty()
|
|
@Column({ default: '' })
|
|
@Expose()
|
|
cart_hash: string;
|
|
|
|
@ApiProperty()
|
|
@Column({ default: '' })
|
|
@Expose()
|
|
number: string;
|
|
|
|
@ApiProperty()
|
|
@Column({ type: 'json', nullable: true })
|
|
@Expose()
|
|
meta_data: any[];
|
|
|
|
@ApiProperty()
|
|
@Column({ default: '' })
|
|
@Expose()
|
|
payment_url: string;
|
|
|
|
@ApiProperty()
|
|
@Column({ default: false })
|
|
@Expose()
|
|
is_editable: boolean;
|
|
|
|
@ApiProperty()
|
|
@Column({ default: false })
|
|
@Expose()
|
|
needs_payment: boolean;
|
|
|
|
@ApiProperty()
|
|
@Column({ default: false })
|
|
@Expose()
|
|
needs_processing: boolean;
|
|
|
|
@ApiProperty()
|
|
@Column({ default: '' })
|
|
@Expose()
|
|
device_type: string;
|
|
|
|
@ApiProperty()
|
|
@Column({ default: '' })
|
|
@Expose()
|
|
source_type: string;
|
|
|
|
@ApiProperty()
|
|
@Column({ default: '' })
|
|
@Expose()
|
|
utm_source: string;
|
|
|
|
@ApiProperty({
|
|
example: '2022-12-12 11:11:11',
|
|
description: '创建时间',
|
|
required: true,
|
|
})
|
|
@CreateDateColumn()
|
|
@Expose()
|
|
createdAt: Date;
|
|
|
|
@ApiProperty({
|
|
example: '2022-12-12 11:11:11',
|
|
description: '更新时间',
|
|
required: true,
|
|
})
|
|
@UpdateDateColumn()
|
|
@Expose()
|
|
updatedAt: Date;
|
|
|
|
// 在插入或更新前处理用户代理字符串
|
|
@BeforeInsert()
|
|
@BeforeUpdate()
|
|
truncateUserAgent() {
|
|
const maxLength = 1024; // 根据数据库限制的实际长度
|
|
if (
|
|
this.customer_user_agent &&
|
|
this.customer_user_agent.length > maxLength
|
|
) {
|
|
this.customer_user_agent = this.customer_user_agent.substring(
|
|
0,
|
|
maxLength
|
|
);
|
|
}
|
|
}
|
|
}
|