| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270 |
- <?php
- namespace app\admin\controller;
- use app\admin\model\Countmidtable;
- use app\admin\model\Users as Usersmodel;
- use app\admin\model\Groups as GroupsModel;
- use app\admin\model\Servicetimelog as ServicetimelogModel;
- use app\admin\model\Kfstatetimes as KfstatetimesModel;
- /**
- * 报表类
- */
- 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);
- $queueData = [];
- $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', 'system'];
- $system = [];
- $systemCount = [];
- // 查询当天的工单.
- $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++;
- }
- if (!isset($system[$va['system']])) {
- $system[$va['system']] = 1;
- } else {
- $system[$va['system']]++;
- }
- }
- // 会话总数.
- $xData[] = $value;
- $chatData[$k] = $allCount;
- // 当天工单总数.
- $serviceData[$k] = model('serviceLog')->countServiceLog($chatLogCountWhere);
- }
- foreach ($system as $k => $v) {
- $systemCount[] = [
- 'value' => $v,
- 'name' => $k,
- ];
- }
- $queueData = (new Countmidtable())->getQueryDay($timeInterval['days_list']);
- $this->assign([
- 'xData' => json_encode($xData),
- 'chatData' => json_encode($chatData),
- 'serviceData' => json_encode($serviceData),
- 'queueData' => json_encode($queueData),
- 'systemCount' => json_encode($systemCount),
- 'evaluate' => json_encode([
- 'evaluateGood' => $evaluateGood,
- 'evaluateSecondary' => $evaluateSecondary,
- 'evaluateBad' => $evaluateBad,
- 'evaluateNo' => $evaluateNo,
- ]),
- ]);
- return $this->fetch('index');
- }//end index()
- public function attendancereport()
- {
- $goups = (new GroupsModel)->where(['status' => 1])->select();
- if (request()->isAjax()) {
- $param = input('param.');
- $limit = $param['pageSize'];
- $offset = ($param['pageNumber'] - 1) * $limit;
- $param = input('param.searchText');
- if (empty($param)) {
- $param = '0|0';
- }
- list($zone, $sgroup) = explode('|', $param);
- if (empty($zone)) {
- $zoneArray1 = [date("Y-m-d")];
- } else {
- $zonesarr = explode(',', $zone);
- $dd = $this->Date_segmentation($zonesarr['0'], $zonesarr['1']);
- $zoneArray1 = $dd['days_list'];
- }
- $zoneArray = array_map(function ($i) {
- return "'$i'";
- }, $zoneArray1);
- $uidarr = (new Usersmodel())->getUidsBygid(intval($sgroup), 1, 1);
- if (!$uidarr) {
- return json(['rows' => [], 'total' => 0]);
- }
- $model1 = new ServicetimelogModel();
- $model2 = new KfstatetimesModel();
- $ret1 = $model1->getDayData($zoneArray1, $uidarr['uids']);
- $ret2 = $model2->getDayData($zoneArray1, $uidarr['uids']);
- $retall = $this->reportDataFormat($ret1, $ret2, $uidarr['objs'], $zoneArray1, $limit, $offset);
- return json($retall);
- }
- $this->assign('groups', $goups);
- return $this->fetch();
- }
- function reportDataFormat($onoffdata, $timesdata, $uobjarr, $dataArray, $limit, $offset)
- {
- $allData = [];
- $all_last = [];
- foreach ($dataArray as $day) {
- foreach ($uobjarr as $uid => $user) {
- $kfuid = 'KF' . $uid;
- if (isset($onoffdata[$day][$kfuid])) {
- $allData[$day][$kfuid] = ['of0' => $onoffdata[$day][$kfuid][0], 'of1' => $onoffdata[$day][$kfuid][1]];
- } else {
- $allData[$day][$kfuid] = ['of0' => '', 'of1' => ''];
- }
- if (isset($timesdata[$day][$kfuid])) {
- $all_last[] = array_merge($timesdata[$day][$kfuid], $allData[$day][$kfuid], ['uname' => $uobjarr[$uid]->user_name,'account' => $uobjarr[$uid]->user_account,'day'=>$day]);
- } else {
- $all_last[] = array_merge(['0' => 0, '1' => 0, '2' => 0, '3' => 0], $allData[$day][$kfuid], ['uname' => $uobjarr[$uid]->user_name, 'account' => $uobjarr[$uid]->user_account,'day'=>$day]);
- }
- }
- }
- $len = count($all_last);
- $return = ['rows' => [], 'total' => $len];
- if ($offset >= $len) {
- return $return;
- }
- $begin = $offset;
- $end = ($offset + $limit);
- $end = ($end > $len) ? $len - 1 : $end;
- for ($i = $begin; $i < $end; $i++) {
- $return['rows'][] = $all_last[$i];
- }
- return $return;
- }
- /**
- * 时间分割
- *
- * @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
|