| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- <?php
- namespace app\admin\controller;
- /**
- * 报表类
- */
- class Report extends Base
- {
- /**
- * 工作报表
- *
- * @access public
- * @return array JsonString
- */
- public function index()
- {
- $param = input('param.');
- $startTime = isset($param['start']) ? $param['start'] : date('Y-m-d', strtotime("-6 day"));
- $endTime = isset($param['end']) ? $param['end'] : date('Y-m-d');
- $timeInterval = $this->Date_segmentation($startTime,$endTime);
- $chatData = [];
- $serviceData = [];
- $xData = [];
- foreach ($timeInterval['days_list'] as $k => $value) {
- $allCount = 0;
- $evaluateGood = 0;
- $evaluateSecondary = 0;
- $evaluateBad = 0;
- $evaluateNo = 0;
- $dayBegin = strtotime($value);
- $dayEnd = strtotime($value) + 24 * 60 * 60;
- $chatLogCountWhere['start_time'] = ['between', [$dayBegin, $dayEnd]];
- $join = [
- 'alarm b' => 'a.servicelog_id = b.servicelog_id',
- ];
- $field = ['alarm_count', 'evaluate_id'];
- // 查询当天的工单.
- $serviceLog = model('serviceLog')->selectServiceLog($field, $join, $chatLogCountWhere);
- foreach ($serviceLog as $ke => $va) {
- $allCount += $va['alarm_count'];
- if ($va['evaluate_id'] == 1) {
- $evaluateGood++;
- } elseif ($va['evaluate_id'] == 2) {
- $evaluateSecondary++;
- } elseif ($va['evaluate_id'] == 3) {
- $evaluateBad++;
- } elseif ($va['evaluate_id'] == 0) {
- $evaluateNo++;
- }
- }
- // 会话总数.
- $xData[] = $value;
- $chatData[$k] = $allCount;
- // 当天工单总数.
- $serviceData[$k] = model('serviceLog')->countServiceLog($chatLogCountWhere);
- }
- $this->assign([
- 'xData' => json_encode($xData),
- 'chatData' => json_encode($chatData),
- 'serviceData' => json_encode($serviceData),
- 'evaluate' => json_encode([
- 'evaluateGood' => $evaluateGood,
- 'evaluateSecondary' => $evaluateSecondary,
- 'evaluateBad' => $evaluateBad,
- 'evaluateNo' => $evaluateNo,
- ]),
- ]);
- return $this->fetch('index');
- }//end index()
- /**
- * 时间分割
- *
- * @access public
- * @return array JsonString
- */
- function Date_segmentation($start_date, $end_date)
- {
- //如果为空,则从今天的0点为开始时间
- if(!empty($start_date))
- $start_date=date('Y-m-d H:i:s',strtotime($start_date));
- else {
- $start_date=date('Y-m-d 00:00:00',time());
- }
- //如果为空,则以明天的0点为结束时间(不存在24:00:00,只会有00:00:00)
- if(!empty($end_date))
- $end_date=date('Y-m-d H:i:s',strtotime($end_date));
- else
- $end_date=date('Y-m-d 00:00:00',strtotime('+1 day'));
- //between 查询 要求必须是从低到高
- if($start_date>$end_date)
- {
- $ttt=$start_date;
- $start_date=$end_date;
- $end_date=$ttt;
- }elseif($start_date==$end_date){
- echo '时间输入错误';die;
- }
- $time_s=strtotime($start_date);
- $time_e=strtotime($end_date);
- $seconds_in_a_day=86400;
- //生成中间时间点数组(时间戳格式、日期时间格式、日期序列)
- $days_inline_array=array();
- $times_inline_array=array();
- //日期序列
- $days_list=array();
- //判断开始和结束时间是不是在同一天
- $days_inline_array[0]=$start_date; //初始化第一个时间点
- $times_inline_array[0]=$time_s; //初始化第一个时间点
- $days_list[]=date('Y-m-d',$time_s);//初始化第一天
- if(
- date('Y-m-d',$time_s)
- ==date('Y-m-d',$time_e)
- ){
- $days_inline_array[1]=$end_date;
- $times_inline_array[1]=$time_e;
- }
- else
- {
- /**
- * A.取开始时间的第二天凌晨0点
- * B.用结束时间减去A
- * C.用B除86400取商,取余
- * D.用A按C的商循环+86400,取得分割时间点,如果C没有余数,则最后一个时间点 与 循环最后一个时间点一致
- */
- $A_temp=date('Y-m-d 00:00:00',$time_s+$seconds_in_a_day);
- $A=strtotime($A_temp);
- $B=$time_e-$A;
- $C_quotient=floor($B/$seconds_in_a_day); //商舍去法取整
- $C_remainder=fmod($B,$seconds_in_a_day); //余数
- $days_inline_array[1]=$A_temp;
- $times_inline_array[1]=$A;
- $days_list[]=date('Y-m-d',$A); //第二天
- for($increase_time=$A,$c_count_t=1;$c_count_t<=$C_quotient;$c_count_t++)
- {
- $increase_time+=$seconds_in_a_day;
- $days_inline_array[]=date('Y-m-d H:i:s',$increase_time);
- $times_inline_array[]=$increase_time;
- $days_list[]=date('Y-m-d',$increase_time);
- }
- $days_inline_array[]=$end_date;
- $times_inline_array[]=$time_e;
- }
- return array(
- 'start_date'=>$start_date,
- 'end_date'=>$end_date,
- 'days_list'=>$days_list,
- 'days_inline'=>$days_inline_array,
- 'times_inline'=>$times_inline_array
- );
- }
- }//end class
|