where('org_id',$this->orgId)
->where('del',0)
->where('todo_mode',3)
->where('work_type_mode',3)
->where('create_yyyymmdd',date('Ymd'))
->count();
$count1 = Db::name('todo')
->where('org_id',$this->orgId)
->where('del',0)
->where('todo_mode',3)
->where('work_type_mode',3)
->where('create_yyyymm',date('Ym'))
->count();
$count2 = Db::name('todo')
->where('org_id',$this->orgId)
->where('del',0)
->where('todo_mode',3)
->where('work_type_mode',3)
->where('create_yyyy',date('Y'))
->count();
HelpHander::success(['count'=>$count,'count1'=>$count1,'count2'=>$count2]);
}
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)
->where('create_yyyymmdd',date('Ymd'))
->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.create_yyyymmdd',date('Ymd'))
->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)
->where('create_yyyymmdd',date('Ymd'))
->avg('xy_time');
//未派工任务数量
$orders = Db::name('orders')
->where('org_id',$this->orgId)
->where('del',0)
->where('create_yyyymmdd',date('Ymd'))
->count();
$ordersCount = Db::name('orders')
->where('org_id',$this->orgId)
->where('del',0)
->where('order_mode',1)
->where('create_yyyymmdd',date('Ymd'))
->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)"))
->limit(5)
->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,1);
$curday = date('Ymd');
$users = Db::name('todo')
->alias('t')
->field('t.to_user_id')
->join('user u','u.id=t.to_user_id')
->where('t.org_id',$this->orgId)
->whereIn('t.todo_mode',[1,2])
->where('t.del',0)
->where('t.work_type_mode',3)
->where('t.create_yyyymmdd',$curday)
->where('u.work',1)
->where('u.enable',1)
->where('u.del',0)
->group('t.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');
if(!$addr){
$addr = Db::name('todo')
->alias('t')
->join('orders o','o.id=t.order_id')
->join('order_convey oc','oc.order_id=o.id')
->join('address a','a.id=oc.start')
->where('t.to_user_id',$v['id'])
->where('t.org_id',$this->orgId)
->where('t.to_user_id',$v['id'])
->whereIn('t.todo_mode',[1,2,3])
->where('t.del',0)
->where('t.create_yyyymmdd',$curday)
->order('t.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');
if(!$addr){
$addr = Db::name('todo')
->alias('t')
->join('orders o','o.id=t.order_id')
->join('order_convey oc','oc.order_id=o.id')
->join('address a','a.id=oc.start')
->where('t.to_user_id',$v['id'])
->where('t.org_id',$this->orgId)
->where('t.to_user_id',$v['id'])
->whereIn('t.todo_mode',[1,2,3])
->where('t.del',0)
->where('t.create_yyyymmdd',$curday)
->order('t.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])
->order('oc.xq_time desc')
->select();
$num = $num1 =0;
foreach ($order as $k=>$v){
if($v['order_mode'] == 1){
$num +=1;
}
if($v['order_mode'] == 4){
$num1 +=1;
}
$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'=>$list,'num'=>$num,'num1'=>$num1]);
}
//标本限时服务
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'];
// }
// $todo = Db::name('todo')
// ->alias('t')
// ->field('t.todo_mode,t.to_user_id,oc.*')
// ->join('order_convey oc','t.order_id=oc.order_id')
// ->where('t.org_id',$this->orgId)
// ->where('t.del',0)
// ->where('t.create_yyyymmdd',date('Ymd'))
// ->where('t.work_type_mode',3)
// ->whereIn('t.todo_mode',[1,2])
// ->order('t.id desc')
// ->select();
// foreach ($todo as $k=>$v){
// $todo[$k]['status'] = '';
// if($v['todo_mode'] == 1){
// $todo[$k]['status'] = '待派发';
// }elseif ($v['todo_mode'] == 2){
// $todo[$k]['status'] = '已派发';
// }
// $todo[$k]['cate_name'] = Db::name('convey_cate')->where('id',$v['type'])->value('title');
// $todo[$k]['start_name'] = Db::name('address')->where('id',$v['start'])->value('title');
// $todo[$k]['user_name'] = Db::name('user')->where('id',$v['to_user_id'])->value('real_name');
// }
//
// $list = [];
// foreach ($todo as $k=>$v){
// $list[$k][] = $v['cate_name'];
// $list[$k][] = $v['start_name'];
// $list[$k][] = date('H:i:s',strtotime($v['xq_time']));
// $list[$k][] = $v['status'];
// $list[$k][] = $v['user_name'];
// }
$map[] = ['o.del', '=', 0];
$map[] = ['o.org_id', '=', $this->orgId];
$map[] = ['o.work_type_mode', '=', 3];
$map[] = ['o.order_mode', 'in', [1, 4]];
$lists = db('orders')
->alias('o')
->join('order_convey oc', 'oc.order_id=o.id')
->field('o.*,oc.type,oc.start,oc.end,oc.xq_time,oc.ywc_time,oc.device_id,oc.name,oc.phone,oc.priority')
->where($map)
->order(['o.order_mode' => 'asc', 'oc.xq_time' => 'desc'])
->select();
$data = [];
foreach ($lists as $k => $v) {
$v = model('Orders')->formatOrder($v);
$v['bed_number'] = '';
$ocp = Db::name('order_convey_patient')
->where('order_id', $v['id'])
->find();
$v['bed_number'] = !empty($ocp)?$ocp['bed_number']:'';
$todo = Db::name('todo')
->alias('t')
->where('t.order_id', $v['id'])
->join('user u', 'u.id = t.to_user_id')
->where('t.todo_mode', 'in', [1, 2, 3, 4])
->where('t.del', 0)
->field('u.real_name,t.create_time,t.confirm_time')
->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'];
}
}
}
$v['real_names'] = $users? implode(',', $users):'';
$v['confirm_time'] = $confirmtime;
$last = strtotime($v['ywc_time']) - time();
$v['last_time'] = $last > 0 ? round($last / 60) : 0;
//是否有延时
$v['delay'] = 0; // 0=未延迟 1=延迟
$v['delay_diff'] = 0;
$v['delay_reason'] = '';
$delays = Db::name('order_delay')
->where('order_id', $v['id'])
->select();
$delays = $delays ? $delays : [];
foreach ($delays as $vv) {
if ($vv['status'] == 0) {
$v['delay'] = 1;
$v['delay_reason'] = Db::name('delay_reason')->where('id',$vv['delay_reason_id'])->value('title');
$vv['diff'] = time() - strtotime($vv['start_time']);
}
$v['delay_diff'] += $vv['diff'];
}
$v['delay_diff'] = round($v['delay_diff'] / 60);
if ($v['delay'] == 1) {
$v['status'] = 3;
} else {
if ($v['order_mode'] == 1) {
$v['status'] = 1;
} else {
$v['status'] = 2;
}
}
$convey = Db::name('convey_cate')
->alias('oc')
->join('time ot', 'ot.id = oc.time_id')
->where('oc.id', $v['type'])
->field('ot.*')
->find();
$createtime = strtotime($v['create_time']);
$curtime = time();
$ct = round(($curtime - $createtime) / 60);
if ($ct < $convey['yy_time']) {
$ss = 0;
}
else {
if ($ct >= $convey['yy_time'] && $ct < $convey['bz_time']) {
$ss = 1;
}
else {
if ($ct >= $convey['bz_time'] && $ct < $convey['jg_time']) {
$ss = 2;
}
else {
if ($ct >= $convey['jg_time'] && $ct < $convey['wjjg_time']) {
$ss = 3;
}
else {
$ss = 4;
}
}
}
}
$v['ss'] = $ss;
$v['xtime'] = date('H:i', strtotime($v['xq_time']));
$v['stime'] = $v['send_time'] ? date('H:i', strtotime($v['send_time'])) : "";
$v['ctime'] = $v['confirm_time'] ? date('H:i', strtotime($v['confirm_time'])) : "";
$v['priorityName'] = isset(model('Orders')->priority[$v['priority']])?model('Orders')->priority[$v['priority']]:'';
// //只取进行中的
if(isset($v['status']) && $v['status'] == 2 && $v['ss'] >0){
$data[] = [
''.$v['type_name'].'',
''.$v['start_name'].'',
''.$v['end_name'].'',
'进行中',
''.$v['real_names'].'',
];
}
}
HelpHander::success($data);
}
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'),
// ];
$dlist = [
'02','04','06','08','10','12','14','16','18','20','22','24'
];
$curDay = date('Y-m-d');
$list = $list1 = $date = [];
foreach ($dlist as $k=>$v){
if($k == 0){
$s = $curDay.' 00:00:00';
}else{
$s = $curDay.' '.$dlist[$k-1].':00:00';
}
$e = $curDay.' '.$v.':00:00';
$count = Db::name('todo')
->where('org_id',$this->orgId)
->where('del',0)
->where('work_type_mode',3)
->where('create_time','>=',$s)
->where('create_time','<',$e)
->count();
$count1 = Db::name('todo')
->where('org_id',$this->orgId)
->where('del',0)
->where('work_type_mode',3)
->where('todo_mode',3)
->where('create_time','>=',$s)
->where('create_time','<',$e)
->count();
$list[$k]= $count;
$list1[$k] = $count1;
}
$data = [
'title'=>$dlist,
'list'=>[
'list1'=>$list1,
'list2'=>$list,
]
];
HelpHander::success($data);
}
public function conveyCateData(){
$date = date('Ymd');
$edate = date("Ymd",strtotime("-1 months",strtotime($date)));
$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('o.create_yyyymmdd',date('Ymd'))
->where('oc.type',$v['id'])
->count();
$nums2 = 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('o.create_yyyymmdd','<=',$date)
->where('o.create_yyyymmdd','>',$edate)
->where('oc.type',$v['id'])
->count();
$cate[$k]['count1'] = round($nums2/30,1);;
}
$lists =array_slice(list_sort_by($cate,'count','desc'),0,6) ;
$data1 = array_column($lists,'title');
$data2 = array_column($lists,'count');
$data3 = array_column($lists,'count1');
$data = [
'title'=>$data1,
'list'=>$data2,
'list1'=>$data3,
];
HelpHander::success($data);
}
public function ysTypeTask(){
$type = input('type',0); //3=紧急 1=超时 2=常规
$fontColor = input('fontColor','#fff'); //字体颜色 //默认白色
$jxzColor = input('jxzColor','#49E9A0'); //进行中颜色
if(!in_array($type,[1,2,3])){
HelpHander::error('参数错误');
}
$ctlist = [];
if(in_array($type,[2,3])){
$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)
->where('oc.priority',$type)
->whereIn('o.order_mode',[1,4])
->order('oc.xq_time desc')
->select();
$num = $num1 =0;
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)):'';
$convey = Db::name('convey_cate')
->alias('oc')
->join('time ot', 'ot.id = oc.time_id')
->where('oc.id', $v['type'])
->field('ot.*')
->find();
$createtime = strtotime($v['create_time']);
$curtime = time();
$ct = round(($curtime - $createtime) / 60);
if ($ct < $convey['yy_time']) {
$ss = 0;
}
else {
if ($ct >= $convey['yy_time'] && $ct < $convey['bz_time']) {
$ss = 1;
}
else {
if ($ct >= $convey['bz_time'] && $ct < $convey['jg_time']) {
$ss = 2;
}
else {
if ($ct >= $convey['jg_time'] && $ct < $convey['wjjg_time']) {
$ss = 3;
}
else {
$ss = 4;
}
}
}
}
if($ss != 4){
if($v['order_mode'] == 1){
$num +=1;
}
if($v['order_mode'] == 4){
$num1 +=1;
}
$ctlist[] = $order[$k];
}
}
}else{
$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])
->order('oc.xq_time desc')
->select();
$num = $num1 =0;
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)):'';
$convey = Db::name('convey_cate')
->alias('oc')
->join('time ot', 'ot.id = oc.time_id')
->where('oc.id', $v['type'])
->field('ot.*')
->find();
$createtime = strtotime($v['create_time']);
$curtime = time();
$ct = round(($curtime - $createtime) / 60);
if ($ct < $convey['yy_time']) {
$ss = 0;
}
else {
if ($ct >= $convey['yy_time'] && $ct < $convey['bz_time']) {
$ss = 1;
}
else {
if ($ct >= $convey['bz_time'] && $ct < $convey['jg_time']) {
$ss = 2;
}
else {
if ($ct >= $convey['jg_time'] && $ct < $convey['wjjg_time']) {
$ss = 3;
}
else {
$ss = 4;
}
}
}
}
if($ss == 4){
if($v['order_mode'] == 1){
$num +=1;
}
if($v['order_mode'] == 4){
$num1 +=1;
}
$ctlist[] = $order[$k];
}
}
}
$list = [];
foreach ($ctlist 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'=>$list,'num'=>$num,'num1'=>$num1]);
}
public function ysTypeUserAll(){
$dmColor = input('dmColor','#FFE400'); //待命运送员颜色 默认黄色
$lists = model('WorkTypeMode')->getRolesUserApp(3,$this->orgId,1);
$curday = date('Ymd');
$userIds = Db::name('todo')
->alias('t')
->field('t.to_user_id')
->join('user u','u.id=t.to_user_id')
->where('t.org_id',$this->orgId)
->whereIn('t.todo_mode',[1,2])
->where('t.del',0)
->where('t.work_type_mode',3)
// ->where('t.create_yyyymmdd',$curday) //去掉时间限制
->where('u.work',1)
->where('u.enable',1)
->where('u.del',0)
->group('t.to_user_id')
->column('t.to_user_id');
// $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');
if(!$addr){
$addr = Db::name('todo')
->alias('t')
->join('orders o','o.id=t.order_id')
->join('order_convey oc','oc.order_id=o.id')
->join('address a','a.id=oc.start')
->where('t.to_user_id',$v['id'])
->where('t.org_id',$this->orgId)
->where('t.to_user_id',$v['id'])
->whereIn('t.todo_mode',[1,2,3])
->where('t.del',0)
->where('t.create_yyyymmdd',$curday)
->order('t.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');
if(!$addr){
$addr = Db::name('todo')
->alias('t')
->join('orders o','o.id=t.order_id')
->join('order_convey oc','oc.order_id=o.id')
->join('address a','a.id=oc.start')
->where('t.to_user_id',$v['id'])
->where('t.org_id',$this->orgId)
->where('t.to_user_id',$v['id'])
->whereIn('t.todo_mode',[1,2,3])
->where('t.del',0)
->where('t.create_yyyymmdd',$curday)
->order('t.id desc')
->value('a.title');
}
$slist2[$k][] = ''.$v['real_name'].'';
$slist2[$k][] = ''.$count.'';
$slist2[$k][] = ''.$addr.'';
}
$data = [
'count'=>count($slist2),
'count1'=>count($slist),
'list'=>array_merge($slist2,$slist),
];
HelpHander::success($data);
}
}