Tongji.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 Tongji extends Backend
  16. {
  17. /**
  18. * 报表统计
  19. */
  20. public function tongji(){
  21. $starttime = strtotime(date('Y-m-d',strtotime("-7 day"))); //默认7天前
  22. $endtime = strtotime(date('Y-m-d')) - 1;
  23. $starttime = strtotime(date('Y-m-d')); //默认7天前
  24. $endtime = strtotime(date('Y-m-d')) + 86399;
  25. //接收
  26. $choicedatetime = input('choicedatetime','');
  27. if(!empty($choicedatetime)){
  28. $choicedatetime = explode(' - ',$choicedatetime);
  29. $starttime = strtotime($choicedatetime[0]);
  30. $endtime = strtotime($choicedatetime[1]) + 86399;
  31. }
  32. $this->view->assign('defaultdatetime',date('Y-m-d',$starttime).' - '.date('Y-m-d',$endtime));
  33. //dump($starttime);
  34. //dump($endtime);
  35. //所有应该参加考试的人
  36. $exam_paper = Db::name('exam_paper')->where('start_time','BETWEEN',[$starttime,$endtime])->where('deletetime',NULL)->column('id,user_ids');
  37. // dump($exam_paper);
  38. $new_exam_paper = [];
  39. foreach($exam_paper as $key => $val){
  40. $new_exam_paper = array_merge($new_exam_paper,explode(',',$val));
  41. }
  42. // dump($new_exam_paper);
  43. $new_exam_paper = array_count_values($new_exam_paper);
  44. // dump($new_exam_paper);
  45. //未通过考试的人
  46. $nopass = Db::name('exam_grade')->where('paper_id','IN',array_keys($exam_paper))->where('is_pass',0)->column('user_id');
  47. // dump($nopass);
  48. $nopass = array_count_values($nopass);
  49. // dump($nopass);
  50. //参加考试的人
  51. $exam_grade = Db::name('exam_grade')->where('paper_id','IN',array_keys($exam_paper))->column('user_id');
  52. // dump($exam_grade);
  53. $exam_grade = array_count_values($exam_grade);
  54. // dump($exam_grade);
  55. //应该参加培训的人
  56. $train_active = Db::name('train_active')->where('starttime','BETWEEN',[$starttime,$endtime])->where('deletetime',NULL)->column('id,user_ids');
  57. // dump($train_active);
  58. $new_train_active = [];
  59. foreach($train_active as $key => $val){
  60. $new_train_active = array_merge($new_train_active,explode(',',$val));
  61. }
  62. // dump($new_train_active);
  63. $new_train_active = array_count_values($new_train_active);
  64. // dump($new_train_active);
  65. //参加签到的人
  66. $user_train = Db::name('user_train')->where('train_id','IN',array_keys($train_active))->column('user_id');
  67. // dump($user_train);
  68. $user_train = array_count_values($user_train);
  69. // dump($user_train);
  70. //参加签到却迟到的人
  71. $user_train_late = Db::name('user_train')->where('train_id','IN',array_keys($train_active))->where('status',2)->column('user_id');
  72. $user_train_late = array_count_values($user_train_late);
  73. //所有用户
  74. $userlist = Db::name('user')->order('idcard_status desc')->select();
  75. foreach($userlist as $key => $user){
  76. $user['realname'] = '';
  77. if($user['idcard_status'] == 1){
  78. $user['realname'] = $user['nickname'];
  79. }
  80. //应参加考试次数
  81. $user['paper_count'] = isset($new_exam_paper[$user['id']]) ? $new_exam_paper[$user['id']] : 0;
  82. //不及格次数
  83. $user['no_pass'] = isset($nopass[$user['id']]) ? $nopass[$user['id']] : 0;
  84. //考试次数
  85. $user['grade_count'] = isset($exam_grade[$user['id']]) ? $exam_grade[$user['id']] : 0;
  86. //缺考次数
  87. $user['no_grade'] = $user['paper_count'] - $user['grade_count'];
  88. if($user['no_grade'] < 0){ $user['no_grade'] = 0;}
  89. //应该签到的次数
  90. $user['train_count'] = isset($new_train_active[$user['id']]) ? $new_train_active[$user['id']] : 0;
  91. //签到的次数
  92. $user['sign_count'] = isset($user_train[$user['id']]) ? $user_train[$user['id']] : 0;
  93. //未到的次数
  94. $user['no_sign'] = $user['train_count'] - $user['sign_count'];
  95. if($user['no_sign'] < 0){ $user['no_sign'] = 0;}
  96. //迟到次数
  97. $user['late'] = isset($user_train_late[$user['id']]) ? $user_train_late[$user['id']] : 0;
  98. //匿名用户
  99. if($user['idcard_status'] != 1){
  100. $user['no_pass'] = 0;
  101. $user['grade_count'] = 0;
  102. $user['no_grade'] = 0;
  103. $user['sign_count'] = 0;
  104. $user['no_sign'] = 0;
  105. $user['late'] = 0;
  106. }
  107. //
  108. $userlist[$key] = $user;
  109. //如果数据都是0,去掉
  110. if($user['paper_count'] == 0 && $user['train_count'] == 0){
  111. unset($userlist[$key]);
  112. }
  113. }
  114. $this->assign('datalist',$userlist);
  115. $this->view->engine->layout(false);
  116. return $this->view->fetch();
  117. }
  118. }