1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000 |
- <?php
- namespace app\api\controller\screen;
- use app\hander\HelpHander;
- use app\api\controller\screen\Index;
- use think\Controller;
- use think\Db;
- class Project extends Controller
- {
- public function __construct()
- {
- parent::__construct();
- $this->orgId = input('orgid')?input('orgid'):0;
- }
- /**
- * 获取用户数
- * @param $orgid 组织id
- * @param $roles 角色id
- * @return mixed
- */
- private function get_user_count($orgid,$roles){
- $count = $this->db
- ->join('user_roles','user.USER_ID = user_roles.USER_ID')
- ->join('user_org','user.USER_ID = user_org.USER_ID')
- ->where_in('user_roles.ROLES_ID',$roles)
- ->where('user.DEL_REF',0)
- ->where('user.ENABLE',1)
- ->where('user_org.ORG_TYPE',0)
- ->where('user_org.ORG_ID',$orgid)
- ->from('user')
- ->count_all_results();
- return $count;
- }
- // 各类人员占比接口
- public function user(){
- $this->load->model(array('OrgModel','RolesModel'));
- $info = $this->OrgModel->show_one(array('ORG_ID'=>$this->orgId,'TYPE'=>'2'));
- if(!$info||$info->ENABLE != 1||$info->DEL_REF != 0){
- $this->error('项目不存在');
- }
- // 1=客户人员 2=综合人员 3=运送人员 4=维修人员 5=保洁人员 6=保安人员 7=调度人员 8=监管人员
- $arr = array(
- array('type' => 5),
- array('type' => 3),
- array('type' => 4),
- array('type' => 6),
- );
- $allcount = 0;
- foreach ($arr as $k=>$v){
- $roles = $this->RolesModel->get_roles_type($this->orgId,$v['type']);
- $arr[$k]['name'] = $roles['name'];
- $arr[$k]['value'] = $this->get_user_count($this->orgId,$roles['roles']);
- $allcount += $arr[$k]['value'];
- }
- $data = array(
- array('value'=>$arr[0]['value'],'name'=>'保洁人员','name2'=>'保洁','bl'=>$allcount>0?round($arr[0]['value']*100/$allcount):0),
- array('value'=>$arr[1]['value'],'name'=>'运送人员','name2'=>'运送','bl'=>$allcount>0?round($arr[1]['value']*100/$allcount):0),
- array('value'=>$arr[2]['value'],'name'=>'维修人员','name2'=>'维修','bl'=>$allcount>0?round($arr[2]['value']*100/$allcount):0),
- array('value'=>$arr[3]['value'],'name'=>'保安人员','name2'=>'保安','bl'=>$allcount>0?round($arr[3]['value']*100/$allcount):0),
- );
- $this->success('成功',['count' => $allcount,'list' => $data]);
- }
- public function todostis(){
- $count1 = Db::name('orders')
- ->where('org_id',$this->orgId)
- ->where('del',0)
- ->where('work_type_mode',3)
- ->where('create_yyyymmdd',date('Ymd'))
- ->where('order_mode','in',[5,6])
- ->count();
- $count2 = Db::name('orders')
- ->where('org_id',$this->orgId)
- ->where('del',0)
- ->where('work_type_mode',1)
- ->where('create_yyyymmdd',date('Ymd'))
- ->where('order_mode','in',[5,6])
- ->count();
- $count3 = Db::name('daily_record')
- ->where('org_id',$this->orgId)
- ->where('create_yyyymmdd',date('Ymd'))
- ->count();
- $arr = [
- [
- 'name' => '运送任务',
- 'count' => $count1
- ],
- [
- 'name' => '维修任务',
- 'count' => $count2
- ],
- [
- 'name' => '日常任务',
- 'count' => $count3
- ]
- ];
- HelpHander::success($arr,'成功');
- }
- public function ysuser(){
- $lists = model('User')->getYsUser($this->orgId,1);
- $nlists = [];
- if(count($lists) > 4){
- $arr = array_rand($lists,4);
- foreach ($arr as $k=>$v){
- $nlists[] = $lists[$v];
- }
- }else{
- $nlists = $lists;
- }
- foreach ($nlists as $k=>$v){
- $count = Db::name('todo')
- ->alias('a')
- ->join('orders b','a.order_id=b.id')
- ->where('a.create_yyyymmdd',date('Ymd'))
- ->where('a.to_user_id',$v['id'])
- ->where('a.todo_mode',3)
- ->where('a.del',0)
- ->where('a.org_id',$this->orgId)
- ->count();
- $nlists[$k]['count'] = $count;
- // $addr = Db::name('user_convey_addr')
- // ->alias('uca')
- // ->join('convey_addr ca','ca.id = uca.ADDR_ID')
- // ->where('uca.USER_ID',$v['USER_ID'])
- // ->order_by('uca.CREATE_TIME DESC')
- // ->select('ca.TITLE')
- // ->get('user_convey_addr as uca')
- // ->row_array();
- $addr = [];
- $nlists[$k]['addr_title'] = $addr?$addr['TITLE']:'';
- }
- HelpHander::success($nlists,'成功');
- }
- // 热点区域
- public function hotaddr(){
- //SELECT count(a.START) as COUNT,a.START FROM order_convey as a JOIN orders as o ON o.ORDER_ID = a.ORDER_ID GROUP BY a.`START` LIMIT 10
- $curDay = date('Ymd');
- $oldDay = date('Ymd',time() - 29*24*60*60);
- $lists = Db::name('order_convey')
- ->alias('oc')
- ->join('orders o','o.id = oc.order_id')
- ->where('o.org_id',$this->orgId)
- ->where('o.create_yyyymmdd',$curDay)
- ->where('o.work_type_mode',3)
- ->where('o.del',0)
- ->where('o.order_mode','in',[5,6])
- ->field('COUNT(oc.start) as count,oc.start')
- ->group('oc.start')
- ->order('count','desc')
- ->limit(10)
- ->select();
- $x = [];
- $y1 = [];
- $y2 = [];
- foreach ($lists as $k=>$v){
- $addr = Db::name('address')
- ->where('id',$v['start'])
- ->find();
- $x[] = $addr?$addr['title']:'';
- $y1[] = $v['count'];
- $count = Db::name('order_convey')
- ->alias('oc')
- ->join('orders o','o.id = oc.order_id')
- ->where('o.org_id',$this->orgId)
- ->where('o.work_type_mode',3)
- ->where('o.create_yyyymmdd','<=',$curDay)
- ->where('o.create_yyyymmdd','>=',$oldDay)
- ->where('o.order_mode','in',[5,6])
- ->where('oc.start',$v['start'])
- ->where('o.del',0)
- ->count();
- $y2[] = round($count/30,2);
- }
- $data = [
- 'x' => $x,
- 'y1' => $y1,
- 'y2' => $y2
- ];
- HelpHander::success($data,'成功');
- }
- public function yscount(){
- $curDay = date('Ymd');
- $tcount = Db::name('orders')
- ->where('org_id',$this->orgId)
- ->where('work_type_mode',3)
- ->where('create_yyyymmdd',$curDay)
- ->where('order_mode','in',[5,6])
- ->where('del',0)
- ->count();
- $fcount = Db::name('order_convey')
- ->alias('oc')
- ->join('orders o','o.id = oc.order_id')
- ->where('o.org_id',$this->orgId)
- ->where('o.work_type_mode',3)
- ->where('o.create_yyyymmdd',$curDay)
- ->whereRaw("TIMESTAMPDIFF(second,o.finish_time,oc.ywc_time) >=0")
- ->where('o.order_mode','in',[5,6])
- ->where('o.del',0)
- ->count();
- $bl1 = $tcount>0?round($fcount/$tcount,3)*100:0;
- $wcount = Db::name('orders')
- ->where('org_id',$this->orgId)
- ->where('del',0)
- ->where('work_type_mode',3)
- ->where('create_yyyymmdd',$curDay)
- ->where('order_mode','in',[1])
- ->count();
- $jxcount = Db::name('orders')
- ->where('org_id',$this->orgId)
- ->where('del',0)
- ->where('work_type_mode',3)
- ->where('create_yyyymmdd',$curDay)
- ->where('order_mode','in',[5])
- ->count();
- $bhcount = Db::name('todo')
- ->alias('a')
- ->join('todo b','a.order_id=b.id')
- ->where('a.org_id',$this->orgId)
- ->where('b.del',0)
- ->where('a.work_type_mode',3)
- ->where('a.create_yyyymmdd',$curDay)
- ->where('a.todo_mode','in',[4])
- ->count();
- $flist = Db::name('orders')
- ->field('(TIMESTAMPDIFF(minute,create_time,send_time)) as minute')
- ->where('org_id',$this->orgId)
- ->where('work_type_mode',3)
- ->where('create_yyyymmdd',$curDay)
- ->where('del',0)
- ->where('order_mode','in',[4,5,6])
- ->select();
- $flist = $flist?$flist:[];
- $c = count($flist);
- $minu = 0;
- foreach ($flist as $k=>$v){
- if($v['minute']){
- $minu += $v['minute'];
- }
- }
- $avg = $c > 0?round($minu/$c,1):0;
- $data = [
- 'count1' => $bl1."%",
- 'count2' => $avg,
- 'count3' => $wcount,
- 'count4' => $jxcount,
- 'count5' => $tcount,
- 'count6' => $bhcount
- ];
- HelpHander::success($data,'成功');
- }
- // 隐患预警数据统计
- public function yinhuan(){
- $list = [
- ['标题', '隐患数量', '转任务量'],
- // ['报修', $bxwc, $bxxy],
- // ['保洁', $bjwc, $bjxy],
- // ['运送', $yswc, $ysxy],
- // ['隐患预警', $yhwc, $yhxy],
- ];
- $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'),
- ];
- foreach ($dlist as $v){
- $tt = date('Ymd',strtotime($v));
- $count = Db::name('orders')
- ->where('org_id',$this->orgId)
- ->where('create_yyyymmdd',$tt)
- ->where('del',0)
- ->where('work_type_mode',4)
- ->count();
- $count1 = Db::name('todo')
- ->alias('a')
- ->join('orders b','a.order_id=b.id')
- ->where('a.org_id',$this->orgId)
- ->where('a.create_yyyymmdd',$tt)
- ->where('a.del',0)
- ->where('a.work_type_mode',4)
- ->where('b.del',0)
- ->group('a.order_id')
- ->count();
- $list[] = [date('m-d',strtotime($v)),$count,$count1];
- }
- $data = [
- 'list' => $list
- ];
- HelpHander::success($data,'成功');
- }
- // 运送数据统计
- public function yusong(){
- $list = [
- ['标题', '工单总量', '完成工单量'],
- ];
- $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'),
- ];
- foreach ($dlist as $v){
- $tt = date('Ymd',strtotime($v));
- $count = $this->db
- ->where('ORG_ID',$this->orgId)
- ->where('CREATE_YYYYMMDD',$tt)
- ->where('DEL_REF',0)
- ->where('WORK_TYPE_MODE',3)
- ->from('orders')
- ->count_all_results();
- $count1 = $this->db
- ->where('ORG_ID',$this->orgId)
- ->where('CREATE_YYYYMMDD',$tt)
- ->where('DEL_REF',0)
- ->where('WORK_TYPE_MODE',3)
- ->where_in('CURR_ORDER_MODE',[9,11])
- ->from('orders')
- ->count_all_results();
- $list[] = [date('m-d',strtotime($v)),$count,$count1];
- }
- $data = [
- 'list' => $list
- ];
- $this->success('成功',$data);
- }
- // 今日运送完成工单总量
- public function yscounttoday(){
- $curDay = date('Ymd');
- $tcount = $this->db
- ->where('ORG_ID',$this->orgId)
- ->where('WORK_TYPE_MODE',3)
- ->where('CREATE_YYYYMMDD',$curDay)
- ->where_in('CURR_ORDER_MODE',[9,11])
- ->from('orders')
- ->count_all_results();
- $data = [
- 'count' => $tcount
- ];
- $this->success('成功',$data);
- }
- // 医废
- public function waste(){
- $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'),
- ];
- $xdata = [];
- $ydata = [];
- foreach ($dlist as $v){
- $tt = date('Ymd',strtotime($v));
- // $count = $this->db
- //// ->where('ORG_ID',$this->orgId)
- //// ->where('CREATE_YYYYMMDD',$tt)
- //// ->where('DEL_REF',0)
- //// ->from('waste_record')
- //// ->count_all_results();
- ///
- $ret = Db::name('waste_record')
- ->where('org_id',$this->orgId)
- ->where('create_yyyymmdd',$tt)
- ->where('del',0)
- ->select();
- $total = 0;
- foreach ($ret as $kk=>$vv){
- $total += $vv['weight'];
- }
- $ydata[] = $total/1000;
- $xdata[] = date('m-d',strtotime($v));
- }
- $data = [
- 'xdata' => $xdata,
- 'ydata' => $ydata
- ];
- HelpHander::success($data,'成功');
- }
- public function ystask(){
- $size = input('size')?input('size'):20;
- $data = model('Orders')->get_cur_day_lists($this->orgId,$size);
- foreach ($data as $k=>$v){
- $data[$k]['create_time'] = date('H:i',strtotime($v['create_time']));
- $data[$k]['send_time'] = $v['send_time']?date('H:i',strtotime($v['send_time'])):'';
- $data[$k]['confirm_time'] = $v['confirm_time']?date('H:i',strtotime($v['confirm_time'])):'';
- }
- HelpHander::success($data,'成功');
- }
- public function ystask_bak(){
- $size = input('size')?input('size'):5;
- $data = model('Orders')->get_cur_day_lists($this->orgId,$size);
- foreach ($data as $k=>$v){
- $data[$k]['xq_time'] = date('H:i',strtotime($v['xq_time']));
- $data[$k]['send_time'] = $v['send_time']?date('H:i',strtotime($v['send_time'])):'';
- $data[$k]['confirm_time'] = $v['confirm_time']?date('H:i',strtotime($v['confirm_time'])):'';
- }
- HelpHander::success($data,'成功');
- }
- public function ystaskcount(){
- $this->load->model('OrdersModel');
- $data = $this->OrdersModel->get_cur_day_count($this->orgId);
- $this->success('成功',['count' => $data]);
- }
- public function daily(){
- $lists = Db::name('daily_record')
- ->alias('dr')
- ->join('daily d','d.id = dr.daily_id')
- ->where('dr.org_id',$this->orgId)
- ->where('dr.create_yyyymmdd',date('Ymd'))
- ->limit(9)
- ->field('d.title,d.content,dr.user_id,dr.create_time')
- ->order('dr.id','desc')
- ->select();
- foreach ($lists as $k=>$v){
- $user = Db::name('user')
- ->where('id',$v['user_id'])
- ->find();
- $lists[$k]['real_name'] = $user?$user['real_name']:'';
- $lists[$k]['create_time'] = date('m-d H:i',strtotime($v['create_time']));
- }
- HelpHander::success($lists,'成功');
- }
- public function patrolList(){
- $lists = Db::name('patrol_record')
- ->alias('pr')
- ->join('address pa','pa.id = pr.patrol_addr_id')
- ->join('patrol_task pt','pt.id = pr.patrol_task_id')
- ->join('user u','u.id = pr.user_id')
- ->where('pr.org_id',$this->orgId)
- ->where('pr.create_yyyymmdd',date('Ymd'))
- ->limit(4)
- ->field('pa.title,pt.title as task_title,u.real_name,pr.create_time')
- ->order('pr.id','DESC')
- ->select();
- foreach ($lists as $k=>$v){
- $lists[$k]['create_time'] = date('m-d H:i',strtotime($v['create_time']));
- }
- HelpHander::success($lists,'成功');
- }
- public function patrolImg(){
- $lists = Db::name('patrol_record')
- ->alias('pr')
- ->join('patrol_task pt','pt.id = pr.patrol_task_id')
- ->where('pr.org_id',$this->orgId)
- ->where('pr.images','<>','null')
- ->where('pr.create_yyyymmdd',date('Ymd'))
- ->limit(9)
- ->field('pt.title as task_title,pr.images')
- ->order('pr.id','DESC')
- ->select();
- foreach ($lists as $k=>$v){
- $imgs = explode(',',$v['images']);
- $lists[$k]['images'] = $imgs[0];
- }
- HelpHander::success($lists?$lists:[],'成功');
- }
- // 评论,满意度
- public function comment(){
- $scores = [
- ['score'=>1,'name'=>'一星','value'=>0],
- ['score'=>2,'name'=>'二星','value'=>0],
- ['score'=>3,'name'=>'三星','value'=>0],
- ['score'=>4,'name'=>'四星','value'=>0],
- ['score'=>5,'name'=>'五星','value'=>0],
- ];
- foreach ($scores as $k=>$v){
- $count = $this->db
- ->where('ORG_ID',$this->orgId)
- ->where('SCORE',$v['score'])
- ->from('comment')
- ->count_all_results();
- $scores[$k]['value'] = $count?$count:0;
- unset($scores[$k]['score']);
- }
- $user = $this->db
- ->select('sum(SCORE) as SCORE,TO_USER_ID')
- ->where('ORG_ID',$this->orgId)
- ->group_by('TO_USER_ID')
- ->distinct()
- ->get('comment_reply')
- ->result_array();
- foreach ($user as $k=>$v){
- $count = $this->db
- ->where('ORG_ID',$this->orgId)
- ->where('TO_USER_ID',$v['TO_USER_ID'])
- ->from('comment_reply')
- ->count_all_results();
- $score = round($v['SCORE']/$count,1);
- $user[$k]['SCORE'] = $score;
- $info = $this->db
- ->join('user_org uo','uo.USER_ID = u.USER_ID')
- ->join('org o','uo.ORG_ID = o.ORG_ID')
- ->where('uo.ORG_TYPE',1)
- ->where('u.USER_ID',$v['TO_USER_ID'])
- ->select('u.REAL_NAME,o.NAME as DEP_NAME')
- ->get('user u')
- ->row_array();
- $user[$k]['REAL_NAME'] = $info['REAL_NAME'];
- $user[$k]['DEP_NAME'] = $info['DEP_NAME'];
- }
- // 获取排名前5的人
- $user = list_sort_by($user,'SCORE', 'desc');
- $lists = [];
- foreach ($user as $k=>$v){
- if($k >= 5){
- continue;
- }
- $lists[] = $v;
- }
- $this->success('成功',['count'=>$scores,'list' => $lists]);
- }
- // 工单统计
- public function todo(){
- $start = date('Y-m-d').' 00:00:00';
- $end = date('Y-m-d').' 23:59:59';
- $fininsh = $this->db
- ->where('ORG_ID',$this->orgId)
- ->where('DEL_REF',0)
- ->where('TODO_MODE',3)
- ->where('DONE_TIME >=',$start)
- ->where('DONE_TIME <=',$end)
- ->from('todo')
- ->count_all_results();
- $unfininsh = $this->db
- ->where('ORG_ID',$this->orgId)
- ->where('DEL_REF',0)
- ->where_in('TODO_MODE',[1,2])
- ->where('DONE_TIME >=',$start)
- ->where('DONE_TIME <=',$end)
- ->from('todo')
- ->count_all_results();
- $undeal = $this->db
- ->where('ORG_ID',$this->orgId)
- ->where('DEL_REF',0)
- ->where_in('CURR_ORDER_MODE',1)
- ->where('CREATTE_TIME >=',$start)
- ->where('CREATTE_TIME <=',$end)
- ->from('orders')
- ->count_all_results();
- $total = $this->db
- ->where('ORG_ID',$this->orgId)
- ->where('DEL_REF',0)
- ->where_in('TODO_MODE',[1,2,3,4,5])
- ->from('todo')
- ->count_all_results();
- $today = $this->db
- ->where('ORG_ID',$this->orgId)
- ->where('DEL_REF',0)
- ->where_in('TODO_MODE',[1,2,3,4,5])
- ->where('CREATE_TIME >=',$start)
- ->where('CREATE_TIME <=',$end)
- ->from('todo')
- ->count_all_results();
- $commentcount = $this->db
- ->where('ORG_ID',$this->orgId)
- ->from('comment')
- ->count_all_results();
- $comment = $this->db
- ->where('ORG_ID',$this->orgId)
- ->select_sum('SCORE')
- ->get('comment')
- ->row_array();
- $data = [
- 'total' => $total,
- 'today' => $today,
- 'finish' => $fininsh,
- 'unfinish' => $unfininsh,
- 'undeal' => $undeal,
- 'comment' => $commentcount&&$comment?round($comment['SCORE']/$commentcount,1):0
- ];
- $this->success('成功',$data);
- }
- // 获取今日最新5条中的随机一条
- public function patrol(){
- $lists = $this->db
- ->select('u.REAL_NAME,pa.TITLE,pr.IMAGES,pt.TITLE as CONTENT,pr.CREATE_TIME')
- ->join('user u','u.USER_ID = pr.USER_ID')
- ->join('patrol_addr pa','pa.PATROL_ADDR_ID = pr.PATROL_ADDR_ID')
- ->join('patrol_task pt','pt.PATROL_TASK_ID = pr.PATROL_TASK_ID')
- ->where('pr.ORG_ID',$this->orgId)
- ->where('pr.CREATE_YYYYMMDD',date('Ymd'))
- ->limit(5)
- ->order_by('pr.PATROL_RECORD_ID DESC')
- ->get('patrol_record pr')
- ->result_array();
- $info = null;
- if($lists){
- $info = $lists[array_rand($lists,1)];
- }
- if($info){
- $imgs = $info['IMAGES']?explode(',',$info['IMAGES']):[];
- $info['IMAGES'] = $imgs?$imgs[0]:'';
- $info['CREATE_TIME'] = date('Y-m-d',strtotime($info['CREATE_TIME']));
- $this->success('成功',$info);
- }else{
- $this->error('失败');
- }
- }
- // 工单指数数据统计
- public function todotime(){
- $bxcount = $this->db
- ->where('ORG_ID',$this->orgId)
- ->where('DEL_REF',0)
- ->where('TODO_MODE',3)
- ->where('WORK_TYPE_MODE',1)
- ->from('todo')
- ->count_all_results();
- $bjcount = $this->db
- ->where('ORG_ID',$this->orgId)
- ->where('DEL_REF',0)
- ->where('TODO_MODE',3)
- ->where('WORK_TYPE_MODE',2)
- ->from('todo')
- ->count_all_results();
- $yscount = $this->db
- ->where('ORG_ID',$this->orgId)
- ->where('DEL_REF',0)
- ->where('TODO_MODE',3)
- ->where('WORK_TYPE_MODE',3)
- ->from('todo')
- ->count_all_results();
- $yhcount = $this->db
- ->where('ORG_ID',$this->orgId)
- ->where('DEL_REF',0)
- ->where('TODO_MODE',3)
- ->where('WORK_TYPE_MODE',4)
- ->from('todo')
- ->count_all_results();
- $bxinfo = $this->db
- ->select_sum('XY_TIME')
- ->select_sum('WC_TIME')
- ->where('ORG_ID',$this->orgId)
- ->where('DEL_REF',0)
- ->where('TODO_MODE',3)
- ->where('WORK_TYPE_MODE',1)
- ->get('todo')
- ->row_array();
- $bxinfo = $bxinfo?$bxinfo:['XY_TIME'=>0,'WC_TIME'=>0];
- $bjinfo = $this->db
- ->select_sum('XY_TIME')
- ->select_sum('WC_TIME')
- ->where('ORG_ID',$this->orgId)
- ->where('DEL_REF',0)
- ->where('TODO_MODE',3)
- ->where('WORK_TYPE_MODE',2)
- ->get('todo')
- ->row_array();
- $bjinfo = $bjinfo?$bjinfo:['XY_TIME'=>0,'WC_TIME'=>0];
- $ysinfo = $this->db
- ->select_sum('XY_TIME')
- ->select_sum('WC_TIME')
- ->where('ORG_ID',$this->orgId)
- ->where('DEL_REF',0)
- ->where('TODO_MODE',3)
- ->where('WORK_TYPE_MODE',3)
- ->get('todo')
- ->row_array();
- $ysinfo = $ysinfo?$ysinfo:['XY_TIME'=>0,'WC_TIME'=>0];
- $yhinfo = $this->db
- ->select_sum('XY_TIME')
- ->select_sum('WC_TIME')
- ->where('ORG_ID',$this->orgId)
- ->where('DEL_REF',0)
- ->where('TODO_MODE',3)
- ->where('WORK_TYPE_MODE',4)
- ->get('todo')
- ->row_array();
- $yhinfo = $yhinfo?$yhinfo:['XY_TIME'=>0,'WC_TIME'=>0];
- $bxwc = $bxcount?round($bxinfo['WC_TIME']/$bxcount/60,1):0;
- $bxxy = $bxcount?round($bxinfo['XY_TIME']/$bxcount/60,1):0;
- $bjwc = $bjcount?round($bjinfo['WC_TIME']/$bjcount/60,1):0;
- $bjxy = $bjcount?round($bjinfo['XY_TIME']/$bjcount/60,1):0;
- $yswc = $yscount?round($ysinfo['WC_TIME']/$yscount/60,1):0;
- $ysxy = $yscount?round($ysinfo['XY_TIME']/$yscount/60,1):0;
- $yhwc = $yhcount?round($yhinfo['WC_TIME']/$yhcount/60,1):0;
- $yhxy = $yhcount?round($yhinfo['XY_TIME']/$yhcount/60,1):0;
- $list = [
- ['标题', '平均完成时', '响应时长'],
- ['报修', $bxwc, $bxxy],
- ['保洁', $bjwc, $bjxy],
- ['运送', $yswc, $ysxy],
- ['隐患预警', $yhwc, $yhxy],
- ];
- $data = [
- 'bx' => $bxcount,
- 'bj' => $bjcount,
- 'ys' => $yscount,
- 'yh' => $yhcount,
- 'list' => $list
- ];
- $this->success('成功',$data);
- }
- // 设备维检
- public function device(){
- $dcount = $this->db
- ->where('ORG_ID',$this->orgId)
- ->where('DEL_REF',0)
- ->where('ENABLE',1)
- ->from('device')
- ->count_all_results();
- $rcount = $this->db
- ->where('ORG_ID',$this->orgId)
- ->from('device_record')
- ->count_all_results();
- $cur = date('Y-m');
- $curTime = strtotime($cur.'-01');
- $month = [];
- for ($i=5;$i>0;$i--){
- $date = strtotime("-".$i." month",$curTime);
- $month[] = date('Y-m',$date);
- }
- $month[] = $cur;
- $list = [];
- foreach ($month as $k=>$v){
- $list[] = $this->db
- ->where('ORG_ID',$this->orgId)
- ->where('CREATE_YYYYMM',str_ireplace('-','',$v))
- ->from('device_record')
- ->count_all_results();
- }
- $data = [
- 'dcount' => $dcount,
- 'rcount' => $rcount,
- 'list' => $list,
- 'month' => $month
- ];
- $this->success('成功',$data);
- }
- // 24小时内记录
- public function patrolRecord(){
- $day = date('Ymd');
- $time = strtotime(date('Y-m-d'));
- $hours = [];
- $plist1 = $plist2 = $plist3 = $plist4 = [];
- for ($i=0;$i<24;$i++){
- $hours[] = $i;
- $stime = date('Y-m-d H:i:s',$time + $i*60*60);
- $etime = date('Y-m-d H:i:s',$time + ($i+1)*60*60);
- $plist1[] = $this->db
- ->where('ORG_ID',$this->orgId)
- ->where('PATROL_MODE',1)
- ->where('CREATE_TIME >=',$stime)
- ->where('CREATE_TIME <',$etime)
- ->where('CREATE_YYYYMMDD',$day)
- ->from('patrol_record')
- ->count_all_results();
- $plist2[] = $this->db
- ->where('ORG_ID',$this->orgId)
- ->where('PATROL_MODE',2)
- ->where('CREATE_TIME >=',$stime)
- ->where('CREATE_TIME <',$etime)
- ->where('CREATE_YYYYMMDD',$day)
- ->from('patrol_record')
- ->count_all_results();
- $plist3[] = $this->db
- ->where('ORG_ID',$this->orgId)
- ->where('PATROL_MODE',3)
- ->where('CREATE_TIME >=',$stime)
- ->where('CREATE_TIME <',$etime)
- ->where('CREATE_YYYYMMDD',$day)
- ->from('patrol_record')
- ->count_all_results();
- $plist4[] = $this->db
- ->where('ORG_ID',$this->orgId)
- ->where('PATROL_MODE',4)
- ->where('CREATE_TIME >=',$stime)
- ->where('CREATE_TIME <',$etime)
- ->where('CREATE_YYYYMMDD',$day)
- ->from('patrol_record')
- ->count_all_results();
- }
- $data = [
- 'hour' => $hours,
- 'plist1' => $plist1,
- 'plist2' => $plist2,
- 'plist3' => $plist3,
- 'plist4' => $plist4
- ];
- $this->success('成功',$data);
- }
- // 报修工单
- public function repair(){
- $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'),
- ];
- $names = [];
- $counts = [];
- foreach ($dlist as $v){
- $names[] = date('m-d',strtotime($v));
- $tt = date('Ymd',strtotime($v));
- $count = Db::name('todo')
- ->alias('a')
- ->join('orders b','a.order_id=b.id')
- ->where('a.del',0)
- ->where('a.org_id',$this->orgId)
- ->where('a.todo_mode',3)
- ->where('a.work_type_mode',1)
- ->where('a.create_yyyymmdd',$tt)
- ->group('a.order_id')
- ->count();
- $counts[] = $count;
- }
- HelpHander::success(['names'=>$names,'counts' => $counts],'成功');
- }
- public function ystypeuser(){
- $this->load->model('UserModel');
- $lists = $this->UserModel->getYsUser($this->orgId,1);
- $lists = $lists?$lists:[];
- $curday = date('Ymd');
- $users = $this->db
- ->where('ORG_ID',$this->orgId)
- ->where_in('TODO_MODE',[1,2])
- ->where('DEL_REF',0)
- ->where('CREATE_YYYYMMDD',$curday)
- ->select('TO_USER_ID')
- ->group_by('TO_USER_ID')
- ->get('todo')
- ->result_array();
- $users = $users?$users:[];
- $userIds = [];
- foreach ($users as $k=>$v){
- $userIds[] = $v['TO_USER_ID'];
- }
- $data = [
- 'list1' => [],
- 'list2' => []
- ];
- $nlists = [];
- foreach ($lists as $k=>$v){
- if(!in_array($v['USER_ID'],$userIds)){
- $nlists[] = $v;
- }
- }
- $slist = [];
- if(count($nlists) > 10){
- $keys = array_rand($nlists,10);
- foreach ($nlists as $k=>$v){
- if(in_array($k,$keys)){
- $slist[] = $v;
- }
- }
- }else{
- $slist = $nlists;
- }
- foreach ($slist as $k=>$v){
- $count = $this->db
- ->where('ORG_ID',$this->orgId)
- ->where('TO_USER_ID',$v['USER_ID'])
- ->where_in('TODO_MODE',[1,2,3])
- ->where('DEL_REF',0)
- ->where('CREATE_YYYYMMDD',$curday)
- ->from('todo')
- ->count_all_results();
- $slist[$k]['COUNT'] = $count;
- $addr = $this->db
- ->join('convey_addr ca','ca.CONVEY_ADDR_ID = cpr.ADDR_ID')
- ->select('ca.TITLE,cpr.CREATE_TIME')
- ->where('USER_ID',$v['USER_ID'])
- ->order_by('cpr.ID desc')
- ->get('convey_plan_record cpr')
- ->row_array();
- $slist[$k]['TITLE'] = $addr?$addr['TITLE']:'';;
- }
- $nlists2 = [];
- foreach ($lists as $k=>$v){
- if(in_array($v['USER_ID'],$userIds)){
- $nlists2[] = $v;
- }
- }
- $slist2 = [];
- if(count($nlists2) > 9){
- $keys2 = array_rand($nlists2,9);
- foreach ($nlists2 as $k=>$v){
- if(in_array($k,$keys2)){
- $slist2[] = $v;
- }
- }
- }else{
- $slist2 = $nlists2;
- }
- foreach ($slist2 as $k=>$v){
- $count = $this->db
- ->where('ORG_ID',$this->orgId)
- ->where('TO_USER_ID',$v['USER_ID'])
- ->where_in('TODO_MODE',[1,2,3])
- ->where('DEL_REF',0)
- ->where('CREATE_YYYYMMDD',$curday)
- ->from('todo')
- ->count_all_results();
- $slist2[$k]['COUNT'] = $count;
- $addr = $this->db
- ->join('convey_addr ca','ca.CONVEY_ADDR_ID = cpr.ADDR_ID')
- ->select('ca.TITLE,cpr.CREATE_TIME')
- ->where('USER_ID',$v['USER_ID'])
- ->order_by('cpr.ID desc')
- ->get('convey_plan_record cpr')
- ->row_array();
- $slist2[$k]['TITLE'] = $addr?$addr['TITLE']:'';
- }
- $data['list1'] = $slist; // 待命人员
- $data['list2'] = $slist2; // 行动人员
- $this->success('成功',$data);
- }
- }
|