Dashboard.php 2.7 KB

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