12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079 |
- <?php
- namespace app\admin\controller;
- use think\App;
- use think\Db;
- class RepairStatistics extends Auth
- {
- public function addrType(){
- $start = input('start',date('Y-m'));
- $end = input('end',date('Y-m'));
- if($start > $end){
- $this->error('开始时间不能大于结束时间');
- }
- $map[] = ['o.create_yyyymm','>=',date('Ym',strtotime($start))];
- $map[] = ['o.create_yyyymm','<=',date('Ym',strtotime($end))];
- $typeIds = input('typeIds');
- if($typeIds !=''){
- $where[] = ['id','in',$typeIds];
- }
- $mode = [
- ['type'=>1,'title'=>'需求数','value'=>[1]],
- ['type'=>2,'title'=>'已派工','value'=>[4]],
- ['type'=>3,'title'=>'已完成','value'=>[5,6]],
- ['type'=>4,'title'=>'已取消','value'=>[2,3]],
- ];
- $addr = Db::name('address')
- ->field('id,title')
- ->where('org_id',$this->orgId)
- ->where('del',0)
- ->where('enable',1)
- ->where('','exp',Db::raw("FIND_IN_SET(1,types)"))
- ->select();
- $where[] = ['org_id','=',$this->orgId];
- $type = Db::name('order_type')
- ->where($where)
- ->where('parent_id',0)
- ->where('del',0)
- ->where('enable',1)
- ->select();
- $type = $type?$type:[];
- $lists = [];
- foreach ($addr as $k=>$v){
- $a = [
- 'title' => $v['title'],
- 'total' => '',
- 'status' => '',
- ];
- foreach ($type as $key=>$val){
- $a['type'.$val['id']] = '';
- }
- $lists[] = $a;
- foreach ($mode as $kk=>$vv){
- $b = [
- 'title' => '',
- 'status' => $vv['title'],
- ];
- $total = 0;
- foreach ($type as $key=>$val){
- $subTypeId = Db::name('order_type')
- ->where('parent_id',$val['id'])
- ->where('del',0)
- ->where('enable',1)
- ->where('org_id',$this->orgId)
- ->column('id');
- $count = Db::name('orders')
- ->alias('o')
- ->join('order_repair or','or.order_id=o.id')
- ->where('o.work_type_mode',1)
- ->where('o.del',0)
- ->where($map)
- ->whereIn('o.order_mode',$vv['value'])
- ->where('or.address_id',$v['id'])
- ->whereIn('or.type_id',$subTypeId)
- ->count();
- $total += $count;
- $b['type'.$val['id']] = $count;
- }
- $b['total'] = $total;
- $lists[] = $b;
- }
- }
- $this->assign('lists',$lists);
- $this->assign('addr',$addr);
- $this->assign('type',$type);
- $typeList = Db::name('order_type')
- ->where('org_id',$this->orgId)
- ->where('parent_id',0)
- ->where('del',0)
- ->where('enable',1)
- ->select();
- $this->assign('typeList',$typeList);
- $this->assign('start',$start);
- $this->assign('end',$end);
- $this->assign('typeIds',$typeIds);
- $this->assign('typeIds2',!empty($typeIds)?explode(',',$typeIds):[]);
- return $this->fetch();
- }
- public function addrTypeExport(){
- $start = input('start',date('Y-m'));
- $end = input('end',date('Y-m'));
- if($start > $end){
- $this->error('开始时间不能大于结束时间');
- }
- $map[] = ['o.create_yyyymm','>=',date('Ym',strtotime($start))];
- $map[] = ['o.create_yyyymm','<=',date('Ym',strtotime($end))];
- $typeIds = input('typeIds','','trim');
- if($typeIds !=''){
- $where[] = ['id','in',$typeIds];
- }
- $mode = [
- ['type'=>1,'title'=>'需求数','value'=>[1]],
- ['type'=>2,'title'=>'已派工','value'=>[4]],
- ['type'=>3,'title'=>'已完成','value'=>[5,6]],
- ['type'=>4,'title'=>'已取消','value'=>[2,3]],
- ];
- $addr = Db::name('address')
- ->field('id,title')
- ->where('org_id',$this->orgId)
- ->where('del',0)
- ->where('enable',1)
- ->where('','exp',Db::raw("FIND_IN_SET(1,types)"))
- ->select();
- $where[] = ['org_id','=',$this->orgId];
- $type = Db::name('order_type')
- ->where($where)
- ->where('parent_id',0)
- ->where('del',0)
- ->where('enable',1)
- ->select();
- $type = $type?$type:[];
- $lists = [];
- foreach ($addr as $k=>$v){
- $a = [
- 'title' => $v['title'],
- 'total' => '',
- ];
- foreach ($type as $key=>$val){
- $a['type'.$val['id']] = '';
- }
- $lists[] = $a;
- foreach ($mode as $kk=>$vv){
- $b = [
- 'title' => $vv['title'],
- ];
- $total = 0;
- foreach ($type as $key=>$val){
- $subTypeId = Db::name('order_type')
- ->where('parent_id',$val['id'])
- ->where('del',0)
- ->where('enable',1)
- ->where('org_id',$this->orgId)
- ->column('id');
- $count = Db::name('orders')
- ->alias('o')
- ->join('order_repair or','or.order_id=o.id')
- ->where('o.work_type_mode',1)
- ->where('o.del',0)
- ->where($map)
- ->whereIn('o.order_mode',$vv['value'])
- ->where('or.address_id',$v['id'])
- ->whereIn('or.type_id',$subTypeId)
- ->count();
- $total += $count;
- $b['type'.$val['id']] = $count;
- }
- $b['total'] = $total;
- $lists[] = $b;
- }
- }
- include_once env('root_path').'/extend/phpexcel/Classes/PHPExcel.php';
- //实例化PHPExcel类
- $objPHPExcel =new \PHPExcel();
- //激活当前的sheet表
- $objPHPExcel->setActiveSheetIndex(0);
- //设置表格头(即excel表格的第一行)
- $sheet = $objPHPExcel->setActiveSheetIndex(0);
- $arr = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T');
- foreach ($arr as $k=>$v) {
- $objPHPExcel->getActiveSheet()->getStyle($v)->getAlignment()->setWrapText(false);//换行
- $objPHPExcel->getActiveSheet()->getStyle($v.'1')->getFont()->setBold(true);
- $objPHPExcel->getActiveSheet()->getStyle($v.'1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle($v.'1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle($v)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle($v)->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
- $objPHPExcel->getActiveSheet()->getColumnDimension($v)->setWidth(18);
- }
- $sheet->setCellValueByColumnAndRow(0, 1, '地点');
- if($type){
- foreach ($type as $k=>$v){
- $sheet->setCellValueByColumnAndRow($k+1, 1, $v['title']);
- }
- }
- $sheet->setCellValueByColumnAndRow(count($type)+1, 1, '总数');
- foreach ($lists as $k=>$v) {
- $sheet->setCellValueByColumnAndRow(0, $k + 2, $v['title']);
- foreach ($type as $kk=>$vv){
- $sheet->setCellValueByColumnAndRow($kk+1, $k + 2, $v['type'.$vv['id']]);
- }
- $sheet->setCellValueByColumnAndRow(count($type)+1, $k + 2, $v['total']);
- }
- //设置保存的Excel表格名称
- $filename = '报修地点报表_' . date('YmdHis', time()) . '.xls';
- //设置当前激活的sheet表格名称
- $objPHPExcel->getActiveSheet()->setTitle('报修地点报表');
- //设置浏览器窗口下载表格
- 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 todoXyTime(){
- $list = Db::name('todo')
- ->where('work_type_mode',1)
- ->where('del',0)
- ->where('todo_mode','in',[2,3])
- ->where('org_id',$this->orgId)
- ->order('id desc')
- ->select();
- $count = Db::name('todo')
- ->where('work_type_mode',1)
- ->where('del',0)
- ->where('todo_mode','in',[2,3])
- ->where('org_id',$this->orgId)
- ->order('id desc')
- ->sum('xy_time');
- foreach ($list as $k=>$v){
- $subType = Db::name('order_type')
- ->alias('ot')
- ->join('order_repair or','or.type_id=ot.id')
- ->where('or.order_id',$v['order_id'])
- ->value('type_id');
- $parentId = Db::name('order_type')->where('id',$subType)->value('parent_id');
- $list[$k]['type_title'] = Db::name('order_type')->where('id',$parentId)->value('title');
- $list[$k]['content'] = Db::name('orders')->where('id',$v['order_id'])->value('content');
- $list[$k]['dep'] = Db::name('orders')->alias('o')->join('dep d','d.id=o.dep_id')->where('o.id',$v['order_id'])->value('d.title');
- $list[$k]['user_name'] = Db::name('user')->where('id',$v['to_user_id'])->value('real_name');
- $list[$k]['xy_time'] = round($v['xy_time']/60,1);
- }
- $this->assign('count',round($count/60,1));
- $this->assign('list',$list);
- return $this->fetch();
- }
- public function xyTimeEcharts(){
- $curTime = date('Y-m-d H:i:s');
- $time = [
- ['title'=>'24小时内','sTime'=>date('Y-m-d H:i:s',strtotime($curTime)-3600*24),'eTime'=>$curTime,'type'=>1],
- ['title'=>'24~48小时','sTime'=>date('Y-m-d H:i:s',strtotime($curTime)-3600*48),'eTime'=>date('Y-m-d H:i:s',strtotime($curTime)-3600*24),'type'=>1],
- ['title'=>'超过72小时','sTime'=>'','eTime'=>date('Y-m-d H:i:s',strtotime($curTime)-3600*72),'type'=>2],
- ['title'=>'未响应','sTime'=>'','eTime'=>'','type'=>3],
- ['title'=>'总数','sTime'=>'','eTime'=>'','type'=>4],
- ];
- $list = [];
- foreach ($time as $k=>$v){
- if($v['type'] == 1){
- $count = Db::name('todo')
- ->where('org_id',$this->orgId)
- ->where('work_type_mode',1)
- ->where('del',0)
- ->where('create_time','>',$v['sTime'])
- ->where('create_time','<=',$v['eTime'])
- ->where('todo_mode','in',[2,3])
- ->count();
- }elseif ($v['type'] == 2){
- $count = Db::name('todo')
- ->where('org_id',$this->orgId)
- ->where('work_type_mode',1)
- ->where('del',0)
- ->where('create_time','<',$v['eTime'])
- ->where('todo_mode','in',[2,3])
- ->count();
- }elseif ($v['type'] == 3){
- $count = Db::name('todo')
- ->where('org_id',$this->orgId)
- ->where('work_type_mode',1)
- ->where('del',0)
- ->where('todo_mode',1)
- ->count();
- }elseif($v['type'] == 4){
- $count = Db::name('todo')
- ->where('org_id',$this->orgId)
- ->where('work_type_mode',1)
- ->where('del',0)
- ->count();
- }
- $list[$k]['title'] = $v['title'];
- $list[$k]['value'] = $count;
- }
- $data = [
- 'title'=>array_column($time,'title'),
- 'list'=>$list,
- ];
- $this->success('','',$data);
- }
- public function xyTimeExport(){
- $list = Db::name('todo')
- ->where('work_type_mode',1)
- ->where('del',0)
- ->where('todo_mode','in',[2,3])
- ->where('org_id',$this->orgId)
- ->order('id desc')
- ->select();
- $count = Db::name('todo')
- ->where('work_type_mode',1)
- ->where('del',0)
- ->where('todo_mode','in',[2,3])
- ->where('org_id',$this->orgId)
- ->order('id desc')
- ->sum('xy_time');
- foreach ($list as $k=>$v){
- $subType = Db::name('order_type')
- ->alias('ot')
- ->join('order_repair or','or.type_id=ot.id')
- ->where('or.order_id',$v['order_id'])
- ->value('type_id');
- $parentId = Db::name('order_type')->where('id',$subType)->value('parent_id');
- $list[$k]['type_title'] = Db::name('order_type')->where('id',$parentId)->value('title');
- $list[$k]['content'] = Db::name('orders')->where('id',$v['order_id'])->value('content');
- $list[$k]['dep'] = Db::name('orders')->alias('o')->join('dep d','d.id=o.dep_id')->where('o.id',$v['order_id'])->value('d.title');
- $list[$k]['user_name'] = Db::name('user')->where('id',$v['to_user_id'])->value('real_name');
- $list[$k]['xy_time'] = round($v['xy_time']/60,1);
- }
- include_once env('root_path').'/extend/phpexcel/Classes/PHPExcel.php';
- //实例化PHPExcel类
- $objPHPExcel =new \PHPExcel();
- //激活当前的sheet表
- $objPHPExcel->setActiveSheetIndex(0);
- //设置表格头(即excel表格的第一行)
- $sheet = $objPHPExcel->setActiveSheetIndex(0);
- $arr = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N');
- foreach ($arr as $k=>$v) {
- $objPHPExcel->getActiveSheet()->getStyle($v)->getAlignment()->setWrapText(false);//换行
- $objPHPExcel->getActiveSheet()->getStyle($v.'1')->getFont()->setBold(true);
- $objPHPExcel->getActiveSheet()->getStyle($v.'1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle($v.'1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle($v)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle($v)->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
- $objPHPExcel->getActiveSheet()->getColumnDimension($v)->setWidth(18);
- }
- $sheet->setCellValueByColumnAndRow(0, 1, '类型');
- $sheet->setCellValueByColumnAndRow(1, 1, '部门');
- $sheet->setCellValueByColumnAndRow(2, 1, '员工');
- $sheet->setCellValueByColumnAndRow(3, 1, '需求描述');
- $sheet->setCellValueByColumnAndRow(4, 1, '状态');
- $sheet->setCellValueByColumnAndRow(5, 1, '响应时间');
- $sheet->setCellValueByColumnAndRow(6, 1, '合计');
- foreach ($list as $k=>$v) {
- $sheet->setCellValueByColumnAndRow(0, $k + 2, $v['type_title']);
- $sheet->setCellValueByColumnAndRow(1, $k + 2, $v['dep']);
- $sheet->setCellValueByColumnAndRow(2, $k + 2, $v['user_name']);
- $sheet->setCellValueByColumnAndRow(3, $k + 2, $v['content']);
- if($v['todo_mode'] == 2){
- $sheet->setCellValueByColumnAndRow(4, $k + 2, '进行中');
- }
- $sheet->setCellValueByColumnAndRow(5, $k + 2, $v['xy_time']);
- }
- $sheet->setCellValueByColumnAndRow(6, $k + 2, round($count/60,1));
- //设置保存的Excel表格名称
- $filename = '报修工单响应时间_' . date('YmdHis', time()) . '.xls';
- //设置当前激活的sheet表格名称
- $objPHPExcel->getActiveSheet()->setTitle('报修工单响应时间');
- //设置浏览器窗口下载表格
- 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 addrWorkHour(){
- $start = input('start',date('Y-m'));
- $end = input('end',date('Y-m'));
- if($start > $end){
- $this->error('开始时间不能大于结束时间');
- }
- $map[] = ['t.create_yyyymm','>=',date('Ym',strtotime($start))];
- $map[] = ['t.create_yyyymm','<=',date('Ym',strtotime($end))];
- $addrIds= input('addrIds','','trim');
- if($addrIds !=''){
- $where[] = ['id','in',$addrIds];
- }
- $where[] = ['org_id','=',$this->orgId];
- $addr = Db::name('address')
- ->field('id,title')
- ->where($where)
- ->where('org_id',$this->orgId)
- ->where('del',0)
- ->where('enable',1)
- ->where('','exp',Db::raw("FIND_IN_SET(1,types)"))
- ->select();
- $addr = $addr?$addr:[];
- $list = [];
- $total = $total2 = 0;
- foreach ($addr as $k=>$v){
- $count = Db::name('todo')
- ->alias('t')
- ->join('order_repair or','or.order_id=t.order_id')
- ->where('or.address_id',$v['id'])
- ->where($map)
- ->where('t.del',0)
- ->where('t.work_type_mode',1)
- ->where('t.org_id',$this->orgId)
- ->where('t.todo_mode',3)
- ->count();
- $total +=$count;
- $count2 = Db::name('todo')
- ->alias('t')
- ->join('order_repair or','or.order_id=t.order_id')
- ->where('or.address_id',$v['id'])
- ->where($map)
- ->where('t.del',0)
- ->where('t.work_type_mode',1)
- ->where('t.org_id',$this->orgId)
- ->where('t.todo_mode',3)
- ->sum('wc_time');
- $total2 +=$count2;
- $list[$k]['title'] = $v['title'];
- $list[$k]['count'] = $count;
- $list[$k]['count2'] = round($count2/60,1);
- }
- $this->assign('list',$list);
- $this->assign('total',$total);
- $this->assign('total2',round($total2/60,1));
- $addrList = Db::name('address')
- ->field('id,title')
- ->where('org_id',$this->orgId)
- ->where('del',0)
- ->where('enable',1)
- ->where('','exp',Db::raw("FIND_IN_SET(1,types)"))
- ->select();
- $this->assign('addrList',$addrList);
- $this->assign('start',$start);
- $this->assign('end',$end);
- $this->assign('addrIds',$addrIds);
- $this->assign('addrIds2',!empty($addrIds)?explode(',',$addrIds):[]);
- return $this->fetch();
- }
- public function addrWorkHourExport(){
- $start = input('start',date('Y-m'));
- $end = input('end',date('Y-m'));
- if($start > $end){
- $this->error('开始时间不能大于结束时间');
- }
- $map[] = ['t.create_yyyymm','>=',date('Ym',strtotime($start))];
- $map[] = ['t.create_yyyymm','<=',date('Ym',strtotime($end))];
- $addrIds= input('addrIds','','trim');
- if($addrIds !=''){
- $where[] = ['id','in',$addrIds];
- }
- $where[] = ['org_id','=',$this->orgId];
- $addr = Db::name('address')
- ->field('id,title')
- ->where($where)
- ->where('org_id',$this->orgId)
- ->where('del',0)
- ->where('enable',1)
- ->where('','exp',Db::raw("FIND_IN_SET(1,types)"))
- ->select();
- $addr = $addr?$addr:[];
- $list = [];
- $total = $total2 = 0;
- foreach ($addr as $k=>$v){
- $count = Db::name('todo')
- ->alias('t')
- ->join('order_repair or','or.order_id=t.order_id')
- ->where('or.address_id',$v['id'])
- ->where($map)
- ->where('t.del',0)
- ->where('t.work_type_mode',1)
- ->where('t.org_id',$this->orgId)
- ->where('t.todo_mode',3)
- ->count();
- $total +=$count;
- $count2 = Db::name('todo')
- ->alias('t')
- ->join('order_repair or','or.order_id=t.order_id')
- ->where('or.address_id',$v['id'])
- ->where($map)
- ->where('t.del',0)
- ->where('t.work_type_mode',1)
- ->where('t.org_id',$this->orgId)
- ->where('t.todo_mode',3)
- ->sum('wc_time');
- $total2 +=$count2;
- $list[$k]['title'] = $v['title'];
- $list[$k]['count'] = $count;
- $list[$k]['count2'] = round($count2/60,1);
- }
- include_once env('root_path').'/extend/phpexcel/Classes/PHPExcel.php';
- //实例化PHPExcel类
- $objPHPExcel =new \PHPExcel();
- //激活当前的sheet表
- $objPHPExcel->setActiveSheetIndex(0);
- //设置表格头(即excel表格的第一行)
- $sheet = $objPHPExcel->setActiveSheetIndex(0);
- $arr = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N');
- foreach ($arr as $k=>$v) {
- $objPHPExcel->getActiveSheet()->getStyle($v)->getAlignment()->setWrapText(false);//换行
- $objPHPExcel->getActiveSheet()->getStyle($v.'1')->getFont()->setBold(true);
- $objPHPExcel->getActiveSheet()->getStyle($v.'1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle($v.'1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle($v)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle($v)->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
- $objPHPExcel->getActiveSheet()->getColumnDimension($v)->setWidth(18);
- }
- $sheet->setCellValueByColumnAndRow(0, 1, '地点');
- $sheet->setCellValueByColumnAndRow(1, 1, '工单数');
- $sheet->setCellValueByColumnAndRow(2, 1, '所需工时');
- foreach ($list as $k=>$v) {
- $sheet->setCellValueByColumnAndRow(0, $k + 2, $v['title']);
- $sheet->setCellValueByColumnAndRow(1, $k + 2, $v['count']);
- $sheet->setCellValueByColumnAndRow(2, $k + 2, $v['count2']);
- }
- $sheet->setCellValueByColumnAndRow(0, count($list)+3, '合计');
- $sheet->setCellValueByColumnAndRow(1, count($list)+3, '总工单数');
- $sheet->setCellValueByColumnAndRow(2, count($list)+3, $total);
- $sheet->setCellValueByColumnAndRow(1, count($list)+4, '总工时');
- $sheet->setCellValueByColumnAndRow(2, count($list)+4, round($total2/60,1));
- $sheet->setCellValueByColumnAndRow(1, count($list)+5, '平均工时');
- if($total > 0){
- $sheet->setCellValueByColumnAndRow(2, count($list)+5, round($total2/60/$total,1));
- }else{
- $sheet->setCellValueByColumnAndRow(2, count($list)+5, 0);
- }
- //设置保存的Excel表格名称
- $filename = '报修地点工时报表_' . date('YmdHis', time()) . '.xls';
- //设置当前激活的sheet表格名称
- $objPHPExcel->getActiveSheet()->setTitle('报修地点工时报表');
- //设置浏览器窗口下载表格
- 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 typeWorkHour(){
- $start = input('start',date('Y-m'));
- $end = input('end',date('Y-m'));
- if($start > $end){
- $this->error('开始时间不能大于结束时间');
- }
- $map[] = ['t.create_yyyymm','>=',date('Ym',strtotime($start))];
- $map[] = ['t.create_yyyymm','<=',date('Ym',strtotime($end))];
- $typeIds = input('typeIds');
- if($typeIds !=''){
- $where[] = ['id','in',$typeIds];
- }
- $addr = Db::name('address')
- ->field('id,title')
- ->where('org_id',$this->orgId)
- ->where('del',0)
- ->where('enable',1)
- ->where('','exp',Db::raw("FIND_IN_SET(1,types)"))
- ->select();
- $where[] = ['org_id','=',$this->orgId];
- $type = Db::name('order_type')
- ->where($where)
- ->where('parent_id',0)
- ->where('del',0)
- ->where('enable',1)
- ->select();
- $type = $type?$type:[];
- $newType = [];
- foreach ($type as $k=>$v){
- $a = [
- 'title'=>$v['title'],
- 'id'=>$v['id'],
- 'type'=>1
- ];
- $newType[]= $a;
- $b= [
- 'title'=>$v['title'].'工时',
- 'id'=>$v['id'],
- 'type'=>2
- ];
- $newType[]= $b;
- }
- $this->assign('newType',$newType);
- $lists = [];
- $total = $total2 = 0 ;
- foreach ($addr as $k=>$v){
- $a = [
- 'title' => $v['title'],
- ];
- foreach ($newType as $key=>$val){
- $subTypeId = Db::name('order_type')
- ->where('parent_id',$val['id'])
- ->where('del',0)
- ->where('enable',1)
- ->where('org_id',$this->orgId)
- ->column('id');
- if($val['type']==1){
- $count = Db::name('todo')
- ->alias('t')
- ->join('order_repair or','or.order_id=t.order_id')
- ->where('t.work_type_mode',1)
- ->where('t.del',0)
- ->where($map)
- ->where('t.todo_mode',3)
- ->where('or.address_id',$v['id'])
- ->whereIn('or.type_id',$subTypeId)
- ->count();
- $total +=$count;
- }elseif ($val['type']==2){
- $wx_time = Db::name('todo')
- ->alias('t')
- ->join('order_repair or','or.order_id=t.order_id')
- ->where('t.work_type_mode',1)
- ->where('t.del',0)
- ->where($map)
- ->where('t.todo_mode',3)
- ->where('or.address_id',$v['id'])
- ->whereIn('or.type_id',$subTypeId)
- ->sum('wc_time');
- $count = round($wx_time/60,1);
- $total2 +=$count;
- }
- $a['type'.$key] = $count;
- }
- $lists[] = $a;
- }
- $this->assign('lists',$lists);
- $this->assign('total',$total);
- $this->assign('total2',$total2);
- $this->assign('addr',$addr);
- $this->assign('type',$type);
- $typeList = Db::name('order_type')
- ->where('org_id',$this->orgId)
- ->where('parent_id',0)
- ->where('del',0)
- ->where('enable',1)
- ->select();
- $this->assign('typeList',$typeList);
- $this->assign('start',$start);
- $this->assign('end',$end);
- $this->assign('typeIds',$typeIds);
- $this->assign('typeIds2',!empty($typeIds)?explode(',',$typeIds):[]);
- return $this->fetch();
- }
- public function typeWorkHourExport(){
- $start = input('start',date('Y-m'));
- $end = input('end',date('Y-m'));
- if($start > $end){
- $this->error('开始时间不能大于结束时间');
- }
- $map[] = ['t.create_yyyymm','>=',date('Ym',strtotime($start))];
- $map[] = ['t.create_yyyymm','<=',date('Ym',strtotime($end))];
- $typeIds = input('typeIds');
- if($typeIds !=''){
- $where[] = ['id','in',$typeIds];
- }
- $addr = Db::name('address')
- ->field('id,title')
- ->where('org_id',$this->orgId)
- ->where('del',0)
- ->where('enable',1)
- ->where('','exp',Db::raw("FIND_IN_SET(1,types)"))
- ->select();
- $where[] = ['org_id','=',$this->orgId];
- $type = Db::name('order_type')
- ->where($where)
- ->where('parent_id',0)
- ->where('del',0)
- ->where('enable',1)
- ->select();
- $type = $type?$type:[];
- $newType = [];
- foreach ($type as $k=>$v){
- $a = [
- 'title'=>$v['title'],
- 'id'=>$v['id'],
- 'type'=>1
- ];
- $newType[]= $a;
- $b= [
- 'title'=>$v['title'].'工时',
- 'id'=>$v['id'],
- 'type'=>2
- ];
- $newType[]= $b;
- }
- $this->assign('newType',$newType);
- $lists = [];
- $total = $total2 = 0 ;
- foreach ($addr as $k=>$v){
- $a = [
- 'title' => $v['title'],
- ];
- foreach ($newType as $key=>$val){
- $subTypeId = Db::name('order_type')
- ->where('parent_id',$val['id'])
- ->where('del',0)
- ->where('enable',1)
- ->where('org_id',$this->orgId)
- ->column('id');
- if($val['type']==1){
- $count = Db::name('todo')
- ->alias('t')
- ->join('order_repair or','or.order_id=t.order_id')
- ->where('t.work_type_mode',1)
- ->where('t.del',0)
- ->where($map)
- ->where('t.todo_mode',3)
- ->where('or.address_id',$v['id'])
- ->whereIn('or.type_id',$subTypeId)
- ->count();
- $total +=$count;
- }elseif ($val['type']==2){
- $wx_time = Db::name('todo')
- ->alias('t')
- ->join('order_repair or','or.order_id=t.order_id')
- ->where('t.work_type_mode',1)
- ->where('t.del',0)
- ->where($map)
- ->where('t.todo_mode',3)
- ->where('or.address_id',$v['id'])
- ->whereIn('or.type_id',$subTypeId)
- ->sum('wc_time');
- $count = round($wx_time/60,1);
- $total2 +=$count;
- }
- $a['type'.$key] = $count;
- }
- $lists[] = $a;
- }
- include_once env('root_path').'/extend/phpexcel/Classes/PHPExcel.php';
- //实例化PHPExcel类
- $objPHPExcel =new \PHPExcel();
- //激活当前的sheet表
- $objPHPExcel->setActiveSheetIndex(0);
- //设置表格头(即excel表格的第一行)
- $sheet = $objPHPExcel->setActiveSheetIndex(0);
- $arr = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T');
- foreach ($arr as $k=>$v) {
- $objPHPExcel->getActiveSheet()->getStyle($v)->getAlignment()->setWrapText(false);//换行
- $objPHPExcel->getActiveSheet()->getStyle($v.'1')->getFont()->setBold(true);
- $objPHPExcel->getActiveSheet()->getStyle($v.'1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle($v.'1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle($v)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle($v)->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
- $objPHPExcel->getActiveSheet()->getColumnDimension($v)->setWidth(18);
- }
- $sheet->setCellValueByColumnAndRow(0, 1, '地点');
- foreach ($newType as $k=>$v){
- $sheet->setCellValueByColumnAndRow($k+1, 1, $v['title']);
- }
- foreach ($lists as $k=>$v) {
- $sheet->setCellValueByColumnAndRow(0, $k + 2, $v['title']);
- foreach ($newType as $kk=>$vv){
- $sheet->setCellValueByColumnAndRow($kk+1, $k + 2, $v['type'.$kk]);
- }
- }
- $sheet->setCellValueByColumnAndRow(0, count($lists)+3, '合计');
- $sheet->setCellValueByColumnAndRow(1, count($lists)+3, '总工单数');
- $sheet->setCellValueByColumnAndRow(2, count($lists)+3, $total);
- $sheet->setCellValueByColumnAndRow(1, count($lists)+4, '总工时');
- $sheet->setCellValueByColumnAndRow(2, count($lists)+4, $total2);
- $sheet->setCellValueByColumnAndRow(1, count($lists)+5, '平均工时');
- if($total > 0){
- $sheet->setCellValueByColumnAndRow(2, count($lists)+5, $total2/$total);
- }else{
- $sheet->setCellValueByColumnAndRow(2, count($lists)+5, 0);
- }
- //设置保存的Excel表格名称
- $filename = '报修类型工时报表_' . date('YmdHis', time()) . '.xls';
- //设置当前激活的sheet表格名称
- $objPHPExcel->getActiveSheet()->setTitle('报修类型工时报表');
- //设置浏览器窗口下载表格
- 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 consumables(){
- $month = input('month',date('Y-m'));
- // $curYear = date('Y',strtotime($month));
- // $curMonth = date('m',strtotime($month));
- $map[] = ['create_yyyymm','=',date('Ym',strtotime($month))];
- $goodsIds = input('goodsIds');
- if($goodsIds !=''){
- $where[] = ['id','in',$goodsIds];
- }
- $where[] = ['org_id','=',$this->orgId];
- $where[] = ['del','=',0];
- $where[] = ['enable','=',1];
- $mate = Db::name('mate_goods')
- ->field('id,title')
- ->where($where)
- ->select();
- $this->assign('mate',$mate);
- //获取某年某个月的总天数
- // $t = cal_days_in_month(CAL_GREGORIAN,$curMonth,$curYear);
- $t = date('t',strtotime($month));
- $sDay = strtotime($month.'-01');
- $arr = [];
- for ($i = 0;$i<$t;$i++){
- $arr[$i]['date'] = date('m-d',$sDay+$i*86400);
- $arr[$i]['ymd'] = date('Y-m-d',$sDay+$i*86400);
- }
- $lists = [];
- foreach ($arr as $k=>$v){
- $a = [
- 'title' => $v['date'],
- ];
- foreach ($mate as $key=>$val){
- $count = Db::name('todo_mate_item')
- ->where('items_id',$val['id'])
- ->where('create_time','>=',$v['ymd'].' 00:00:00')
- ->where('create_time','<=',$v['ymd'].' 23:59:59')
- ->sum('total');
- $a['type'.$val['id']] = $count;
- }
- $lists[] = $a;
- }
- $subtotal = []; $total = 0 ;
- foreach ($mate as $k=>$v){
- $c = Db::name('todo_mate_item')
- ->where('items_id',$v['id'])
- ->where('create_time','>=',$month.'-01 00:00:00')
- ->where('create_time','<=',$month.'-31 23:59:59')
- ->sum('total');
- $total +=$c;
- $subtotal[$k] = $c;
- }
- $this->assign('lists',$lists);
- $this->assign('subtotal',$subtotal);
- $this->assign('total',$total);
- $mateGoods = Db::name('mate_goods')
- ->field('id,title')
- ->where('org_id',$this->orgId)
- ->where('del',0)
- ->where('enable',1)
- ->select();
- $this->assign('mateGoods',$mateGoods);
- $this->assign('month',$month);
- $this->assign('goodsIds',$goodsIds);
- $this->assign('goodsIds2',!empty($goodsIds)?explode(',',$goodsIds):[]);
- return $this->fetch();
- }
- public function consumablesExport(){
- $month = input('month',date('Y-m'));
- // $curYear = date('Y',strtotime($month));
- // $curMonth = date('m',strtotime($month));
- $map[] = ['create_yyyymm','=',date('Ym',strtotime($month))];
- $goodsIds = input('goodsIds');
- if($goodsIds !=''){
- $where[] = ['id','in',$goodsIds];
- }
- $where[] = ['org_id','=',$this->orgId];
- $where[] = ['del','=',0];
- $where[] = ['enable','=',1];
- $mate = Db::name('mate_goods')
- ->field('id,title')
- ->where($where)
- ->select();
- // $this->assign('mate',$mate);
- //获取某年某个月的总天数
- // $t = cal_days_in_month(CAL_GREGORIAN,$curMonth,$curYear);
- $t = date('t',strtotime($month));
- $sDay = strtotime($month.'-01');
- $arr = [];
- for ($i = 0;$i<$t;$i++){
- $arr[$i]['date'] = date('m-d',$sDay+$i*86400);
- $arr[$i]['ymd'] = date('Y-m-d',$sDay+$i*86400);
- }
- $lists = [];
- foreach ($arr as $k=>$v){
- $a = [
- 'title' => $v['date'],
- ];
- foreach ($mate as $key=>$val){
- $count = Db::name('todo_mate_item')
- ->where('items_id',$val['id'])
- ->where('create_time','>=',$v['ymd'].' 00:00:00')
- ->where('create_time','<=',$v['ymd'].' 23:59:59')
- ->sum('total');
- $a['type'.$val['id']] = $count;
- }
- $lists[] = $a;
- }
- $subtotal = []; $total = 0 ;
- foreach ($mate as $k=>$v){
- $c = Db::name('todo_mate_item')
- ->where('items_id',$v['id'])
- ->where('create_time','>=',$month.'-01 00:00:00')
- ->where('create_time','<=',$month.'-31 23:59:59')
- ->sum('total');
- $total +=$c;
- $subtotal[$k] = $c;
- }
- include_once env('root_path').'/extend/phpexcel/Classes/PHPExcel.php';
- //实例化PHPExcel类
- $objPHPExcel =new \PHPExcel();
- //激活当前的sheet表
- $objPHPExcel->setActiveSheetIndex(0);
- //设置表格头(即excel表格的第一行)
- $sheet = $objPHPExcel->setActiveSheetIndex(0);
- $arr2 = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T');
- foreach ($arr2 as $k=>$v) {
- $objPHPExcel->getActiveSheet()->getStyle($v)->getAlignment()->setWrapText(false);//换行
- $objPHPExcel->getActiveSheet()->getStyle($v.'1')->getFont()->setBold(true);
- $objPHPExcel->getActiveSheet()->getStyle($v.'1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle($v.'1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle($v)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle($v)->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
- $objPHPExcel->getActiveSheet()->getColumnDimension($v)->setWidth(18);
- }
- $sheet->setCellValueByColumnAndRow(0, 1, '日期');
- foreach ($mate as $k=>$v){
- $sheet->setCellValueByColumnAndRow($k+1, 1, $v['title']);
- }
- foreach ($lists as $k=>$v) {
- $sheet->setCellValueByColumnAndRow(0, $k + 2, $v['title']);
- foreach ($mate as $kk=>$vv){
- $sheet->setCellValueByColumnAndRow($kk+1, $k + 2, $v['type'.$vv['id']]);
-
- }
- }
- $sheet->setCellValueByColumnAndRow(0, count($lists)+3, '小计');
- foreach ($subtotal as $k=>$v){
- $sheet->setCellValueByColumnAndRow($k+1, count($lists)+3, $v);
- }
- $sheet->setCellValueByColumnAndRow(0, count($lists)+4, '总计');
- $sheet->setCellValueByColumnAndRow(1, count($lists)+4, $total);
- //设置保存的Excel表格名称
- $filename = '报修耗材报表_' . date('YmdHis', time()) . '.xlsx';
- //设置当前激活的sheet表格名称
- $objPHPExcel->getActiveSheet()->setTitle('报修耗材报表');
- //设置浏览器窗口下载表格
- 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, 'Excel2007');
- //下载文件在浏览器窗口
- return $objWriter->save('php://output');
- }
- }
|