Dashboard.php 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace app\admin\controller\exam;
  3. use addons\exam\enum\CommonStatus;
  4. use addons\exam\enum\RoomSignupStatus;
  5. use addons\exam\model\UserModel;
  6. use app\admin\model\exam\GradeModel;
  7. use app\admin\model\exam\PaperModel;
  8. use app\admin\model\exam\QuestionModel;
  9. use app\admin\model\exam\RoomGradeModel;
  10. use app\admin\model\exam\RoomModel;
  11. use app\admin\model\exam\RoomSignupModel;
  12. use app\common\controller\Backend;
  13. use fast\Date;
  14. use think\Db;
  15. /**
  16. * 控制台
  17. * @icon fa fa-dashboard
  18. * @remark 用于展示当前系统中的统计数据、统计报表及重要实时数据
  19. */
  20. class Dashboard extends Backend
  21. {
  22. /**
  23. * 查看
  24. */
  25. public function index()
  26. {
  27. try {
  28. \think\Db::execute("SET @@sql_mode='';");
  29. } catch (\Exception $e) {
  30. }
  31. $column = [];
  32. $start_time = Date::unixtime('day', -6);
  33. $end_time = Date::unixtime('day', 0, 'end');
  34. $join_list = UserModel::where('jointime', 'between time', [$start_time, $end_time])
  35. ->field('jointime, status, COUNT(*) AS nums, DATE_FORMAT(FROM_UNIXTIME(jointime), "%Y-%m-%d") AS join_date')
  36. ->group('join_date')
  37. ->select();
  38. for ($time = $start_time; $time <= $end_time;) {
  39. $column[] = date("Y-m-d", $time);
  40. $time += 86400;
  41. }
  42. $user_list = array_fill_keys($column, 0);
  43. foreach ($join_list as $k => $v) {
  44. $user_list[$v['join_date']] = $v['nums'];
  45. }
  46. $today_time = Date::unixtime('day', 0, 'begin');
  47. $this->view->assign([
  48. // 用户总数
  49. 'total_user_count' => UserModel::count(),
  50. // 今日新增用户数
  51. 'today_user_count' => UserModel::where('createtime', '>', $today_time)->count(),
  52. // 总题数
  53. 'total_question_count' => QuestionModel::where('status', CommonStatus::NORMAL)->count(),
  54. // 总试卷数
  55. 'total_paper_count' => PaperModel::where('status', CommonStatus::NORMAL)->count(),
  56. //总培训数
  57. 'total_peixun_count' => Db::name('train_active')->where('deletetime',null)->count(),
  58. // 总考场数
  59. // 'total_room_count' => RoomModel::where('status', CommonStatus::NORMAL)->count(),
  60. // 总参与考试次数
  61. 'total_exam_user_count' => GradeModel::count(),
  62. // 今日参与考试次数
  63. 'today_exam_user_count' => GradeModel::where('createtime', '>', $today_time)->count(),
  64. // 总参与考场考试次数
  65. // 'total_room_user_count' => RoomGradeModel::count(),
  66. // 今日参与考场考试次数
  67. // 'today_room_user_count' => RoomGradeModel::where('createtime', '>', $today_time)->count(),
  68. // 待处理报名数量
  69. // 'total_wait_apply_signup_count' => RoomSignupModel::where('status', RoomSignupStatus::WAIT)->count(),
  70. ]);
  71. $this->assignconfig('column', array_keys($user_list));
  72. $this->assignconfig('user_data', array_values($user_list));
  73. return $this->view->fetch();
  74. }
  75. }