schangxiang@126.com
2025-09-09 3d8966ba2c81e7e0365c8b123e861d18ee4f94f5
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
import { default as BaseController } from "../baseController";
import { Post } from "egg-shell-decorators";
import { PurchaseReturn } from "../../entity/inbound/purchase/purchaseReturn";
import { PurchaseReturnList } from "../../entity/inbound/purchase/purchaseReturnList";
// const sortingInstanceName = "SortingInstance_StorageCheck";
export default class ReturnController extends BaseController {
  //#region 复制单据
  @Post()
  public async copySaleOrder() {
    let { ctx } = this;
    let body = ctx.request.body;
    let return_Id = body.return_Id;
    let returnCode = await ctx.service.common.getCodeRegular(104); //得到自动编号
    try {
      let returninfo = await this.dbRead.findOne(PurchaseReturn, {
        return_Id: return_Id
      });
      let returnNew = new PurchaseReturn();
      returnNew = { ...returninfo };
      returnNew.return_Id = 0;
      returnNew.returnCode = returnCode;
      returnNew.sortingStatus = 1;
      returnNew.sortingDate = null;
      returnNew.statusID = 1;
      returnNew.statusText = "新建";
      returnNew.auditing = 0;
      returnNew.auditor = "";
      returnNew.auditDate = null;
 
      await this.dbWrite.insert(PurchaseReturn, returnNew);
      //如果订单主表新增成功,在复制明细
      if (returnNew.return_Id > 0) {
        let saleQuotationList = await this.dbRead.find(PurchaseReturnList, {
          return_Id: return_Id
        });
        for (let detail of saleQuotationList) {
          let detailNew = new PurchaseReturnList();
          detailNew = { ...detail };
          detailNew.orderList_Id = 0;
          detailNew.return_Id = returnNew.return_Id;
          await this.dbWrite.insert(PurchaseReturnList, detailNew);
        }
 
        this.info.msg = "复制成功!";
        this.info.result = true;
      } else {
        this.info.msg = "错误信息:复制失败!";
        this.info.result = false;
        //info.Data = 0;
      }
    } catch (ex) {
      this.info.result = false;
      this.info.msg = "错误信息:" + ex.message;
    }
 
    ctx.body = this.info;
  }
 
  //#endregion
}