base.js
1.29 KB
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
/*
* @Author: limin
* @Date: 2019-11-21 11:20:01
* @Last Modified by: limin
* @Last Modified time: 2019-12-04 15:53:54
*/
"use strict";
const Controller = require("egg").Controller;
/**
* @Controller base
* @Description 数据大屏-用户
*/
class BaseController extends Controller {
constructor(ctx) {
super(ctx);
this.session = ctx.session;
this.request = ctx.request;
this.BaseService = ctx.service.base;
this.CacheService = ctx.service.cache; //redis 缓存服务
this.ServerResponseCode = ctx.response.ServerResponseCode;
this.ServerResponse = ctx.response.ServerResponse;
}
/**
* @Router GET /base/provinces
* @Description 获取所有省份
*/
async provinces() {
const data = await this.BaseService.provinces();
this.ctx.body = this.ServerResponse.Success({ data });
}
/**
* @Router GET /base/cities
* @Description 通过省份id获取城市
* @Request query integer pid 省份id
*/
async cities_by_pid() {
const nPid = this.request.query.pid;
if(!nPid){
this.ctx.body = this.ServerResponse.Error(null,this.ServerResponseCode.ILLEGAL_ARGUMENT);
return
}
const data = await this.BaseService.cities_by_pid(nPid)
this.ctx.body = this.ServerResponse.Success(data);
}
}
module.exports = BaseController;