orgId]; $lists = Db::name('task')->where($map)->order('start_time desc')->limit(50)->select(); $lists = $lists?$lists:[]; $news = []; try{ foreach ($lists as $k=>$v){ $arr = [ 'id' => $v['id'], 'start_time' => $v['start_time'], 'cate' => 0, 'content' => '', 'cate_title' => '', 'user_name' => '', ]; $arr['user_name'] = Db::name('user')->where('id',$v['user_id'])->value('real_name'); if($v['type'] == 1){ // 订单 $order = Db::name('todo')->where('todo_mode','in',[1,2])->where('del',0)->where('id',$v['bus_id'])->find(); if(!$order || $order['work_type_mode'] == 2 || $order['work_type_mode'] == 4){ continue; } $arr['status'] = $order['todo_mode'] == 1?0:1; if($order['work_type_mode'] == 1){ // 报修,检查是否有报修地点 $addressId = Db::name('order_repair')->where('order_id',$order['order_id'])->value('address_id'); $addressId = $addressId ?$addressId:0; $address = Db::name('address')->where('id',$addressId)->field('id,title,xyz')->find(); if(!$address){ continue; } $xyz = $address['xyz']?explode(',',$address['xyz']):[]; if(empty($xyz) || $xyz[0] == ''){ $address['xyz'] = []; }else{ $address['xyz'] = $xyz; } $arr['cate'] = 1; // 报修 $arr['cate_title'] = '报修'; $arr['address'] = $address; $arr['content'] = Db::name('orders')->where('id',$order['order_id'])->value('content'); }elseif($order['work_type_mode'] == 3){ // 运送 $addr = Db::name('order_convey')->where('order_id',$order['order_id'])->find(); if(!$addr){ continue; } $start = Db::name('address')->where('id',$addr['start'])->field('id,title,xyz')->find(); $xyz = $start['xyz']?explode(',',$start['xyz']):[]; if(empty($xyz) || $xyz[0] == ''){ $start['xyz'] = []; }else{ $start['xyz'] = $xyz; } $end = Db::name('address')->where('id',$addr['end'])->field('id,title,xyz')->find(); $xyz = $end['xyz']?explode(',',$end['xyz']):[]; if(empty($xyz) || $xyz[0] == ''){ $end['xyz'] = []; }else{ $end['xyz'] = $xyz; } $cateTitle = Db::name('convey_cate')->where('id',$addr['type'])->value('title'); $arr['cate'] = 2; // 运送 $arr['cate_title'] = '运送'; $arr['start'] = $start; $arr['end'] = $end; $arr['content'] = '从'.$start['title'].'至'.$end['title'].'执行'.$cateTitle.'任务'; } } else{ // 巡更 $ptask = Db::name('patrol_task')->where('status','in',[0,1])->where('del',0)->where('id',$v['bus_id'])->find(); if(!$ptask){ continue; } $arr['content'] = $ptask['title']; $arr['status'] = $ptask['status']; if($ptask['patrol_mode'] == 1){ // 巡更 $arr['cate'] = 3; $arr['cate_title'] = '巡更'; }else if($ptask['patrol_mode'] == 2){ //巡视 $arr['cate'] = 4; $arr['cate_title'] = '巡视'; }else if($ptask['patrol_mode'] == 3){ //巡查 $arr['cate'] = 5; $arr['cate_title'] = '巡查'; }else{ // 巡检 $arr['cate'] = 6; $arr['cate_title'] = '巡检'; } $addrids = Db::name('patrol_task_addr') ->where('patrol_task_id',$ptask['id']) ->column('address_id'); $addrs = Db::name('address')->where('id','in',$addrids)->field('id,title,xyz')->select(); $addrs = $addrs?$addrs:[]; foreach ($addrs as $kk=>$vv){ $xyz = $vv['xyz']?explode(',',$vv['xyz']):[]; if(empty($xyz) || $xyz[0] == ''){ $addrs[$kk]['xyz'] = []; }else{ $addrs[$kk]['xyz'] = $xyz; } } $arr['addrs'] = $addrs; } $news[] = $arr; } }catch (Exception $e){ } $addrList = Db::name('convey_plan_record')->where('org_id',$this->orgId)->field('addr_id,count(*) as count')->group('addr_id')->distinct(true)->select(); $addrList = $addrList?$addrList:[]; $newaddrs = []; foreach ($addrList as $k=>$v){ $title = Db::name('address')->where('id',$v['addr_id'])->value('title'); // $newaddrs[] = [$title,$v['count']]; $newaddrs[] = [ 'title' => $title, 'count' => $v['count'] ]; } $data = [ 'task' => $news, 'addrs' => $newaddrs ]; HelpHander::success($data); } public function taskList(){ $list = Db::name('task') ->where('org_id',$this->orgId) ->where('type','in',[1,2]) ->order('id desc') ->limit(20) ->select(); $patrolStatus = [ 0=>'未执行', 1=>'执行中', 2=>'已完成', 3=>'未完成', 5=>'中断', 6=>'已关闭', ]; $data = []; foreach ($list as $k=>$v){ $taskType = $userName = $content = $statusTxt = ''; if($v['type'] == 1){ $todo = Db::name('todo') ->where('id',$v['bus_id']) ->find(); if($todo){ $taskType = Db::name('work_type_mode')->where('id',$todo['work_type_mode'])->value('name'); $userName = Db::name('user')->where('id',$todo['to_user_id'])->value('real_name'); if($todo['work_type_mode'] == 3){ $orderConvey = Db::name('order_convey')->where('order_id',$todo['order_id']) ->find(); $sAddr = Db::name('address')->where('id',$orderConvey['start'])->value('title'); $eAddr = Db::name('address')->where('id',$orderConvey['end'])->value('title'); $content = '即将从'.$sAddr.'至'.$eAddr.','.$todo['todo_content']; }else{ $content = $todo['todo_content']; } $statusTxt = Db::name('todo_mode')->where('id',$todo['todo_mode'])->value('out_content'); } }elseif ($v['type'] == 2){ $patrol = Db::name('patrol_task') ->where('id',$v['bus_id']) ->find(); if($patrol){ $taskType = Db::name('patrol_mode')->where('id',$patrol['patrol_mode'])->value('name'); $uids = Db::name('patrol_task_user')->where('patrol_task_id',$patrol['id'])->column('user_id'); $user = Db::name('user')->whereIn('id',$uids)->column('real_name'); $userName = $user ? implode(',',$user):''; $content = $patrol['title']; $statusTxt = $patrolStatus[$patrol['status']]; } } $data[] = [$taskType.'任务',$userName,$content,$statusTxt]; } HelpHander::success($data); } }