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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import { Post } from "egg-shell-decorators";
import BaseController from "../baseController";
import { In } from "typeorm";
import { TMSWayBill } from "../../entity/express/tms/tmsWayBill";
import { TMSDistribution } from "../../entity/tms/biz/tmsDistribution";
import { TMSDistributionDetail } from "../../entity/tms/biz/tmsDistributionDetail";
import { BaseDriver } from "../../entity/tms/base/baseDriver";
import { BaseVehicle } from "../../entity/tms/base/baseVehicle";
/**
 * 配送任务
 */
export default class BillDistributionController extends BaseController {
  /**
   * 司机车辆信息
   */
  @Post()
  public async distributionbill() {
    let { ctx } = this;
    let userInfo = await ctx.helper.userInfo();
    try {
      let driverDataList = await this.dbRead.find(BaseDriver, {
        userProduct_Id: userInfo.userProduct_Id
      });
      if (!driverDataList) {
        this.info.result = false;
        this.info.msg = "数据不存在";
        ctx.body = this.info;
        return;
      }
 
      let vehicleDataList = await this.dbRead.find(BaseVehicle, {
        userProduct_Id: userInfo.userProduct_Id
      });
      if (!vehicleDataList) {
        this.info.result = false;
        this.info.msg = "数据不存在";
        ctx.body = this.info;
        return;
      }
      this.info.result = true;
      this.info.data = { driverDataList, vehicleDataList };
      ctx.body = this.info;
    } catch (error) {
      let msg = "异常错误信息:" + error.message;
      this.info.result = false;
      this.info.msg = msg;
      ctx.body = this.info;
    }
  }
 
  /**
   * 生成配送单
   */
  @Post()
  public async generateBill() {
    let { ctx } = this;
    let body = ctx.request.body;
    let userInfo = await ctx.helper.userInfo(); // 权限
    let formdata = body.formData;
    try {
      // 校验数据
      if (!formdata) {
        this.info.result = false;
        this.info.msg = "数据不存在";
        ctx.body = this.info;
        return;
      }
      //  修改运单状态
      await this.dbWrite.update(
        TMSWayBill,
        {
          wayBill_Id: In(body.wayBill_Ids)
        },
        {
          orderStatus: "配送中"
        }
      );
      // 获取选中的运单
      const tmsList = await this.dbRead.find(TMSWayBill, {
        where: {
          userProduct_Id: userInfo.userProduct_Id,
          wayBill_Id: In(body.wayBill_Ids)
        }
      });
      let data = new TMSDistribution();
      data.distributionCode = await this.ctx.service.common.getCodeRegular(1802);
      data.truckNo = formdata.truckNo;
      data.vehicleType = formdata.vehicleType;
      data.carrierName = formdata.carrierName;
      data.driverName = formdata.driverName;
      data.tel = formdata.tel;
      data.totalQuantity = formdata.totalQuantity;
      data.totalWeight = formdata.totalWeight;
      data.totalVolume = formdata.totalVolume;
      data.totalNumber = formdata.totalNumber;
      data.type = "配送单";
      data.stats = "待接单";
      // 设置账套信息
      await this.setAccountInfo(data);
      await this.dbWrite.insert(TMSDistribution, data);
 
      // 配送派车单
      for (let item of tmsList) {
        let detail = new TMSDistributionDetail();
        detail.distribution_Id = data.distribution_Id;
        detail.wayBillCode = item.wayBillCode;
        detail.stats = item.orderStatus;
        detail.outStation = item.outStation;
        detail.arriveStation = item.arriveStation;
        detail.distributionSite = item.siteName;
        detail.distributionAddress = item.siteAddress;
        detail.consigneeName = item.consigneeName;
        detail.consigneeMobileTwo = item.consigneeMobileTwo;
        detail.consigneeAddress = item.consigneeAddress;
        detail.distributionRoute = item.distributionRoute;
        detail.totalQuantity = item.totalQuantity;
        detail.totalWeight = item.totalWeight;
        detail.requirement = item.requirement;
        detail.billingName = item.billingName;
        detail.billingMobile = item.billingMobile;
        detail.billingAddress = item.billingAddress;
        detail.take = item.take;
        detail.degrees = item.degrees;
        detail.generate = item.generate;
        detail.createDate = item.createDate;
        detail.creator = item.creator;
        await this.dbWrite.insert(TMSDistributionDetail, detail);
      }
 
      this.info.msg = "生成成功!";
      this.info.result = true;
      ctx.body = this.info;
    } catch (ex) {
      let msg = "异常错误信息:" + ex.message;
      this.info.result = false;
      this.info.msg = msg;
      ctx.body = this.info;
    }
  }
  //#endregion
}