common.js 923 B

123456789101112131415161718192021222324252627282930313233343536
  1. 'use strict';
  2. const _ = require('lodash');
  3. const Controller = require('egg').Controller;
  4. const { CrudController } = require('naf-framework-mongoose/lib/controller');
  5. // 共通方法管理
  6. class CommonController extends Controller {
  7. constructor(ctx) {
  8. super(ctx);
  9. this.service = this.ctx.service.util;
  10. }
  11. async findone() {
  12. const data = await this.service.findone(this.ctx.params, this.ctx.request.query);
  13. this.ctx.ok({ data });
  14. }
  15. async findyear() {
  16. const url = 'http://v.juhe.cn/calendar/year?key=ed73fa73956ff995bad705d664002595&year=' + this.ctx.query.year;
  17. const res = await this.ctx.curl(url, {
  18. method: 'get',
  19. headers: {
  20. 'content-type': 'application/json',
  21. },
  22. dataType: 'json',
  23. });
  24. const result = res.data.result.data;
  25. const data = JSON.parse(JSON.stringify(result));
  26. this.ctx.ok({ data });
  27. }
  28. }
  29. module.exports = CommonController;