Feature: Add shipment item, update in create and delete shipment
This commit is contained in:
parent
cbd5ddc4d2
commit
14913f4db4
|
|
@ -4,9 +4,13 @@ import {
|
||||||
Column,
|
Column,
|
||||||
CreateDateColumn,
|
CreateDateColumn,
|
||||||
Entity,
|
Entity,
|
||||||
|
JoinColumn,
|
||||||
|
ManyToOne,
|
||||||
PrimaryGeneratedColumn,
|
PrimaryGeneratedColumn,
|
||||||
UpdateDateColumn,
|
UpdateDateColumn,
|
||||||
} from 'typeorm';
|
} from 'typeorm';
|
||||||
|
import { Shipment } from './shipment.entity';
|
||||||
|
import { Order } from './order.entity';
|
||||||
|
|
||||||
@Entity('shipment_item')
|
@Entity('shipment_item')
|
||||||
@Exclude()
|
@Exclude()
|
||||||
|
|
@ -17,17 +21,19 @@ export class ShipmentItem {
|
||||||
id: number;
|
id: number;
|
||||||
|
|
||||||
@ApiProperty()
|
@ApiProperty()
|
||||||
@Column()
|
|
||||||
@Expose()
|
@Expose()
|
||||||
shipment_id: string;
|
@ManyToOne(() => Shipment)
|
||||||
|
@JoinColumn({ name: 'shipment_id' })
|
||||||
|
shipment_id: number;
|
||||||
|
|
||||||
@ApiProperty()
|
@ApiProperty()
|
||||||
@Column()
|
|
||||||
@Expose()
|
@Expose()
|
||||||
productId: number;
|
@ManyToOne(() => Order)
|
||||||
|
@JoinColumn({ name: 'order_id' })
|
||||||
|
order_id: number;
|
||||||
|
|
||||||
@ApiProperty()
|
@ApiProperty()
|
||||||
@Column()
|
@Column({ nullable: true })
|
||||||
@Expose()
|
@Expose()
|
||||||
name: string;
|
name: string;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -240,6 +240,7 @@ export class LogisticsService {
|
||||||
order.shipmentId = null;
|
order.shipmentId = null;
|
||||||
orderRepo.save(order);
|
orderRepo.save(order);
|
||||||
|
|
||||||
|
await manager.delete('shipment_item', { shipment_id: shipmentId });
|
||||||
shipmentRepo.remove(shipment);
|
shipmentRepo.remove(shipment);
|
||||||
|
|
||||||
const res = await this.uniExpressService.deleteShipment(shipment.return_tracking_number);
|
const res = await this.uniExpressService.deleteShipment(shipment.return_tracking_number);
|
||||||
|
|
@ -372,6 +373,7 @@ export class LogisticsService {
|
||||||
await dataSource.transaction(async manager => {
|
await dataSource.transaction(async manager => {
|
||||||
const orderRepo = manager.getRepository(Order);
|
const orderRepo = manager.getRepository(Order);
|
||||||
const shipmentRepo = manager.getRepository(Shipment);
|
const shipmentRepo = manager.getRepository(Shipment);
|
||||||
|
const shipmentItemRepo = manager.getRepository(ShipmentItem);
|
||||||
const tracking_provider = 'UniUni'; // todo: id未确定,后写进常数
|
const tracking_provider = 'UniUni'; // todo: id未确定,后写进常数
|
||||||
|
|
||||||
// 同步物流信息到woocommerce
|
// 同步物流信息到woocommerce
|
||||||
|
|
@ -394,6 +396,17 @@ export class LogisticsService {
|
||||||
});
|
});
|
||||||
order.shipmentId = shipment.id;
|
order.shipmentId = shipment.id;
|
||||||
shipmentId = shipment.id;
|
shipmentId = shipment.id;
|
||||||
|
|
||||||
|
// onchange shipment
|
||||||
|
await data.sales.forEach(async (item) => {
|
||||||
|
console.log('item', item)
|
||||||
|
const shipmentItem: ShipmentItem = new ShipmentItem;
|
||||||
|
shipmentItem.sku = item.sku;
|
||||||
|
shipmentItem.quantity = item.quantity;
|
||||||
|
shipmentItem.shipment_id = shipmentId;
|
||||||
|
shipmentItem.order_id = orderId;
|
||||||
|
await shipmentItemRepo.save(shipmentItem);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 同步订单状态到woocommerce
|
// 同步订单状态到woocommerce
|
||||||
|
|
@ -527,9 +540,9 @@ export class LogisticsService {
|
||||||
const orderShipments = await orderShipmentRepo.findBy({
|
const orderShipments = await orderShipmentRepo.findBy({
|
||||||
shipment_id: id,
|
shipment_id: id,
|
||||||
});
|
});
|
||||||
const shipmentItems = await shipmentItemRepo.findBy({ shipment_id: id });
|
const shipmentItems = await shipmentItemRepo.findBy({ shipment_id: Number(id) });
|
||||||
await shipmentRepo.delete({ id });
|
await shipmentRepo.delete({ id });
|
||||||
await shipmentItemRepo.delete({ shipment_id: id });
|
await shipmentItemRepo.delete({ shipment_id: Number(id) });
|
||||||
await orderShipmentRepo.delete({ shipment_id: id });
|
await orderShipmentRepo.delete({ shipment_id: id });
|
||||||
for (const item of shipmentItems) {
|
for (const item of shipmentItems) {
|
||||||
const stock = await stockRepo.findOne({
|
const stock = await stockRepo.findOne({
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue