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,
|
||||
CreateDateColumn,
|
||||
Entity,
|
||||
JoinColumn,
|
||||
ManyToOne,
|
||||
PrimaryGeneratedColumn,
|
||||
UpdateDateColumn,
|
||||
} from 'typeorm';
|
||||
import { Shipment } from './shipment.entity';
|
||||
import { Order } from './order.entity';
|
||||
|
||||
@Entity('shipment_item')
|
||||
@Exclude()
|
||||
|
|
@ -17,17 +21,19 @@ export class ShipmentItem {
|
|||
id: number;
|
||||
|
||||
@ApiProperty()
|
||||
@Column()
|
||||
@Expose()
|
||||
shipment_id: string;
|
||||
@ManyToOne(() => Shipment)
|
||||
@JoinColumn({ name: 'shipment_id' })
|
||||
shipment_id: number;
|
||||
|
||||
@ApiProperty()
|
||||
@Column()
|
||||
@Expose()
|
||||
productId: number;
|
||||
@ManyToOne(() => Order)
|
||||
@JoinColumn({ name: 'order_id' })
|
||||
order_id: number;
|
||||
|
||||
@ApiProperty()
|
||||
@Column()
|
||||
@Column({ nullable: true })
|
||||
@Expose()
|
||||
name: string;
|
||||
|
||||
|
|
|
|||
|
|
@ -240,6 +240,7 @@ export class LogisticsService {
|
|||
order.shipmentId = null;
|
||||
orderRepo.save(order);
|
||||
|
||||
await manager.delete('shipment_item', { shipment_id: shipmentId });
|
||||
shipmentRepo.remove(shipment);
|
||||
|
||||
const res = await this.uniExpressService.deleteShipment(shipment.return_tracking_number);
|
||||
|
|
@ -372,6 +373,7 @@ export class LogisticsService {
|
|||
await dataSource.transaction(async manager => {
|
||||
const orderRepo = manager.getRepository(Order);
|
||||
const shipmentRepo = manager.getRepository(Shipment);
|
||||
const shipmentItemRepo = manager.getRepository(ShipmentItem);
|
||||
const tracking_provider = 'UniUni'; // todo: id未确定,后写进常数
|
||||
|
||||
// 同步物流信息到woocommerce
|
||||
|
|
@ -394,6 +396,17 @@ export class LogisticsService {
|
|||
});
|
||||
order.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
|
||||
|
|
@ -527,9 +540,9 @@ export class LogisticsService {
|
|||
const orderShipments = await orderShipmentRepo.findBy({
|
||||
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 shipmentItemRepo.delete({ shipment_id: id });
|
||||
await shipmentItemRepo.delete({ shipment_id: Number(id) });
|
||||
await orderShipmentRepo.delete({ shipment_id: id });
|
||||
for (const item of shipmentItems) {
|
||||
const stock = await stockRepo.findOne({
|
||||
|
|
|
|||
Loading…
Reference in New Issue