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
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import { default as BaseController } from "../../baseController";
import { Post } from "egg-shell-decorators";
import { BaseExpressCorp } from "../../../entity/basicInfo/base/baseExpressCorp";
import { SysParamValue } from "../../../entity/sys/core/sysParamValue";
import { TMSPort } from '../../../entity/express/tms/tmsPort';
 
export default class ExpressCorpController extends BaseController {
  //#region 根据快递公司ID获取快递公司信息
  /**
   * 根据快递公司ID获取快递公司信息
   */
  @Post()
  public async getById() {
    let { ctx } = this;
    let body = ctx.body;
    let userInfo = await ctx.helper.userInfo();
    let userProduct_Id = userInfo.userProduct_Id;
    if (!body.id) {
      this.info.result = false;
      this.info.msg = "ID不存在";
      ctx.body = this.info;
      return;
    }
 
    try {
      let dataList = await this.dbRead.find(BaseExpressCorp, {
        select: ["expressCorp_Id", "expressCorpCode", "expressCorpName"],
        where: {
          expressCorp_Id: body.id,
          userProduct_Id: userProduct_Id
        },
        order: {
          expressCorp_Id: "ASC"
        }
      });
 
      this.info.result = true;
      this.info.data = dataList;
    } catch (error) {
      this.info.result = false;
      this.info.data = error.message;
    }
    ctx.body = this.info;
  }
  //#endregion
 
  //#region 获得快递公司列表
  /**
   * 获得快递公司列表
   */
  @Post()
  public async getList() {
    let { ctx } = this;
    let body = ctx.body;
    let userInfo = await ctx.helper.userInfo();
    let userProduct_Id = userInfo.userProduct_Id;
    let where: any = {
      userProduct_Id: userProduct_Id
    };
    if (body.expressCorpType) {
      where.expressCorpType = body.expressCorpType;
    }
 
    try {
      let dataList = await this.dbRead.find(BaseExpressCorp, {
        select: ["expressCorp_Id", "expressCorpCode", "expressCorpName"],
        where: where,
        order: {
          expressCorp_Id: "ASC"
        }
      });
 
      this.info.result = true;
      this.info.data = dataList;
    } catch (error) {
      this.info.result = false;
      this.info.data = error.message;
    }
    ctx.body = this.info;
  }
  //#endregion
 
  //#region getExpressCorpType 获得快递公司类别
  /**
   * 获得快递公司类别
   */
  @Post()
  public async getExpressCorpType() {
    var modelList = await this.dbRead.find(SysParamValue, {
      userProduct_Id: (await this.userInfo).userProduct_Id,
      type_Id: 503,
      enable: 1
    });
    if (modelList.length == 0) {
      modelList = await this.dbRead
        .createQueryBuilder(SysParamValue, "t")
        .where(`type_Id=503 And isnull(userProduct_Id, 0)=0 And enable=1`)
        .getMany();
    }
    if (modelList.length > 0) {
      this.info.result = true;
      this.info.data = modelList.map(item => {
        return {
          value: item.value01,
          name: item.value02
        };
      });
    } else {
      this.info.result = false;
      this.info.msg = "您还没有添加快递信息!";
    }
    this.ctx.body = this.info;
  }
  //#endregion
  /**
   * 运单根据口岸获取关联下拉框类别
   */
  @Post()
  public async getWayBillExpressCorpType() {
    let { ctx } = this;
    let body = ctx.request.body;
    try {
      if (!body.port_Id) {
        this.info.result = false;
        this.info.msg = "请先选择口岸!";
        ctx.body = this.info;
        return;
      }
      //根据口岸ID查询口岸信息
      let dataInfo = await this.dbRead.findOne(TMSPort, {
        port_Id: body.port_Id
      });
      if (dataInfo) {
        if (dataInfo.portExpress) {
          this.info.result = true;
          let portExpress = JSON.parse(dataInfo.portExpress);
          this.info.data = ctx.helper.arrayToCase(portExpress);
          ctx.body = this.info;
          return;
        }
      } else {
        this.info.result = false;
        this.info.msg = "口岸信息不存在!";
        ctx.body = this.info;
        return;
      }
    } catch (ex) {
      let msg = "异常错误信息:" + ex.message;
      this.info.result = false;
      this.info.msg = msg;
      ctx.body = this.info;
      return;
    }
  }
  //#endregion
}