123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218 |
- <?php
- namespace app\api\controller\screen;
- use app\hander\HelpHander;
- use app\api\controller\screen\Index;
- use think\Db;
- use think\Exception;
- use think\helper\Time;
- class Task extends Index
- {
- /**
- * 任务列表
- */
- public function lists(){
- $map[] = ['type','in',[1,2]];
- $map[] = ['org_id','=',$this->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);
- }
- }
|