MainController.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2013-2019 http://www.thinkcmf.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: 小夏 < 449134904@qq.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\admin\controller;
  12. use app\activity\model\ActivityModel;
  13. use app\activity\model\ActivitySiteModel;
  14. use app\admin\model\UserModel;
  15. use app\business\model\BusinessJoinModel;
  16. use app\business\model\BusinessModel;
  17. use cmf\controller\AdminBaseController;
  18. use think\Db;
  19. class MainController extends AdminBaseController
  20. {
  21. /**
  22. * 后台欢迎页
  23. */
  24. public function index()
  25. {
  26. $dashboardWidgets = [];
  27. $widgets = cmf_get_option('admin_dashboard_widgets');
  28. $defaultDashboardWidgets = [
  29. '_SystemCmfHub' => ['name' => 'CmfHub', 'is_system' => 1],
  30. '_SystemCmfDocuments' => ['name' => 'CmfDocuments', 'is_system' => 1],
  31. '_SystemMainContributors' => ['name' => 'MainContributors', 'is_system' => 1],
  32. '_SystemContributors' => ['name' => 'Contributors', 'is_system' => 1],
  33. '_SystemCustom1' => ['name' => 'Custom1', 'is_system' => 1],
  34. '_SystemCustom2' => ['name' => 'Custom2', 'is_system' => 1],
  35. '_SystemCustom3' => ['name' => 'Custom3', 'is_system' => 1],
  36. '_SystemCustom4' => ['name' => 'Custom4', 'is_system' => 1],
  37. '_SystemCustom5' => ['name' => 'Custom5', 'is_system' => 1],
  38. ];
  39. if (empty($widgets)) {
  40. $dashboardWidgets = $defaultDashboardWidgets;
  41. } else {
  42. foreach ($widgets as $widget) {
  43. if ($widget['is_system']) {
  44. $dashboardWidgets['_System' . $widget['name']] = ['name' => $widget['name'], 'is_system' => 1];
  45. } else {
  46. $dashboardWidgets[$widget['name']] = ['name' => $widget['name'], 'is_system' => 0];
  47. }
  48. }
  49. foreach ($defaultDashboardWidgets as $widgetName => $widget) {
  50. $dashboardWidgets[$widgetName] = $widget;
  51. }
  52. }
  53. $dashboardWidgetPlugins = [];
  54. $hookResults = hook('admin_dashboard');
  55. if (!empty($hookResults)) {
  56. foreach ($hookResults as $hookResult) {
  57. if (isset($hookResult['width']) && isset($hookResult['view']) && isset($hookResult['plugin'])) { //验证插件返回合法性
  58. $dashboardWidgetPlugins[$hookResult['plugin']] = $hookResult;
  59. if (!isset($dashboardWidgets[$hookResult['plugin']])) {
  60. $dashboardWidgets[$hookResult['plugin']] = ['name' => $hookResult['plugin'], 'is_system' => 0];
  61. }
  62. }
  63. }
  64. }
  65. $smtpSetting = cmf_get_option('smtp_setting');
  66. $this->assign('dashboard_widgets', $dashboardWidgets);
  67. $this->assign('dashboard_widget_plugins', $dashboardWidgetPlugins);
  68. $this->assign('has_smtp_setting', empty($smtpSetting) ? false : true);
  69. $admin_id = session('ADMIN_ID');
  70. $this->assign('admin_id', session('ADMIN_ID'));
  71. if ($admin_id == 1) {
  72. $activityCount = ActivityModel::count();
  73. $this->assign('activity_count', $activityCount);
  74. $userCount = UserModel::where('user_type', 2)->count();
  75. $this->assign('user_count', $userCount);
  76. } else {
  77. $role_id = Db::name('role_user')->where('user_id',$admin_id)->value('role_id');
  78. $this->assign('role_id', $role_id);
  79. if ($role_id == 2) {
  80. $activityCount = ActivityModel::where('user_id', $admin_id)->count();
  81. $this->assign('activity_count', $activityCount);
  82. $info = ActivitySiteModel::get($admin_id);
  83. $this->assign('info', $info);
  84. } elseif ($role_id == 3) {
  85. $joinCount = BusinessJoinModel::where('business_id',$admin_id)->count();
  86. $this->assign('join_count',$joinCount);
  87. $info = BusinessModel::get($admin_id);
  88. $this->assign('info',$info);
  89. }
  90. }
  91. return $this->fetch();
  92. }
  93. public function dashboardWidget()
  94. {
  95. $dashboardWidgets = [];
  96. $widgets = $this->request->param('widgets/a');
  97. if (!empty($widgets)) {
  98. foreach ($widgets as $widget) {
  99. if ($widget['is_system']) {
  100. array_push($dashboardWidgets, ['name' => $widget['name'], 'is_system' => 1]);
  101. } else {
  102. array_push($dashboardWidgets, ['name' => $widget['name'], 'is_system' => 0]);
  103. }
  104. }
  105. }
  106. cmf_set_option('admin_dashboard_widgets', $dashboardWidgets, true);
  107. $this->success('更新成功!');
  108. }
  109. }