1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717 |
- <?php
- /**
- * Created by PhpStorm.
- * User: my
- * Date: 2021/4/12
- * Time: 16:04
- */
- namespace app\admin\controller;
- use think\App;
- use think\Db;
- class Statistics extends Auth{
- public function __construct(App $app) {
- parent::__construct($app);
- }
- /**
- * 订单统计
- *
- * @author wst
- * @date 2021/4/12 16:05
- */
- public function OrderTotal(){
- $data = (new Wyorders())->OrderTotal(cur_org_id());
- $this->assign('data',$data);
- $this->assign('meta_title','订单统计');
- return $this->fetch();
- }
- /**
- * 完成工时统计
- *
- * @author wst
- * @date 2021/4/12 16:05
- */
- public function duration(){
- $month = request()->get('month')?request()->get('month'):date('Y-m');
- $data = (new \app\model\Todo())->duration(cur_org_id(),$month);
- $this->assign('data',$data);
- $this->assign('month',$month);
- $this->assign('meta_title','完成工时统计');
- return $this->fetch();
- }
- /**
- * 巡更工作量统计
- *
- * @author wst
- * @date 2021/4/12 18:13
- */
- public function PatrolWork(){
- $data = (new \app\model\PatrolAddr())->PatrolWork(cur_org_id(),1);
- $this->assign('data',$data);
- $this->assign('meta_title','巡检巡查工作量统计');
- return $this->fetch();
- }
- /**
- * 设备台账工作量统计
- *
- * @author wst
- * @date 2021/4/12 18:13
- */
- public function DeviceWork(){
- $data = (new \app\common\model\Device())->DeviceWork(cur_org_id());
- $this->assign('data',$data);
- $this->assign('meta_title','设备维保工作量统计');
- return $this->fetch();
- }
- /**
- * 日常工作工作量统计
- *
- * @author wst
- * @date 2021/4/12 18:13
- */
- public function DailyWork(){
- $data = (new \app\common\model\Daily())->DailyWork(cur_org_id());
- $this->assign('data',$data);
- $this->assign('meta_title','日常工作量统计');
- return $this->fetch();
- }
- /**
- * 巡更人员工作量统计
- *
- * @author wst
- * @date 2021/4/12 18:13
- */
- public function WorkerPatrol(){
- $search['start'] = request()->get('start');
- $search['end'] = request()->get('end');
- if(empty($search['start'])){ // 未传时间默认近7天的
- $search['start'] = date('Y-m-d',time()-(6*24*60*60));
- $search['end'] = date('Y-m-d');
- }
- $data = (new \app\model\PatrolTask())->WorkerPatrol(cur_org_id(),$search,1);
- $this->assign('data',$data);
- $this->assign('month',$search);
- $this->assign('meta_title','巡检巡查人员工作量统计');
- return $this->fetch();
- }
- //预约统计
- public function ServiceCount(){
- $type=input('type');
- $start=input('start');
- $end=input('end');
- if($type == 1){
- $meta_title = '餐饮预约统计';
- }elseif ($type == 2){
- $meta_title = '美发预约统计';
- }elseif ($type == 3){
- $meta_title = '洗衣预约统计';
- }elseif ($type == 4){
- $meta_title = '医疗预约统计';
- }elseif ($type == 5){
- $meta_title = '活动室预约统计';
- }
- //获取服务id
- $serviceId = Db::name('service')->where('org_id',$this->org_id)->where('type',$type)->value('id');
- if(!$serviceId){
- $data = [];
- $this->assign('data',$data);
- }
- if(!$start && !$end){
- $end = date('Y-m-d H:i:s');
- $start = date('Y-m-d H:i:s',strtotime("$start -1 month"));
- }
- if($start >= $end){
- $this->error('开始时间不能大于结束时间');
- }
- if($type == 1 || $type == 2){
- $map[] = ['service_id','=',$serviceId];
- $cateList = Db::name('service_cate')->where($map)->order('id asc')->select()->toArray();
- $map[] = ['del','=',0];
- $itemList = Db::name('service_item')->where($map)->order('id asc')->select()->toArray();
- $this->assign('itemList',$itemList);
- $this->assign('cateList',$cateList);
- if($start && $end){
- $where[] = ['sb.create_time','>=',$start];
- $where[] = ['sb.create_time','<=',$end];
- }
- $where[] = ['sb.service_id','=',$serviceId];
- $where[] = ['sb.org_id','=',$this->org_id];
- $data = [];
- foreach ($itemList as $k=>$v){
- $data[$k]['title']= $v['title'];
- foreach ($cateList as $kk=>$vv){
- $bookList = Db::name('service_book')
- ->alias('sb')
- ->field('sb.*')
- ->join('service_book_cate sbc','sbc.service_book_id=sb.id')
- ->where('sb.service_item_id',$v['id'])
- ->where('sbc.service_cate_id',$vv['id'])
- ->where($where)
- ->select()
- ->toArray();
- $total = 0;
- foreach ($bookList as $kay=>$val){
- $total +=$val['nums'];
- }
- $data[$k]['list'][$kk] = $total;
- }
- }
- $count = [];
- foreach ($cateList as $k=>$v){
- $bookList = Db::name('service_book')
- ->alias('sb')
- ->field('sb.*')
- ->join('service_book_cate sbc','sbc.service_book_id=sb.id')
- ->where('sbc.service_cate_id',$v['id'])
- ->where($where)
- ->select()
- ->toArray();
- $countNum = 0;
- foreach ($bookList as $kk=>$vv){
- $countNum +=$vv['nums'];
- }
- $count[$k]['count'] = $countNum;
- }
- $this->assign('count',$count);
- }
- if($type == 3){
- $where[] = ['service_id','=',$serviceId];
- $where[] = ['org_id','=',$this->org_id];
- if($start && $end){
- $where[] = ['create_time','>=',$start];
- $where[] = ['create_time','<=',$end];
- }
- $data = [];
- $bookList = Db::name('service_book')->where($where)->select()->toArray();
- $total = 0;
- foreach ($bookList as $k=>$v){
- $total +=$v['nums'];
- }
- $data['k'] = 1;
- $data['count'] = $total;
- }
- if($type == 4 || $type == 5){
- $map[] = ['service_id','=',$serviceId];
- $map[] = ['del','=',0];
- $itemList = Db::name('service_item')->where($map)->order('id asc')->select()->toArray();
- $this->assign('itemList',$itemList);
- $where[] = ['create_time','>=',$start];
- $where[] = ['create_time','<=',$end];
- $where[] = ['service_id','=',$serviceId];
- $where[] = ['org_id','=',$this->org_id];
- $data = [];
- foreach ($itemList as $k=>$v){
- $data[$k]['id']= $v['id'];
- $data[$k]['title']= $v['title'];
- $bookList = Db::name('service_book')
- ->where('service_item_id',$v['id'])
- ->where($where)
- ->select()
- ->toArray();
- $total = 0;
- foreach ($bookList as $kay=>$val){
- $total +=$val['nums'];
- }
- $data[$k]['count'] = $total;
- }
- $countNum = 0;
- foreach ($data as $kay =>$val){
- $countNum += $val['count'];
- }
- $this->assign('countNum',$countNum);
- }
- $this->assign('start',$start);
- $this->assign('end',$end);
- $this->assign('data',$data);
- $this->assign('type',$type);
- $this->assign('meta_title',$meta_title);
- return $this->fetch();
- }
- public function serviceCountDetails(){
- $month = input('month');
- $itemId = input('itemId',0);
- $serviceId = input('serviceId',0);
- if(!$month && !$itemId){
- $this->error('参数错误');
- }
- $startMonth = $month.'-1 00:00:00';
- $endMonth = $month.'-31 23:59:59';
- $sWeek = date('Y-m-d', (time() - ((date('w') == 0 ? 7 : date('w')) - 1) * 24 * 3600));
- $eWeek = date('Y-m-d', (time() + (7 - (date('w') == 0 ? 7 : date('w'))) * 24 * 3600));
- $startWeek = $sWeek.' 00:00:00';
- $endWeek = $eWeek.' 23:59:59';
- $day = date('Y-m-d');
- $startDay= $day.' 00:00:00';
- $endDay= $day.' 23:59:59';
- $cateList = Db::name('service_cate')->where('service_id',$serviceId)->where('enable',1)->select()->toArray();
- foreach ($cateList as $k=>$v){
- $bookCate = Db::name('service_book_cate')
- ->where('service_book_cate_id',$v['id'])
- ->select()
- ->toArray();
- $ids = [];
- foreach ($bookCate as $kay=>$val){
- $ids[] = $val['service_book_id'];
- }
- $newIds = array_unique($ids);
- $bookList = Db::name('service_book')
- ->whereIn('id',$newIds)
- ->where('service_item_id',$itemId)
- ->where('service_id',$serviceId)
- ->where('org_id',$this->org_id)
- ->whereTime('create_time', 'between', [$startMonth, $endMonth])
- ->select()->toArray();
- $nums = 0;
- foreach ($bookList as $kk=>$vv){
- $nums +=$vv['nums'];
- }
- $bookList1 = Db::name('service_book')
- ->whereIn('id',$newIds)
- ->where('service_item_id',$itemId)
- ->where('service_id',$serviceId)
- ->where('org_id',$this->org_id)
- ->whereTime('create_time', 'between', [$startWeek, $endWeek])
- ->select()->toArray();
- $nums1 = 0;
- foreach ($bookList1 as $kk=>$vv){
- $nums1 +=$vv['nums'];
- }
- $bookList2 = Db::name('service_book')
- ->whereIn('id',$newIds)
- ->where('service_item_id',$itemId)
- ->where('service_id',$serviceId)
- ->where('org_id',$this->org_id)
- ->whereTime('create_time', 'between', [$startDay, $endDay])
- ->select()->toArray();
- $nums2 = 0;
- foreach ($bookList2 as $kk=>$vv){
- $nums2 +=$vv['nums'];
- }
- $cateList[$k]['count'] = $nums;
- $cateList[$k]['week'] = $nums1;
- $cateList[$k]['day'] = $nums2;
- }
- $this->assign('meta_title','餐厅统计');
- $this->assign('data',$cateList);
- return $this->fetch();
- }
- public function userWork()
- {
- if(request()->isAjax()){
- //分页参数
- $length = input('rows',10,'intval'); //每页条数
- $page = input('page',1,'intval'); //第几页
- $start = ($page - 1) * $length; //分页开始位置
- //排序
- $sortRow = input('sidx','id','trim'); //排序列
- $sort = input('sord','desc','trim'); //排序方式
- $order = $sortRow.' '.$sort;
- $title = input('title','','trim');
- if($title){
- $map[] = ['u.nickname','like','%'.$title.'%'];
- }
- $map= empty($map) ? true: $map;
- $ret = Db::name('user')
- ->alias('u')
- ->field('u.id,u.nickname')
- ->join('user_org uo', 'uo.user_id=u.id')
- ->where('uo.org_id', $this->org_id)
- ->where('u.enable', 1)
- ->where('u.del', 0)
- ->where($map)
- ->limit($start,$length)
- ->order($order)
- ->select()
- ->toArray();
- foreach ($ret as $k => $v) {
- //获取本月开始时间结束时间
- $smonth = date('Y-m') . '-1 00:00:00';
- $emonth = date('Y-m') . '-31 23:59:59';
- $where[] = ['update_time','>=',$smonth];
- $where[] = ['update_time','<=',$emonth];
- $userWork = Db::name('user_work')
- ->where('user_id', $v['id'])
- ->where($where)
- ->whereNotNull('start_time')
- ->whereNotNull('end_time')
- ->select()
- ->toArray();
- $num = 0;
- foreach ($userWork as $kk => $vv) {
- $stime = strtotime($vv['start_time']);
- $etime = strtotime($vv['end_time']);
- $newTime = $etime - $stime;
- $num += $newTime;
- }
- $ret[$k]['month'] = $num;
- //获取本周开始时间 结束时间
- $sweek = date('Y-m-d', (time() - ((date('w') == 0 ? 7 : date('w')) - 1) * 24 * 3600)) . ' 00:00:00';
- $eweek = date('Y-m-d', (time() + (7 - (date('w') == 0 ? 7 : date('w'))) * 24 * 3600)) . ' 23:59:59';
- $where2[] = ['update_time','>=',$sweek];
- $where2[] = ['update_time','<=',$eweek];
- $userWork2 = Db::name('user_work')
- ->where('user_id', $v['id'])
- ->where($where2)
- ->whereNotNull('start_time')
- ->whereNotNull('end_time')
- ->select()->toArray();
- $num2 = 0;
- foreach ($userWork2 as $kk => $vv) {
- $stime = strtotime($vv['start_time']);
- $etime = strtotime($vv['end_time']);
- $newTime = $etime - $stime;
- $num2 += $newTime;
- }
- $ret[$k]['week'] = $num2;
- //获取今天开始时间 结束时间
- $sday = date('Y-m-d') . ' 00:00:00';
- $eday = date('Y-m-d') . ' 23:59:59';
- $where3[] = ['update_time','>=',$sday];
- $where3[] = ['update_time','<=',$eday];
- $userWork3 = Db::name('user_work')
- ->where('user_id', $v['id'])
- ->where($where3)
- ->whereNotNull('start_time')
- ->whereNotNull('end_time')
- ->select()->toArray();
- $num3 = 0;
- foreach ($userWork3 as $kk => $vv) {
- $stime = strtotime($vv['start_time']);
- $etime = strtotime($vv['end_time']);
- $newTime = $etime - $stime;
- $num3 += $newTime;
- }
- $ret[$k]['day'] = $num3;
- }
- //数据返回
- $totalCount = Db::name('user')
- ->alias('u')
- ->field('u.id,u.nickname')
- ->join('user_org uo', 'uo.user_id=u.id')
- ->where('uo.org_id', $this->org_id)
- ->where('u.enable', 1)
- ->where('u.del', 0)
- ->where($map)
- ->count();;
- $totalPage = ceil($totalCount/$length);
- $result['page'] = $page;
- $result['total'] = $totalPage;
- $result['records'] = $totalCount;
- $result['rows'] = $ret;
- return json($result);
- }else{
- $this->assign('meta_title','用户工作时长统计');
- return $this->fetch();
- }
- }
- //耗材统计
- public function mateItems(){
- $month = input('month','','trim');
- if($month){
- $smonth = $month.'-01 :00:00:00';
- $emonth = $month.'-31 :23:59:59';
- $where[] = ['t.done_time','>=',$smonth];
- $where[] = ['t.done_time','<=',$emonth];
- }else{
- //本月
- $month = date('Y-m');
- $sdate = date('Y-m').'-01 :00:00:00';
- $edate = date('Y-m').'-31 :23:59:59';
- $where[] = ['t.done_time','>=',$sdate];
- $where[] = ['t.done_time','<=',$edate];
- //本周
- $sweek = date('Y-m-d', (time() - ((date('w') == 0 ? 7 : date('w')) - 1) * 24 * 3600)) . ' 00:00:00';
- $eweek = date('Y-m-d', (time() + (7 - (date('w') == 0 ? 7 : date('w'))) * 24 * 3600)) . ' 23:59:59';
- $where2[] = ['t.done_time','>=',$sweek];
- $where2[] = ['t.done_time','<=',$eweek];
- //当天
- $sday = date('Y-m-d') . ' 00:00:00';
- $eday = date('Y-m-d') . ' 23:59:59';
- $where3[] = ['t.done_time','>=',$sday];
- $where3[] = ['t.done_time','<=',$eday];
- }
- $map[] = ['enable','=',1];
- $map[] = ['org_id','=',$this->org_id];
- $map= empty($map) ? true: $map;
- $ret = Db::name('dep')->where($map)->select()->toArray();
- foreach ($ret as $k=>$v){
- //本月
- $todo = Db::name('todo')
- ->alias('t')
- ->field('t.id,t.to_user_id,t.mate_price')
- ->join('user_dep ud','ud.user_id=t.to_user_id')
- ->where('ud.dep_id',$v['id'])
- ->where('t.todo_mode',3)
- ->where('t.del',0)
- ->where('t.org_id',$this->org_id)
- ->where($where)
- ->select()
- ->toArray();
- $total = 0;
- foreach ($todo as $kk=>$vv){
- $total +=$vv['mate_price'];
- }
- $ret[$k]['month'] = $total;
- //本周
- $ret[$k]['week'] = 0;
- if(!empty($where2)){
- $todo = Db::name('todo')
- ->alias('t')
- ->field('t.id,t.to_user_id,t.mate_price')
- ->join('user_dep ud','ud.user_id=t.to_user_id')
- ->where('ud.dep_id',$v['id'])
- ->where('t.todo_mode',3)
- ->where('t.del',0)
- ->where('t.org_id',$this->org_id)
- ->where($where2)
- ->select()
- ->toArray();
- $total2 = 0;
- foreach ($todo as $kk=>$vv){
- $total2 +=$vv['mate_price'];
- }
- $ret[$k]['week'] = $total2;
- }
- $ret[$k]['day'] = 0;
- if(!empty($where3)){
- //当天
- $todo = Db::name('todo')
- ->alias('t')
- ->field('t.id,t.to_user_id,t.mate_price')
- ->join('user_dep ud','ud.user_id=t.to_user_id')
- ->where('ud.dep_id',$v['id'])
- ->where('t.todo_mode',3)
- ->where('t.del',0)
- ->where('t.org_id',$this->org_id)
- ->where($where3)
- ->select()
- ->toArray();
- $total3 = 0;
- foreach ($todo as $kk=>$vv){
- $total3 +=$vv['mate_price'];
- }
- $ret[$k]['day'] = $total3;
- }
- }
- $this->assign('data',$ret);
- $this->assign('month',$month);
- $this->assign('meta_title','耗材统计列表');
- return $this->fetch();
- }
- public function mateItemsDetails($id,$month){
- $sdate = $month.'-1 00:00:00';
- $edate = $month.'-31 23:59:59';
- $map[] = ['t.done_time','>=',$sdate];
- $map[] = ['t.done_time','<=',$edate];
- if(request()->isAjax()){
- //分页参数
- $length = input('rows',10,'intval'); //每页条数
- $page = input('page',1,'intval'); //第几页
- $start = ($page - 1) * $length; //分页开始位置
- //排序
- $sortRow = input('sidx','id','trim'); //排序列
- $sort = input('sord','desc','trim'); //排序方式
- $order = $sortRow.' '.$sort;
- $ret = Db::name('todo')
- ->alias('t')
- ->field('t.to_user_id,tmi.*')
- ->join('user_dep ud','ud.user_id=t.to_user_id')
- ->join('todo_mate_item tmi','tmi.todo_id=t.id')
- ->where('ud.dep_id',$id)
- ->where('t.todo_mode',3)
- ->where('t.del',0)
- ->where('t.org_id',$this->org_id)
- ->where($map)
- ->limit($start,$length)
- ->order($order)
- ->select()
- ->toArray();
- foreach ($ret as $k=>$v){
- $ret[$k]['title']=Db::name('mate_items')
- ->where('id',$v['items_id'])
- ->value('title');
- $ret[$k]['nickname']=Db::name('user')
- ->where('id',$v['to_user_id'])
- ->value('nickname');
- }
- //数据返回
- $totalCount = Db::name('todo')
- ->alias('t')
- ->field('tmi.*')
- ->join('user_dep ud','ud.user_id=t.to_user_id')
- ->join('todo_mate_item tmi','tmi.todo_id=t.id')
- ->where('ud.dep_id',$id)
- ->where('t.todo_mode',3)
- ->where('t.del',0)
- ->where('t.org_id',$this->org_id)
- ->where($map)
- ->count();
- $totalPage = ceil($totalCount/$length);
- $result['page'] = $page;
- $result['total'] = $totalPage;
- $result['records'] = $totalCount;
- $result['rows'] = $ret;
- return json($result);
- }else{
- $this->assign('meta_title','部门使用耗材列表');
- $this->assign('id',$id);
- $this->assign('month',$month);
- return $this->fetch();
- }
- }
- //报修科室使用材料统计
- public function cltj(){
- $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';
- $data = $this->cltjData($start1,$end1);
- $this->assign('data', $data);
- $this->assign('start', $start);
- $this->assign('end', $end);
- return $this->fetch();
- }
- public function cltjData($start,$end){
- $orgId = $this->orgId;
- $ret = Db::name('order_repair')
- ->alias('a')
- ->join('orders b','a.order_id=b.id')
- ->where('b.org_id',$orgId)
- ->where('a.address_id','>',0)
- ->field('a.address_id')
- ->distinct(true)
- ->select();
- $map = [];
- if(!empty($start)){
- $map[] = ['t.done_time','>=',$start];
- }
- if(!empty($end)){
- $map[] = ['t.done_time','<',$end];
- }
- $map[] = ['t.del','=',0];
- $map[] = ['t.org_id','=',$orgId];
- foreach ($ret as $k=>$v){
- $map1 = [];
- $todo = Db::name('todo_mate_item')
- ->alias('tmi')
- ->join('todo_mate tm','tm.id = tmi.todo_mate_id')
- ->join('todo t','tm.todo_id = t.id')
- ->join('orders o','o.id = t.order_id')
- ->join('order_repair r','o.id = r.order_id')
- ->where('r.address_id',$v['address_id'])
- ->where($map)
- ->sum('tmi.total_money');
- $num =$todo?round($todo,2):0;
- if($num<=0){
- unset($ret[$k]);
- }else{
- $ret[$k]['month'] = $num;
- if(!empty($start)){
- $map1[] = ['t.done_time','>=',$start];
- }
- if(!empty($end)){
- $map1[] = ['t.done_time','<',$end];
- }
- $map1[] = ['t.del','=',0];
- $map1[] = ['t.org_id','=',$orgId];
- $map1[] = ['r.address_id','=',$v['address_id']];
- $lists =Db::name('todo_mate_item')
- ->alias('tmi')
- ->join('todo_mate tm','tm.id = tmi.todo_mate_id')
- ->join('todo t','tm.todo_id = t.id')
- ->join('orders o','o.id = t.order_id')
- ->join('user u','u.id = t.to_user_id')
- ->join('order_repair r','o.id = r.order_id')
- ->join('mate_goods ma','ma.id = tmi.items_id')
- ->field('tmi.*,u.real_name,ma.title')
- ->where($map1)
- ->select();
- if(empty($lists)){
- unset($ret[$k]);
- continue;
- }
- $ret[$k]['rows'] = count($lists);
- $ret[$k]['items'] = $lists;
- $ret[$k]['title'] =Db::name('address')
- ->where('id',$v['address_id'])
- ->value('title');
- }
- }
- return $ret;
- }
- //耗材统计导出
- public function cltjExport()
- {
- set_time_limit(0);
- ini_set("memory_limit", "1024M");
- $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';
- $data = $this->cltjData($start1,$end1);
- $title = '报修科室使用材料统计报表';
- header("Content-type: application/vnd.ms-excel");
- header("Content-Type: application/force-download");
- header("Content-Disposition: attachment; filename=".$title.".xls");
- header('Expires:0');
- header('Pragma:public');
- $res = '';
- $res.='<table style="border-top: 1px solid #ddd;border-left: 1px solid #ddd;border-spacing: 0;">';
- $res.='<tr style="background: #ffffff;">';
- $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">科室名称</th>';
- $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">材料名称</th>';
- $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">数量</th>';
- $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">单价</th>';
- $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">总价</th>';
- $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">小计</th>';
- $res.='</tr>';
- foreach ($data as $k=>$v){
- $res.='<tr style="background: #ffffff;">';
- $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd" rowspan="'.$v['rows'].'">'.$v['title'].'</td>';
- $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v['items'][0]['title'].'</td>';
- $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v['items'][0]['total'].'</td>';
- $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v['items'][0]['money'].'</td>';
- $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v['items'][0]['total_money'].'</td>';
- $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd" rowspan="'.$v['rows'].'">'.$v['month'].'</td>';
- $res.='</tr>';
- if(count($v['items']) >=2){
- foreach ($v['items'] as $k1=>$v1){
- if($k1>0){
- $res.='<tr style="background: #ffffff;">';
- $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v1['title'].'</td>';
- $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v1['total'].'</td>';
- $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v1['money'].'</td>';
- $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v1['total_money'].'</td>';
- $res.='</tr>';
- }
- }
- }
- }
- echo $res;
- }
- //员工维修工作量
- public function finishTime(){
- $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';
- $data = $this->finishTimeData($start1,$end1);
- $this->assign('data', $data);
- $this->assign('start', $start);
- $this->assign('end', $end);
- return $this->fetch();
- }
- public function finishTimeData($start,$end) {
- $org_id = $this->orgId;
- $list = (new \app\common\model\WorkTypeMode())->getRolesUser(1,$this->orgId);
- $a = [];
- foreach ($list as $k=>$v){
- if($v['user']){
- foreach ($v['user'] as $k1=>$v1){
- $a[] = $v1;
- }
- }
- }
- $accepted = $nFinish=0;
- $list = $a;
- $map = [];
- if(!empty($start)){
- $map[] = ['todo.create_yyyymmdd','>=',date('Ymd',strtotime($start))];
- }
- if(!empty($end)){
- $map[] = ['todo.create_yyyymmdd','<=',date('Ymd',strtotime($end))];
- }
- foreach ($list as $k=>$v){
- $hs = 0;
- $orderList = Db::name('todo')
- ->alias('todo')
- ->where('todo.org_id',$org_id)
- ->where('todo.todo_mode',3)
- ->where('todo.to_user_id',$v['id'])
- ->where('todo.work_type_mode',1)
- ->where($map)
- ->select();
- foreach ($orderList as $k1=>$v1){
- $hs += strtotime($v1['done_time'])-strtotime($v1['create_time']);
- }
- $hszj = $hs >0?round($hs/3600,2):0;
- $list[$k]['hszj'] = $hszj;
- $wc_time = Db::name('todo')
- ->alias('todo')
- ->where('todo.org_id',$org_id)
- ->where('todo.todo_mode',3)
- ->where('todo.to_user_id',$v['id'])
- ->where('todo.work_type_mode',1)
- ->where($map)
- ->sum('todo.wc_time');
- $total = $wc_time?round($wc_time/3600,2):0;
- $list[$k]['total'] = $total;
- $nums = Db::name('todo')
- ->alias('todo')
- ->where('todo.org_id',$org_id)
- ->where('todo.todo_mode',3)
- ->where('todo.to_user_id',$v['id'])
- ->where('todo.work_type_mode',1)
- ->where($map)
- ->count();
- $list[$k]['num'] =$nums;
- if($nums>0){
- $avg = round($total/$nums,2);
- }else{
- $avg = 0;
- }
- $list[$k]['avg'] = $avg;
- $dep = Db::name('user_dep')
- ->alias('a')
- ->join('dep o','a.dep_id=o.id')
- ->where('a.user_id',$v['id'])
- ->field('o.title')
- ->find();
- $list[$k]['dep'] = $dep?$dep['title']:'';
- // 已接工
- $list[$k]['accepted'] = Db::name('todo')
- ->alias('todo')
- ->where('todo.org_id',$org_id)
- ->where('todo.todo_mode','>',1)
- ->where('todo.to_user_id',$v['id'])
- ->where('todo.work_type_mode',1)
- ->where($map)
- ->count();
- $accepted += $list[$k]['accepted'];
- // 未完工
- $list[$k]['nFinish'] = Db::name('todo')
- ->alias('todo')
- ->where('todo.org_id',$org_id)
- ->where('todo.todo_mode','in',[2,4,5,6,7,8])
- ->where('todo.to_user_id',$v['id'])
- ->where('todo.work_type_mode',1)
- ->where($map)
- ->count();
- $nFinish += $list[$k]['nFinish'];
- }
- return $list;
- }
- //excel导出
- public function finishTimeExport() {
- $meta_title = '维修人员工作时长';
- $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';
- $ret = $this->finishTimeData($start1,$end1);
- 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', '接工量')
- ->setCellValue('D1', '完工量')
- ->setCellValue('E1', '未完工量')
- ->setCellValue('F1', '维修耗时')
- ->setCellValue('G1', '工时总计');
- // 设置表格头水平居中
- $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('D1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('E1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('F1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('G1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('H1')->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)->getStyle('D')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('E')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('F')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('G')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('H')->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(50);
- $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]['real_name']);
- $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $ret[$i]['dep']);
- $objPHPExcel->getActiveSheet()->setCellValue('C' . ($i + 2), $ret[$i]['accepted']);
- $objPHPExcel->getActiveSheet()->setCellValue('D' . ($i + 2), $ret[$i]['num']);
- $objPHPExcel->getActiveSheet()->setCellValue('E' . ($i + 2), $ret[$i]['nFinish']);
- $objPHPExcel->getActiveSheet()->setCellValue('F' . ($i + 2), $ret[$i]['hszj']);
- $objPHPExcel->getActiveSheet()->setCellValue('G' . ($i + 2), $ret[$i]['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 bzwx(){
- $cur = date('Y-m-d');
- $start = input('start', date('Y-m-d', strtotime('' . $cur . ' -1 week')));
- $end = input('end', date('Y-m-d'));
- $title = input('title','');
- $start1 = $start . ' 00:00:00';
- $end1 = $end . ' 23:59:59';
- $data = $this->bzwxData($start1,$end1,$title);
- $this->assign('data', $data);
- $this->assign('start', $start);
- $this->assign('end', $end);
- $this->assign('title', $title);
- return $this->fetch();
- }
- public function bzwxData($start,$end,$title){
- $org_id = $this->orgId;
- $m = [];
- if(!empty($title)){
- $m[] =['title','like','%'.$title.'%'];
- }
- $list = Db::name('dep')
- ->where('del',0)
- ->where('enable',1)
- ->where('org_id',$org_id)
- ->select();
- $map = [];
- if(!empty($start)){
- $map[] = ['create_yyyymmdd','>=',date('Ymd',strtotime($start))];
- }
- if(!empty($end)){
- $map[] = ['create_yyyymmdd','<=',date('Ymd',strtotime($end))];
- }
- $accepted = $nFinish=0;
- foreach ($list as $k=>$v){
- $user = Db::name('user_dep')
- ->alias('b')
- ->join('user a','b.user_id=a.id')
- ->where('a.del',0)
- ->where('a.enable',1)
- ->where('b.dep_id',$v['id'])
- ->field('b.user_id')
- ->select();
- $ids = $user?array_column($user,'user_id'):[];
- $list[$k]['num'] =0;
- $list[$k]['accepted'] =0;
- $list[$k]['nFinish'] =0;
- if(!empty($ids)){
- $nums =Db::name('todo')
- ->where('org_id',$org_id)
- ->where('to_user_id','in',$ids)
- ->where('work_type_mode',1)
- ->where('todo_mode','in',[2,3,9])
- ->where($map)
- ->count();
- $list[$k]['num'] =$nums;
- // 已接工
- $list[$k]['accepted'] = Db::name('todo')
- ->where('org_id',$org_id)
- ->where('to_user_id','in',$ids)
- ->where('work_type_mode',1)
- ->where('todo_mode','>',1)
- ->where($map)
- ->count();
- $accepted += $list[$k]['accepted'];
- // 未完工
- $list[$k]['nFinish'] = Db::name('todo')
- ->where('org_id',$org_id)
- ->where('to_user_id','in',$ids)
- ->where('work_type_mode',1)
- ->where('todo_mode','in',[2,4,5,6,7])
- ->where($map)
- ->count();
- $nFinish += $list[$k]['nFinish'];
- if($nums==0 && $list[$k]['accepted']==0 && $list[$k]['nFinish']==0){
- unset($list[$k]);
- }
- }else{
- unset($list[$k]);
- }
- }
- return $list;
- }
- //excel导出
- public function bzwxExport() {
- $meta_title = '班组维修工作量统计表';
- $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';
- $title = input('title','');
- $ret = $this->bzwxData($start1,$end1,$title);
- 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', '完工量')
- ->setCellValue('D1', '未完工量');
- // 设置表格头水平居中
- $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('D1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('E1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('F1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('G1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('H1')->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)->getStyle('D')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('E')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('F')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('G')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('H')->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(50);
- $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]['title']);
- $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $ret[$i]['accepted']);
- $objPHPExcel->getActiveSheet()->setCellValue('C' . ($i + 2), $ret[$i]['num']);
- $objPHPExcel->getActiveSheet()->setCellValue('D' . ($i + 2), $ret[$i]['nFinish']);
- }
- //设置保存的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 bxks(){
- $cur = date('Y-m-d');
- $start = input('start', date('Y-m-d', strtotime('' . $cur . ' -1 week')));
- $end = input('end', date('Y-m-d'));
- $title = input('title','');
- $start1 = $start . ' 00:00:00';
- $end1 = $end . ' 23:59:59';
- $data = $this->bxksData($start1,$end1,$title);
- $this->assign('data', $data);
- $this->assign('start', $start);
- $this->assign('end', $end);
- $this->assign('title', $title);
- return $this->fetch();
- }
- public function bxksData($start,$end,$title){
- $org_id = $this->orgId;
- $map = [];
- if(!empty($title)){
- $ks = Db::name('address')
- ->where('org_id',$org_id)
- ->where('del',0)
- ->where('enable',1)
- ->where('title','like','%'.$title.'%')
- ->select();
- if(empty($ks)){
- $map[] = ['a.address_id','=',-1];
- }else{
- $map[] = ['a.address_id','in',array_column($ks,'id')];
- }
- }
- $ret =Db::name('order_repair')
- ->alias('a')
- ->join('orders b','a.order_id=b.id')
- ->where('b.org_id',$org_id)
- ->where('a.address_id','>',0)
- ->where($map)
- ->field('a.address_id')
- ->distinct(true)
- ->select();
- if(!empty($start)){
- $map1[] = ['t.create_yyyymmdd','>=',date('Ymd',strtotime($start))];
- }
- if(!empty($end)){
- $map1[] = ['t.create_yyyymmdd','<=',date('Ymd',strtotime($end))];
- }
- $map1[] = ['t.del','=',0];
- $map1[] = ['t.org_id','=',$org_id];
- foreach ($ret as $k=>$v){
- $num = Db::name('order_repair')
- ->alias('a')
- ->join('orders t','a.order_id = t.id')
- ->where('a.address_id',$v['address_id'])
- ->where($map1)
- ->count();
- $ret[$k]['num'] = $num;
- $ret[$k]['title'] = Db::name('address')
- ->where('id',$v['address_id'])
- ->value('title');
- }
- return $ret;
- }
- //excel导出
- public function bxksExport() {
- $meta_title = '报修科室统计';
- $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';
- $title = input('title','');
- $ret = $this->bxksData($start1,$end1,$title);
- 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', '报修订单数量');
- // 设置表格头水平居中
- $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('D1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('E1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('F1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('G1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('H1')->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)->getStyle('D')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('E')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('F')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('G')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('H')->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(50);
- $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]['title']);
- $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $ret[$i]['num']);
- }
- //设置保存的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 grcltj(){
- $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';
- $data = $this->grcltjData($start1,$end1);
- $this->assign('data', $data);
- $this->assign('start', $start);
- $this->assign('end', $end);
- return $this->fetch();
- }
- public function grcltjData($start,$end){
- $orgId = $this->orgId;
- $ret = Db::name('todo_mate')
- ->alias('a')
- ->join('todo b','a.todo_id=b.id')
- ->field('a.*')
- ->where('a.org_id',$orgId)
- ->where('a.type',0)
- ->where('b.del',0)
- ->group('a.user_id')
- ->select();
- $map = [];
- if(!empty($start)){
- $map[] = ['tmi.create_time','>=',$start];
- }
- if(!empty($end)){
- $map[] = ['tmi.create_time','<',$end];
- }
- $map[] = ['t.del','=',0];
- $map[] = ['tm.org_id','=',$orgId];
- foreach ($ret as $k=>$v){
- $map1 = [];
- $todo = Db::name('todo_mate_item')
- ->alias('tmi')
- ->join('todo_mate tm','tm.id = tmi.todo_mate_id')
- ->join('todo t','tm.todo_id = t.id')
- ->join('orders o','o.id = t.order_id')
- ->where('tmi.user_id',$v['user_id'])
- ->where($map)
- ->sum('tmi.total_money');
- $num =$todo?round($todo,2):0;
- if($num<=0){
- unset($ret[$k]);
- }else{
- $ret[$k]['month'] = $num;
- if(!empty($start)){
- $map1[] = ['t.create_time','>=',$start];
- }
- if(!empty($end)){
- $map1[] = ['t.create_time','<',$end];
- }
- $map1[] = ['t.del','=',0];
- $map1[] = ['t.org_id','=',$orgId];
- $map1[] = ['tm.user_id','=',$v['user_id']];
- $lists =Db::name('todo_mate_item')
- ->alias('tmi')
- ->join('todo_mate tm','tm.id = tmi.todo_mate_id')
- ->join('todo t','tm.todo_id = t.id')
- ->join('orders o','o.id = t.order_id')
- ->join('user u','u.id = t.to_user_id')
- ->join('mate_goods ma','ma.id = tmi.items_id')
- ->field('tmi.*,u.real_name,ma.title')
- ->where($map1)
- ->select();
- if(empty($lists)){
- unset($ret[$k]);
- continue;
- }
- $ret[$k]['rows'] = count($lists);
- $ret[$k]['items'] = $lists;
- $ret[$k]['real_name'] = Db::name('user')
- ->where('id',$v['user_id'])
- ->value('real_name');
- }
- }
- return $ret;
- }
- public function grcltjExport()
- {
- set_time_limit(0);
- ini_set("memory_limit", "1024M");
- $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';
- $data = $this->grcltjData($start1,$end1);
- $title = '工人耗材用量统计';
- header("Content-type: application/vnd.ms-excel");
- header("Content-Type: application/force-download");
- header("Content-Disposition: attachment; filename=".$title.".xls");
- header('Expires:0');
- header('Pragma:public');
- $res = '';
- $res.='<table style="border-top: 1px solid #ddd;border-left: 1px solid #ddd;border-spacing: 0;">';
- $res.='<tr style="background: #ffffff;">';
- $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">工人名称</th>';
- $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">材料名称</th>';
- $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">数量</th>';
- $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">单价</th>';
- $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">总价</th>';
- $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">使用时间</th>';
- $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">小计</th>';
- $res.='</tr>';
- foreach ($data as $k=>$v){
- $res.='<tr style="background: #ffffff;">';
- $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd" rowspan="'.$v['rows'].'">'.$v['real_name'].'</td>';
- $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v['items'][0]['title'].'</td>';
- $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v['items'][0]['total'].'</td>';
- $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v['items'][0]['money'].'</td>';
- $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v['items'][0]['total_money'].'</td>';
- $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v['items'][0]['create_time'].'</td>';
- $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd" rowspan="'.$v['rows'].'">'.$v['month'].'</td>';
- $res.='</tr>';
- if(count($v['items']) >=2){
- foreach ($v['items'] as $k1=>$v1){
- if($k1>0){
- $res.='<tr style="background: #ffffff;">';
- $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v1['title'].'</td>';
- $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v1['total'].'</td>';
- $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v1['money'].'</td>';
- $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v1['total_money'].'</td>';
- $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v1['create_time'].'</td>';
- $res.='</tr>';
- }
- }
- }
- }
- echo $res;
- }
- public function bxrcltj(){
- $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';
- $data = $this->bxrcltjData($start1,$end1);
- $this->assign('data', $data);
- $this->assign('start', $start);
- $this->assign('end', $end);
- return $this->fetch();
- }
- public function bxrcltjData($start,$end){
- $orgId = $this->orgId;
- $ret = Db::name('orders')
- ->alias('a')
- ->where('org_id',$orgId)
- ->where('del',0)
- ->where('finish_time','>=',$start)
- ->where('finish_time','<',$end)
- ->group('user_id')
- ->select();
- $map = [];
- if(!empty($start)){
- $map[] = ['t.done_time','>=',$start];
- }
- if(!empty($end)){
- $map[] = ['t.done_time','<',$end];
- }
- $map[] = ['t.del','=',0];
- $map[] = ['t.org_id','=',$orgId];
- foreach ($ret as $k=>$v){
- $map1 = [];
- $todo = Db::name('todo_mate_item')
- ->alias('tmi')
- ->join('todo_mate tm','tm.id = tmi.todo_mate_id')
- ->join('todo t','tm.todo_id = t.id')
- ->join('orders o','o.id = t.order_id')
- ->where('o.user_id',$v['user_id'])
- ->where($map)
- ->sum('tmi.total_money');
- $num =$todo?round($todo,2):0;
- if($num<=0){
- unset($ret[$k]);
- }else{
- $ret[$k]['month'] = $num;
- if(!empty($start)){
- $map1[] = ['t.done_time','>=',$start];
- }
- if(!empty($end)){
- $map1[] = ['t.done_time','<',$end];
- }
- $map1[] = ['t.del','=',0];
- $map1[] = ['t.org_id','=',$orgId];
- $map1[] = ['o.user_id','=',$v['user_id']];
- $lists =Db::name('todo_mate_item')
- ->alias('tmi')
- ->join('todo_mate tm','tm.id = tmi.todo_mate_id')
- ->join('todo t','tm.todo_id = t.id')
- ->join('orders o','o.id = t.order_id')
- ->join('user u','u.id = t.to_user_id')
- ->join('mate_goods ma','ma.id = tmi.items_id')
- ->field('tmi.*,u.real_name,ma.title')
- ->where($map1)
- ->select();
- if(empty($lists)){
- unset($ret[$k]);
- continue;
- }
- $ret[$k]['rows'] = count($lists);
- $ret[$k]['items'] = $lists;
- $ret[$k]['title'] =Db::name('user')
- ->where('id',$v['user_id'])
- ->value('real_name');
- }
- }
- return $ret;
- }
- //耗材统计导出
- public function bxrcltjExport()
- {
- set_time_limit(0);
- ini_set("memory_limit", "1024M");
- $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';
- $data = $this->bxrcltjData($start1,$end1);
- $title = '报修人耗材统计报表';
- header("Content-type: application/vnd.ms-excel");
- header("Content-Type: application/force-download");
- header("Content-Disposition: attachment; filename=".$title.".xls");
- header('Expires:0');
- header('Pragma:public');
- $res = '';
- $res.='<table style="border-top: 1px solid #ddd;border-left: 1px solid #ddd;border-spacing: 0;">';
- $res.='<tr style="background: #ffffff;">';
- $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">报修人</th>';
- $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">材料名称</th>';
- $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">数量</th>';
- $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">单价</th>';
- $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">使用人</th>';
- $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">使用时间</th>';
- $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">总价</th>';
- $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">小计</th>';
- $res.='</tr>';
- foreach ($data as $k=>$v){
- $res.='<tr style="background: #ffffff;">';
- $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd" rowspan="'.$v['rows'].'">'.$v['title'].'</td>';
- $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v['items'][0]['title'].'</td>';
- $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v['items'][0]['total'].'</td>';
- $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v['items'][0]['money'].'</td>';
- $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v['items'][0]['real_name'].'</td>';
- $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v['items'][0]['create_time'].'</td>';
- $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v['items'][0]['total_money'].'</td>';
- $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd" rowspan="'.$v['rows'].'">'.$v['month'].'</td>';
- $res.='</tr>';
- if(count($v['items']) >=2){
- foreach ($v['items'] as $k1=>$v1){
- if($k1>0){
- $res.='<tr style="background: #ffffff;">';
- $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v1['title'].'</td>';
- $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v1['total'].'</td>';
- $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v1['money'].'</td>';
- $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v1['real_name'].'</td>';
- $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v1['create_time'].'</td>';
- $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v1['total_money'].'</td>';
- $res.='</tr>';
- }
- }
- }
- }
- echo $res;
- }
- public function wlflcltj(){
- $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';
- $data = $this->wlflcltjData($start1,$end1);
- $this->assign('data', $data);
- $this->assign('start', $start);
- $this->assign('end', $end);
- return $this->fetch();
- }
- public function wlflcltjData($start,$end){
- $orgId = $this->orgId;
- $ret = Db::name('mate_cate')
- ->where('org_id',$orgId)
- ->where('del',0)
- ->where('enable',1)
- ->select();
- $map = [];
- if(!empty($start)){
- $map[] = ['t.done_time','>=',$start];
- }
- if(!empty($end)){
- $map[] = ['t.done_time','<',$end];
- }
- $map[] = ['t.del','=',0];
- $map[] = ['t.org_id','=',$orgId];
- foreach ($ret as $k=>$v){
- $map1 = [];
- $todo = Db::name('todo_mate_item')
- ->alias('tmi')
- ->join('todo_mate tm','tm.id = tmi.todo_mate_id')
- ->join('mate_goods mg','tmi.items_id=mg.id')
- ->join('mate_cate mc','mg.cate_id = mc.id')
- ->join('todo t','tm.todo_id = t.id')
- ->join('orders o','o.id = t.order_id')
- ->where('mc.id',$v['id'])
- ->where($map)
- ->sum('tmi.total_money');
- $num =$todo?round($todo,2):0;
- if($num<=0){
- unset($ret[$k]);
- }else{
- $ret[$k]['month'] = $num;
- if(!empty($start)){
- $map1[] = ['t.done_time','>=',$start];
- }
- if(!empty($end)){
- $map1[] = ['t.done_time','<',$end];
- }
- $map1[] = ['t.del','=',0];
- $map1[] = ['t.org_id','=',$orgId];
- $map1[] = ['mc.id','=',$v['id']];
- $lists =Db::name('todo_mate_item')
- ->alias('tmi')
- ->join('todo_mate tm','tm.id = tmi.todo_mate_id')
- ->join('mate_goods mg','tmi.items_id=mg.id')
- ->join('mate_cate mc','mg.cate_id = mc.id')
- ->join('todo t','tm.todo_id = t.id')
- ->join('orders o','o.id = t.order_id')
- ->join('user u','u.id = t.to_user_id')
- ->join('mate_goods ma','ma.id = tmi.items_id')
- ->field('tmi.*,u.real_name,ma.title')
- ->where($map1)
- ->select();
- if(empty($lists)){
- unset($ret[$k]);
- continue;
- }
- $ret[$k]['rows'] = count($lists);
- $ret[$k]['items'] = $lists;
- }
- }
- return $ret;
- }
- //耗材统计导出
- public function wlflcltjExport()
- {
- set_time_limit(0);
- ini_set("memory_limit", "1024M");
- $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';
- $data = $this->wlflcltjData($start1,$end1);
- $title = '物料分类统计报表';
- header("Content-type: application/vnd.ms-excel");
- header("Content-Type: application/force-download");
- header("Content-Disposition: attachment; filename=".$title.".xls");
- header('Expires:0');
- header('Pragma:public');
- $res = '';
- $res.='<table style="border-top: 1px solid #ddd;border-left: 1px solid #ddd;border-spacing: 0;">';
- $res.='<tr style="background: #ffffff;">';
- $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">分类名称</th>';
- $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">材料名称</th>';
- $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">数量</th>';
- $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">单价</th>';
- $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">使用人</th>';
- $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">使用时间</th>';
- $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">总价</th>';
- $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">小计</th>';
- $res.='</tr>';
- foreach ($data as $k=>$v){
- $res.='<tr style="background: #ffffff;">';
- $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd" rowspan="'.$v['rows'].'">'.$v['title'].'</td>';
- $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v['items'][0]['title'].'</td>';
- $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v['items'][0]['total'].'</td>';
- $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v['items'][0]['money'].'</td>';
- $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v['items'][0]['real_name'].'</td>';
- $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v['items'][0]['create_time'].'</td>';
- $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v['items'][0]['total_money'].'</td>';
- $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd" rowspan="'.$v['rows'].'">'.$v['month'].'</td>';
- $res.='</tr>';
- if(count($v['items']) >=2){
- foreach ($v['items'] as $k1=>$v1){
- if($k1>0){
- $res.='<tr style="background: #ffffff;">';
- $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v1['title'].'</td>';
- $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v1['total'].'</td>';
- $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v1['money'].'</td>';
- $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v1['real_name'].'</td>';
- $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v1['create_time'].'</td>';
- $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v1['total_money'].'</td>';
- $res.='</tr>';
- }
- }
- }
- }
- echo $res;
- }
- }
|