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 @@
- +
- {$totalviews} - {:__('Total view')} + {$totaladdon} + {:__('Total addon')}
- +
- {$totalorder} - {:__('Total order')} + {$totalcategory} + {:__('Total category')}
- +
- {$totalorderamount} - {:__('Total order amount')} + {$totaladdon} + {:__('Total admin')}
@@ -229,7 +228,7 @@
-
+
{$todayuserlogin}
{:__('Today user login')}
@@ -239,27 +238,17 @@
-
+
-
{$todayorder}
-
{:__('Today order')}
+
{$threednu}
+
{:__('Three dnu')}
-
-
-
-
{$unsettleorder}
-
{:__('Unsettle order')}
-
-
-
-
-
-
-
+
+
{$sevendnu}
{:__('Seven dnu')}
@@ -268,8 +257,8 @@
-
-
+
+
{$sevendau}
{:__('Seven dau')}
@@ -278,6 +267,16 @@
+
+
+
+
{$thirtydau}
+
{:__('Thirty dau')}
+
+
+
+
+
@@ -296,9 +295,14 @@
{:__('Category count')}
-

1234

-
1234
- {:__('Category count tips')} +
+
+

{$totalcategory}

+
+ {:__('Category count tips')} +
+
+
@@ -308,12 +312,23 @@
{:__('Real time')} -
{:__('Attachment count')}
+
{:__('Database count')}
-

1043

-
2592
- {:__('Attachment count tips')} +
+
+

{$dbtablenums}

+
+ {:__('Database table nums')} +
+
+
+

{$dbsize|format_bytes=###,'',0}

+
+ {:__('Database size')} +
+
+
@@ -324,21 +339,21 @@
{:__('Real time')} -
{:__('Article count')}
+
{:__('Attachment count')}
-

1234

-
- {:__('Comment count')} +

{$attachmentnums}

+
+ {:__('Attachment nums')}
-

6754

-
- {:__('Like count')} +

{$attachmentsize|format_bytes=###,'',0}

+
+ {:__('Attachment size')}
@@ -351,21 +366,21 @@
{:__('Real time')} -
{:__('News count')}
+
{:__('Picture count')}
-

5302

-
- {:__('Comment count')} +

{$picturenums}

+
+ {:__('Picture nums')}
-

8205

-
- {:__('Like count')} +

{$picturesize|format_bytes=###,'',0}

+
+ {:__('Picture size')}
@@ -385,12 +400,3 @@
- - - diff --git a/application/common.php b/application/common.php index 43b53a30..67bf8e02 100755 --- a/application/common.php +++ b/application/common.php @@ -33,15 +33,16 @@ if (!function_exists('format_bytes')) { * 将字节转换为可读文本 * @param int $size 大小 * @param string $delimiter 分隔符 + * @param int $precision 小数位数 * @return string */ - function format_bytes($size, $delimiter = '') + function format_bytes($size, $delimiter = '', $precision = 2) { $units = array('B', 'KB', 'MB', 'GB', 'TB', 'PB'); for ($i = 0; $size >= 1024 && $i < 6; $i++) { $size /= 1024; } - return round($size, 2) . $delimiter . $units[$i]; + return round($size, $precision) . $delimiter . $units[$i]; } } diff --git a/public/assets/js/backend/dashboard.js b/public/assets/js/backend/dashboard.js index 078d1def..ab8409c2 100755 --- a/public/assets/js/backend/dashboard.js +++ b/public/assets/js/backend/dashboard.js @@ -11,11 +11,19 @@ define(['jquery', 'bootstrap', 'backend', 'addtabs', 'table', 'echarts', 'echart text: '', subtext: '' }, + color: [ + "#18d1b1", + "#3fb1e3", + "#626c91", + "#a0a7e6", + "#c4ebad", + "#96dee8" + ], tooltip: { trigger: 'axis' }, legend: { - data: [__('Sales'), __('Orders')] + data: [__('Register user')] }, toolbox: { show: false, @@ -27,7 +35,7 @@ define(['jquery', 'bootstrap', 'backend', 'addtabs', 'table', 'echarts', 'echart xAxis: { type: 'category', boundaryGap: false, - data: Orderdata.column + data: Config.column }, yAxis: {}, grid: [{ @@ -37,7 +45,7 @@ define(['jquery', 'bootstrap', 'backend', 'addtabs', 'table', 'echarts', 'echart bottom: 30 }], series: [{ - name: __('Sales'), + name: __('Register user'), type: 'line', smooth: true, areaStyle: { @@ -48,55 +56,13 @@ define(['jquery', 'bootstrap', 'backend', 'addtabs', 'table', 'echarts', 'echart width: 1.5 } }, - data: Orderdata.paydata - }, - { - name: __('Orders'), - type: 'line', - smooth: true, - areaStyle: { - normal: {} - }, - lineStyle: { - normal: { - width: 1.5 - } - }, - data: Orderdata.createdata - }] + data: Config.userdata + }] }; // 使用刚指定的配置项和数据显示图表。 myChart.setOption(option); - //动态添加数据,可以通过Ajax获取数据然后填充 - setInterval(function () { - Orderdata.column.push((new Date()).toLocaleTimeString().replace(/^\D*/, '')); - var amount = Math.floor(Math.random() * 200) + 20; - Orderdata.createdata.push(amount); - Orderdata.paydata.push(Math.floor(Math.random() * amount) + 1); - - //按自己需求可以取消这个限制 - if (Orderdata.column.length >= 20) { - //移除最开始的一条数据 - Orderdata.column.shift(); - Orderdata.paydata.shift(); - Orderdata.createdata.shift(); - } - myChart.setOption({ - xAxis: { - data: Orderdata.column - }, - series: [{ - name: __('Sales'), - data: Orderdata.paydata - }, - { - name: __('Orders'), - data: Orderdata.createdata - }] - }); - }, 2000); $(window).resize(function () { myChart.resize(); });