222
schangxiang@126.com
2025-06-13 6a8393408d8cefcea02b7a598967de8dc1e565c2
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
import BaseController from "../../baseController";
import { Post } from "egg-shell-decorators";
import * as mssql from "mssql";
import { vSaleOuterCase } from "../../../entity/outbound/stat/vSaleOuterCase";
import { SaleOrder } from "../../../entity/outbound/sale/saleOrder";
 
/**
 * 装箱单统计
 */
export default class vSaleOuterSaseController extends BaseController {
  // #region 获取装箱快递单号
  @Post()
  public async getExpresss() {
    let { ctx } = this;
    let userInfo = await this.userInfo;
    let body = ctx.request.body;
    let userProduct_Id = userInfo.userProduct_Id;
    let caseNumbers = body.caseNumbers;
    if (!Array.isArray(caseNumbers) || !caseNumbers.length) {
      this.info.msg = "装箱单号不能为空";
      this.info.result = false;
      this.ctx.body = this.info;
      return;
    }
 
    try {
      const connection: any = await this.dbWrite.connection;
      for (let caseNumber of caseNumbers) {
        // 出库单装箱拆分第一个箱的快递单号沿用出库单获取的快递单号
        let caseInfo = await this.dbRead.findOne(vSaleOuterCase, {
          userProduct_Id: userInfo.userProduct_Id,
          caseNumber: caseNumber
        });
        if (caseNumber.indexOf("-01") >= 0) {
          let orderInfo = await this.dbRead.findOne(SaleOrder, {
            userProduct_Id: userInfo.userProduct_Id,
            orderCode: caseInfo.orderCode
          });
          let sql = `Update Sale_OuterList Set extendField10=@0 From Sale_Outer INNER JOIN Sale_OuterList ON Sale_Outer.Outer_Id=Sale_OuterList.Outer_Id 
            Where Sale_Outer.Order_Id=@1 And Sale_OuterList.CaseNumber=@2;`;
          await this.dbWrite.query(sql, [
            orderInfo.expressCode, // 0
            orderInfo.order_Id, // 1
            caseNumber // 2
          ]);
          continue;
        }
        if (caseInfo.expressCorpType === 10) {
          // 10-中通快递
          let request = new mssql.Request(connection.driver.master);
          request.input("caseNumber", caseNumber);
          request.input("userProduct_Id", userProduct_Id);
          request.output("ZTOrder_Id", mssql.Int);
          request.output("outMsg", mssql.NVarChar(2000));
          let result = await request.execute("sp_ExpressZT_Order_Case");
          let outMsg = result.output.outMsg;
          if (outMsg) {
            this.info.msg = outMsg;
            this.info.result = false;
            this.ctx.body = this.info;
            return;
          }
        } else if (caseInfo.expressCorpType === 6) {
          // 6 - 申通快递;
          let request = new mssql.Request(connection.driver.master);
          request.input("caseNumber", caseNumber);
          request.input("userProduct_Id", userProduct_Id);
          request.output("outMsg", mssql.NVarChar(2000));
          let result = await request.execute("sp_ExpressST_Order_Case");
          let outMsg = result.output.outMsg;
          if (outMsg) {
            this.info.msg = outMsg;
            this.info.result = false;
            this.ctx.body = this.info;
            return;
          }
        }
      }
 
      this.info.msg = "获取快递单号成功";
      this.info.result = true;
      ctx.body = this.info;
    } catch (error) {
      this.info.result = false;
      this.info.msg = error.message;
      ctx.body = this.info;
    }
  }
 
  // #endregion
}