Dashboard.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\Admin;
  4. use app\admin\model\User;
  5. use app\common\controller\Backend;
  6. use app\common\model\Attachment;
  7. use app\common\model\SysConfig;
  8. use fast\Date;
  9. use think\Db;
  10. /**
  11. * 控制台
  12. *
  13. * @icon fa fa-dashboard
  14. * @remark 用于展示当前系统中的统计数据、统计报表及重要实时数据
  15. */
  16. class Dashboard extends Backend
  17. {
  18. /**
  19. * 查看
  20. */
  21. public function index()
  22. {
  23. try {
  24. \think\Db::execute("SET @@sql_mode='';");
  25. } catch (\Exception $e) {
  26. }
  27. $column = [];
  28. $starttime = Date::unixtime('day', -6);
  29. $endtime = Date::unixtime('day', 0, 'end');
  30. $joinlist = Db("user")->where('jointime', 'between time', [$starttime, $endtime])
  31. ->field('jointime, status, COUNT(*) AS nums, DATE_FORMAT(FROM_UNIXTIME(jointime), "%Y-%m-%d") AS join_date')
  32. ->group('join_date')
  33. ->select();
  34. for ($time = $starttime; $time <= $endtime;) {
  35. $column[] = date("Y-m-d", $time);
  36. $time += 86400;
  37. }
  38. $userlist = array_fill_keys($column, 0);
  39. foreach ($joinlist as $k => $v) {
  40. $userlist[$v['join_date']] = $v['nums'];
  41. }
  42. $dbTableList = Db::query("SHOW TABLE STATUS");
  43. $this->view->assign([
  44. //'totaluser' => User::count(),
  45. 'totaluser' => 0,
  46. 'totaladdon' => SysConfig::look('video_view_seconds',0),
  47. //'totaladmin' => Admin::count(),
  48. 'totaladmin' => 0,
  49. 'totalcategory' => \app\common\model\Category::count(),
  50. //'todayusersignup' => User::whereTime('jointime', 'today')->count(),
  51. 'todayusersignup' => 0,
  52. //'todayuserlogin' => User::whereTime('logintime', 'today')->count(),
  53. 'todayuserlogin' => 0,
  54. //'sevendau' => User::whereTime('jointime|logintime|prevtime', '-7 days')->count(),
  55. 'sevendau' => 0,
  56. //'thirtydau' => User::whereTime('jointime|logintime|prevtime', '-30 days')->count(),
  57. 'thirtydau' => 0,
  58. //'threednu' => User::whereTime('jointime', '-3 days')->count(),
  59. 'threednu' => 0,
  60. //'sevendnu' => User::whereTime('jointime', '-7 days')->count(),
  61. 'sevendnu' => 0,
  62. 'dbtablenums' => count($dbTableList),
  63. 'dbsize' => array_sum(array_map(function ($item) {
  64. return $item['Data_length'] + $item['Index_length'];
  65. }, $dbTableList)),
  66. 'attachmentnums' => Attachment::count(),
  67. 'attachmentsize' => Attachment::sum('filesize'),
  68. 'picturenums' => Attachment::where('mimetype', 'like', 'image/%')->count(),
  69. 'picturesize' => Attachment::where('mimetype', 'like', 'image/%')->sum('filesize'),
  70. ]);
  71. $this->assignconfig('column', array_keys($userlist));
  72. $this->assignconfig('userdata', array_values($userlist));
  73. return $this->view->fetch();
  74. }
  75. }