dashboard_controller.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. 'use strict';
  2. /**
  3. * 控制面板
  4. *
  5. * @author CaiAoLin
  6. * @date 2017/11/23
  7. * @version
  8. */
  9. const auditConst = require('../const/audit');
  10. module.exports = app => {
  11. class DashboardController extends app.BaseController {
  12. /**
  13. * 控制面板页面
  14. *
  15. * @param {Object} ctx - egg全局变量
  16. * @return {void}
  17. */
  18. async index(ctx) {
  19. const auditTenders = await ctx.service.ledgerAudit.getAuditTender(ctx.session.sessionUser.accountId);
  20. const auditStages = await ctx.service.stageAudit.getAuditStage(ctx.session.sessionUser.accountId);
  21. const auditChanges = await ctx.service.changeAudit.getAuditChange(ctx.session.sessionUser.accountId);
  22. const projectAccountInfo = await ctx.service.projectAccount.getDataById(ctx.session.sessionUser.accountId);
  23. const pa = await ctx.service.projectAccount.getDataById(ctx.session.sessionUser.accountId);
  24. const lastNotice = pa.last_notice ? pa.last_notice : (pa.last_notice === 0 ? new Date() : new Date(pa.last_login * 1000));
  25. const noticeLedger = await ctx.service.ledgerAudit.getNoticeTender(ctx.session.sessionProject.id, pa.id, lastNotice);
  26. const noticeStage = await ctx.service.stageAudit.getNoticeStage(ctx.session.sessionProject.id, pa.id, lastNotice);
  27. const noticeChange = await ctx.service.changeAudit.getNoticeChange(ctx.session.sessionProject.id, pa.id, lastNotice);
  28. const renderData = {
  29. auditTenders,
  30. auditStages,
  31. auditChanges,
  32. role: projectAccountInfo.role,
  33. acLedger: auditConst.ledger,
  34. acStage: auditConst.stage,
  35. acChange: auditConst.flow,
  36. noticeLedger,
  37. noticeStage,
  38. noticeChange,
  39. };
  40. await this.layout('dashboard/index.ejs', renderData);
  41. await ctx.service.projectAccount.defaultUpdate({
  42. id: this.ctx.session.sessionUser.accountId,
  43. last_notice: new Date(),
  44. });
  45. }
  46. }
  47. return DashboardController;
  48. };