diff --git a/application/admin/controller/Dashboard.php b/application/admin/controller/Dashboard.php index 4175baf8..6d79275e 100644 --- a/application/admin/controller/Dashboard.php +++ b/application/admin/controller/Dashboard.php @@ -2,13 +2,17 @@ namespace app\admin\controller; +use app\admin\model\Admin; +use app\admin\model\User; use app\common\controller\Backend; -use think\Config; +use app\common\model\Attachment; +use fast\Date; +use think\Db; /** * 控制台 * - * @icon fa fa-dashboard + * @icon fa fa-dashboard * @remark 用于展示当前系统中的统计数据、统计报表及重要实时数据 */ class Dashboard extends Backend @@ -19,37 +23,47 @@ class Dashboard extends Backend */ public function index() { - $seventtime = \fast\Date::unixtime('day', -7); - $paylist = $createlist = []; - for ($i = 0; $i < 7; $i++) - { - $day = date("Y-m-d", $seventtime + ($i * 86400)); - $createlist[$day] = mt_rand(20, 200); - $paylist[$day] = mt_rand(1, mt_rand(1, $createlist[$day])); + $column = []; + $starttime = Date::unixtime('day', -6); + $endtime = Date::unixtime('day', 0, 'end'); + $joinlist = Db("user")->where('jointime', 'between time', [$starttime, $endtime]) + ->field('jointime, status, COUNT(*) AS nums, DATE_FORMAT(FROM_UNIXTIME(jointime), "%Y-%m-%d") AS join_date') + ->group('join_date') + ->select(); + for ($time = $starttime; $time <= $endtime;) { + $column[] = date("Y-m-d", $time); + $time += 86400; } - $hooks = config('addons.hooks'); - $uploadmode = isset($hooks['upload_config_init']) && $hooks['upload_config_init'] ? implode(',', $hooks['upload_config_init']) : 'local'; - $addonComposerCfg = ROOT_PATH . '/vendor/karsonzhang/fastadmin-addons/composer.json'; - Config::parse($addonComposerCfg, "json", "composer"); - $config = Config::get("composer"); - $addonVersion = isset($config['version']) ? $config['version'] : __('Unknown'); + $userlist = array_fill_keys($column, 0); + foreach ($joinlist as $k => $v) { + $userlist[$v['join_date']] = $v['nums']; + } + + $dbTableList = Db::query("SHOW TABLE STATUS"); $this->view->assign([ - 'totaluser' => 35200, - 'totalviews' => 219390, - 'totalorder' => 32143, - 'totalorderamount' => 174800, - 'todayuserlogin' => 321, - 'todayusersignup' => 430, - 'todayorder' => 2324, - 'unsettleorder' => 132, - 'sevendnu' => '80%', - 'sevendau' => '32%', - 'paylist' => $paylist, - 'createlist' => $createlist, - 'addonversion' => $addonVersion, - 'uploadmode' => $uploadmode + 'totaluser' => User::count(), + 'totaladdon' => count(get_addon_list()), + 'totaladmin' => Admin::count(), + 'totalcategory' => \app\common\model\Category::count(), + 'todayusersignup' => User::whereTime('jointime', 'today')->count(), + 'todayuserlogin' => User::whereTime('logintime', 'today')->count(), + 'sevendau' => User::whereTime('jointime|logintime', '-7 days')->count(), + 'thirtydau' => User::whereTime('jointime|logintime', '-30 days')->count(), + 'threednu' => User::whereTime('jointime', '-3 days')->count(), + 'sevendnu' => User::whereTime('jointime', '-7 days')->count(), + 'dbtablenums' => count($dbTableList), + 'dbsize' => array_sum(array_map(function ($item) { + return $item['Data_length'] + $item['Index_length']; + }, $dbTableList)), + 'attachmentnums' => Attachment::count(), + 'attachmentsize' => Attachment::sum('filesize'), + 'picturenums' => Attachment::where('mimetype', 'like', 'image/%')->count(), + 'picturesize' => Attachment::where('mimetype', 'like', 'image/%')->sum('filesize'), ]); + $this->assignconfig('column', array_keys($userlist)); + $this->assignconfig('userdata', array_values($userlist)); + return $this->view->fetch(); } diff --git a/application/admin/lang/zh-cn/dashboard.php b/application/admin/lang/zh-cn/dashboard.php index 0008f079..0b244d19 100644 --- a/application/admin/lang/zh-cn/dashboard.php +++ b/application/admin/lang/zh-cn/dashboard.php @@ -6,34 +6,34 @@ return [ 'Type' => '栏目类型', 'Image' => '图片', 'Total user' => '总会员数', - 'Total view' => '总访问数', - 'Total order' => '总订单数', - 'Total order amount' => '总金额', + 'Total addon' => '总插件数', + 'Total category' => '总分类数', + 'Total admin' => '总管理员数', 'Today user signup' => '今日注册', 'Today user login' => '今日登录', 'Today order' => '今日订单', 'Unsettle order' => '未处理订单', + 'Three dnu' => '三日新增', 'Seven dnu' => '七日新增', 'Seven dau' => '七日活跃', + 'Thirty dau' => '月活跃', 'Custom zone' => '这里是你的自定义数据', - 'Sales' => '成交数', - 'Orders' => '订单数', + 'Register user' => '注册用户数', 'Real time' => '实时', 'Category count' => '分类统计', 'Category count tips' => '当前分类总记录数', + 'Database count' => '数据库统计', + 'Database table nums' => '数据表数量', + 'Database size' => '占用空间', 'Attachment count' => '附件统计', + 'Attachment nums' => '附件数量', + 'Attachment size' => '附件大小', 'Attachment count tips' => '当前上传的附件数量', - 'Article count' => '文章统计', - 'News count' => '新闻统计', - 'Comment count' => '评论次数', - 'Like count' => '点赞次数', - 'Recent news' => '最新新闻', - 'Recent discussion' => '最新发贴', + 'Picture count' => '图片统计', + 'Picture nums' => '图片数量', + 'Picture size' => '图片大小', 'Server info' => '服务器信息', 'PHP version' => 'PHP版本', - 'Fastadmin version' => '主框架版本', - 'Fastadmin addon version' => '插件版本', - 'Thinkphp version' => 'ThinkPHP版本', 'Sapi name' => '运行方式', 'Debug mode' => '调试模式', 'Software' => '环境信息', diff --git a/application/admin/view/dashboard/index.html b/application/admin/view/dashboard/index.html index d70af3b3..1a07e447 100644 --- a/application/admin/view/dashboard/index.html +++ b/application/admin/view/dashboard/index.html @@ -150,7 +150,6 @@ } - #statistics .panel { min-height: 150px; } @@ -183,28 +182,28 @@