where('org_id',$this->orgId) ->where('del',0) ->where('todo_mode',3) ->where('work_type_mode',3) ->count(); HelpHander::success($count); } public function todoStatusNum(){ $list = [ ['name'=>'待派工','mode'=>1], ['name'=>'进行中','mode'=>2], ['name'=>'已完成','mode'=>3], ['name'=>'已超时','mode'=>5], ]; foreach ($list as $k=>$v){ $list[$k]['value'] = Db::name('todo') ->where('org_id',$this->orgId) ->where('del',0) ->where('todo_mode',$v['mode']) ->where('work_type_mode',3) ->count(); } $todo = Db::name('todo') ->alias('t') ->field('t.done_time,oc.ywc_time') ->join('order_convey oc','oc.order_id=t.order_id') ->where('t.org_id',$this->orgId) ->where('t.del',0) ->where('t.todo_mode',3) ->select(); $count = count($todo); $nums = 0; //标准时间的送达的数量 foreach ($todo as $k=>$v){ if($v['done_time'] < $v['ywc_time']){ $nums +=1; } } $bl = '0%'; if($count >0){ $bl = round($nums/$count*100,1).'%'; } $count1 = $bl; //平均响应时间 $count2 = Db::name('todo') ->where('org_id',$this->orgId) ->where('del',0) ->where('todo_mode',3) ->avg('xy_time'); //未派工任务数量 $orders = Db::name('orders') ->where('org_id',$this->orgId) ->where('del',0) ->count(); $ordersCount = Db::name('orders') ->where('org_id',$this->orgId) ->where('del',0) ->where('order_mode',1) ->count(); $count3 = '0%'; if($orders > 0){ $count3 = round($ordersCount/$orders*100,1).'%'; } $data = [ 'list'=>$list, 'legend'=>['待派工','进行中','已完成','已超时'], 'count'=>[ 'count1'=>$count1, 'count2'=>round($count2/360,1), 'count3'=>$count3, ], ]; HelpHander::success($data); } //运送热点区域数据 public function addrData(){ $date = date('Ymd'); $edate = date("Ymd",strtotime("-1 months",strtotime($date))); $addr = Db::name('address') ->field('id,title') ->where('del',0) ->where('enable',1) ->where('org_id',$this->orgId) ->where('','exp',Db::raw("FIND_IN_SET(2,types)")) ->select(); foreach ($addr as $k=>$v){ $addr[$k]['nums1'] = Db::name('todo') ->alias('t') ->join('todo_convey tc','tc.todo_id=t.id') ->where('tc.start',$v['id']) ->where('t.org_id',$this->orgId) ->where('t.del',0) ->where('t.create_yyyymmdd','=',$date) ->count(); $nums2 = Db::name('todo') ->alias('t') ->join('todo_convey tc','tc.todo_id=t.id') ->where('tc.start',$v['id']) ->where('t.org_id',$this->orgId) ->where('t.del',0) ->where('t.create_yyyymmdd','<=',$date) ->where('t.create_yyyymmdd','>',$edate) ->count(); $addr[$k]['nums2'] = round($nums2/30,1); // $addr[$k]['nums2'] = $nums2; } $lists =array_slice(list_sort_by($addr,'nums1','desc'),0,5) ; $data1 = array_column($lists,'nums1'); $data2 = array_column($lists,'nums2'); $title = array_column($lists,'title'); $data = [ 'data1'=>$data1, 'data2'=>$data2, 'title'=>$title, ]; HelpHander::success($data); } public function ysTypeUser(){ $lists = model('WorkTypeMode')->getRolesUserApp(3,$this->orgId); $curday = date('Ymd'); $users = Db::name('todo') ->field('to_user_id') ->where('org_id',$this->orgId) ->whereIn('todo_mode',[1,2]) ->where('del',0) ->where('work_type_mode',3) ->where('create_yyyymmdd',$curday) ->group('to_user_id') ->select(); $users = $users?$users:[]; $userIds = []; foreach ($users as $k=>$v){ $userIds[] = $v['to_user_id']; } $nlists = $nlists2 = []; foreach ($lists as $k=>$v){ if(!in_array($v['id'],$userIds)){ $nlists[] = $v; } } $slist = $slist2 = []; foreach ($nlists as $k=>$v){ $count = Db::name('todo') ->where('org_id',$this->orgId) ->where('to_user_id',$v['id']) ->whereIn('todo_mode',[1,2,3]) ->where('del',0) ->where('create_yyyymmdd',$curday) ->count(); $addr = Db::name('convey_plan_record') ->alias('cpr') ->join('address a','a.id = cpr.addr_id') ->where('cpr.user_id',$v['id']) ->where('cpr.create_yyyymmdd',$curday) ->order('cpr.id desc') ->value('a.title'); $slist[$k][] = ''.$v['real_name'].''; $slist[$k][] = ''.$count.''; $slist[$k][] = ''.$addr.''; } foreach ($lists as $k=>$v){ if(in_array($v['id'],$userIds)){ $nlists2[] = $v; } } foreach ($nlists2 as $k=>$v){ $count = Db::name('todo') ->where('org_id',$this->orgId) ->where('to_user_id',$v['id']) ->whereIn('todo_mode',[1,2,3]) ->where('del',0) ->where('create_yyyymmdd',$curday) ->count(); $addr = Db::name('convey_plan_record') ->alias('cpr') ->join('address a','a.id = cpr.addr_id') ->where('cpr.create_yyyymmdd',$curday) ->where('cpr.user_id',$v['id']) ->order('cpr.id desc') ->value('a.title'); $slist2[$k][] = ''.$v['real_name'].''; $slist2[$k][] = ''.$count.''; $slist2[$k][] = ''.$addr?$addr:''.''; } $data = [ 'list1'=>[ 'list'=>$slist2, 'count'=>count($slist2), ], 'list2'=>[ 'list'=>$slist, 'count'=>count($slist), ], ]; HelpHander::success($data); } public function ysTask(){ $order = Db::name('orders') ->alias('o') ->field('o.*,oc.type,oc.start,oc.end,oc.xq_time,oc.ywc_time,oc.device_id,oc.name,oc.phone,oc.priority') ->join('order_convey oc','oc.order_id=o.id') ->where('o.create_yyyymmdd',date('Ymd')) ->where('o.work_type_mode',3) ->where('o.org_id',$this->orgId) ->where('o.del',0) ->whereIn('o.order_mode',[1,4,5]) ->order('oc.xq_time') ->select(); foreach ($order as $k=>$v){ $order[$k]['xq_time'] = date('H:i',strtotime($v['xq_time'])); $order[$k]['start_name'] = Db::name('address')->where('id',$v['start'])->value('title'); $order[$k]['end_name'] = Db::name('address')->where('id',$v['end'])->value('title'); $order[$k]['type_name'] = Db::name('convey_cate')->where('id',$v['type'])->value('title'); $todo = Db::name('todo') ->alias('t') ->field('u.real_name,t.create_time,t.confirm_time') ->join('user u','u.id = t.to_user_id') ->whereIn('t.todo_mode',[1,2,3]) ->where('t.del',0) ->where('t.order_id',$v['id']) ->order('t.id asc') ->select(); $users = []; $confirmTime = ''; foreach ($todo as $kk=>$vv){ $users[] = $vv['real_name']; if(!$confirmTime && $vv['confirm_time']){ $confirmTime = $vv['confirm_time']; }else if($confirmTime && $vv['confirm_time'] && $vv['confirm_time'] < $confirmTime){ $confirmTime = $vv['confirm_time']; } } $send_time = $todo?$todo[0]['create_time']:''; $order[$k]['real_names'] = implode(',',$users); $order[$k]['send_time'] = !empty($send_time)?date('H:i',strtotime($send_time)):''; $order[$k]['confirm_time'] = !empty($confirmTime)?date('H:i',strtotime($confirmTime)):''; } $list = []; foreach ($order as $k=>$v) { if($v['order_mode'] == 1){ $list[$k][] = '新任务'; $list[$k][] = $v['type_name']; $list[$k][] = $v['start_name']; $list[$k][] = $v['end_name']; $list[$k][] = $v['xq_time']; $list[$k][] = $v['real_names']; $list[$k][] = $v['send_time']; $list[$k][] = $v['confirm_time']; } elseif($v['order_mode'] == 5 && $v['confirm_time']){ $list[$k][] = '已派工'; $list[$k][] = ''.$v['type_name'].''; $list[$k][] = ''.$v['start_name'].''; $list[$k][] = ''.$v['end_name'].''; $list[$k][] = ''.$v['xq_time'].''; $list[$k][] = ''.$v['real_names'].''; $list[$k][] = ''.$v['send_time'].''; $list[$k][] = ''.$v['confirm_time'].''; }else{ $list[$k][] = '进行中'; $list[$k][] = ''.$v['type_name'].''; $list[$k][] = ''.$v['start_name'].''; $list[$k][] = ''.$v['end_name'].''; $list[$k][] = ''.$v['xq_time'].''; $list[$k][] = ''.$v['real_names'].''; $list[$k][] = ''.$v['send_time'].''; $list[$k][] = ''.$v['confirm_time'].''; } } HelpHander::success($list); } //标本限时服务 public function conveyOrder(){ $order = Db::name('orders') ->alias('o') ->field('o.order_mode,oc.*') ->join('order_convey oc','oc.order_id=o.id') ->where('o.org_id',$this->orgId) ->where('o.del',0) ->where('o.create_yyyymmdd',date('Ymd')) ->where('o.work_type_mode',3) ->whereIn('o.order_mode',[1,4,5]) ->order('o.id desc') ->select(); foreach ($order as $k=>$v){ $order[$k]['status'] = ''; if($v['order_mode'] == 1){ $order[$k]['status'] = '待派发'; }elseif ($v['order_mode'] == 4){ $order[$k]['status'] = '已派发'; }elseif ($v['order_mode'] == 5){ $order[$k]['status'] = '已完成'; } $order[$k]['cate_name'] = Db::name('convey_cate')->where('id',$v['type'])->value('title'); $order[$k]['start_name'] = Db::name('address')->where('id',$v['start'])->value('title'); } $list = []; foreach ($order as $k=>$v){ $list[$k][] = $v['cate_name']; $list[$k][] = $v['start_name']; $list[$k][] = $v['xq_time']; $list[$k][] = $v['status']; } HelpHander::success($list); } public function ysOrderWeek(){ $dlist = [ date('Y-m-d',strtotime('-6 days')), date('Y-m-d',strtotime('-5 days')), date('Y-m-d',strtotime('-4 days')), date('Y-m-d',strtotime('-3 days')), date('Y-m-d',strtotime('-2 days')), date('Y-m-d',strtotime('-1 days')), date('Y-m-d'), ]; $list = $list1 = $date = []; foreach ($dlist as $k=>$v){ $data[] = date('m-d',strtotime($v)); $tt = date('Ymd',strtotime($v)); $count = Db::name('todo') ->where('org_id',$this->orgId) ->where('create_yyyymmdd',$tt) ->where('del',0) ->where('work_type_mode',3) ->count(); $count1 = Db::name('todo') ->where('org_id',$this->orgId) ->where('create_yyyymmdd',$tt) ->where('del',0) ->where('work_type_mode',3) ->where('todo_mode',3) ->count(); $list[$k]= $count; $list1[$k] = $count1; } $data = [ 'title'=>$data, 'list'=>[ 'list1'=>$list, 'list2'=>$list1, ] ]; HelpHander::success($data); } public function conveyCateData(){ $cate = Db::name('convey_cate') ->field('id,title') ->where('del',0) ->where('enable',1) ->where('org_id',$this->orgId) ->select(); foreach ($cate as $k=>$v){ $cate[$k]['count'] = Db::name('orders') ->alias('o') ->join('order_convey oc','oc.order_id=o.id') ->whereIn('o.order_mode',[1,4,5,6]) ->where('o.del',0) ->where('o.work_type_mode',3) ->where('oc.type',$v['id']) ->count(); } $lists =array_slice(list_sort_by($cate,'count','desc'),0,6) ; $data1 = array_column($lists,'title'); $data2 = array_column($lists,'count'); $data = [ 'title'=>$data1, 'list'=>$data2, ]; HelpHander::success($data); } }