common.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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 findbyids() {
  16. const data = await this.service.findbyids(this.ctx.params, this.ctx.request.body);
  17. this.ctx.ok({ data });
  18. }
  19. async findbymodel() {
  20. const data = await this.service.findmodel(this.ctx.request.query);
  21. this.ctx.ok({ data });
  22. }
  23. async findyear() {
  24. const url = 'http://v.juhe.cn/calendar/year?key=ed73fa73956ff995bad705d664002595&year=' + this.ctx.query.year;
  25. const res = await this.ctx.curl(url, {
  26. method: 'get',
  27. headers: {
  28. 'content-type': 'application/json',
  29. },
  30. dataType: 'json',
  31. });
  32. const result = res.data.result.data;
  33. const data = JSON.parse(JSON.stringify(result));
  34. this.ctx.ok({ data });
  35. }
  36. }
  37. module.exports = CommonController;