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
import { default as BaseController } from "../../baseController";
import { Post } from "egg-shell-decorators";
import { BaseCity } from "../../../entity/basicInfo/base/baseCity";
 
export default class CityController extends BaseController {
  //#region 根据货主ID获取货主信息
  /**
   * 根据货主ID获取货主信息
   */
  @Post()
  public async getById() {
    let { ctx } = this;
    let body = ctx.body;
    if (!body.id) {
      this.info.result = false;
      this.info.msg = "ID不存在";
      ctx.body = this.info;
      return;
    }
 
    try {
      let dataList = await this.dbRead.find(BaseCity, {
        select: ["city_Id", "cityName", "parentId"],
        where: {
          city_Id: body.city_Id
        }
      });
 
      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 getAll() {
    let { ctx } = this;
 
    try {
      let dataList = await this.dbRead.find(BaseCity, {
        select: ["city_Id", "cityName", "parentId"]
      });
 
      this.info.result = true;
      this.info.data = dataList;
    } catch (error) {
      this.info.result = false;
      this.info.data = error.message;
    }
    ctx.body = this.info;
  }
  //#endregion
}