base.js 1.29 KB
/*
 * @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;