123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493 |
- <?php
- namespace app\admin\controller;
- use function PHPSTORM_META\map;
- use think\App;
- use think\Db;
- class PatrolStatistics extends Auth {
- public function patrol() {
- $cur = date('Y-m-d');
- $start = input('start', date('Y-m-d', strtotime('' . $cur . ' -1 week')));
- $end = input('end', date('Y-m-d'));
- $start1 = $start . ' 00:00:00';
- $end1 = $end . ' 23:59:59';
- $type = input('type', 1);
- $list = $this->patrolData($start1, $end1, $type);
- $this->assign('type', $type);
- $this->assign('list', $list);
- $this->assign('start', $start);
- $this->assign('end', $end);
- return $this->fetch();
- }
- public function patrolData($start1, $end1, $type) {
- $map1[] = ['create_time', '>=', $start1];
- $map1[] = ['create_time', '<=', $end1];
- $map1[] = ['org_id', '=', $this->orgId];
- $list = Db::name('patrol_record')
- ->where($map1)
- ->where('patrol_mode', $type)
- ->group('patrol_addr_id')
- ->distinct(true)
- ->select();
- foreach ($list as $k => $v) {
- $list[$k]['title'] = Db::name('address')
- ->where('id', $v['patrol_addr_id'])
- ->value('title');
- $c = Db::name('patrol_record')
- ->where($map1)
- ->where('is_normal', 0)
- ->where('patrol_addr_id', $v['patrol_addr_id'])
- ->where('patrol_mode', $type)
- ->count();
- $list[$k]['count'] = $c ? $c : 0;
- $normal = Db::name('patrol_record')
- ->where($map1)
- ->where('is_normal', 1)
- ->where('patrol_addr_id', $v['patrol_addr_id'])
- ->where('patrol_mode', $type)
- ->count();
- $list[$k]['normal'] = $normal ? $normal : 0;
- }
- return $list;
- }
- public function patrolExport() {
- $cur = date('Y-m-d');
- $start = input('start', date('Y-m-d', strtotime('' . $cur . ' -1 week')));
- $end = input('end', date('Y-m-d'));
- $start1 = $start . ' 00:00:00';
- $end1 = $end . ' 23:59:59';
- $type = input('type', 1);
- $ret = $this->patrolData($start1, $end1, $type);
- include_once env('root_path') . '/extend/phpexcel/Classes/PHPExcel.php';
- //实例化PHPExcel类
- $objPHPExcel = new \PHPExcel();
- //激活当前的sheet表
- $objPHPExcel->setActiveSheetIndex(0);
- //设置表格头(即excel表格的第一行)
- $objPHPExcel->setActiveSheetIndex(0)
- ->setCellValue('A1', '智慧点')
- ->setCellValue('B1', '总数')
- ->setCellValue('C1', '总数(异常)');
- // 设置表格头水平居中
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('A1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('B1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('C1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- //设置列水平居中
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('A')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('B')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('C')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- //设置单元格宽度
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('A')->setWidth(10);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('B')->setWidth(20);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('C')->setWidth(20);
- //循环刚取出来的数组,将数据逐一添加到excel表格。
- for ($i = 0; $i < count($ret); $i++) {
- $objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 2), $ret[$i]['title']);
- $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $ret[$i]['count']);
- $objPHPExcel->getActiveSheet()->setCellValue('C' . ($i + 2), $ret[$i]['normal']);
- }
- $n = Db::name('patrol_mode')
- ->where('id', $type)
- ->value('name');
- //设置保存的Excel表格名称
- $filename = $n . '工作量统计分析_' . date('YmdHis', time()) . '.xls';
- //设置当前激活的sheet表格名称
- $objPHPExcel->getActiveSheet()->setTitle($n . '工作量统计分析');
- //设置浏览器窗口下载表格
- ob_end_clean();
- header("Content-Type: application/force-download");
- header("Content-Type: application/octet-stream");
- header("Content-Type: application/download");
- header('Content-Disposition:inline;filename="' . $filename);
- //生成excel文件
- $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
- //下载文件在浏览器窗口
- return $objWriter->save('php://output');
- }
- public function work() {
- $cur = date('Y-m-d');
- $start = input('start', date('Y-m-d', strtotime('' . $cur . ' -1 week')));
- $end = input('end', date('Y-m-d'));
- $start1 = $start . ' 00:00:00';
- $end1 = $end . ' 23:59:59';
- $type = input('type', 1);
- $list = $this->workData($start1, $end1, $type);
- $this->assign('type', $type);
- $this->assign('list', $list);
- $this->assign('start', $start);
- $this->assign('end', $end);
- return $this->fetch();
- }
- public function workData($start1, $end1, $type) {
- $map1[] = ['create_time', '>=', $start1];
- $map1[] = ['create_time', '<=', $end1];
- $map1[] = ['org_id', '=', $this->orgId];
- $list = Db::name('patrol_record')
- ->where($map1)
- ->where('patrol_mode', $type)
- ->group('user_id')
- ->distinct(true)
- ->select();
- foreach ($list as $k => $v) {
- $list[$k]['title'] = Db::name('user')
- ->where('id', $v['user_id'])
- ->value('real_name');
- $c = Db::name('patrol_record')
- ->where($map1)
- ->where('user_id', $v['user_id'])
- ->where('patrol_mode', $type)
- ->count();
- $list[$k]['count'] = $c ? $c : 0;
- $c1 = Db::name('patrol_record')
- ->where($map1)
- ->where('user_id', $v['user_id'])
- ->where('patrol_mode', $type)
- ->where('is_normal', 0)
- ->count();
- $list[$k]['count1'] = $c1 ? $c1 : 0;
- $c2 = Db::name('patrol_record')
- ->where($map1)
- ->where('user_id', $v['user_id'])
- ->where('patrol_mode', $type)
- ->where('is_normal', 1)
- ->count();
- $list[$k]['count2'] = $c2 ? $c2 : 0;
- $taskCount = Db::name('patrol_task_user')
- ->alias('a')
- ->join('patrol_task b','a.patrol_task_id=b.id')
- ->where('a.user_id',$v['user_id'])
- ->where('b.org_id',$this->orgId)
- ->where('b.status','<>',6)
- ->where('b.start_time','>=',$start1)
- ->where('b.end_time','<=',$end1)
- ->where('b.patrol_mode','=',$type)
- ->count();
- $ywcCount = Db::name('patrol_task_user')
- ->alias('a')
- ->join('patrol_task b','a.patrol_task_id=b.id')
- ->where('a.user_id',$v['user_id'])
- ->where('b.org_id',$this->orgId)
- ->where('b.status','=',2)
- ->where('b.start_time','>=',$start1)
- ->where('b.end_time','<=',$end1)
- ->where('b.patrol_mode','=',$type)
- ->count();
- $wcl = $taskCount>0?round($ywcCount/$taskCount,2)*100:0;
- $wcl = $wcl.'%';
- $list[$k]['wcl'] = $wcl;
- $list[$k]['count3'] = $ywcCount;
- $list[$k]['count4'] = $taskCount;
- }
- return $list;
- }
- public function workList(){
- $user_id = input('user_id','','trim');
- if($user_id!=''){
- $map[] = ['user_id','=',$user_id];
- }
- $is_normal = input('is_normal','','trim');
- if($is_normal!==''){
- $map[] = ['is_normal','=',$is_normal];
- }
- $type = input('type','','trim');
- if($type != ''){
- $map[] = ['patrol_mode','=',$type];
- }
- $start = input('start',date('Y-m-d', strtotime('' . date('Y-m-d') . ' -1 week')));
- if($start != ''){
- $map[] = ['create_time','>=',$start.' 00:00:00'];
- }
- $end = input('end', date('Y-m-d'));
- if($end != ''){
- $map[] = ['create_time','<=',$end.' 23:59:59'];
- }
- if(request()->isAjax()){
- //分页参数
- $length = input('rows',10,'intval'); //每页条数
- $page = input('page',1,'intval'); //第几页
- $start = ($page - 1) * $length; //分页开始位置
- //排序
- $sortRow = input('sidx','sort','trim'); //排序列
- $sort = input('sord','asc','trim'); //排序方式
- $order = $sortRow.' '.$sort.' ,id desc';
- $map[] = ['org_id','=',$this->orgId];
- $map= empty($map) ? true: $map;
- //数据查询
- $lists = Db::name('patrol_record')
- ->where($map)
- ->limit($start,$length)
- ->order($order)
- ->select();
- foreach ($lists as $k=>$v){
- $lists[$k]['address_title'] = Db::name('address')
- ->where('id', $v['patrol_addr_id'])
- ->value('title');
- $lists[$k]['task_user'] = Db::name('user')
- ->where('id', $v['user_id'])->value('real_name');
- $lists[$k]['task_title'] = Db::name('patrol_task')
- ->where('id', $v['patrol_task_id'])
- ->value('title');
- }
- //数据返回
- $totalCount = Db::name('patrol_record')->where($map)->count();
- $totalPage = ceil($totalCount/$length);
- $result['page'] = $page;
- $result['total'] = $totalPage;
- $result['records'] = $totalCount;
- $result['rows'] = $lists;
- return json($result);
- }else{
- $type = input('type',1);
- $t = Db::name('patrol_mode')
- ->where('id',$type)
- ->value('name');
- $this->assign('is_normal',$is_normal);
- $this->assign('type',$type);
- $this->assign('start',$start);
- $this->assign('end',$end);
- $this->assign('user_id',$user_id);
- $this->assign('meta_title',$t.'人员工作量统计');
- return $this->fetch();
- }
- }
- public function workList1(){
- $user_id = input('user_id','','trim');
- if($user_id!=''){
- $map[] = ['a.user_id','=',$user_id];
- }
- $is_normal = input('is_normal','','trim');
- if($is_normal!==''){
- if($is_normal==1){//总数
- $map[] = ['b.status','<>',6];
- }
- if($is_normal==2){//已完成
- $map[] = ['b.status','=',2];
- }
- }
- $type = input('type','','trim');
- if($type != ''){
- $map[] = ['b.patrol_mode','=',$type];
- }
- $start = input('start',date('Y-m-d', strtotime('' . date('Y-m-d') . ' -1 week')));
- if($start != ''){
- $map[] = ['b.start_time','>=',$start.' 00:00:00'];
- }
- $end = input('end', date('Y-m-d'));
- if($end != ''){
- $map[] = ['b.end_time','<=',$end.' 23:59:59'];
- }
- if(request()->isAjax()){
- //分页参数
- $length = input('rows',10,'intval'); //每页条数
- $page = input('page',1,'intval'); //第几页
- $start = ($page - 1) * $length; //分页开始位置
- $map[] = ['b.org_id','=',$this->orgId];
- $map= empty($map) ? true: $map;
- //数据查询
- $lists = Db::name('patrol_task_user')
- ->alias('a')
- ->join('patrol_task b','a.patrol_task_id=b.id')
- ->field('b.*,a.user_id')
- ->where($map)
- ->limit($start,$length)
- ->order('b.id','desc')
- ->select();
- foreach ($lists as $k=>$v){
- $lists[$k]['task_user'] = Db::name('user')
- ->where('id', $v['user_id'])->value('real_name');
- }
- //数据返回
- $totalCount = Db::name('patrol_task_user')
- ->alias('a')
- ->join('patrol_task b','a.patrol_task_id=b.id')->where($map)->count();
- $totalPage = ceil($totalCount/$length);
- $result['page'] = $page;
- $result['total'] = $totalPage;
- $result['records'] = $totalCount;
- $result['rows'] = $lists;
- return json($result);
- }else{
- $type = input('type',1);
- $t = Db::name('patrol_mode')
- ->where('id',$type)
- ->value('name');
- $this->assign('is_normal',$is_normal);
- $this->assign('type',$type);
- $this->assign('start',$start);
- $this->assign('end',$end);
- $this->assign('user_id',$user_id);
- $this->assign('meta_title',$t.'人员工作量统计');
- return $this->fetch();
- }
- }
- public function workExport() {
- $cur = date('Y-m-d');
- $start = input('start', date('Y-m-d', strtotime('' . $cur . ' -1 week')));
- $end = input('end', date('Y-m-d'));
- $start1 = $start . ' 00:00:00';
- $end1 = $end . ' 23:59:59';
- $type = input('type', 1);
- $ret = $this->workData($start1, $end1, $type);
- include_once env('root_path') . '/extend/phpexcel/Classes/PHPExcel.php';
- //实例化PHPExcel类
- $objPHPExcel = new \PHPExcel();
- //激活当前的sheet表
- $objPHPExcel->setActiveSheetIndex(0);
- //设置表格头(即excel表格的第一行)
- $objPHPExcel->setActiveSheetIndex(0)
- ->setCellValue('A1', 'ID')
- ->setCellValue('B1', '姓名')
- ->setCellValue('C1', '工作记录(总数)')
- ->setCellValue('D1', '工作记录(正常)')
- ->setCellValue('E1', '工作记录(异常)')
- ->setCellValue('F1', '完成率')
- ->setCellValue('G1', '需要完成')
- ->setCellValue('H1', '已完成');
- // 设置表格头水平居中
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('A1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('B1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('C1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- //设置列水平居中
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('A')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('B')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('C')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- //设置单元格宽度
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('A')->setWidth(10);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('B')->setWidth(20);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('C')->setWidth(20);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('D')->setWidth(20);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('E')->setWidth(20);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('F')->setWidth(20);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('G')->setWidth(20);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('H')->setWidth(20);
- //循环刚取出来的数组,将数据逐一添加到excel表格。
- for ($i = 0; $i < count($ret); $i++) {
- $objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 2), $ret[$i]['id']);
- $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $ret[$i]['title']);
- $objPHPExcel->getActiveSheet()->setCellValue('C' . ($i + 2), $ret[$i]['count']);
- $objPHPExcel->getActiveSheet()->setCellValue('D' . ($i + 2), $ret[$i]['count1']);
- $objPHPExcel->getActiveSheet()->setCellValue('E' . ($i + 2), $ret[$i]['count2']);
- $objPHPExcel->getActiveSheet()->setCellValue('F' . ($i + 2), $ret[$i]['wcl']);
- $objPHPExcel->getActiveSheet()->setCellValue('G' . ($i + 2), $ret[$i]['count4']);
- $objPHPExcel->getActiveSheet()->setCellValue('H' . ($i + 2), $ret[$i]['count3']);
- }
- $n = Db::name('patrol_mode')
- ->where('id', $type)
- ->value('name');
- //设置保存的Excel表格名称
- $filename = $n . '人员工作量统计_' . date('YmdHis', time()) . '.xls';
- //设置当前激活的sheet表格名称
- $objPHPExcel->getActiveSheet()->setTitle($n . '人员工作量统计');
- //设置浏览器窗口下载表格
- ob_end_clean();
- header("Content-Type: application/force-download");
- header("Content-Type: application/octet-stream");
- header("Content-Type: application/download");
- header('Content-Disposition:inline;filename="' . $filename);
- //生成excel文件
- $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
- //下载文件在浏览器窗口
- return $objWriter->save('php://output');
- }
- public function patrolList(){
- $patrol_addr_id = input('patrol_addr_id','','trim');
- if($patrol_addr_id!=''){
- $map[] = ['patrol_addr_id','=',$patrol_addr_id];
- }
- $is_normal = input('is_normal','','trim');
- if($is_normal!==''){
- $map[] = ['is_normal','=',$is_normal];
- }
- $type = input('type','','trim');
- if($type != ''){
- $map[] = ['patrol_mode','=',$type];
- }
- $start = input('start',date('Y-m-d', strtotime('' . date('Y-m-d') . ' -1 week')));
- if($start != ''){
- $map[] = ['create_time','>=',$start.' 00:00:00'];
- }
- $end = input('end', date('Y-m-d'));
- if($end != ''){
- $map[] = ['create_time','<=',$end.' 23:59:59'];
- }
- if(request()->isAjax()){
- //分页参数
- $length = input('rows',10,'intval'); //每页条数
- $page = input('page',1,'intval'); //第几页
- $start = ($page - 1) * $length; //分页开始位置
- //排序
- $sortRow = input('sidx','sort','trim'); //排序列
- $sort = input('sord','asc','trim'); //排序方式
- $order = $sortRow.' '.$sort.' ,id desc';
- $map[] = ['org_id','=',$this->orgId];
- $map= empty($map) ? true: $map;
- //数据查询
- $lists = Db::name('patrol_record')
- ->where($map)
- ->limit($start,$length)
- ->order($order)
- ->select();
- foreach ($lists as $k=>$v){
- $lists[$k]['address_title'] = Db::name('address')
- ->where('id', $v['patrol_addr_id'])
- ->value('title');
- $lists[$k]['task_user'] = Db::name('user')
- ->where('id', $v['user_id'])->value('real_name');
- $lists[$k]['task_title'] = Db::name('patrol_task')
- ->where('id', $v['patrol_task_id'])
- ->value('title');
- }
- //数据返回
- $totalCount = Db::name('patrol_record')->where($map)->count();
- $totalPage = ceil($totalCount/$length);
- $result['page'] = $page;
- $result['total'] = $totalPage;
- $result['records'] = $totalCount;
- $result['rows'] = $lists;
- return json($result);
- }else{
- $type = input('type',1);
- $t = Db::name('patrol_mode')
- ->where('id',$type)
- ->value('name');
- $this->assign('is_normal',$is_normal);
- $this->assign('type',$type);
- $this->assign('start',$start);
- $this->assign('end',$end);
- $this->assign('patrol_addr_id',$patrol_addr_id);
- $this->assign('meta_title',$t.'检查记录');
- return $this->fetch();
- }
- }
- }
|