123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533 |
- <?php
- namespace app\api\controller\screen;
- use app\api\controller\screen\Index;
- use app\hander\HelpHander;
- use think\Db;
- use think\helper\Time;
- class Popup extends Index
- {
- // 项目大屏--员工实时在岗情况
- public function userPraise(){
- $allUids = model('WorkTypeMode')->getWorkerUserIds($this->orgId);
- $users = [];
- if($allUids){
- $users = Db::name('user')
- ->where('id','in',$allUids)
- ->order('score desc,id asc')
- ->field('id,real_name,score')
- ->limit(10)
- ->select();
- $users = $users?$users:[];
- }
- $data = [];
- foreach ($users as $k=>$v){
- $top = 'TOP'.($k+1);
- $data[$k]['top'] = $top;
- $data[$k]['name'] = $v['real_name'];
- $data[$k]['score'] = $v['score'];
- }
- HelpHander::success($data);
- }
- public function hotMate(){
- $map[] = ['tm.org_id','=',$this->orgId];
- $lists = Db::name('todo_mate_item')
- ->alias('tmi')
- ->join('todo_mate tm','tm.id = tmi.todo_mate_id')
- ->where($map)
- ->field('sum(total) as total,items_id')
- ->group('items_id')
- ->distinct(true)
- ->order('total desc')
- ->limit(10)
- ->select();
- $data = [];
- foreach ($lists as $k=>$v){
- $top = 'TOP'.($k+1);
- $name = Db::name('mate_goods')->where('id',$v['items_id'])->value('title');
- $data[$k]['top'] = $top;
- $data[$k]['name'] = $name ? $name :'';
- $data[$k]['count'] = $v['total'];
- }
- HelpHander::success($data);
- }
- public function hotDep(){
- $type = input('type/d',1);
- if(!in_array($type,[1,2])){
- HelpHander::error('参数错误');
- }
- if($type == 1){ // 运送
- $map[] = ['work_type_mode','=',3];
- $map[] = ['org_id','=',$this->orgId];
- $map[] = ['del','=',0];
- $lists = Db::name('orders')
- ->where($map)
- ->field('count(*) as count,dep_id')
- ->group('dep_id')
- ->distinct(true)
- ->order('count desc')
- ->limit(10)
- ->select();
- }else{ // 陪护
- $map[] = ['org_id','=',$this->orgId];
- $lists = Db::name('ph_orders')
- ->where($map)
- ->field('count(*) as count,dep_id')
- ->group('dep_id')
- ->distinct(true)
- ->order('count desc')
- ->limit(10)
- ->select();
- }
- $data = [];
- foreach ($lists as $k=>$v){
- $top = 'TOP'.($k+1);
- $depName = Db::name('dep')->where('id',$v['dep_id'])->value('title');
- $data[$k]['top'] = $top;
- $data[$k]['dep_name'] = $depName?$depName:'';
- $data[$k]['count'] = $v['count'];
- }
- HelpHander::success($data);
- }
- public function cateTodoCount(){
- //保洁
- $bjCount = Db::name('todo')
- ->where('del',0)
- ->where('create_yyyymmdd',date('Ymd'))
- ->where('work_type_mode',2)
- ->count();
- $bjCount2 = Db::name('todo')
- ->where('del',0)
- ->where('todo_mode',3)
- ->where('create_yyyymmdd',date('Ymd'))
- ->where('work_type_mode',2)
- ->count();
- //报修
- $bxCount = Db::name('todo')
- ->where('del',0)
- ->where('create_yyyymmdd',date('Ymd'))
- ->where('work_type_mode',1)
- ->count();
- $bxCount2 = Db::name('todo')
- ->where('del',0)
- ->where('todo_mode',3)
- ->where('create_yyyymmdd',date('Ymd'))
- ->where('work_type_mode',1)
- ->count();
- //隐患
- $yhCount = Db::name('todo')
- ->where('del',0)
- ->where('create_yyyymmdd',date('Ymd'))
- ->where('work_type_mode',4)
- ->count();
- $yhCount2 = Db::name('todo')
- ->where('del',0)
- ->where('todo_mode',3)
- ->where('create_yyyymmdd',date('Ymd'))
- ->where('work_type_mode',4)
- ->count();
- //运送
- $ysCount = Db::name('todo')
- ->where('del',0)
- ->where('create_yyyymmdd',date('Ymd'))
- ->where('work_type_mode',3)
- ->count();
- $ysCount2 = Db::name('todo')
- ->where('del',0)
- ->where('todo_mode',3)
- ->where('create_yyyymmdd',date('Ymd'))
- ->where('work_type_mode',3)
- ->count();
- //陪护
- $phCount = Db::name('ph_todo')
- ->where('create_time','>=',date('Y-m-d').' 00:00:00')
- ->where('create_time','<=',date('Y-m-d').' 23:59:59')
- ->count();
- $phCount2 = Db::name('ph_todo')
- ->where('create_time','>=',date('Y-m-d').' 00:00:00')
- ->where('create_time','<=',date('Y-m-d').' 23:59:59')
- ->where('status',2)
- ->count();
- $data = [
- ['name'=>'报修','num'=>$bxCount,'num1'=>$bxCount2],
- ['name'=>'保洁','num'=>$bjCount,'num1'=>$bjCount2],
- ['name'=>'运送','num'=>$ysCount,'num1'=>$ysCount2],
- ['name'=>'应急','num'=>$yhCount,'num1'=>$yhCount2],
- ['name'=>'陪护','num'=>$phCount,'num1'=>$phCount2],
- ];
- HelpHander::success($data);
- }
- public function orderCount(){
- $mode = input('mode/d',1);
- $type = input('type/d',1);
- if(!in_array($type,[1,2,3])||!in_array($mode,[1,2,3,4])){
- HelpHander::error('参数错误');
- }
- $date = [];
- $curDay = date('Y-m-d');
- if($type == 1){ // 日统计
- $date[] = '03';
- $date[] = '06';
- $date[] = '09';
- $date[] = '12';
- $date[] = '15';
- $date[] = '18';
- $date[] = '21';
- $date[] = '24';
- }else if($type == 2){ // 周统计
- $ms = Time::week();
- $start = $ms[0];
- $end = $ms[1] + 1;
- $date[] = date('Y-m-d',$start);
- $i = 1;
- while (($start + $i*24*60*60) < $end){
- $date[] = date('Y-m-d',$start + $i*24*60*60);
- $i++;
- }
- }else{ // 月统计
- $ms = Time::month();
- $start = $ms[0];
- $end = $ms[1] + 1;
- $i = 1;
- while (($start + $i*24*60*60) < $end){
- $date[] = date('Y-m-d',$start + $i*24*60*60);
- $i++;
- }
- }
- $d1 = [];
- $d2 = [];
- $d = [];
- $data = [];
- foreach ($date as $k=>$v){
- $map = [];
- $map[] = ['org_id','=',$this->orgId];
- $map[] = ['work_type_mode','=',$mode];
- $map[] = ['del','=',0];
- if($type == 1){ // 日统计
- if($k == 0){
- $s = $curDay.' 00:00:00';
- }else{
- $s = $curDay.' '.$date[$k-1].':00:00';
- }
- $e = $curDay.' '.$v.':00:00';
- $map[] = ['create_time','egt',$s];
- $map[] = ['create_time','lt',$e];
- $d[] = (int)$v;
- $data[$k]['name'] = $v;
- }else{
- $map[] = ['create_yyyymmdd','=',date('Ymd',strtotime($v))];
- $d[] = date('m-d',strtotime($v));
- $data[$k]['name'] = date('m-d',strtotime($v));
- }
- $order = Db::name('orders')->where($map)->count();
- $todo = Db::name('todo')->where($map)->count();
- $d1[] = $todo;
- $d2[] = $order;
- $data[$k]['order_num'] = $order;
- $data[$k]['todo_num'] = $todo;
- }
- // HelpHander::success(['d'=>$d,'d1'=>$d1,'d2'=>$d2]);
- HelpHander::success($data);
- }
- public function patrolRealTime(){
- $mode = input('mode');
- $page = input('page',1);
- $size = input('size',9);
- if(!in_array($mode,[1,2,3,4])){
- HelpHander::error('参数错误');
- }
- $lists = Db::name('patrol_record')
- ->field('create_time,user_id,patrol_addr_form_id,patrol_mode,is_normal,content as info,patrol_task_id,patrol_addr_id')
- ->where('patrol_mode',$mode)
- ->where('org_id',$this->orgId)
- ->page($page,$size)
- ->order('id desc')
- ->select();
- $data = [];
- foreach ($lists as $k=>$v){
- $addrForm = Db::name('patrol_addr_form')
- ->alias('a')
- ->join('patrol_task_addr b','b.patrol_form_id = a.id')
- ->where('b.id',$v['patrol_addr_form_id'])
- ->value('a.title');
- $modeTitle = Db::name('patrol_mode')
- ->where('id',$v['patrol_mode'])
- ->value('name');
- $user = Db::name('user')->where('id',$v['user_id'])->value('real_name');
- $is_normal = '无异常' ;
- if($v['is_normal'] == 1){
- $is_normal = '有异常' ;
- }
- $time = date('Y-m-d H:i',strtotime($v['create_time']));
- $content = '员工-'.$user.'完成'.$addrForm.$modeTitle.','.$is_normal;
- $data[$k]['time'] = $time;
- $data[$k]['content'] = $content;
- $data[$k]['info'] = $v['info'];
- $data[$k]['task_name'] = Db::name('patrol_task')->where('id',$v['patrol_task_id'])->value('title');
- $data[$k]['addr_name'] = Db::name('address')->where('id',$v['patrol_addr_id'])->value('title');
- }
- $count = Db::name('patrol_record')
- ->where('patrol_mode',$mode)
- ->where('org_id',$this->orgId)
- ->count();
- $dt = [
- 'list'=>$data,
- 'count'=>$count
- ];
- HelpHander::success($dt);
- }
- public function taskList(){
- $mode = input('mode/d',1);
- if(!in_array($mode,[1,2,3,4,5])){
- HelpHander::error('参数错误');
- }
- $data = [];
- if($mode == 5){
- $lists = Db::name('ph_orders')
- ->where('org_id',$this->orgId)
- ->where('status','in',[1,2])
- ->order('id desc')
- ->field('id,sn,cate_id,status,create_time,start,end,contact,phone')
- ->limit(20)
- ->select();
- foreach ($lists as $k=>$v){
- $cate = Db::name('cate')->where('id',$v['cate_id'])->value('title');
- $stxt = '新订单';
- $users = '';
- if($v['status'] == 2){
- $stxt = '服务中';
- $unames = Db::name('ph_todo')
- ->alias('t')
- ->join('worker w','t.worker_id = w.id')
- ->join('user u','u.id = w.user_id')
- ->where('t.order_id',$v['id'])
- ->where('t.status',1)
- ->column('real_name');
- $users = $unames?implode(',',$unames):'';
- }
- $data[$k]['status'] = $stxt;
- $data[$k]['sn'] = $v['sn'];
- $data[$k]['cate'] = $cate;
- $data[$k]['user'] = $users;
- $data[$k]['time'] = $v['create_time'];
- $data[$k]['st'] = $v['start'];
- $data[$k]['et'] = $v['end'];
- $data[$k]['contact'] = $v['contact'];
- $data[$k]['phone'] = $v['phone'];
- }
- }else{
- $lists = Db::name('orders')
- ->where('org_id',$this->orgId)
- ->where('order_mode','in',[1,4])
- ->where('work_type_mode',$mode)
- ->where('del',0)
- ->order('id desc')
- ->limit(20)
- ->field('id,order_mode,create_time,send_time,content,dep_id,sn,user_id')
- ->select();
- foreach ($lists as $k=>$v){
- $dep = Db::name('dep')->where('id',$v['dep_id'])->value('title');
- $status = Db::name('order_mode')->where('id',$v['order_mode'])->value('out_content');
- $userName = Db::name('user')->where('id',$v['user_id'])->value('real_name');
- if($mode == 1){ // 报修
- $type = Db::name('order_repair')
- ->alias('or')
- ->leftJoin('order_type ot','ot.id = or.type_id')
- ->where('or.order_id',$v['id'])
- ->value('title');
- // $data[] = [$status,$dep,$type?$type:'',$v['content'],$v['create_time']];
- $data[$k]['status'] = $status;
- $data[$k]['dep'] = $dep;
- $data[$k]['cate'] = $type?$type:'';
- $data[$k]['content'] = $v['content'];
- $data[$k]['time'] = $v['create_time'];
- $data[$k]['sn'] = $v['sn'];
- $data[$k]['user_name'] = $userName;
- $data[$k]['send_time'] = $v['send_time'];
- }else if($mode == 3){ //运送
- $convey = Db::name('order_convey')
- ->alias('oc')
- ->join('convey_cate cc','cc.id = oc.type')
- ->where('oc.order_id',$v['id'])
- ->field('oc.*,cc.title as cate_title')
- ->find();
- $start = Db::name('address')->where('id',$convey['start'])->value('title');
- $end = Db::name('address')->where('id',$convey['end'])->value('title');
- $todos = Db::name('todo')
- ->alias('t')
- ->join('user u','u.id = t.to_user_id')
- ->where('t.order_id',$v['id'])
- ->where('t.del',0)
- ->where('t.todo_mode','in',[1,2,3])
- ->field('t.confirm_time,u.real_name')
- ->select();
- $todos = $todos?$todos:[];
- $unames = [];
- $confirm = '';
- foreach ($todos as $tk=>$tv){
- $unames[] = $tv['real_name'];
- if(!$confirm){
- $confirm = $tv['confirm_time'];
- }
- }
- $un = $unames?implode(',',$unames):'';
- $send = $v['send_time']?date('H:i',strtotime($v['send_time'])):'';
- $xq = date('H:i',strtotime($convey['xq_time']));
- $confirm = $confirm?date('H:i',strtotime($confirm)):'';
- // $data[] = [$status,$convey['cate_title'],$start,$end,$xq,$un,$send,$confirm];
- $data[$k]['status'] = $status;
- $data[$k]['cate'] = $convey['cate_title'];
- $data[$k]['start'] = $start;
- $data[$k]['end'] = $end;
- $data[$k]['xq'] = $xq;
- $data[$k]['un'] = $un;
- $data[$k]['send'] = $send;
- $data[$k]['confirm'] = $confirm;
- $data[$k]['sn'] = $v['sn'];
- $data[$k]['user_name'] = $userName;
- $data[$k]['send_time'] = $v['send_time'];
- }else{ // 保洁,应急
- // $data[] = [$status,$dep,$v['content'],$v['create_time']];
- $data[$k]['status'] = $status;
- $data[$k]['dep'] = $dep;
- $data[$k]['content'] = $v['content'];
- $data[$k]['time'] = $v['create_time'];
- $data[$k]['sn'] = $v['sn'];
- $data[$k]['user_name'] = $userName;
- $data[$k]['send_time'] = $v['send_time'];
- }
- }
- }
- HelpHander::success($data);
- }
- public function wxTodoData(){
- $page = input('page',1);
- $size = input('size',9);
- $list = Db::name('todo')
- ->field('id,order_id,todo_mode,create_time,to_user_id,confirm_time,xy_time,wc_time,todo_content')
- ->where('org_id',$this->orgId)
- ->whereIn('todo_mode',[1,2,3])
- ->where('del',0)
- ->where('create_yyyymmdd','>=',date('Ymd',strtotime('-3 day')))
- ->where('create_yyyymmdd','<=',date('Ymd'))
- ->where('work_type_mode',1)
- ->page($page,$size)
- ->select();
- foreach ($list as $k=>$v){
- if($v['todo_mode'] == 1){
- $list[$k]['status'] = '新任务';
- }elseif ($v['todo_mode'] == 2){
- $list[$k]['status'] = '进行中';
- }elseif ($v['todo_mode'] == 3){
- $list[$k]['status'] = '已完成';
- }
- $repair = Db::name('order_type')
- ->alias('ot')
- ->field('ot.id,ot.title,ot.parent_id')
- ->join('order_repair or','or.type_id=ot.id')
- ->where('or.order_id',$v['order_id'])
- ->find();
- $list[$k]['cate_title'] = Db::name('order_type')->where('id',$repair['parent_id'])->value('title');
- $list[$k]['address'] = Db::name('address')
- ->alias('a')
- ->join('order_repair or','or.address_id=a.id')
- ->where('or.order_id',$v['order_id'])
- ->where('a.org_id',$this->orgId)
- ->value('a.title');
- $list[$k]['create_time'] = date('H:i',strtotime($v['create_time']));
- $list[$k]['confirm_time'] = $v['confirm_time']? date('H:i',strtotime($v['confirm_time'])):'';
- $list[$k]['user_name'] = Db::name('user')->where('id',$v['to_user_id'])->value('real_name');
- $list[$k]['xy_time'] = $v['xy_time'] ? round($v['xy_time']/60,1):'';
- $list[$k]['wc_time'] = $v['wc_time'] ? round($v['wc_time']/60,1):'';
- }
- $count = Db::name('todo')
- ->where('org_id',$this->orgId)
- ->whereIn('todo_mode',[1,2,3])
- ->where('del',0)
- ->where('create_yyyymmdd','>=',date('Ymd',strtotime('-3 day')))
- ->where('create_yyyymmdd','<=',date('Ymd'))
- ->where('work_type_mode',1)
- ->count();
- $data = [
- 'list'=>$list,
- 'count'=>$count,
- ];
- HelpHander::success($data);
- }
- public function patrolRecord(){
- $page = input('page',1);
- $size = input('size',9);
- $lists = Db::name('patrol_record')
- ->alias('a')
- ->join('patrol_task t','a.patrol_task_id = t.id')
- ->join('address b','a.patrol_addr_id = b.id')
- ->join('user c','a.user_id = c.id')
- ->where('a.create_yyyymmdd','>=',date('Ymd',strtotime('-3 day')))
- ->where('a.create_yyyymmdd','<=',date('Ymd'))
- ->where('a.org_id',$this->orgId)
- ->field('a.images,a.create_time,b.title as address,c.real_name as name,t.title as task_title,a.is_normal,a.content')
- ->page($page,$size)
- ->order('a.id desc')
- ->select();
- foreach ($lists as $k=>$v){
- $lists[$k]['is_normal_text'] = $v['is_normal'] == 0 ? '正常':'异常';
- }
- $count = Db::name('patrol_record')
- ->alias('a')
- ->join('patrol_task t','a.patrol_task_id = t.id')
- ->join('address b','a.patrol_addr_id = b.id')
- ->join('user c','a.user_id = c.id')
- ->where('a.create_yyyymmdd','>=',date('Ymd',strtotime('-3 day')))
- ->where('a.create_yyyymmdd','<=',date('Ymd'))
- ->where('a.org_id',$this->orgId)
- ->count();
- $data = [
- 'list'=>$lists,
- 'count'=>$count
- ];
- HelpHander::success($data);
- }
- }
|