| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398 | 
							- <?php
 
- namespace app\api\controller\screen;
 
- use app\api\controller\screen\Index;
 
- use app\hander\HelpHander;
 
- use think\Db;
 
- use think\helper\Time;
 
- class Todo extends Index
 
- {
 
-     //各类型当天工单总数
 
-     public function cateTodoCount(){
 
-         //保洁
 
-         $bjCount = Db::name('todo')
 
-             ->where('del',0)
 
-             ->where('create_yyyymmdd',date('Ymd'))
 
-             ->where('org_id',$this->orgId)
 
-             ->where('work_type_mode',2)
 
-             ->count();
 
-         $bjCount2 = Db::name('todo')
 
-             ->where('del',0)
 
-             ->where('todo_mode',3)
 
-             ->where('create_yyyymmdd',date('Ymd'))
 
-             ->where('work_type_mode',2)
 
-             ->where('org_id',$this->orgId)
 
-             ->count();
 
-         //报修
 
-         $bxCount = Db::name('todo')
 
-             ->where('del',0)
 
-             ->where('create_yyyymmdd',date('Ymd'))
 
-             ->where('work_type_mode',1)
 
-             ->where('org_id',$this->orgId)
 
-             ->count();
 
-         $bxCount2 = Db::name('todo')
 
-             ->where('del',0)
 
-             ->where('todo_mode',3)
 
-             ->where('create_yyyymmdd',date('Ymd'))
 
-             ->where('work_type_mode',1)
 
-             ->where('org_id',$this->orgId)
 
-             ->count();
 
-         //隐患
 
-         $yhCount = Db::name('todo')
 
-             ->where('del',0)
 
-             ->where('create_yyyymmdd',date('Ymd'))
 
-             ->where('work_type_mode',4)
 
-             ->where('org_id',$this->orgId)
 
-             ->count();
 
-         $yhCount2 = Db::name('todo')
 
-             ->where('del',0)
 
-             ->where('todo_mode',3)
 
-             ->where('create_yyyymmdd',date('Ymd'))
 
-             ->where('work_type_mode',4)
 
-             ->where('org_id',$this->orgId)
 
-             ->count();
 
-         //运送
 
-         $ysCount = Db::name('todo')
 
-             ->where('del',0)
 
-             ->where('create_yyyymmdd',date('Ymd'))
 
-             ->where('work_type_mode',3)
 
-             ->where('org_id',$this->orgId)
 
-             ->count();
 
-         $ysCount2 = Db::name('todo')
 
-             ->where('del',0)
 
-             ->where('todo_mode',3)
 
-             ->where('create_yyyymmdd',date('Ymd'))
 
-             ->where('work_type_mode',3)
 
-             ->where('org_id',$this->orgId)
 
-             ->count();
 
-         //陪护
 
-         $phCount = Db::name('ph_todo')
 
-             ->where('create_time','>=',date('Y-m-d').' 00:00:00')
 
-             ->where('create_time','<=',date('Y-m-d').' 23:59:59')
 
-             ->where('org_id',$this->orgId)
 
-             ->count();
 
-         $phCount2 = Db::name('ph_todo')
 
-             ->where('create_time','>=',date('Y-m-d').' 00:00:00')
 
-             ->where('create_time','<=',date('Y-m-d').' 23:59:59')
 
-             ->where('status',2)
 
-             ->where('org_id',$this->orgId)
 
-             ->count();
 
-         $data = [
 
-             'bj'=>$bjCount.'/'.$bjCount2,
 
-             'bx'=>$bxCount.'/'.$bxCount2,
 
-             'yh'=>$yhCount.'/'.$yhCount2,
 
-             'ys'=>$ysCount.'/'.$ysCount2,
 
-             'ph'=>$phCount.'/'.$phCount2,
 
-         ];
 
-         HelpHander::success($data);
 
-     }
 
-     //任务数据总览
 
-     public function taskList(){
 
-         $mode = input('mode/d',1);
 
-         if(!in_array($mode,[1,2,3,4,5])){
 
-             HelpHander::error('参数错误');
 
-         }
 
-         $data = [];
 
-         $header = ['状态', '任务类型', '始发地', '目的地', '需求时间', '执行人', '接单时间', '完成时间'];
 
-         if($mode == 5){
 
-             $header = ['状态', '开始时间', '结束时间', '工作天数', '创建时间'];
 
-             $todo = Db::name('ph_todo')
 
-                 ->where('org_id',$this->orgId)
 
- //                ->where('status','in',[1,2])
 
-                 ->order('id desc')
 
-                 ->limit(30)
 
-                 ->select();
 
-             foreach ($todo as $k=>$v){
 
-                 $data[$k]['status'] = $v['status'];
 
-                 $data[$k]['start'] = date('H:i',strtotime($v['start']));
 
-                 $data[$k]['end'] = date('H:i',strtotime($v['end']));
 
-                 $data[$k]['day'] = $v['day'];
 
-                 $data[$k]['create_time'] = date('H:i',strtotime($v['create_time']));
 
-             }
 
-         }else{
 
-             if($mode == 1){
 
-                 $header = ['状态', '执行人', '报修事项', '内容', '接单时间','完成时间'];
 
-             }else if($mode == 2||$mode == 4){
 
-                 $header = ['状态', '执行人', '内容', '接单时间','完成时间'];
 
-             }
 
-             $todo = Db::name('todo')
 
-                 ->where('org_id',$this->orgId)
 
-                 ->where('work_type_mode',$mode)
 
-                 ->where('del',0)
 
-                 ->order('id desc')
 
-                 ->limit(30)
 
-                 ->field('id,order_id,to_user_id,todo_mode,create_time,confirm_time,todo_content,done_time')
 
-                 ->select();
 
-             foreach ($todo as $k=>$v){
 
-                 $userName = Db::name('user')->where('id',$v['to_user_id'])->value('real_name');
 
-                 if($mode == 1){ // 报修
 
-                     $type = Db::name('order_repair')
 
-                         ->alias('or')
 
-                         ->leftJoin('order_type ot','ot.id = or.type_id')
 
-                         ->where('or.order_id',$v['order_id'])
 
-                         ->value('title');
 
-                   $data[$k]['todo_mode'] = $v['todo_mode'];
 
-                   $data[$k]['user_name'] = $userName?$userName:'';
 
-                   $data[$k]['type'] = $type?$type:'';
 
-                   $data[$k]['content'] = $v['todo_content'];
 
-                   $data[$k]['confirm_time'] = $v['confirm_time']?date('H:i',strtotime($v['confirm_time'])):'';
 
-                   $data[$k]['done_time'] = $v['done_time']?date('H:i',strtotime($v['done_time'])):'';
 
-                 }else if($mode == 3){ //运送
 
-                     $convey = Db::name('order_convey')
 
-                         ->alias('oc')
 
-                         ->join('convey_cate cc','cc.id = oc.type')
 
-                         ->where('oc.order_id',$v['order_id'])
 
-                         ->field('oc.*,cc.title as cate_title')
 
-                         ->find();
 
-                     $userName = Db::name('user')->where('id',$v['to_user_id'])->value('real_name');
 
-                     $start = Db::name('address')->where('id',$convey['start'])->value('title');
 
-                     $end = Db::name('address')->where('id',$convey['end'])->value('title');
 
-                     $data[$k]['todo_mode'] = $v['todo_mode'];
 
-                     $data[$k]['type'] = $convey?$convey['cate_title']:'';
 
-                     $data[$k]['start'] = $start?$start:'';
 
-                     $data[$k]['end'] = $end?$end:'';
 
-                     $data[$k]['xq_time'] = $convey?date('H:i',strtotime($convey['xq_time'])):'';
 
-                     $data[$k]['user_name'] = $userName?$userName:'';
 
-                     $data[$k]['confirm_time'] = $v['confirm_time']?date('H:i',strtotime($v['confirm_time'])):'';
 
-                     $data[$k]['done_time'] = $v['done_time']?date('H:i',strtotime($v['done_time'])):'';
 
-                 }else{ // 保洁,应急
 
-                     $data[$k]['todo_mode'] = $v['todo_mode'];
 
-                     $data[$k]['user_name'] = $userName?$userName:'';
 
-                     $data[$k]['content'] = $v['todo_content'];
 
-                     $data[$k]['confirm_time'] = $v['confirm_time']?date('H:i',strtotime($v['confirm_time'])):'';
 
-                     $data[$k]['done_time'] = $v['done_time']?date('H:i',strtotime($v['done_time'])):'';
 
-                 }
 
-             }
 
-         }
 
-         $lists = [];
 
-         if($mode == 1){
 
-             foreach ($data as $k=>$v){
 
-                 $status = Db::name('todo_mode')->where('id',$v['todo_mode'])->value('out_content');
 
-                 if($v['todo_mode'] == 1){
 
-                     $lists[$k][] = '<span style="color:#FFDA0A;">新订单</span>';
 
-                     $lists[$k][] = '<span style="color:#FFDA0A;">'.$v['user_name'].'</span>';
 
-                     $lists[$k][] = '<span style="color:#FFDA0A;">'.$v['type'].'</span>';
 
-                     $lists[$k][] = '<span style="color:#FFDA0A;">'.$v['content'].'</span>';
 
-                     $lists[$k][] = '<span style="color:#FFDA0A;">'.$v['confirm_time'].'</span>';
 
-                     $lists[$k][] = '<span style="color:#FFDA0A;">'.$v['done_time'].'</span>';
 
-                 }else if($v['todo_mode'] == 2){
 
-                     $lists[$k][] = '<span style="color:#0FC2DD;">进行中</span>';
 
-                     $lists[$k][] = '<span style="color:#0FC2DD;">'.$v['user_name'].'</span>';
 
-                     $lists[$k][] = '<span style="color:#0FC2DD;">'.$v['type'].'</span>';
 
-                     $lists[$k][] = '<span style="color:#0FC2DD;">'.$v['content'].'</span>';
 
-                     $lists[$k][] = '<span style="color:#0FC2DD;">'.$v['confirm_time'].'</span>';
 
-                     $lists[$k][] = '<span style="color:#0FC2DD;">'.$v['done_time'].'</span>';
 
-                 }else{
 
-                     $lists[$k][] = $status;
 
-                     $lists[$k][] = $v['user_name'];
 
-                     $lists[$k][] = $v['type'];
 
-                     $lists[$k][] = $v['content'];
 
-                     $lists[$k][] = $v['confirm_time'];
 
-                     $lists[$k][] = $v['done_time'];
 
-                 }
 
-             }
 
-         }else if($mode == 2 || $mode == 4){
 
-             foreach ($data as $k=>$v){
 
-                 $status = Db::name('todo_mode')->where('id',$v['todo_mode'])->value('out_content');
 
-                 if($v['todo_mode'] == 1){
 
-                     $lists[$k][] = '<span style="color:#FFDA0A;">新订单</span>';
 
-                     $lists[$k][] = '<span style="color:#FFDA0A;">'.$v['user_name'].'</span>';
 
-                     $lists[$k][] = '<span style="color:#FFDA0A;">'.$v['content'].'</span>';
 
-                     $lists[$k][] = '<span style="color:#FFDA0A;">'.$v['confirm_time'].'</span>';
 
-                     $lists[$k][] = '<span style="color:#FFDA0A;">'.$v['done_time'].'</span>';
 
-                 }else if($v['todo_mode'] == 2){
 
-                     $lists[$k][] = '<span style="color:#0FC2DD;">进行中</span>';
 
-                     $lists[$k][] = '<span style="color:#0FC2DD;">'.$v['user_name'].'</span>';
 
-                     $lists[$k][] = '<span style="color:#0FC2DD;">'.$v['content'].'</span>';
 
-                     $lists[$k][] = '<span style="color:#0FC2DD;">'.$v['confirm_time'].'</span>';
 
-                     $lists[$k][] = '<span style="color:#0FC2DD;">'.$v['done_time'].'</span>';
 
-                 }else{
 
-                     $lists[$k][] = $status;
 
-                     $lists[$k][] = $v['user_name'];
 
-                     $lists[$k][] = $v['content'];
 
-                     $lists[$k][] = $v['confirm_time'];
 
-                     $lists[$k][] = $v['done_time'];
 
-                 }
 
-             }
 
-         }else if($mode == 3){
 
-             foreach ($data as $k=>$v){
 
-                 $status = Db::name('todo_mode')->where('id',$v['todo_mode'])->value('out_content');
 
-                 if($v['todo_mode'] == 1){
 
-                     $lists[$k][] = '<span style="color:#FFDA0A;">新订单</span>';
 
-                     $lists[$k][] = '<span style="color:#FFDA0A;">'.$v['type'].'</span>';
 
-                     $lists[$k][] = '<span style="color:#FFDA0A;">'.$v['start'].'</span>';
 
-                     $lists[$k][] = '<span style="color:#FFDA0A;">'.$v['end'].'</span>';
 
-                     $lists[$k][] = '<span style="color:#FFDA0A;">'.$v['xq_time'].'</span>';
 
-                     $lists[$k][] = '<span style="color:#FFDA0A;">'.$v['user_name'].'</span>';
 
-                     $lists[$k][] = '<span style="color:#FFDA0A;">'.$v['confirm_time'].'</span>';
 
-                     $lists[$k][] = '<span style="color:#FFDA0A;">'.$v['done_time'].'</span>';
 
-                 }elseif($v['todo_mode'] == 2){
 
-                     $lists[$k][] = '<span style="color:#0FC2DD;">进行中</span>';
 
-                     $lists[$k][] = '<span style="color:#0FC2DD;">'.$v['type'].'</span>';
 
-                     $lists[$k][] = '<span style="color:#0FC2DD;">'.$v['start'].'</span>';
 
-                     $lists[$k][] = '<span style="color:#0FC2DD;">'.$v['end'].'</span>';
 
-                     $lists[$k][] = '<span style="color:#0FC2DD;">'.$v['xq_time'].'</span>';
 
-                     $lists[$k][] = '<span style="color:#0FC2DD;">'.$v['user_name'].'</span>';
 
-                     $lists[$k][] = '<span style="color:#0FC2DD;">'.$v['confirm_time'].'</span>';
 
-                     $lists[$k][] = '<span style="color:#0FC2DD;">'.$v['done_time'].'</span>';
 
-                 }else{
 
-                     $lists[$k][] = $status;
 
-                     $lists[$k][] = $v['type'];
 
-                     $lists[$k][] = $v['start'];
 
-                     $lists[$k][] = $v['end'];
 
-                     $lists[$k][] = $v['xq_time'];
 
-                     $lists[$k][] = $v['user_name'];
 
-                     $lists[$k][] = $v['confirm_time'];
 
-                     $lists[$k][] = $v['done_time'];
 
-                 }
 
-             }
 
-         }else if($mode == 5){
 
-             foreach ($data as $k=>$v){
 
-                 $status = '';
 
-                if($v['status'] == 0){
 
-                    $status = '作废';
 
-                }else if($v['status'] == 1){
 
-                    $status = '服务中';
 
-                }else if($v['status'] == 2){
 
-                    $status = '已结束';
 
-                }
 
-                 $lists[$k][] = $status;
 
-                 $lists[$k][] = $v['start'];
 
-                 $lists[$k][] = $v['end'];
 
-                 $lists[$k][] = $v['day'];
 
-                 $lists[$k][] = $v['create_time'];
 
-             }
 
-         }
 
-         HelpHander::success(['data'=>$lists,'header'=>$header]);
 
-     }
 
-     //今日工单总数 //项目工单总数 //项目订单总数 //项目任务总数
 
-     public function todoCountData(){
 
-         $todayCount = Db::name('todo')
 
-             ->where('del',0)
 
-             ->where('org_id',$this->orgId)
 
-             ->where('create_yyyymmdd',date('Ymd'))
 
-             ->count();
 
-         $todoCount = Db::name('todo')
 
-             ->where('del',0)
 
-             ->where('org_id',$this->orgId)
 
-             ->count();
 
-         $orderCount = Db::name('orders')
 
-             ->where('del',0)
 
-             ->where('org_id',$this->orgId)
 
-             ->count();
 
-         $task1 = Db::name('device_task')
 
-             ->where('del',0)
 
-             ->where('org_id',$this->orgId)
 
-             ->count();
 
-         $task2 = Db::name('patrol_task')
 
-             ->where('del',0)
 
-             ->where('org_id',$this->orgId)
 
-             ->count();
 
-         $taskCount = $task1+$task2;
 
-         $data = [
 
-             'todayCount'=>$todayCount,
 
-             'todoCount'=>$todoCount,
 
-             'orderCount'=>$orderCount,
 
-             'taskCount'=>$taskCount,
 
-         ];
 
-         HelpHander::success($data);
 
-     }
 
-     public function todayTodoData(){
 
-         $date = date('Ymd');
 
-         $count = Db::name('todo')
 
-             ->where('create_yyyymmdd',$date)
 
-             ->where('del',0)
 
-             ->count();
 
-         $count2 = Db::name('todo')
 
-             ->where('create_yyyymmdd',$date)
 
-             ->where('del',0)
 
-             ->where('todo_mode',3)
 
-             ->count();
 
-         $map[] = ['del','=',0];
 
-         $map[] = ['create_yyyymmdd','=',$date];
 
-         $bjCount = Db::name('todo')->where('work_type_mode',2)->where($map)->count();
 
-         $bj = Db::name('todo')->where('work_type_mode',2)->where('todo_mode',3)->where($map)->count();
 
-         $ysCount = Db::name('todo')->where('work_type_mode',3)->where($map)->count();
 
-         $ys = Db::name('todo')->where('work_type_mode',3)->where('todo_mode',3)->where($map)->count();
 
-         $bxCount = Db::name('todo')->where('work_type_mode',1)->where($map)->count();
 
-         $bx = Db::name('todo')->where('work_type_mode',1)->where('todo_mode',3)->where($map)->count();
 
-         $yhCount = Db::name('todo')->where('work_type_mode',4)->where($map)->count();
 
-         $yh = Db::name('todo')->where('work_type_mode',4)->where('todo_mode',3)->where($map)->count();
 
-         $bl = $bjBl = $ysBl = $bxBl = $yhBl = 0;
 
-         if($count > 0){
 
-             $bl = round($count2/$count*100,0);
 
-         }
 
-         if($bjCount >0){
 
-             $bjBl = round($bj/$bjCount*100,0);
 
-         }
 
-         if($ysCount >0){
 
-             $ysBl = round($ys/$ysCount*100,0);
 
-         }
 
-         if($bxCount >0){
 
-             $bxBl = round($bx/$bxCount*100,0);
 
-         }
 
-         if($yhCount >0){
 
-             $yhBl = round($yh/$yhCount*100,0);
 
-         }
 
-         $count3 = 0;
 
-         if($count == 0){
 
-             $count3 = 100;
 
-         }else{
 
-             $count3 =  $count - $count2;
 
-         }
 
-         $data = [
 
-             'count'=>$count,
 
-             'bl'=>$bl,
 
-             'bjBl'=>$bjBl,
 
-             'bj'=>$bj,
 
-             'ysBl'=>$ysBl,
 
-             'ys'=>$ys,
 
-             'bxBl'=>$bxBl,
 
-             'bx'=>$bx,
 
-             'yhBl'=>$yhBl,
 
-             'yh'=>$yh,
 
-             'list'=>[
 
-                 ['value'=>$count2],
 
-                 ['value'=>$count3],
 
-             ]
 
-         ];
 
-         HelpHander::success($data);
 
-     }
 
- }
 
 
  |