| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255 | <?phpnamespace app\h5\controller;use app\common\model\WorkTypeMode;use app\hander\HelpHander;use think\App;use think\Controller;use think\Db;use think\helper\Time;class Statistics extends Controller{    private $orgId = 0;    public function initialize()    {        parent::initialize();        $this->orgId = input('orgId/d',0);//        halt($this->orgId);        if($this->orgId <= 0){            $this->redirect(url('index/errorPage'));        }    }    protected function checkToken(){        $token = input('token','','trim');        if(!$token){            if(request()->isAjax()){                $this->error('登录信息失效');            }else{                $this->redirect(url('index/errorPage'));            }        }        $user = Db::name('token')->where('token',$token)->find();        if(!$user) {            if(request()->isAjax()){                $this->error('登录信息失效');            }else{                $this->redirect(url('index/errorPage'));            }        }        return $user['user_id'];    }    public function orders(){        $type = input('type/d',1);        $mode = input('mode/d',1);        if($mode == 1){            $list = [                ['id' => [5],'type'=>'已完成订单'],                ['id' => [1],'type'=>'待处理订单'],                ['id' => [4],'type'=>'已派发订单'],                ['id' => [2,3],'type'=>'已取消订单'],                ['id' => [6],'type'=>'已评价订单'],                ['id' => [-1],'type'=>'挂起订单'],            ];        }else{            $list = [                ['id' => [5],'type'=>'已完成订单'],                ['id' => [1],'type'=>'待处理订单'],                ['id' => [4],'type'=>'已派发订单'],                ['id' => [2,3],'type'=>'已取消订单'],                ['id' => [6],'type'=>'已评价订单'],            ];        }        $map[] = ['del','=',0];        $map[] = ['org_id','=',$this->orgId];        $map[] = ['work_type_mode','=',$mode];        if($type == 1){ //日统计            $map[] = ['create_yyyymmdd','=',date('Ymd')];        }else if($type == 2){ //月统计            $map[] = ['create_yyyymm','=',date('Ym')];        }        $allcount = 0;        if($mode == 1){            foreach ($list as $k=>$v){                if(in_array(4,$v['id'])){                    $a1 = 0;                    $order =  Db::name('orders')->where($map)->where('order_mode','in',$v['id'])->select();                    foreach ($order as $kk=>$vv){                        $todo = Db::name('todo')->where('order_id',$vv['id'])->where('pause',1)->where('todo_mode',2)->where('del',0)->find();                        if($todo){                            $a1 +=1;                        }                    }                    $cost = count($order)-$a1;                }elseif(in_array(-1,$v['id'])){                    $a2 = 0;                    $order =  Db::name('orders')->where($map)->where('order_mode',4)->select();                    foreach ($order as $kk=>$vv){                        $todo = Db::name('todo')->where('order_id',$vv['id'])->where('del',0)->where('todo_mode',2)->where('pause',1)->find();                        if($todo){                            $a2 +=1;                        }                    }                    $cost = $a2;                }else{                    $cost =  Db::name('orders')->where($map)->where('order_mode','in',$v['id'])->count();                }                $list[$k]['cost'] = $cost;                $list[$k]['a'] = '1';                $allcount += $list[$k]['cost'];            }        }else{            foreach ($list as $k=>$v){                $list[$k]['cost'] =  Db::name('orders')->where($map)->where('order_mode','in',$v['id'])->count();                $list[$k]['a'] = '1';                $allcount += $list[$k]['cost'];            }        }        $this->assign('list',$list);        $this->assign('allcount',$allcount);        $this->assign('orgId',$this->orgId);        $this->assign('type',$type);        $this->assign('mode',$mode);        return $this->fetch();    }    public function users() {        $lists = Db::name('roles')->where('id','in',(new WorkTypeMode())->workerRoles)->field('id,name')->select();        $lists = $lists?$lists:[];        $allcount = 0;        foreach ($lists as $k=>$v){            $lists[$k]['color'] = '#325699';            $roleIds = model('Roles')->getRoleIds($v['id'],$this->orgId);            $map = [];            $map[] = ['u.del','=',0];            $map[] = ['u.enable','=',1];            if($roleIds){                $map[] = ['ur.roles_id','in',$roleIds];            }else{                $map[] = ['ur.roles_id','=',-1];            }            $count = Db::name('user_roles')                ->alias('ur')                ->join('user u','u.id = ur.user_id')                ->where($map)                ->count();            $lists[$k]['cost'] = $count;            $lists[$k]['a'] = '1';            $allcount += $count;        }        $this->assign('list',$lists);        $this->assign('orgId',$this->orgId);        $this->assign('allcount',$allcount);        return $this->fetch();    }    public function comment() {        $type = input('type/d',1);        if($type == 1){ //日统计            $map[] =['c.create_yyyymmdd','=',date('Ymd')];        }else if($type == 2){ //月统计            $map[] =['c.create_yyyymm','=',date('Ym')];        }        $map[] = ['c.org_id','=',$this->orgId];        $tlist = [            ['work_type_mode'=> 0,'name'=>'一键呼叫'],            ['work_type_mode'=> 1,'name'=>'报修'],            ['work_type_mode'=> 2,'name'=>'保洁'],            ['work_type_mode'=> 3,'name'=>'运送'],            ['work_type_mode'=> 4,'name'=>'安保'],            ['work_type_mode'=> 15,'name'=>'品质整改']        ];        $list = [];        foreach ($tlist as $k=>$v){            $ss = Db::name('comment')                ->alias('c')                ->join('orders o','o.id = c.from_id')                ->where('c.type',$v['work_type_mode'])                ->where('o.del',0)                ->where($map)                ->field('count(*) as count,sum(score) as score,c.type')                ->find();            $list[] = array(                'year' => $v['name'],                'sales' => $ss&&$ss['count']>0?round($ss['score']/$ss['count'],1):0,                'count' => $ss['count'],                'work_type_mode'=>$ss['type']?$ss['type']:$v['work_type_mode'],            );        }        $this->assign('list',$list);        $this->assign('orgId',$this->orgId);        $this->assign('type',$type);        return $this->fetch();    }    public function daily() {        $type = input('type/d',0);        $map[] = ['org_id','=',$this->orgId];        if($type == 0){ //日统计            $map[] = ['create_yyyymmdd','=',date('Ymd')];        } else if($type == 1){ //月统计            $map[] = ['create_yyyymm','=',date('Ym')];        }        $alladdr = Db::name('daily_record')->where($map)->group('daily_id')->count();        $allcount = Db::name('daily_record')->where($map)->count();        $this->assign('allcount',$allcount);        $this->assign('alladdr',$alladdr);        $this->assign('orgId',$this->orgId);        $this->assign('type',$type);        return $this->fetch();    }    public function device() {        $type = input('type/d',0);        $map[] = ['org_id','=',$this->orgId];        if($type == 0){ //日统计            $map[] = ['create_yyyymmdd','=',date('Ymd')];        } else if($type == 1){ //月统计            $map[] = ['create_yyyymm','=',date('Ym')];        }        $device = Db::name('device_record')->where($map)->group('device_id')->count();        $allcount = Db::name('device_record')->where($map)->count();        $this->assign('allcount',$allcount);        $this->assign('device',$device);        $this->assign('orgId',$this->orgId);        $this->assign('type',$type);        return $this->fetch();    }    public function patrol() {        $type = input('type/d',0);        $mode = input('mode/d',1);        $map[] = ['org_id','=',$this->orgId];        $map[] = ['del','=',0];        $map[] = ['patrol_mode','=',$mode];        if($type == 0){ //日统计            $map[] = ['create_yyyymmdd','=',date('Ymd')];        } else if($type == 1){ //月统计            $map[] = ['create_yyyymm','=',date('Ym')];        }        $tt = 3;        if($mode == 2){            $tt = 4;        }else if($mode == 3){            $tt = 5;        }else if($mode == 4){            $tt = 6;        }        $bluetooth = model('Address')->getListByTypeCount($tt,$this->orgId);        $complete = Db::name('patrol_task')->where($map)->where('status', 2)->count();        $incomplete = Db::name('patrol_task')->where($map)->where('status', 3)->count();        $allcount = Db::name('patrol_task')->where($map)->count();        $ratio = 0;        if($allcount > 0) {            $ratio = round($complete / $allcount*100,2);        }        $mode_name = Db::name('patrol_mode')->where('id', $mode)->field('name')->find();        $this->assign('allcount',$allcount);        $this->assign('bluetooth',$bluetooth);        $this->assign('complete',$complete);        $this->assign('incomplete',$incomplete);        $this->assign('orgId',$this->orgId);        $this->assign('type',$type);        $this->assign('ratio',$ratio);        $this->assign('mode',$mode);        $this->assign('mode_name',$mode_name);        return $this->fetch();    }    public function ordersList(){        $page = input('page',1);        $size = input('size',20);        $type = input('type',-1);//订单状态        $mode = input('mode',0);//订单类型        $day = input('day',0);//日,月,总计        if(!$type){            $where[]=['order_mode','in',[-1]];        }        //全部订单        if($type == -1){            $where[]=['order_mode','in',[1,2,3,4,5,6]];        }        //已完成订单        if($type == 0){            $where[]=['order_mode','in',[5]];        }        //待处理订单        if($type == 1){            $where[]=['order_mode','in',[1]];        }        //已派发订单        if($type == 2){            $where[]=['order_mode','in',[4]];        }        //已取消订单        if($type == 3){            $where[]=['order_mode','in',[2,3]];        }        //已评价订单        if($type == 4){            $where[]=['order_mode','in',[6]];        }        if($type == 5){ //挂起订单            $where[]=['order_mode','in',[4]];        }        if($day == 1){    //日订单            $where[] = ['create_yyyymmdd','=',date('Ymd')];        }else if($day == 2){  //月订单            $where[] = ['create_yyyymm','=',date('Ym')];        }        //订单类型        if(in_array($mode,array(1,2,3,4))){            $where[] = ['work_type_mode','=',$mode];        }else{            $where[] = ['work_type_mode','>',0];        }        $andWhere = array(            'del' => 0,            'org_id' => $this->orgId        );        if($page > 1){            $list = Db::name('orders')                ->field('id,dep_id,work_type_mode,order_mode,user_id,create_time,org_id')                ->where($where)                ->where($andWhere)                ->page($page,$size)                ->order('id desc')                ->select();            foreach ($list as $k=>$v){                if($type == 2 && $v['order_mode'] == 4){                    $list[$k]['out_content'] = Db::name('order_mode')->where('id',$v['order_mode'])->value('out_content');                    $list[$k]['user_name'] = Db::name('user')->where('id',$v['user_id'])->value('real_name');                    $dep = Db::name('dep')->where('id',$v['dep_id'])->value('title');                    $list[$k]['dep_name'] = $dep?$dep :'' ;                    $todo = Db::name('todo')->where('order_id',$v['id'])->where('del',0)->where('todo_mode',2)->where('pause',1)->find();                    if($todo){                        unset($list[$k]);                    }                }elseif($type == 5 && $v['order_mode'] == 4){                    $list[$k]['user_name'] = Db::name('user')->where('id',$v['user_id'])->value('real_name');                    $dep = Db::name('dep')->where('id',$v['dep_id'])->value('title');                    $list[$k]['dep_name'] = $dep?$dep :'' ;                    $list[$k]['out_content'] = '挂起';                    $todo = Db::name('todo')->where('order_id',$v['id'])->where('del',0)->where('todo_mode',2)->where('pause',1)->find();                    if(!$todo){                        unset($list[$k]);                    }                }else if($type == -1){                    if($v['order_mode'] == 4){                        $todo = Db::name('todo')->where('order_id',$v['id'])->where('del',0)->where('todo_mode',2)->where('pause',1)->find();                        $list[$k]['out_content'] = $todo ? '挂起': Db::name('order_mode')->where('id',$v['order_mode'])->value('out_content');                    }else{                        $list[$k]['out_content'] = Db::name('order_mode')->where('id',$v['order_mode'])->value('out_content');                    }                    $list[$k]['user_name'] = Db::name('user')->where('id',$v['user_id'])->value('real_name');                    $dep = Db::name('dep')->where('id',$v['dep_id'])->value('title');                    $list[$k]['dep_name'] = $dep?$dep :'' ;                }else{                    $list[$k]['out_content'] = Db::name('order_mode')->where('id',$v['order_mode'])->value('out_content');                    $list[$k]['user_name'] = Db::name('user')->where('id',$v['user_id'])->value('real_name');                    $dep = Db::name('dep')->where('id',$v['dep_id'])->value('title');                    $list[$k]['dep_name'] = $dep?$dep :'' ;                }            }            $this->success('','',array_values($list));        }else{            $list = Db::name('orders')                ->field('id,dep_id,work_type_mode,order_mode,user_id,create_time,org_id')                ->where($where)                ->where($andWhere)                ->page($page,$size)                ->order('id desc')                ->select();            foreach ($list as $k=>$v){                if($type == 2 && $v['order_mode'] == 4){                    $list[$k]['out_content'] = Db::name('order_mode')->where('id',$v['order_mode'])->value('out_content');                    $list[$k]['user_name'] = Db::name('user')->where('id',$v['user_id'])->value('real_name');                    $dep = Db::name('dep')->where('id',$v['dep_id'])->value('title');                    $list[$k]['dep_name'] = $dep?$dep :'' ;                    $todo = Db::name('todo')->where('order_id',$v['id'])->where('del',0)->where('todo_mode',2)->where('pause',1)->find();                    if($todo){                        unset($list[$k]);                    }                }elseif($type == 5 && $v['order_mode'] == 4){                    $list[$k]['user_name'] = Db::name('user')->where('id',$v['user_id'])->value('real_name');                    $dep = Db::name('dep')->where('id',$v['dep_id'])->value('title');                    $list[$k]['dep_name'] = $dep?$dep :'' ;                    $list[$k]['out_content'] = '挂起';                    $todo = Db::name('todo')->where('order_id',$v['id'])->where('del',0)->where('todo_mode',2)->where('pause',1)->find();                    if(!$todo){                        unset($list[$k]);                    }                }else if($type == -1){                    if($v['order_mode'] == 4){                        $todo = Db::name('todo')->where('order_id',$v['id'])->where('del',0)->where('todo_mode',2)->where('pause',1)->find();                        $list[$k]['out_content'] = $todo ? '挂起': Db::name('order_mode')->where('id',$v['order_mode'])->value('out_content');                    }else{                        $list[$k]['out_content'] = Db::name('order_mode')->where('id',$v['order_mode'])->value('out_content');                    }                    $list[$k]['user_name'] = Db::name('user')->where('id',$v['user_id'])->value('real_name');                    $dep = Db::name('dep')->where('id',$v['dep_id'])->value('title');                    $list[$k]['dep_name'] = $dep?$dep :'' ;                }else{                    $list[$k]['out_content'] = Db::name('order_mode')->where('id',$v['order_mode'])->value('out_content');                    $list[$k]['user_name'] = Db::name('user')->where('id',$v['user_id'])->value('real_name');                    $dep = Db::name('dep')->where('id',$v['dep_id'])->value('title');                    $list[$k]['dep_name'] = $dep?$dep :'' ;                }            }            $this->assign('mode',$mode);            $this->assign('orgId',$this->orgId);            $this->assign('type',$type);            $this->assign('day',$day);            $this->assign('list',array_values($list));            return $this->fetch();        }    }    public function ordersDetails(){        $id = input('id',0);        $info = model('Orders')->detail($id);        $info['create_time'] = date('Y-m-d H:i',strtotime($info['create_time']));        $info['images'] = $info['images']?explode(',',$info['images']):[];        $info['videos'] = $info['videos']?explode(',',$info['videos']):[];        $this->assign('info',$info);        return $this->fetch();    }    public function ordersSubDetails(){        $id = input('id',0);        $info = Db::name('todo')->where('id',$id)->find();        $info['sign'] = $info['sign']?explode(',',$info['sign']):[];        $info['cons'] = [];        if ($info['work_type_mode'] == 1) {            $todo_mate = Db::name('todo_mate')                ->where('order_id',$info['order_id'])                ->select();            if(!empty($todo_mate)){                $cons = Db::name('todo_mate_item')                    ->alias('a')                    ->join('mate_goods b','b.id = a.items_id')                    ->where('a.todo_mate_id','in',array_column($todo_mate,'id'))                    ->field('a.*,b.title')                    ->select();                foreach ($cons as $k1=>$v1){                    $pInfo = Db::name('mate_goods')                        ->where('id',$v1['pid'])                        ->find();                    $info['cons'][] = [                        'title' =>$v1['title'],                        'total' =>$v1['total'],                        'money' =>$v1['money'],                        'total_money' =>$v1['total_money'],                    ];                }            }        }        $this->assign('info',$info);        return $this->fetch();    }    public function videoPlay(){        $src = input('url');        $this->assign('url',$src);        return $this->fetch();    }    //巡更任务列表    public function patrolList() {        $page = input('page',1);        $size = input('size',20);        $type = input('type',0);//巡更状态        $mode = input('mode',0);//巡更类型        $day = input('day',0);//日,月,总计        if($type==2){            $where[] = ['status','=',2];        }        if($type==3){            $where[] = ['status','=',3];        }        $where[] = ['org_id','=',$this->orgId];        $where[] = ['del','=',0];        if($day == 0){    //日订单            $where[] = ['create_yyyymmdd','=',date('Ymd')];        }else if($day == 1){  //月订单            $where[] = ['create_yyyymm','=',date('Ym')];        }else if($day == 2){  //总订单        }        //订单类型        if(in_array($mode,array(1,2,3,4))){            $where[] = ['patrol_mode','=',$mode];        }else{            $where[] = ['patrol_mode','>',0];        }        if($page > 1){            $list = Db::name('patrol_task')                ->field('id,title,start_time,end_time,status,patrol_mode,org_id')                ->where($where)                ->order('id desc')                ->page($page,$size)                ->select();            foreach ($list as $k=>$v){                $user = Db::name('patrol_task_user')                    ->alias('ptu')                    ->join('user u','u.id=ptu.user_id')                    ->where('ptu.patrol_task_id',$v['id'])                    ->column('u.real_name');                $list[$k]['real_name']=$user?implode(',',$user):'';                $dep = Db::name('patrol_task_user')                    ->alias('ptu')                    ->join('user_dep ud','ud.user_id=ptu.user_id')                    ->join('dep d','d.id=ud.dep_id')                    ->where('ptu.patrol_task_id',$v['id'])                    ->column('d.title');                $list[$k]['dep']=$dep?implode(',',$dep):'';            }            HelpHander::success($list);        }else{            $list = Db::name('patrol_task')                ->field('id,title,start_time,end_time,status,patrol_mode,org_id')                ->where($where)                ->order('id desc')                ->page($page,$size)                ->select();            foreach ($list as $k=>$v){                $user = Db::name('patrol_task_user')                    ->alias('ptu')                    ->join('user u','u.id=ptu.user_id')                    ->where('ptu.patrol_task_id',$v['id'])                    ->column('u.real_name');                $list[$k]['real_name']=$user?implode(',',$user):'';                $dep = Db::name('patrol_task_user')                    ->alias('ptu')                    ->join('user_dep ud','ud.user_id=ptu.user_id')                    ->join('dep d','d.id=ud.dep_id')                    ->where('ptu.patrol_task_id',$v['id'])                    ->column('d.title');                $list[$k]['dep']=$dep?implode(',',$dep):'';            }            $this->assign('list',$list);            $this->assign('mode',$mode);            $this->assign('type',$type);            $this->assign('day',$day);            $this->assign('orgId',$this->orgId);            return $this->fetch();        }    }    public function patrolDetails(){        $id = input('id',0);        $info = Db::name('patrol_task')            ->where('id',$id)            ->where('del',0)            ->find();        $info['interrupt_img']= $info['interrupt_img']?explode(',',$info['interrupt_img']):[];        $info['patrol_type']= Db::name('patrol_mode')->where('id',$info['patrol_mode'])->value('name');        //巡更人员        $taskUser= Db::name('patrol_task_user')            ->alias('ptu')            ->join('user u','u.id=ptu.user_id')            ->where('ptu.patrol_task_id',$info['id'])            ->column('u.real_name');        $info['patrol_user']=$taskUser?implode(',',$taskUser):'';        //巡更地点        $address = Db::name('patrol_task_addr')            ->alias('pta')            ->field('a.id,a.title,pta.id as patrol_form_id,pta.patrol_task_id')//            ->join('patrol_addr_form paf','paf.id=pta.patrol_form_id')            ->join('address a','a.id=pta.address_id')            ->where('pta.patrol_task_id',$id)            ->select();        foreach ($address as $kk=>$vv){            $record = Db::name('patrol_record')                ->where('patrol_task_id',$vv['patrol_task_id'])                ->where('patrol_addr_id',$vv['id'])                ->where('patrol_addr_form_id',$vv['patrol_form_id'])                ->find();            $address[$kk]['status'] = $record?1:0;        }        $info['patrol_address']=$address?$address:[];        $this->assign('info',$info);        return $this->fetch();    }    public function patrolSonDetails(){        $addrFormId = input('addrFormId',0);        $id = input('id',0);        $task = Db::name('patrol_task')            ->field('end_time,patrol_mode')            ->where('id',$id)            ->where('del',0)            ->find();        //巡更人员        $taskUser = Db::name('patrol_task_user')            ->alias('ptu')            ->join('user u','u.id=ptu.user_id')            ->where('ptu.patrol_task_id',$id)            ->column('u.real_name');        $info = Db::name('patrol_record')            ->field('images,content,check_json')            ->where('patrol_task_id',$id)            ->where('patrol_addr_form_id',$addrFormId)            ->find();        $info['img'] = $info['images']?explode(',',$info['images']):[];        $info['forms'] =$info['check_json']?json_decode($info['check_json'],true):[];        $info['patrol_user']=$taskUser?implode(',',$taskUser):'';        $info['patrol_time']=$task['end_time'];        $info['patrol_type']= Db::name('patrol_mode')->where('id',$task['patrol_mode'])->value('name');        $this->assign('info',$info);        return $this->fetch();    }    //用户列表    public function userList(){        $page = input('page',1);        $size = input('size',20);        $rolesId = input('rolesId',0);        if($page > 1){            if($rolesId == 0){                $rolesIds =  Db::name('roles')                    ->whereIn('parent_id',[4,5,6,7,8,9,10,11])                    ->where('org_id',$this->orgId)                    ->where('del',0)                    ->where('enable',1)                    ->column('id');                $list = Db::name('user')                    ->alias('u')                    ->field('u.id,u.real_name,u.head_image,u.create_time,u.mobile')                    ->join('user_roles ur','ur.user_id=u.id')                    ->where('u.del',0)                    ->where('u.enable',1)                    ->whereIn('ur.roles_id',$rolesIds)                    ->order('u.id desc')                    ->page($page,$size)                    ->select();            }else{                $rolesIds =  Db::name('roles')                    ->where('parent_id',$rolesId)                    ->where('org_id',$this->orgId)                    ->where('del',0)                    ->where('enable',1)                    ->column('id');                $list = Db::name('user')                    ->alias('u')                    ->field('u.id,u.real_name,u.head_image,u.create_time,u.mobile')                    ->join('user_roles ur','ur.user_id=u.id')                    ->where('u.del',0)                    ->where('u.enable',1)                    ->whereIn('ur.roles_id',$rolesIds)                    ->order('u.id desc')                    ->page($page,$size)                    ->select();            }            HelpHander::success($list);        }else{            if($rolesId == 0){                $rolesIds =  Db::name('roles')                    ->whereIn('parent_id',[4,5,6,7,8,9,10,11])                    ->where('org_id',$this->orgId)                    ->where('del',0)                    ->where('enable',1)                    ->column('id');                $list = Db::name('user')                    ->alias('u')                    ->field('u.id,u.real_name,u.head_image,u.create_time,u.mobile')                    ->join('user_roles ur','ur.user_id=u.id')                    ->where('u.del',0)                    ->where('u.enable',1)                    ->whereIn('ur.roles_id',$rolesIds)                    ->order('u.id desc')                    ->page($page,$size)                    ->select();            }else{                $rolesIds =  Db::name('roles')                    ->where('parent_id',$rolesId)                    ->where('org_id',$this->orgId)                    ->where('del',0)                    ->where('enable',1)                    ->column('id');                $list = Db::name('user')                    ->alias('u')                    ->field('u.id,u.real_name,u.head_image,u.create_time,u.mobile')                    ->join('user_roles ur','ur.user_id=u.id')                    ->where('u.del',0)                    ->where('u.enable',1)                    ->whereIn('ur.roles_id',$rolesIds)                    ->order('u.id desc')                    ->page($page,$size)                    ->select();            }        }        $this->assign('rolesId',$rolesId);        $this->assign('orgId',$this->orgId);        $this->assign('list',$list);        return $this->fetch();    }    public function commentList() {        $page = input('page',1);        $size = input('size',20);        $day = input('day',1);//日,月,总计        $mode = input('mode',0);        $where[] = ['o.del','=',0];        $where[] = ['o.org_id','=',$this->orgId];        $where[] = ['c.type','=',$mode];        if($day == 1){    //日订单            $where[] = ['c.create_yyyymmdd','=',date('Ymd')];        }else if($day == 2){  //月订单            $where[] = ['c.create_yyyymm','=',date('Ym')];        }        if($page > 1){            $list = Db::name('comment')                ->alias('c')                ->field('c.*')                ->join('orders o','o.id=c.from_id')                ->where($where)                ->order('c.id desc')                ->page($page,$size)                ->select();            foreach ($list as $k=>$v){                $list[$k]['user_name']= Db::name('user')->where('id',$v['user_id'])->value('real_name');            }            HelpHander::success($list);        }else{            $list = Db::name('comment')                ->alias('c')                ->field('c.*')                ->join('orders o','o.id=c.from_id')                ->where($where)                ->order('c.id desc')                ->page($page,$size)                ->select();            foreach ($list as $k=>$v){                $list[$k]['user_name']= Db::name('user')->where('id',$v['user_id'])->value('real_name');            }        }        $this->assign('list',$list);        $this->assign('day',$day);        $this->assign('mode',$mode);        $this->assign('orgId',$this->orgId);        return $this->fetch();    }    public function commentDetails(){        $id = input('id',0);        $info = Db::name('comment')->where('id',$id)->find();        $info['user_name'] = Db::name('user')->where('id',$info['user_id'])->value('real_name');        $this->assign('info',$info);        return $this->fetch();    }    //日常工作统计    public function dailyList() {        $page = input('page',1);        $size = input('size',20);        $day = input('day',0);//日,月,总计        if($day == 0){    //日订单            $where[] = ['create_yyyymmdd','=',date('Ymd')];        }else if($day == 1){  //月订单            $where[] = ['create_yyyymm','=',date('Ym')];        }        $where[] = ['org_id','=',$this->orgId];        $dailyIds = Db::name('daily_record')->where($where)->group('daily_id')->column('daily_id');        if($dailyIds){            $map[] = ['id','in',$dailyIds];        }else{            $map[] = ['id','in',[0]];        }        if($page>1){            $list = Db::name('daily')                ->field('id,title,enable')                ->where('org_id',$this->orgId)                ->where($map)                ->order('id desc')                ->page($page,$size)                ->select();            foreach ($list as $k=>$v){                $user =  Db::name('daily_user')                    ->alias('du')                    ->join('user u','u.id=du.user_id')                    ->where('du.daily_id',$v['id'])                    ->where('u.del',0)                    ->where('u.enable',1)                    ->column('u.real_name');                $list[$k]['work_user']=$user?implode(',',$user):'';            }            HelpHander::success($list);        }else{            $list = Db::name('daily')                ->field('id,title,enable')                ->where('org_id',$this->orgId)                ->where($map)                ->order('id desc')                ->page($page,$size)                ->select();            foreach ($list as $k=>$v){                $user =  Db::name('daily_user')                    ->alias('du')                    ->join('user u','u.id=du.user_id')                    ->where('du.daily_id',$v['id'])                    ->where('u.del',0)                    ->where('u.enable',1)                    ->column('u.real_name');                $list[$k]['work_user']=$user?implode(',',$user):'';            }        }        $this->assign('list',$list);        $this->assign('day',$day);        $this->assign('orgId',$this->orgId);        return $this->fetch();    }    public function dailyRecordList() {        $page = input('page',1);        $size = input('size',20);        $day = input('day',0);//日,月,总计        if($day == 0){    //日订单            $where[] = ['create_yyyymmdd','=',date('Ymd')];        }else if($day == 1){  //月订单            $where[] = ['create_yyyymm','=',date('Ym')];        }        $where[] = ['org_id','=',$this->orgId];        if($page>1){            $list = Db::name('daily_record')                ->field('id,user_id,create_time,org_id')                ->where($where)                ->order('id desc')                ->page($page,$size)                ->select();            foreach ($list as $k=>$v){                $list[$k]['user_name'] = Db::name('user')->where('id',$v['user_id'])->value('real_name');            }            HelpHander::success($list);        }else{            $list = Db::name('daily_record')                ->field('id,user_id,create_time,org_id')                ->where($where)                ->order('id desc')                ->page($page,$size)                ->select();            foreach ($list as $k=>$v){                $list[$k]['user_name'] = Db::name('user')->where('id',$v['user_id'])->value('real_name');            }        }        $this->assign('list',$list);        $this->assign('day',$day);        $this->assign('orgId',$this->orgId);        return $this->fetch();    }    public function dailyRecordDetails(){        $id = input('id',0);        $info = Db::name('daily_record')->where('id',$id)->find();        $info['img'] = $info['images']?explode(',',$info['images']):[];        //任务内容        $daily = Db::name('daily')->where('id',$info['daily_id'])->find();        $info['daily_content'] = $daily['content'] ? $daily['content']:'';        $info['daily_title'] = $daily['title'] ? $daily['title']:'';        $info['user_name'] = Db::name('user')->where('id',$info['user_id'])->value('real_name');        $info['forms'] = json_decode($info['check_json'],true);        $this->assign('info',$info);        return $this->fetch();    }    //设备台账统计    public function deviceList() {        $page = input('page',1);        $size = input('size',20);        $day = input('day',0);//日,月,总计        if($day == 0){    //日订单            $where[] = ['create_yyyymmdd','=',date('Ymd')];        }else if($day == 1){  //月订单            $where[] = ['create_yyyymm','=',date('Ym')];        }        $where[] = ['org_id','=',$this->orgId];        $deviceIds = Db::name('device_record')->where($where)->group('device_id')->column('device_id');        if($deviceIds){            $map[] = ['id','in',$deviceIds];        }else{            $map[] = ['id','in',[0]];        }        if($page>1){            $list = Db::name('device')                ->field('id,title,enable')                ->where('org_id',$this->orgId)                ->where($map)                ->order('id desc')                ->page($page,$size)                ->select();            foreach ($list as $k=>$v){                $user =  Db::name('device_user')                    ->alias('du')                    ->join('user u','u.id=du.user_id')                    ->where('du.device_id',$v['id'])                    ->where('u.del',0)                    ->where('u.enable',1)                    ->column('u.real_name');                $list[$k]['work_user']=$user?implode(',',$user):'';            }            HelpHander::success($list);        }else{            $list = Db::name('device')                ->field('id,title,enable')                ->where('org_id',$this->orgId)                ->where($map)                ->order('id desc')                ->page($page,$size)                ->select();            foreach ($list as $k=>$v){                $user =  Db::name('device_user')                    ->alias('du')                    ->join('user u','u.id=du.user_id')                    ->where('du.device_id',$v['id'])                    ->where('u.del',0)                    ->where('u.enable',1)                    ->column('u.real_name');                $list[$k]['work_user']=$user?implode(',',$user):'';            }        }        $this->assign('list',$list);        $this->assign('day',$day);        $this->assign('orgId',$this->orgId);        return $this->fetch();    }    public function deviceRecordList() {        $page = input('page',1);        $size = input('size',20);        $day = input('day',0);//日,月,总计        if($day == 0){    //日订单            $where[] = ['create_yyyymmdd','=',date('Ymd')];        }else if($day == 1){  //月订单            $where[] = ['create_yyyymm','=',date('Ym')];        }        $where[] = ['org_id','=',$this->orgId];        if($page>1){            $list = Db::name('device_record')                ->field('id,user_id,create_time,org_id')                ->where($where)                ->order('id desc')                ->page($page,$size)                ->select();            foreach ($list as $k=>$v){                $list[$k]['user_name'] = Db::name('user')->where('id',$v['user_id'])->value('real_name');            }            HelpHander::success($list);        }else{            $list = Db::name('device_record')                ->field('id,user_id,create_time,org_id')                ->where($where)                ->order('id desc')                ->page($page,$size)                ->select();            foreach ($list as $k=>$v){                $list[$k]['user_name'] = Db::name('user')->where('id',$v['user_id'])->value('real_name');            }        }        $this->assign('list',$list);        $this->assign('day',$day);        $this->assign('orgId',$this->orgId);        return $this->fetch();    }    public function deviceRecordDetails(){        $id = input('id',0);        $info = Db::name('device_record')->where('id',$id)->find();        $info['img'] = $info['images']?explode(',',$info['images']):[];        //任务内容        $daily = Db::name('device')->where('id',$info['device_id'])->find();        $info['device_content'] = $daily['content'] ? $daily['content']:'';        $info['device_title'] = $daily['title'] ? $daily['title']:'';        $info['user_name'] = Db::name('user')->where('id',$info['user_id'])->value('real_name');        $info['forms'] = json_decode($info['check_json'],true);        $this->assign('info',$info);        return $this->fetch();    }    public function complain(){        $type = input('type',0);        $week = Time::week();        $sw = date('Ymd',$week[0]);        $ew = date('Ymd',$week[1]);        if($type == 0){            $map[] = ['create_yyyymmdd','>=',$sw];            $map[] = ['create_yyyymmdd','<=',$ew];        }elseif ($type == 1){            $map[] = ['create_yyyymm','=',date('Ym')];        }        $map[] = ['org_id','=',$this->orgId];        $map[] = ['del','=',0];        $data = [            ['name'=>'已处理','status'=>2],            ['name'=>'处理中','status'=>1],            ['name'=>'待处理','status'=>0],        ];        foreach ($data as $k=>$v){            $count = 0;            if($v['status'] == 2){                $complain =  Db::name('complain')->where($map)->select();                foreach ($complain as $kk=>$vv){                    if($vv['status'] == 1 && $vv['order_id'] > 0){                        $order = Db::name('orders')->where('id',$vv['order_id'])->find();                        if(in_array($order['order_mode'],[3,5,6])){                            $count +=1;                        }                    }elseif ($vv['status'] == 1 && $vv['order_id'] == 0){                           $count +=1;                    }                }            }elseif ($v['status'] == 1){                $complain =  Db::name('complain')->where($map)->select();                foreach ($complain as $kk=>$vv){                    if($vv['status'] == 1 && $vv['order_id'] > 0){                        $order = Db::name('orders')->where('id',$vv['order_id'])->find();                        if(!in_array($order['order_mode'],[3,5,6])){                            $count +=1;                        }                    }                }            }elseif ($v['status'] == 0){                $count =  Db::name('complain')->where($map)->where('status',0)->count();            }            $data[$k]['cost'] = $count;        }        $count =  Db::name('complain')->where($map)->count();        $this->assign('list',$data);        $this->assign('count',$count);        $this->assign('orgId',$this->orgId);        $this->assign('type',$type);        return $this->fetch();    }    public function complainList(){        $type = input('type/d',0);        $status= input('status',-1);        $week = Time::week();        $sw = date('Ymd',$week[0]);        $ew = date('Ymd',$week[1]);        if($type == 0){            $map[] = ['create_yyyymmdd','>=',$sw];            $map[] = ['create_yyyymmdd','<=',$ew];        }elseif ($type == 1){            $map[] = ['create_yyyymm','=',date('Ym')];        }        $map[] = ['org_id','=',$this->orgId];        $map[] = ['del','=',0];        $list = [];        if($status == 0){            $list =  Db::name('complain')->where($map)->where('status',0)->order('id desc')->select();            foreach ($list as $k=>$v){                $list[$k]['statusTxt'] = '待处理';            }        }elseif ($status == -1){            $list = Db::name('complain')->where($map)->order('id desc')->select();            foreach ($list as $k=>$v){                $statusTxt = '';                if($v['status'] == 1 && $v['order_id'] == 0){                    $statusTxt = '已处理';                }elseif($v['status'] == 1 && $v['order_id'] > 0){                    $order = Db::name('orders')->where('id',$v['order_id'])->find();                    if(in_array($order['order_mode'],[3,5,6])){                        $statusTxt = '已处理';                    }else{                        $statusTxt = '处理中';                    }                }elseif($v['status'] == 0){                    $statusTxt = '待处理';                }                $list[$k]['statusTxt'] = $statusTxt;            }        } else{            $complain =  Db::name('complain')->where($map)->select();            foreach ($complain as $k=>$v){                $statusTxt = '';                if($v['status'] == 1 && $v['order_id'] == 0){                    $statusTxt = '已处理';                }else if($v['status'] == 1 && $v['order_id'] > 0){                    $order = Db::name('orders')->where('id',$v['order_id'])->find();                    if(in_array($order['order_mode'],[3,5,6])){                        $statusTxt = '已处理';                    }else{                        $statusTxt = '处理中';                    }                }elseif($v['status'] == 0){                    $statusTxt = '待处理';                }                $complain[$k]['statusTxt'] = $statusTxt;            }            foreach ($complain as $k=>$v){                if($status == 2){                    if($v['status'] == 1 && $v['order_id'] > 0){                        $order = Db::name('orders')->where('id',$v['order_id'])->find();                        if(in_array($order['order_mode'],[3,5,6])){                            $list[$k] = $v;                        }                    }elseif($v['status'] == 1 && $v['order_id'] == 0){                        $list[$k] = $v;                    }                }elseif ($status == 1){                    if($v['status'] == 1 && $v['order_id'] > 0){                        $order = Db::name('orders')->where('id',$v['order_id'])->find();                        if(!in_array($order['order_mode'],[3,5,6])){                            $list[$k] = $v;                        }                    }                }            }        }        foreach ($list as $k=>$v){            if($v['hide'] == 1){                $list[$k]['user_name'] = '匿名';            }else{                $list[$k]['user_name'] = Db::name('user')->where('id',$v['create_user_id'])->value('real_name');            }        }        $this->assign('list',$list);        $this->assign('orgId',$this->orgId);        $this->assign('type',$type);        return $this->fetch();    }    public function complainDetail(){        $id = input('id',0);        $info = Db::name('complain')->where('id',$id)->find();        $info['images'] = !empty($info['images'])?explode(',',$info['images']):[];        $info['create_time'] = date('Y-m-d H:i',strtotime($info['create_time']));        $statusTxt = '';        if($info['status'] == 1 && $info['order_id'] == 0){            $statusTxt = '已处理';        }elseif($info['status'] == 1 && $info['order_id'] > 0){            $order = Db::name('orders')->where('id',$info['order_id'])->find();            if(in_array($order['order_mode'],[3,5,6])){                $statusTxt = '已处理';            }else{                $statusTxt = '处理中';            }        }elseif($info['status'] == 0){            $statusTxt = '待处理';        }        $info['statusTxt'] = $statusTxt;        if($info['hide'] == 1){            $info['user_name'] = '匿名';            $info['mobile'] = '';        }else{            $info['user_name'] = Db::name('user')->where('id',$info['create_user_id'])->value('real_name');            $info['mobile'] = Db::name('user')->where('id',$info['create_user_id'])->value('mobile');        }        $info['dep_name'] = db('dep')->where('id',$info['dep_id'])->value('title');        $this->assign('info',$info);        return $this->fetch();    }}
 |