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
import BaseController from "../baseController";
import { Post } from "egg-shell-decorators";
import { TMSFreightPrice } from "../../entity/express/tms/tmsFreightPrice";
import { BaseConsignor } from "../../entity/basicInfo/consignor/baseConsignor";
 
/**
 * 运费价格设置
 */
export default class FreightPriceController extends BaseController {
  //#region getFreightPriceList 获取运费模板中的数据
  /// <summary>
  /// 获取运费模板中的数据
  /// </summary>
  /// <returns></returns>
  @Post()
  public async getFreightPriceList() {
    try {
      var model = await this.dbRead.find(TMSFreightPrice, {
        userProduct_Id: (await this.userInfo).userProduct_Id,
        port_Id: this.body.port_Id
      });
      if (model != null) {
        this.info.result = true;
        this.info.data = model;
      }
    } catch (e) {
      this.info.result = false;
      this.info.msg = e.message;
    }
    this.ctx.body = this.info;
  }
  //#endregion
 
  //#region saveTemplateSettingList 保存运费模板设置
  @Post()
  public async saveTemplateSettingList() {
    if (!this.body.port_Id) {
      this.info.result = false;
      this.info.msg = "口岸不能为空";
      this.ctx.body = this.info;
      return;
    }
    for (var item of this.body.dataList) {
      let conInfo = await this.dbRead.findOne(BaseConsignor, {
        consignor_Id: this.body.consignor_Id
      });
      if (conInfo != null) {
        item.creator = conInfo.consignorName;
        item.createID = conInfo.consignor_Id;
      }
      let model = await this.dbRead.findOne(TMSFreightPrice, {
        expressCorp_Id: item.expressCorp_Id,
        port_Id: item.port_Id
      });
      if (!model) {
        let fre = new TMSFreightPrice();
        fre.expressCorp_Id = item.expressCorp_Id;
        fre.expressCorpName = item.expressCorpName;
        fre.port_Id = item.port_Id;
        fre.portName = item.portName;
        fre.feeRate = item.feeRate;
        fre.unit = item.unit;
        fre.unit_Id = item.unit_Id;
        fre.remark = item.remark;
        fre.createID = item.createID;
        fre.creator = item.creator;
        await this.setAccountInfo(fre);
        fre.enable = item.enable;
        fre.createDate = new Date();
        await this.dbWrite.save(fre);
      } else {
        model.expressCorp_Id = item.expressCorp_Id;
        model.expressCorpName = item.expressCorpName;
        model.port_Id = item.port_Id;
        model.portName = item.portName;
        model.feeRate = item.feeRate;
        model.unit = item.unit;
        model.unit_Id = item.unit_Id;
        model.remark = item.remark;
        model.createID = item.createID;
        model.creator = item.creator;
        await this.setAccountInfo(model);
        model.enable = item.enable;
        await this.dbWrite.save(model);
      }
    }
    this.info.result = true;
    this.info.msg = "保存成功";
    this.ctx.body = this.info;
  }
  //#endregion
}