123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423 |
- <?php
- namespace app\api\controller\screen;
- use app\hander\HelpHander;
- use app\api\controller\screen\Index;
- use think\Db;
- class Convey extends Index
- {
- public function todoNum(){
- $count = Db::name('todo')
- ->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][] = '<span style="color: #FFE400">'.$v['real_name'].'</span>';
- $slist[$k][] = '<span style="color: #FFE400">'.$count.'</span>';
- $slist[$k][] = '<span style="color: #FFE400">'.$addr.'</span>';
- }
- 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][] = '<span style="color: #11E799">'.$v['real_name'].'</span>';
- $slist2[$k][] = '<span style="color: #11E799">'.$count.'</span>';
- $slist2[$k][] = '<span style="color: #11E799">'.$addr?$addr:''.'</span>';
- }
- $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][] = '<span style="color:#0FC2DD;">已派工</span>';
- $list[$k][] = '<span style="color:#0FC2DD;">'.$v['type_name'].'</span>';
- $list[$k][] = '<span style="color:#0FC2DD;">'.$v['start_name'].'</span>';
- $list[$k][] = '<span style="color:#0FC2DD;">'.$v['end_name'].'</span>';
- $list[$k][] = '<span style="color:#0FC2DD;">'.$v['xq_time'].'</span>';
- $list[$k][] = '<span style="color:#0FC2DD;">'.$v['real_names'].'</span>';
- $list[$k][] = '<span style="color:#0FC2DD;">'.$v['send_time'].'</span>';
- $list[$k][] = '<span style="color:#0FC2DD;">'.$v['confirm_time'].'</span>';
- }else{
- $list[$k][] = '<span style="color:#49E9A0;">进行中</span>';
- $list[$k][] = '<span style="color:#49E9A0;">'.$v['type_name'].'</span>';
- $list[$k][] = '<span style="color:#49E9A0;">'.$v['start_name'].'</span>';
- $list[$k][] = '<span style="color:#49E9A0;">'.$v['end_name'].'</span>';
- $list[$k][] = '<span style="color:#49E9A0;">'.$v['xq_time'].'</span>';
- $list[$k][] = '<span style="color:#49E9A0;">'.$v['real_names'].'</span>';
- $list[$k][] = '<span style="color:#49E9A0;">'.$v['send_time'].'</span>';
- $list[$k][] = '<span style="color:#49E9A0;">'.$v['confirm_time'].'</span>';
- }
- }
- 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);
- }
- }
|