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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import { default as BaseController } from "../../baseController";
import { Post } from "egg-shell-decorators";
import { AppAddress } from "../../../entity/crm/app/appAddress";
export default class AppAddressController extends BaseController {
  //#region 获得货主地址列表
  /**
   * 获得货主地址列表
   */
  @Post()
  public async getList() {
    let { ctx } = this;
    let userInfo = await ctx.helper.userInfo();
    let body = ctx.request.body;
    try {
      let dataList = await this.dbRead.find(AppAddress, {
        userProduct_Id: userInfo.userProduct_Id,
        user_Id: body.user_Id
      });
      if (!dataList) {
        this.info.result = false;
        this.info.msg = "数据不存在";
        ctx.body = this.info;
        return;
      }
      this.info.result = true;
      this.info.data = dataList;
      ctx.body = this.info;
      this.info.msg = "获取成功";
    } catch (error) {
      this.info.result = false;
      this.info.msg = "数据获取失败" + error.message;
      this.info.data = error.message;
    }
    ctx.body = this.info;
  }
  //#endregion
 
  //#region 货主地址修改
  /**
   *地址修改
   */
  @Post()
  public async updateAddress() {
    let { ctx } = this;
    let userInfo = await ctx.helper.userInfo();
    let body = ctx.request.body;
 
    try {
      let dataList = await this.dbRead.find(AppAddress, {
        userProduct_Id: userInfo.userProduct_Id,
        address_Id: body.address_Id
      });
 
      this.info.result = true;
      this.info.data = dataList;
      await this.dbWrite.update(
        AppAddress,
        {
          address_Id: body.address_Id
        },
        {
          // 修改地址
          consignee: body.consignee, // 收货人名称
          mobile: body.mobile, // 手机号
          isDefault: body.isDefault, //
          detailAddress: body.detailAddress,
          provinceName: body.provinceName,
          cityName: body.cityName,
          regionName: body.regionName
        }
      );
      this.info.result = true;
      this.info.msg = "修改成功";
      ctx.body = this.info;
    } catch (error) {
      this.info.result = false;
      this.info.msg = "修改失败" + error.message;
      this.info.data = error.message;
    }
    ctx.body = this.info;
  }
  //#endregion
 
  //#region 新建货主地址
  /**
   *新建地址
   */
  @Post()
  public async saveAddress() {
    let { ctx } = this;
    // let userInfo = await ctx.helper.userInfo();
    try {
      // 保存数据
      let dataInfo = this.body;
      dataInfo.isDefault = dataInfo.isDefault ? 1 : 0;
      dataInfo.user_Id = 1; // 暂时使用超级管理员
      dataInfo.userTrueName = "超级管理员";
 
      // 设置账套数据
      await this.setAccountInfo(dataInfo);
      await this.dbWrite.save(AppAddress, dataInfo);
      if (dataInfo.isDefault === 1) {
        let sql = `Update App_Address set isDefault=0 where address_Id!='${dataInfo.address_Id}'`;
        await this.dbWrite.query(sql);
      }
 
      this.info.result = true;
      this.info.msg = "保存成功";
      ctx.body = this.info;
    } catch (error) {
      this.info.result = false;
      this.info.msg = "新建失败" + error.message;
    }
    ctx.body = this.info;
  }
  //#endregion
 
  //#region 货主地址删除
  /**
   *删除地址
   */
  @Post()
  public async deleteAddress() {
    let { ctx } = this;
    let body = ctx.request.body;
    try {
      await this.dbWrite.delete(AppAddress, {
        address_Id: body.address_Id
      });
      this.info.result = true;
      this.info.msg = "已删除";
      ctx.body = this.info;
    } catch (error) {
      this.info.result = false;
      this.info.msg = "删除失败:" + error.message;
    }
    ctx.body = this.info;
  }
  //#endregion
 
  //#region 获得单条地址
  /**
   *获得单条地址
   */
  @Post()
  public async getAddress() {
    let { ctx } = this;
    try {
      let dataInfo = await this.dbRead.findOne(AppAddress, {
        address_Id: this.body.address_Id
      });
      this.info.result = true;
      this.info.data = dataInfo;
 
      ctx.body = this.info;
    } catch (error) {
      this.info.result = false;
      this.info.msg = "获取失败:" + error.message;
    }
    ctx.body = this.info;
  }
  //#endregion
}