333
schangxiang@126.com
2025-09-19 18966e02fb573c7e2bb0c6426ed792b38b910940
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import BaseService from "../baseService";
import { PurchaseOrder } from "../../entity/inbound/purchase/purchaseOrder";
import { In, Not } from "typeorm";
import moment = require("moment");
import { BaseProductInfo } from "../../entity/basicInfo/base/baseProductInfo";
// import { BaseProductPosition } from "../../entity/storage/product/baseProductPosition";
 
/**
 * 预到货单Service
 */
export default class OrderService extends BaseService {
  //#region Stop
  public async stop() {
    let orderList = await this.dbRead.find(PurchaseOrder, {
      order_Id: In(this.body.idValues)
    });
    for (let orderInfo of orderList) {
      await this.ctx.service.inbound.orderHelper.setStatusHistory(orderInfo.order_Id, orderInfo.statusText, "终止", "单据状态", "订单终止");
      await this.dbRead.update(PurchaseOrder, orderInfo.order_Id, {
        statusID: 9,
        statusText: "终止",
        auditing: 0,
        auditor: null,
        auditDate: null
      });
    }
    this.info.result = true;
    this.info.msg = "终止成功!";
 
    return this.info;
  }
  //#endregion
 
  //#region Open
  public async open() {
    let orderList = await this.dbRead.find(PurchaseOrder, {
      order_Id: In(this.body.idValues)
    });
    for (let orderInfo of orderList) {
      if (orderInfo.statusText != "终止") {
        this.info.result = false;
        this.info.msg = "只有状态为终止, 才能开启!";
        this.ctx.body = this.info;
        return this.info;
      }
      await this.ctx.service.inbound.orderHelper.setStatusHistory(orderInfo.order_Id, orderInfo.statusText, "开启", "单据状态", "订单开启");
      await this.dbRead.update(PurchaseOrder, orderInfo.order_Id, {
        statusID: 1,
        statusText: "新建",
        auditing: 0,
        auditor: null,
        auditDate: null
      });
    }
 
    this.info.result = true;
    this.info.msg = "开启成功!";
 
    return this.info;
  }
  //#endregion
 
  //#region onCopyBefore 复制前事件
  public async onCopyBefore(dataInfo: PurchaseOrder) {
    if (dataInfo.arrivedDate) {
      dataInfo.arrivedDate = moment(dataInfo.arrivedDate).toDate();
    }
    dataInfo.auditing = 0;
    dataInfo.statusID = 1;
    dataInfo.statusText = "新建";
    for (let detailInfo of dataInfo.purchaseOrderList) {
      detailInfo.enterQuantity = 0;
      detailInfo.returnQuantity = 0;
      detailInfo.orderList_Id = 0;
      detailInfo.singleSignCode = this.ctx.service.common.getGUID(); // 重新给唯一码
    }
 
    this.info.result = true;
    this.info.msg = "处理完毕";
 
    return this.info;
  }
  //#endregion
 
  /**
   * 添加保存前事件
   */
  public async onAddSaveBefore(t: PurchaseOrder) {
    // let userInfo = await this.userInfo;
 
    this.info.result = true;
    // EU箱入库自动生成EU箱号
    if (!t.order_Id && t.orderType === "EU箱入库") {
      let code = await this.ctx.service.common.getCodeRegular(251001);
      t.plateCode = code;
    }
    let where = {
      poCode: t.poCode
    };
    // 编辑时排除自己
    if (t.order_Id) {
      where["order_Id"] = Not(t.order_Id);
    }
    let plateCodeNo = await this.dbRead.find(PurchaseOrder, where);
    if (plateCodeNo.length > 0) {
      this.info.result = false;
      this.info.msg = `采购单号${t.poCode}已创建,不可重复创建!`;
      return this.info;
    }
 
    // 更新明细图片
    for (let detail of t["Purchase_OrderList"]) {
      let prodInfo = await this.dbRead.findOne(BaseProductInfo, detail.product_Id);
      if (prodInfo) {
        detail.images = prodInfo.images;
      }
    }
    return this.info;
  }
}