123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- <?php
- // +----------------------------------------------------------------------
- // | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2013-2019 http://www.thinkcmf.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
- // +----------------------------------------------------------------------
- // | Author: 小夏 < 449134904@qq.com>
- // +----------------------------------------------------------------------
- namespace app\admin\controller;
- use app\activity\model\ActivityModel;
- use app\activity\model\ActivitySiteModel;
- use app\admin\model\UserModel;
- use app\business\model\BusinessJoinModel;
- use app\business\model\BusinessModel;
- use cmf\controller\AdminBaseController;
- use think\Db;
- class MainController extends AdminBaseController
- {
- /**
- * 后台欢迎页
- */
- public function index()
- {
- $dashboardWidgets = [];
- $widgets = cmf_get_option('admin_dashboard_widgets');
- $defaultDashboardWidgets = [
- '_SystemCmfHub' => ['name' => 'CmfHub', 'is_system' => 1],
- '_SystemCmfDocuments' => ['name' => 'CmfDocuments', 'is_system' => 1],
- '_SystemMainContributors' => ['name' => 'MainContributors', 'is_system' => 1],
- '_SystemContributors' => ['name' => 'Contributors', 'is_system' => 1],
- '_SystemCustom1' => ['name' => 'Custom1', 'is_system' => 1],
- '_SystemCustom2' => ['name' => 'Custom2', 'is_system' => 1],
- '_SystemCustom3' => ['name' => 'Custom3', 'is_system' => 1],
- '_SystemCustom4' => ['name' => 'Custom4', 'is_system' => 1],
- '_SystemCustom5' => ['name' => 'Custom5', 'is_system' => 1],
- ];
- if (empty($widgets)) {
- $dashboardWidgets = $defaultDashboardWidgets;
- } else {
- foreach ($widgets as $widget) {
- if ($widget['is_system']) {
- $dashboardWidgets['_System' . $widget['name']] = ['name' => $widget['name'], 'is_system' => 1];
- } else {
- $dashboardWidgets[$widget['name']] = ['name' => $widget['name'], 'is_system' => 0];
- }
- }
- foreach ($defaultDashboardWidgets as $widgetName => $widget) {
- $dashboardWidgets[$widgetName] = $widget;
- }
- }
- $dashboardWidgetPlugins = [];
- $hookResults = hook('admin_dashboard');
- if (!empty($hookResults)) {
- foreach ($hookResults as $hookResult) {
- if (isset($hookResult['width']) && isset($hookResult['view']) && isset($hookResult['plugin'])) { //验证插件返回合法性
- $dashboardWidgetPlugins[$hookResult['plugin']] = $hookResult;
- if (!isset($dashboardWidgets[$hookResult['plugin']])) {
- $dashboardWidgets[$hookResult['plugin']] = ['name' => $hookResult['plugin'], 'is_system' => 0];
- }
- }
- }
- }
- $smtpSetting = cmf_get_option('smtp_setting');
- $this->assign('dashboard_widgets', $dashboardWidgets);
- $this->assign('dashboard_widget_plugins', $dashboardWidgetPlugins);
- $this->assign('has_smtp_setting', empty($smtpSetting) ? false : true);
- $admin_id = session('ADMIN_ID');
- $this->assign('admin_id', session('ADMIN_ID'));
- if ($admin_id == 1) {
- $activityCount = ActivityModel::count();
- $this->assign('activity_count', $activityCount);
- $userCount = UserModel::where('user_type', 2)->count();
- $this->assign('user_count', $userCount);
- } else {
- $role_id = Db::name('role_user')->where('user_id',$admin_id)->value('role_id');
- $this->assign('role_id', $role_id);
- if ($role_id == 2) {
- $activityCount = ActivityModel::where('user_id', $admin_id)->count();
- $this->assign('activity_count', $activityCount);
- $info = ActivitySiteModel::get($admin_id);
- $this->assign('info', $info);
- } elseif ($role_id == 3) {
- $joinCount = BusinessJoinModel::where('business_id',$admin_id)->count();
- $this->assign('join_count',$joinCount);
- $info = BusinessModel::get($admin_id);
- $this->assign('info',$info);
- }
- }
- return $this->fetch();
- }
- public function dashboardWidget()
- {
- $dashboardWidgets = [];
- $widgets = $this->request->param('widgets/a');
- if (!empty($widgets)) {
- foreach ($widgets as $widget) {
- if ($widget['is_system']) {
- array_push($dashboardWidgets, ['name' => $widget['name'], 'is_system' => 1]);
- } else {
- array_push($dashboardWidgets, ['name' => $widget['name'], 'is_system' => 0]);
- }
- }
- }
- cmf_set_option('admin_dashboard_widgets', $dashboardWidgets, true);
- $this->success('更新成功!');
- }
- }
|