Report.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\Countmidtable;
  4. /**
  5. * 报表类
  6. */
  7. class Report extends Base
  8. {
  9. /**
  10. * 工作报表
  11. *
  12. * @access public
  13. * @return array JsonString
  14. */
  15. public function index()
  16. {
  17. $param = input('param.');
  18. $startTime = isset($param['start']) ? $param['start'] : date('Y-m-d', strtotime("-6 day"));
  19. $endTime = isset($param['end']) ? $param['end'] : date('Y-m-d');
  20. $timeInterval = $this->Date_segmentation($startTime, $endTime);
  21. $queueData = [];
  22. $chatData = [];
  23. $serviceData = [];
  24. $xData = [];
  25. foreach ($timeInterval['days_list'] as $k => $value) {
  26. $allCount = 0;
  27. $evaluateGood = 0;
  28. $evaluateSecondary = 0;
  29. $evaluateBad = 0;
  30. $evaluateNo = 0;
  31. $dayBegin = strtotime($value);
  32. $dayEnd = strtotime($value) + 24 * 60 * 60;
  33. $chatLogCountWhere['start_time'] = ['between', [$dayBegin, $dayEnd]];
  34. $join = [
  35. 'alarm b' => 'a.servicelog_id = b.servicelog_id',
  36. ];
  37. $field = ['alarm_count', 'evaluate_id', 'system'];
  38. $system = [];
  39. $systemCount = [];
  40. // 查询当天的工单.
  41. $serviceLog = model('serviceLog')->selectServiceLog($field, $join, $chatLogCountWhere);
  42. foreach ($serviceLog as $ke => $va) {
  43. $allCount += $va['alarm_count'];
  44. if ($va['evaluate_id'] == 1) {
  45. $evaluateGood++;
  46. } elseif ($va['evaluate_id'] == 2) {
  47. $evaluateSecondary++;
  48. } elseif ($va['evaluate_id'] == 3) {
  49. $evaluateBad++;
  50. } elseif ($va['evaluate_id'] == 0) {
  51. $evaluateNo++;
  52. }
  53. if (!isset($system[$va['system']])) {
  54. $system[$va['system']] = 1;
  55. } else {
  56. $system[$va['system']]++;
  57. }
  58. }
  59. // 会话总数.
  60. $xData[] = $value;
  61. $chatData[$k] = $allCount;
  62. // 当天工单总数.
  63. $serviceData[$k] = model('serviceLog')->countServiceLog($chatLogCountWhere);
  64. }
  65. foreach ($system as $k => $v) {
  66. $systemCount[] = [
  67. 'value' => $v,
  68. 'name' => $k,
  69. ];
  70. }
  71. $queueData =(new Countmidtable())->getQueryDay($timeInterval['days_list']);
  72. $this->assign([
  73. 'xData' => json_encode($xData),
  74. 'chatData' => json_encode($chatData),
  75. 'serviceData' => json_encode($serviceData),
  76. 'queueData' => json_encode($queueData),
  77. 'systemCount' => json_encode($systemCount),
  78. 'evaluate' => json_encode([
  79. 'evaluateGood' => $evaluateGood,
  80. 'evaluateSecondary' => $evaluateSecondary,
  81. 'evaluateBad' => $evaluateBad,
  82. 'evaluateNo' => $evaluateNo,
  83. ]),
  84. ]);
  85. return $this->fetch('index');
  86. }//end index()
  87. /**
  88. * 时间分割
  89. *
  90. * @access public
  91. * @return array JsonString
  92. */
  93. function Date_segmentation($start_date, $end_date)
  94. {
  95. //如果为空,则从今天的0点为开始时间
  96. if (!empty($start_date))
  97. $start_date = date('Y-m-d H:i:s', strtotime($start_date));
  98. else {
  99. $start_date = date('Y-m-d 00:00:00', time());
  100. }
  101. //如果为空,则以明天的0点为结束时间(不存在24:00:00,只会有00:00:00)
  102. if (!empty($end_date))
  103. $end_date = date('Y-m-d H:i:s', strtotime($end_date));
  104. else
  105. $end_date = date('Y-m-d 00:00:00', strtotime('+1 day'));
  106. //between 查询 要求必须是从低到高
  107. if ($start_date > $end_date) {
  108. $ttt = $start_date;
  109. $start_date = $end_date;
  110. $end_date = $ttt;
  111. } elseif ($start_date == $end_date) {
  112. echo '时间输入错误';
  113. die;
  114. }
  115. $time_s = strtotime($start_date);
  116. $time_e = strtotime($end_date);
  117. $seconds_in_a_day = 86400;
  118. //生成中间时间点数组(时间戳格式、日期时间格式、日期序列)
  119. $days_inline_array = array();
  120. $times_inline_array = array();
  121. //日期序列
  122. $days_list = array();
  123. //判断开始和结束时间是不是在同一天
  124. $days_inline_array[0] = $start_date; //初始化第一个时间点
  125. $times_inline_array[0] = $time_s; //初始化第一个时间点
  126. $days_list[] = date('Y-m-d', $time_s);//初始化第一天
  127. if (date('Y-m-d', $time_s) == date('Y-m-d', $time_e)) {
  128. $days_inline_array[1] = $end_date;
  129. $times_inline_array[1] = $time_e;
  130. } else {
  131. /**
  132. * A.取开始时间的第二天凌晨0点
  133. * B.用结束时间减去A
  134. * C.用B除86400取商,取余
  135. * D.用A按C的商循环+86400,取得分割时间点,如果C没有余数,则最后一个时间点 与 循环最后一个时间点一致
  136. */
  137. $A_temp = date('Y-m-d 00:00:00', $time_s + $seconds_in_a_day);
  138. $A = strtotime($A_temp);
  139. $B = $time_e - $A;
  140. $C_quotient = floor($B / $seconds_in_a_day); //商舍去法取整
  141. $C_remainder = fmod($B, $seconds_in_a_day); //余数
  142. $days_inline_array[1] = $A_temp;
  143. $times_inline_array[1] = $A;
  144. $days_list[] = date('Y-m-d', $A); //第二天
  145. for ($increase_time = $A, $c_count_t = 1; $c_count_t <= $C_quotient; $c_count_t++) {
  146. $increase_time += $seconds_in_a_day;
  147. $days_inline_array[] = date('Y-m-d H:i:s', $increase_time);
  148. $times_inline_array[] = $increase_time;
  149. $days_list[] = date('Y-m-d', $increase_time);
  150. }
  151. $days_inline_array[] = $end_date;
  152. $times_inline_array[] = $time_e;
  153. }
  154. return array(
  155. 'start_date' => $start_date,
  156. 'end_date' => $end_date,
  157. 'days_list' => $days_list,
  158. 'days_inline' => $days_inline_array,
  159. 'times_inline' => $times_inline_array
  160. );
  161. }
  162. }//end class