// app/core/base_controller.js const { Controller } = require('egg'); class BaseController extends Controller { get user() { return this.ctx.session.user; } success(data) { this.ctx.status = 200; this.ctx.body = { code: 0, success: true, data, }; } fail(msg) { this.ctx.status = 200; this.ctx.body = { code: 1, success: false, msg, }; } notFound(msg) { msg = msg || 'not found'; this.ctx.throw(404, msg); } } module.exports = BaseController;