12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- 'use strict';
- const _ = require('lodash');
- const Controller = require('egg').Controller;
- const { CrudController } = require('naf-framework-mongoose/lib/controller');
- // 共通方法管理
- class CommonController extends Controller {
- constructor(ctx) {
- super(ctx);
- this.service = this.ctx.service.util;
- }
- async findone() {
- const data = await this.service.findone(this.ctx.params, this.ctx.request.query);
- this.ctx.ok({ data });
- }
- async findbyids() {
- const data = await this.service.findbyids(this.ctx.params, this.ctx.request.body);
- this.ctx.ok({ data });
- }
- async findbymodel() {
- const data = await this.service.findmodel(this.ctx.request.query);
- this.ctx.ok({ data });
- }
- async findyear() {
- const url = 'http://v.juhe.cn/calendar/year?key=ed73fa73956ff995bad705d664002595&year=' + this.ctx.query.year;
- const res = await this.ctx.curl(url, {
- method: 'get',
- headers: {
- 'content-type': 'application/json',
- },
- dataType: 'json',
- });
- const result = res.data.result.data;
- const data = JSON.parse(JSON.stringify(result));
- this.ctx.ok({ data });
- }
- }
- module.exports = CommonController;
|