dashboard.controller.js 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. const dashboardService = require('../service/dashboard.service');
  2. const util = require('../utils/util');
  3. module.exports = {
  4. async getDashBoard(ctx) {
  5. const { total: totalProjects } = await dashboardService.getTotalProjects();
  6. const { total: totalUpdatesProjects } = await dashboardService.getTotalUpdatesByToday();
  7. const { total: totalCreatedProjects } = await dashboardService.getTotalCreatedByToday();
  8. const { total: totalPages } = await dashboardService.getTotalPages();
  9. const { total: createdPages } = await dashboardService.getCreatedPagesByToday();
  10. const { total: updatedPages } = await dashboardService.getUpdatedPagesByToday();
  11. const { total: totalLibs } = await dashboardService.getTotalLibs();
  12. const { total: createdLibs } = await dashboardService.getCreatedLibsByToday();
  13. const { total: updatedLibs } = await dashboardService.getUpdatedLibsByToday();
  14. const { total: totalUsers } = await dashboardService.getTotalUsers();
  15. const { total: totalUsersByToday } = await dashboardService.getTotalUsersByToday();
  16. const { total: loginUsersByToday } = await dashboardService.getLoginUsersByToday();
  17. const res = await dashboardService.getUsersByWeek();
  18. const { total: totalMoney } = await dashboardService.getTotalRecharge();
  19. const { total: todayRecharge } = await dashboardService.getTotalRechargeByToday();
  20. // 页面发布次数
  21. const { total: pagesPublish } = await dashboardService.getPagesPublish();
  22. // 组件发布次数
  23. const { total: libsPublish } = await dashboardService.getLibsPublish();
  24. util.success(ctx, {
  25. totalProjects,
  26. totalUpdatesProjects,
  27. totalCreatedProjects,
  28. totalPages,
  29. createdPages,
  30. updatedPages,
  31. totalLibs,
  32. createdLibs,
  33. updatedLibs,
  34. totalUsers,
  35. totalUsersByToday,
  36. loginUsersByToday,
  37. getUsersByWeek: res,
  38. recharge: {
  39. totalMoney: totalMoney / 100,
  40. todayRecharge: todayRecharge / 100,
  41. },
  42. charts1: [
  43. {
  44. name: '项目总数',
  45. value: totalProjects,
  46. },
  47. {
  48. name: '页面总数',
  49. value: totalPages,
  50. },
  51. {
  52. name: '组件总数',
  53. value: totalLibs,
  54. },
  55. {
  56. name: '用户总数',
  57. value: totalUsers,
  58. },
  59. ],
  60. charts2: [
  61. {
  62. name: '页面发布次数',
  63. value: pagesPublish,
  64. },
  65. {
  66. name: '组件发布次数',
  67. value: libsPublish,
  68. },
  69. ],
  70. });
  71. },
  72. async getUserList(ctx) {
  73. const { pageNum = 1, pageSize = 10, userId } = ctx.request.query;
  74. const { total } = await dashboardService.getUserCount(Number(userId || 0));
  75. if (total == 0) {
  76. return util.success(ctx, {
  77. list: [],
  78. total: 0,
  79. pageSize,
  80. pageNum,
  81. });
  82. }
  83. const list = await dashboardService.getUserList(pageNum, pageSize, Number(userId || 0));
  84. util.success(ctx, {
  85. list,
  86. total,
  87. pageSize: +pageSize,
  88. pageNum: +pageNum,
  89. });
  90. },
  91. };