1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705 |
- <?php
- namespace app\admin\controller;
- use app\common\model\Config;
- use think\Db;
- class Index extends Auth
- {
- public function index(){
- $userInfo = Db::name('user')
- ->where('id',$this->userId)
- ->find();
- $this->assign('userInfo',$userInfo);
- // 判断用户是否是调度
- $isDispatch = 0;
- if(check_is_dispatch($this->userId) || check_two_dispatch($this->userId)){
- $isDispatch = 1;
- }
- $this->assign('isDispatch',$isDispatch);
- $order = 0;
- // 判断用户是否是调度
- $level1 = check_is_dispatch($this->userId);
- $level2 = check_two_dispatch($this->userId);
- $level2onoff = two_dispatch_off($this->orgId);
- if(!$level1 && !$level2){
- $order = -1;
- }else{
- // 一级调度
- if($level1 || (!$level2onoff && $level2)){
- $map[] = ['org_id','=',$this->orgId];
- $map[] = ['del','=',0];
- $map[] = ['order_mode','=',1];
- if($level2onoff){
- $map[] = ['is_deal','=',0];
- }
- if(!is_admin($this->userId)){
- $auth = get_dispatch_auth($this->userId);
- if($auth){
- $map[] = ['work_type_mode', 'in', $auth];
- $where[] = ['o.work_type_mode', 'in', $auth];
- }else{
- $map[] = ['work_type_mode', '=', -1];
- $where[] = ['o.work_type_mode', '=', -1];
- }
- }
- $order = Db::name('orders')->where($map)->count();
- //$驳回的订单
- $where[] = ['o.del','=',0];
- $where[] = ['t.del','=',0];
- $bh = Db::name('orders')
- ->alias('o')
- ->join('todo t','t.order_id=o.id')
- ->where('t.todo_mode',4)
- ->where('t.org_id',$this->orgId)
- ->where('o.order_mode',4)
- ->where('o.org_id',$this->orgId)
- ->where($where)
- ->group('o.id')
- ->count();
- $order = $order + $bh;
- } else if($level2 && $level2onoff) { // 二级调度
- $rolesId = Db::name('user_roles')->where('user_id',$this->userId)->value('roles_id');
- if(!$rolesId){
- $order = 0;
- }else{
- $map[] = ['b.org_id','=',$this->orgId];
- $map[] = ['b.del','=',0];
- $map[] = ['b.order_mode','=',1];
- $map[] = ['b.is_deal','=',1];
- $map[] = ['a.roles_id','=',$rolesId];
- if(!is_admin($this->userId)){
- $auth = get_dispatch_auth($this->userId);
- if($auth){
- $map[] = ['b.work_type_mode', 'in', $auth];
- }else{
- $map[] = ['b.work_type_mode', '=', -1];
- }
- }
- $order = Db::name('dispatch_log')
- ->alias('a')
- ->join('orders b','b.id = a.order_id')
- ->where($map)
- ->field('a.*')
- ->count();
- }
- }
- }
- $complainCount = Db::name('complain')->where('del',0)->where('org_id',$this->orgId)->where('status',0)->where('order_id',0)->count();
- $hiddendangerCount = Db::name('hiddendanger')->where('del',0)->where('org_id',$this->orgId)->where('status',0)->where('order_id',0)->count();
- $endCount = $order+$complainCount+$hiddendangerCount;
- $this->assign('orderNums',$endCount);
- //今日看板
- $dayOrderNums1 = Db::name('orders')
- ->where('org_id',$this->orgId)
- ->where('del',0)
- ->where('order_mode',1)
- ->where('create_time','>=',date('Y-m-d').' 00:00:00')
- ->where('create_time','<=',date('Y-m-d').' 23:59:59')
- ->count();
- $dayOrderNums2 = Db::name('orders')
- ->where('org_id',$this->orgId)
- ->where('del',0)
- ->where('order_mode',4)
- ->where('create_time','>=',date('Y-m-d').' 00:00:00')
- ->where('create_time','<=',date('Y-m-d').' 23:59:59')
- ->count();
- $dayOrderNums3 = Db::name('orders')
- ->where('org_id',$this->orgId)
- ->where('del',0)
- ->where('order_mode',5)
- ->where('create_time','>=',date('Y-m-d').' 00:00:00')
- ->where('create_time','<=',date('Y-m-d').' 23:59:59')
- ->count();
- $dayOrderNums4 = Db::name('orders')
- ->where('org_id',$this->orgId)
- ->where('del',0)
- ->where('order_mode',6)
- ->where('create_time','>=',date('Y-m-d').' 00:00:00')
- ->where('create_time','<=',date('Y-m-d').' 23:59:59')
- ->count();
- $dayOrderNums5 = Db::name('orders')
- ->where('org_id',$this->orgId)
- ->where('del',0)
- ->where('order_mode',2)
- ->where('create_time','>=',date('Y-m-d').' 00:00:00')
- ->where('create_time','<=',date('Y-m-d').' 23:59:59')
- ->count();
- $dayOrderNums6 = Db::name('orders')
- ->where('org_id',$this->orgId)
- ->where('del',0)
- ->where('order_mode',3)
- ->where('create_time','>=',date('Y-m-d').' 00:00:00')
- ->where('create_time','<=',date('Y-m-d').' 23:59:59')
- ->count();
- $dayOrderCount =[
- 'count1'=> $dayOrderNums1,
- 'count2'=> $dayOrderNums2,
- 'count3'=> $dayOrderNums3,
- 'count4'=> $dayOrderNums4,
- 'count5'=> $dayOrderNums5,
- 'count6'=> $dayOrderNums6,
- ];
- $this->assign('dayOrderCount',$dayOrderCount);
- $notice = Db::name('notice')
- ->where('org_id',$this->orgId)
- ->where('del',0)
- ->where('user_id',$this->userId)
- ->field('id,title,create_time,content')
- ->order('id desc')
- ->limit(2)
- ->select();
- $this->assign('notice',$notice);
- //常用模块
- $module = Db::name('user_menu')->where('user_id',$this->userId)->order('count desc')->select();
- $id = 500;
- $menus = model('Menu')->getMenuTree($this->rolesId,$this->orgId);
- $this->assign('menus',$menus);
- $submenus = [];
- foreach ($menus as $k=>$v){
- if($v['id'] == $id){
- $submenus = $v['child'];
- break;
- }
- }
- $lists11 = [];
- foreach ($submenus as $k=>$v){
- // if(!$v['url']){
- // $v['url'] = url('Index/submenu',['id'=>$v['id'],'t'=>1]);
- // }
- $lists11[] = $v;
- }
- $this->assign('submenus',$submenus);
- $limit = 6;
- $modules = [];
- foreach ($module as $k=>$v){
- foreach ($lists11 as $kk=>$vv){
- if(count($modules) == $limit){
- continue;
- }
- if($vv['id'] == $v['menu_id']){
- $v['title'] = $vv['title'];
- $v['url'] = $vv['url'];
- $v['img'] = $vv['img'];
- $v['des'] = $vv['des'];
- $modules[] = $v;
- break;
- }
- }
- }
- $this->assign('module',$modules);
- $userEndMenu = $submenus;
- $threeMenu = model('Menu')->getMenuTree1($this->rolesId,$this->orgId,'');
- $this->assign('userEndMenu',$userEndMenu);
- $authMenuIds = array_column($threeMenu,'id');
- //固定模块
- $fixedModule = Db::name('menu')
- ->where('id',500)
- ->where('del',0)
- ->find();
- $fixedModule1 = Db::name('menu')
- ->where('id',1)
- ->where('del',0)
- ->find();
- $fixedModule2 = Db::name('menu')
- ->where('id',144)
- ->where('del',0)
- ->find();
- $fixedModule3 = Db::name('menu')
- ->where('id',163)
- ->where('del',0)
- ->find();
- $fixedModule4 = Db::name('menu')
- ->where('id',28)
- ->where('del',0)
- ->find();
- $fixedModuleAuth = $fixedModuleAuth1 = $fixedModuleAuth2 = $fixedModuleAuth3 = $fixedModuleAuth4 = 0 ;
- if(in_array($fixedModule['id'],$authMenuIds)){
- $fixedModuleAuth = 1 ;
- }
- if(in_array($fixedModule1['id'],$authMenuIds)){
- $fixedModuleAuth1 = 1 ;
- }
- if(in_array($fixedModule2['id'],$authMenuIds)){
- $fixedModuleAuth2 = 1 ;
- }
- if(in_array($fixedModule3['id'],$authMenuIds)){
- $fixedModuleAuth3 = 1 ;
- }
- if(in_array($fixedModule4['id'],$authMenuIds)){
- $fixedModuleAuth4 = 1 ;
- }
- $this->assign('fixedModule',$fixedModule);
- $this->assign('fixedModule1',$fixedModule1);
- $this->assign('fixedModule2',$fixedModule2);
- $this->assign('fixedModule3',$fixedModule3);
- $this->assign('fixedModule4',$fixedModule4);
- $this->assign('fixedModuleAuth',$fixedModuleAuth);
- $this->assign('fixedModuleAuth1',$fixedModuleAuth1);
- $this->assign('fixedModuleAuth2',$fixedModuleAuth2);
- $this->assign('fixedModuleAuth3',$fixedModuleAuth3);
- $this->assign('fixedModuleAuth4',$fixedModuleAuth4);
- // APP下载二维码
- $download = think_encrypt(url('h5/Index/download','',true,true));
- $this->assign('download',$download);
- // 小程序二维码
- $wxcode = Db::name('org')->where('id',$this->orgId)->value('wxqrcode');
- $this->assign('wxcode',$wxcode);
- // 陪护h5
- $phcode = think_encrypt(config('app.ph_url').'?orgId='.$this->orgId);
- $this->assign('phcode',$phcode);
- // 点餐h5
- $shopcode = think_encrypt(config('app.shop_url').'?orgId='.$this->orgId);
- $this->assign('shopcode',$shopcode);
- // 商城h5
- $xshopcode = think_encrypt(config('app.xshop_url').'?orgId='.$this->orgId);
- $this->assign('xshopcode',$xshopcode);
- return $this->fetch();
- }
- public function ocount(){
- $order = 0;
- // 判断用户是否是调度
- $level1 = check_is_dispatch($this->userId);
- $level2 = check_two_dispatch($this->userId);
- $level2onoff = two_dispatch_off($this->orgId);
- if(!$level1 && !$level2){
- $order = -1;
- }else{
- // 一级调度
- if($level1 || (!$level2onoff && $level2)){
- $map[] = ['org_id','=',$this->orgId];
- $map[] = ['del','=',0];
- $map[] = ['order_mode','=',1];
- if($level2onoff){
- $map[] = ['is_deal','=',0];
- }
- if(!is_admin($this->userId)){
- $auth = get_dispatch_auth($this->userId);
- if($auth){
- $map[] = ['work_type_mode', 'in', $auth];
- $where[] = ['o.work_type_mode', 'in', $auth];
- }else{
- $map[] = ['work_type_mode', '=', -1];
- $where[] = ['work_type_mode', '=', -1];
- }
- }
- $order = Db::name('orders')->where($map)->count();
- //$驳回的订单
- $where[] = ['o.del','=',0];
- $where[] = ['t.del','=',0];
- $bh = Db::name('orders')
- ->alias('o')
- ->join('todo t','t.order_id=o.id')
- ->where('t.todo_mode',4)
- ->where('t.org_id',$this->orgId)
- ->where('o.order_mode',4)
- ->where('o.org_id',$this->orgId)
- ->where($where)
- ->group('o.id')
- ->count();
- $order = $order + $bh;
- } else if($level2 && $level2onoff) { // 二级调度
- $rolesId = Db::name('user_roles')->where('user_id',$this->userId)->value('roles_id');
- if(!$rolesId){
- $order = 0;
- }else{
- $map[] = ['b.org_id','=',$this->orgId];
- $map[] = ['b.del','=',0];
- $map[] = ['b.order_mode','=',1];
- $map[] = ['b.is_deal','=',1];
- $map[] = ['a.roles_id','=',$rolesId];
- if(!is_admin($this->userId)){
- $auth = get_dispatch_auth($this->userId);
- if($auth){
- $map[] = ['b.work_type_mode', 'in', $auth];
- }else{
- $map[] = ['b.work_type_mode', '=', -1];
- }
- }
- $order = Db::name('dispatch_log')
- ->alias('a')
- ->join('orders b','b.id = a.order_id')
- ->where($map)
- ->field('a.*')
- ->count();
- }
- }
- $complainCount = Db::name('complain')->where('del',0)->where('org_id',$this->orgId)->where('status',0)->where('order_id',0)->count();
- $hiddendangerCount = Db::name('hiddendanger')->where('del',0)->where('org_id',$this->orgId)->where('status',0)->where('order_id',0)->count();
- $endCount = $order+$complainCount+$hiddendangerCount;
- }
- $this->success('成功','',['count'=>$endCount]);
- }
- public function def(){
- $id = 500;
- $menus = model('Menu')->getMenuTree($this->rolesId,$this->orgId);
- $submenus = [];
- foreach ($menus as $k=>$v){
- if($v['id'] == $id){
- $submenus = $v['child'];
- break;
- }
- }
- $lists = [];
- foreach ($submenus as $k=>$v){
- if(!$v['url']){
- // $v['url'] = url('Index/indexsub',['id'=>$v['id'],'t'=>1]);
- }
- $lists[] = $v;
- }
- $this->assign('lists',$lists);
- // 获取常用模块
- $cys = Db::name('user_menu')
- ->where('user_id',$this->userId)
- ->order('count desc,id asc')
- ->select();
- $cys = $cys?$cys:[];
- $ncys = [];
- foreach ($cys as $k=>$v){
- foreach ($lists as $kk=>$vv){
- if(count($ncys) == 5){
- continue;
- }
- if($vv['id'] == $v['menu_id']){
- $v['title'] = $vv['title'];
- $v['url'] = $vv['url'];
- $v['img'] = $vv['img'];
- $v['des'] = $vv['des'];
- $ncys[] = $v;
- break;
- }
- }
- }
- $this->assign('cys',$ncys);
- // 自定义模块
- $usermenus = Db::name('user_menu_group')->where('user_id',$this->userId)->order('sort asc,id asc')->select();
- $usermenus = $usermenus?$usermenus:[];
- $groupMenuList = $usermenus;
- $allmenus = [];
- foreach ($usermenus as $k=>$v){
- $menus = [];
- if($v['menus']){
- $menuids = explode(',',$v['menus']);
- $allmenus = array_merge($allmenus,$menuids);
- foreach ($lists as $kk=>$vv){
- if(in_array($vv['id'],$menuids)){
- $menus[] = $vv;
- }
- }
- }
- $usermenus[$k]['menus'] = $menus;
- }
- $menus = [];
- foreach ($lists as $kk=>$vv){
- if(!$allmenus || !in_array($vv['id'],$allmenus)){
- $menus[] = $vv;
- }
- }
- $usermenus[] = [
- 'id' => 0,
- 'title' => '综合模块',
- 'menus' => $menus
- ];
- $arr[] = [
- 'id'=>0,
- 'title'=>'综合模块',
- ];
- $this->assign('usermenusgroup',array_merge($arr,$groupMenuList));
- $this->assign('usermenus',$usermenus);
- $menuInfo = Db::name('menu')->where('id',$id)->find();
- $menuTitle = $menuInfo['title'];
- $menuTitle1 = $menuTitle2 = '';
- // if($menuInfo){
- // $menuInfo1 = Db::name('menu')->where('pid',$menuInfo['id'])->find();
- // if($menuInfo1){
- // $menuTitle1 = $menuInfo1['title'];
- // $menuInfo2 = Db::name('menu')->where('pid',$menuInfo1['id'])->find();
- // if($menuInfo2){
- // $menuTitle2 = $menuInfo2['title'];
- // }
- // }
- // }
- $this->assign('menuTitle',$menuTitle);
- $this->assign('menuTitle1',$menuTitle1);
- $this->assign('menuTitle2',$menuTitle2);
- return $this->fetch();
- }
- public function todo(){
- $mode = input('mode',1);
- $todoList = Db::name('todo')
- ->where('org_id',$this->orgId)
- ->where('del',0)
- ->where('work_type_mode',$mode)
- ->limit(11)
- ->order('id desc')
- ->select();
- foreach ($todoList as $k=>$v){
- $todoList[$k]['work_type_mode_text'] = Db::name('work_type_mode')->where('id',$v['work_type_mode'])->value('name');
- $todoList[$k]['to_user_name'] = Db::name('user')->where('id',$v['to_user_id'])->value('real_name');
- $todoList[$k]['user_name'] = Db::name('user')->where('id',$v['create_user_id'])->value('real_name');
- $todoList[$k]['content'] = Db::name('orders')->where('id',$v['order_id'])->value('content');
- $todomode = Db::name('todo_mode')->where('id',$v['todo_mode'])->find();
- $todoList[$k]['todo_mode_text'] = $todomode?$todomode['in_content']:'';
- $todoList[$k]['todo_mode_color'] = $todomode?$todomode['color']:'';
- }
- //数据返回
- $totalCount = count($todoList);
- $totalPage = 1;
- $result['page'] = 1;
- $result['total'] = $totalPage;
- $result['records'] = $totalCount;
- $result['rows'] = $todoList;
- return json($result);
- }
- public function attendanceCount1(){
- $group = Db::name('attendance_group')
- ->where('del',0)
- ->where('org_id',$this->orgId)
- ->select();
- $groupsId = [];
- $groupsId2 = [];
- $week = date('w');
- foreach ($group as $k=>$v){
- $content = json_decode($v['content'],true);
- if($v['type'] == 1){
- foreach ($content['week'] as $kk=>$vv){
- if($vv['week'] == $week && $vv['class_id'] > 0){
- $groupsId[] = $v['id'];
- }
- }
- }
- if($v['type'] == 2){
- $groupClass = Db::name('attendance_group_class')
- ->where('group_id',$v['id'])
- ->where('org_id',$this->orgId)
- ->where('day',date('Y-m-d'))
- ->find();
- if($groupClass){
- $groupsId2[] = $v['id'];
- }
- }
- }
- $endGroupIds = array_unique(array_merge($groupsId,$groupsId2));
- $userCount = Db::name('attendance_group_user')
- ->where('org_id',$this->orgId)
- ->whereIn('group_id',$endGroupIds)
- ->count();
- $userIds = Db::name('attendance_group_user')
- ->where('org_id',$this->orgId)
- ->whereIn('group_id',$endGroupIds)
- ->column('user_id');
- $attendanceNums = 0;
- foreach ($userIds as $k=>$v){
- $attendanceRecord = Db::name('attendance_record')
- ->where('user_id',$v)
- ->where('org_id',$this->orgId)
- // ->where('status',1)
- ->where('create_time','>=',date('Y-m-d').' 00:00:00')
- ->where('create_time','<=',date('Y-m-d').' 23:59:59')
- ->select();
- $flag = 0;
- if($attendanceRecord){
- foreach ($attendanceRecord as $kk=>$vv){
- if($vv['status'] == 1){
- }else{
- $flag = 1;
- }
- }
- if($flag == 0){
- $attendanceNums +=1;
- }
- }
- }
- $attendanceNums3 = $userCount-$attendanceNums;
- $attendanceCount1 = [
- 'count1' => $userCount, //总人数
- 'count2' => $attendanceNums, //在职人数
- 'count3' => $attendanceNums3>0?$attendanceNums3:0, //缺勤人数
- 'bl' => $userCount>0?round($attendanceNums/$userCount,2)*100:0,
- 'bl2' => $userCount>0?round($attendanceNums3/$userCount,2)*100:0,
- ];
- $this->success('','',$attendanceCount1);
- }
- public function changeOrg(){
- if(request()->isAjax()){
- $id = input('id/d');
- $info = Db::name('org')->where('id',$id)->find();
- if($info['type'] != 2){
- $this->error('管理机构不能切换');
- }
- session('orgId',$info['id']);
- session('orgName',$info['name']);
- $this->success('切换成功');
- }else{
- $tree = model('Org')->getTreeByRoles($this->rolesId,$this->userId);
- $this->assign('tree',$tree);
- return $this->fetch();
- }
- }
- public function order(){
- // 判断用户是否是调度
- $level1 = check_is_dispatch($this->userId);
- $level2 = check_two_dispatch($this->userId);
- $level2onoff = two_dispatch_off($this->orgId);
- if(!$level1 && !$level2){
- $this->error('不是调度');
- }
- $order = 0;
- // 一级调度
- if($level1 || (!$level2onoff && $level2)){
- $map[] = ['org_id','=',$this->orgId];
- $map[] = ['del','=',0];
- $map[] = ['order_mode','=',1];
- if($level2onoff){
- $map[] = ['is_deal','=',0];
- }
- if(!is_admin($this->userId)){
- $auth = get_dispatch_auth($this->userId);
- if($auth){
- $map[] = ['work_type_mode', 'in', $auth];
- $where[] = ['o.work_type_mode', 'in', $auth];
- }else{
- $map[] = ['work_type_mode', '=', -1];
- $where[] = ['o.work_type_mode', '=', -1];
- }
- }
- $order = Db::name('orders')->where($map)->count();
- //$驳回的订单
- $where[] = ['o.del','=',0];
- $where[] = ['t.del','=',0];
- $bh = Db::name('orders')
- ->alias('o')
- ->join('todo t','t.order_id=o.id')
- ->where('t.todo_mode',4)
- ->where('t.org_id',$this->orgId)
- ->where('o.order_mode',4)
- ->where('o.org_id',$this->orgId)
- ->where($where)
- ->group('o.id')
- ->count();
- $order = $order + $bh;
- } else if($level2 && $level2onoff) { // 二级调度
- $rolesId = Db::name('user_roles')->where('user_id',$this->userId)->value('roles_id');
- if(!$rolesId){
- $this->error('无订单');
- }
- $map[] = ['b.org_id','=',$this->orgId];
- $map[] = ['b.del','=',0];
- $map[] = ['b.order_mode','=',1];
- $map[] = ['b.is_deal','=',1];
- $map[] = ['a.roles_id','=',$rolesId];
- if(!is_admin($this->userId)){
- $auth = get_dispatch_auth($this->userId);
- if($auth){
- $map[] = ['b.work_type_mode', 'in', $auth];
- }else{
- $map[] = ['b.work_type_mode', '=', -1];
- }
- }
- $order = Db::name('dispatch_log')
- ->alias('a')
- ->join('orders b','b.id = a.order_id')
- ->where($map)
- ->field('a.*')
- ->count();
- }
- $complainCount = Db::name('complain')->where('del',0)->where('org_id',$this->orgId)->where('status',0)->where('order_id',0)->count();
- $hiddendangerCount = Db::name('hiddendanger')->where('del',0)->where('org_id',$this->orgId)->where('status',0)->where('order_id',0)->count();
- $endCount = $order+$complainCount+$hiddendangerCount;
- if(!empty($endCount)){
- $this->success('','',$endCount);
- }else{
- $this->error('无订单');
- }
- }
- public function ordersList() {
- $orderType = input('orderType',1);
- $mode = input('mode', 0);
- $level1 = check_is_dispatch($this->userId);
- $level2 = check_two_dispatch($this->userId);
- $turnoff = two_dispatch_off($this->orgId);
- if (request()->isAjax()) {
- //分页参数
- $length = input('rows', 10, 'intval'); //每页条数
- $page = input('page', 1, 'intval'); //第几页
- $start = ($page - 1) * $length; //分页开始位置
- //排序
- $sortRow = input('sidx', 'id', 'trim'); //排序列
- $sort = input('sord', 'desc', 'trim'); //排序方式
- $order = $sortRow . ' ' . $sort;
- if($orderType == 1){
- $content = input('content', '', 'trim');
- if ($content) {
- $map[] = ['content', 'like', '%' . $content . '%'];
- }
- $dep_id = input('dep_id', '', 'trim');
- if ($dep_id != '') {
- $map[] = ['dep_id', '=', $dep_id];
- }
- $order_mode = input('order_mode', 1);
- $map6 = [];
- if ($order_mode != '') {
- if($level1 && $turnoff && $mode != 15){ // 一级调度且二级调度开关开着,品质整改例外
- if ($order_mode == 1) {
- $map[] = ['is_deal', '=', 0];
- }else if ($order_mode == 4) {
- $map6[] = ['is_deal', '=', 1];
- }
- }
- if($order_mode==100){//已挂起
- $gq = Db::name('todo')
- ->where('work_type_mode',1)
- ->where('todo_mode',2)
- ->where('pause',1)
- ->column('order_id');
- if(empty($gq)){
- $map[] = ['id', '=', -1];
- }else{
- $map[] = ['id', 'in', $gq];
- }
- }else{
- $map[] = ['order_mode', '=', $order_mode];
- }
- }
- $b = input('start', '', 'trim');
- $e = input('end', '', 'trim');
- if ($b) {
- $b = date('Ymd', strtotime($b));
- $map[] = ['create_yyyymmdd', '>=', $b];
- }
- if ($e) {
- $e = date('Ymd', strtotime($e));
- $map[] = ['create_yyyymmdd', '<=', $e];
- }
- $map[] = ['del', '=', 0];
- $map[] = ['org_id', '=', $this->orgId];
- if($mode==-1){
- $map[] = ['source_type', '=', 4];
- }
- $type = input('type', '', 'trim');
- $oids = [];
- if ($type != '') {
- $map1[] = ['parent_id', '=', $type];
- $type_id = Db::name('order_type')
- ->where($map1)
- ->where('org_id', $this->orgId)
- ->where('enable', 1)
- ->column('id');
- if (!empty($type_id)) {
- $map3[] = ['type_id', 'in', $type_id];
- $ids = Db::name('order_repair')
- ->where($map3)
- ->column('order_id');
- if (!empty($ids)) {
- $oids = $ids;
- }
- else {
- $oids = [];
- }
- }
- else {
- $oids = [];
- }
- }
- if($level2 && $turnoff){ // 二级调度
- $roles_id = Db::name('user_roles')
- ->where('user_id', $this->userId)
- ->value('roles_id');
- $ids = Db::name('dispatch_log')
- ->where('roles_id', $roles_id)
- ->whereOr('to_user_id', $this->userId)
- ->column('order_id');
- if (empty($ids)) {
- $map[] = ['id', '=', -1];
- } else {
- if($type != ''){
- $oids = array_intersect($oids,$ids);
- if($oids){
- $map[] = ['id', 'in', $oids];
- }else{
- $map[] = ['id', '=', -1];
- }
- }else{
- $map[] = ['id', 'in', $ids];
- }
- }
- }else{
- if($type != ''){
- if($oids){
- $map[] = ['id', 'in', $oids];
- }else{
- $map[] = ['id', '=', 0];
- }
- }
- }
- if($mode == 15){ // 品质检查,单独处理
- $map[] = ['work_type_mode','=',$mode];
- }else{
- $work_type_mode = input('work_type_mode','','trim');
- if(!is_admin($this->userId)){
- $auth = get_dispatch_auth($this->userId);
- if($auth){
- $map[] = ['work_type_mode', 'in', $auth];
- if($mode > 0){
- $map[] = ['work_type_mode', '=', $mode];
- }else{
- if($work_type_mode!=''){
- $map[] = ['work_type_mode','=',$work_type_mode];
- }
- }
- }else{
- $map[] = ['work_type_mode', '=', -1];
- }
- }else{
- if($mode > 0){
- $map[] = ['work_type_mode', '=', $mode];
- }else{
- if($work_type_mode!=''){
- $map[] = ['work_type_mode','=',$work_type_mode];
- }
- }
- }
- }
- $map = empty($map) ? true : $map;
- //数据查询
- $lists = db('orders')->where($map)
- ->whereOr($map6)
- ->limit($start, $length)->order($order)->select();
- foreach ($lists as $k => $v) {
- $lists[$k] = model('orders')->formatOrder($v);
- if ($turnoff && $level1 && $v['order_mode'] == 1 && $v['is_deal'] == 1) {
- $lists[$k]['order_mode_text'] = '已派发';
- }
- $lists[$k]['bh_nums'] = Db::name('todo')->where('order_id',$v['id'])->where('del',0)->where('todo_mode',4)->count();
- $gq = Db::name('todo')
- ->where('order_id',$v['id'])
- ->where('work_type_mode',1)
- ->where('todo_mode',2)
- ->where('pause',1)
- ->find();
- $lists[$k]['gq'] = $gq?'存在挂起':'';
- }
- //数据返回
- $totalCount = db('orders')->where($map)->count();
- }elseif($orderType == 2){
- $map[] = ['del','=',0];
- $map[] = ['org_id','=',$this->orgId];
- $hour = (new Config())->getConfig('org_complain_hour',$this->orgId);
- $hour = $hour>0?$hour:0;
- $endTime = date('Y-m-d H:i:s',time() - $hour*60*60);
- $type = input('type/d',0);
- if($hour > 0 && $type == 1){
- $map[] = ['create_time','<',$endTime];
- $map[] = ['status','=',0];
- }
- $from = input('from', '', 'trim');
- if ($from!='') {
- $map[] = ['from','=',$from];
- }
- $map[] = ['status','=',0];
- $map[] = ['order_id','=',0];
- $map= empty($map) ? true: $map;
- //数据查询
- $lists = db('complain')->where($map)
- ->limit($start,$length)->order($order)->select();
- foreach ($lists as $k=>$v){
- $lists[$k]['depName'] = Db::name('dep')
- ->where('id',$v['dep_id'])
- ->value('title');
- // $lists[$k]['fromName'] = model('Complain')->from[$v['from']];
- $lists[$k]['fromName'] = '';
- if($v['order_id'] > 0 && $v['bus_type'] != 0){
- if($v['to_from']){
- $lists[$k]['fromName'] = '一键呼叫';
- }else{
- $lists[$k]['fromName'] = '隐患';
- }
- }
- $lists[$k]['worktypemode'] = '';
- if($v['order_id'] > 0 && in_array($v['bus_type'],[0,1])){
- $worktype = Db::name('orders')
- ->alias('o')
- ->join('work_type_mode w','o.work_type_mode = w.id')
- ->where('o.id',$v['order_id'])
- ->value('w.name');
- $lists[$k]['worktypemode'] = $worktype?$worktype:'';
- }
- if($v['hide'] == 1){
- $lists[$k]['realName'] = '匿名';
- }else{
- $lists[$k]['realName'] = Db::name('user')
- ->where('id',$v['create_user_id'])
- ->value('real_name');
- }
- $orderMode = 0;
- if($v['order_id'] > 0){
- $orderMode = Db::name('orders')->where('id',$v['order_id'])->value('order_mode');
- }
- $lists[$k]['statusTxt'] = model('Complain')->formatStatus($v['status'],$v['order_id'],$v['id']);
- $lists[$k]['order_mode'] = $orderMode;
- if($v['create_time'] < $endTime && $v['status']==0){
- $lists[$k]['statusTxt'] = $lists[$k]['statusTxt'].'<span style="color:red;">(已超时)</span>';
- }
- }
- //数据返回
- $totalCount = db('complain')->where($map)->count();
- }elseif ($orderType == 3){
- $map[] = ['del','=',0];
- $map[] = ['org_id','=',$this->orgId];
- $map[] = ['status','=',0];
- $map[] = ['order_id','=',0];
- $from = input('from', '', 'trim');
- if ($from!='') {
- $map[] = ['from','=',$from];
- }
- $map= empty($map) ? true: $map;
- //数据查询
- $lists = db('hiddendanger')->where($map)
- ->limit($start,$length)->order($order)->select();
- foreach ($lists as $k=>$v){
- $lists[$k]['depName'] = Db::name('dep')
- ->where('id',$v['dep_id'])
- ->value('title');
- // $lists[$k]['fromName'] = model('Hiddendanger')->from[$v['from']];
- $lists[$k]['fromName'] = '';
- if($v['order_id'] > 0 && $v['bus_type'] != 0){
- if($v['to_from']){
- $lists[$k]['fromName'] = '一键呼叫';
- }else{
- $lists[$k]['fromName'] = '投诉';
- }
- }
- $lists[$k]['worktypemode'] = '';
- if($v['order_id'] > 0 && in_array($v['bus_type'],[0,1])){
- $worktype = Db::name('orders')
- ->alias('o')
- ->join('work_type_mode w','o.work_type_mode = w.id')
- ->where('o.id',$v['order_id'])
- ->value('w.name');
- $lists[$k]['worktypemode'] = $worktype?$worktype:'';
- }
- $lists[$k]['realName'] = Db::name('user')
- ->where('id',$v['create_user_id'])
- ->value('real_name');
- // $lists[$k]['statusTxt'] = $v['status']==1?'已处理':"未处理";
- $orderMode = 0;
- if($v['order_id'] > 0){
- $orderMode = Db::name('orders')->where('id',$v['order_id'])->value('order_mode');
- }
- $lists[$k]['statusTxt'] = model('Hiddendanger')->formatStatus($v['status'],$v['order_id'],$v['id']);
- $lists[$k]['order_mode'] = $orderMode;
- }
- //数据返回
- $totalCount = db('hiddendanger')->where($map)->count();
- }elseif($orderType == 4){
- $order_mode = input('order_mode', 4);
- $map6 = [];
- if ($order_mode != '') {
- if($level1 && $turnoff && $mode != 15){ // 一级调度且二级调度开关开着,品质整改例外
- if ($order_mode == 1) {
- $map[] = ['is_deal', '=', 0];
- }else if ($order_mode == 4) {
- $map6[] = ['is_deal', '=', 1];
- }
- }
- if($order_mode==100){//已挂起
- $gq = Db::name('todo')
- ->where('work_type_mode',1)
- ->where('todo_mode',2)
- ->where('pause',1)
- ->column('order_id');
- if(empty($gq)){
- $map[] = ['id', '=', -1];
- }else{
- $map[] = ['id', 'in', $gq];
- }
- }else{
- $map[] = ['order_mode', '=', $order_mode];
- }
- }
- $map[] = ['del', '=', 0];
- $map[] = ['org_id', '=', $this->orgId];
- if($mode==-1){
- $map[] = ['source_type', '=', 4];
- }
- $type = input('type', '', 'trim');
- $oids = [];
- if ($type != '') {
- $map1[] = ['parent_id', '=', $type];
- $type_id = Db::name('order_type')
- ->where($map1)
- ->where('org_id', $this->orgId)
- ->where('enable', 1)
- ->column('id');
- if (!empty($type_id)) {
- $map3[] = ['type_id', 'in', $type_id];
- $ids = Db::name('order_repair')
- ->where($map3)
- ->column('order_id');
- if (!empty($ids)) {
- $oids = $ids;
- }
- else {
- $oids = [];
- }
- }
- else {
- $oids = [];
- }
- }
- if($level2 && $turnoff){ // 二级调度
- $roles_id = Db::name('user_roles')
- ->where('user_id', $this->userId)
- ->value('roles_id');
- $ids = Db::name('dispatch_log')
- ->where('roles_id', $roles_id)
- ->whereOr('to_user_id', $this->userId)
- ->column('order_id');
- if (empty($ids)) {
- $map[] = ['id', '=', -1];
- } else {
- if($type != ''){
- $oids = array_intersect($oids,$ids);
- if($oids){
- $map[] = ['id', 'in', $oids];
- }else{
- $map[] = ['id', '=', -1];
- }
- }else{
- $map[] = ['id', 'in', $ids];
- }
- }
- }else{
- if($type != ''){
- if($oids){
- $map[] = ['id', 'in', $oids];
- }else{
- $map[] = ['id', '=', 0];
- }
- }
- }
- if($mode == 15){ // 品质检查,单独处理
- $map[] = ['work_type_mode','=',$mode];
- }else{
- $work_type_mode = input('work_type_mode','','trim');
- if(!is_admin($this->userId)){
- $auth = get_dispatch_auth($this->userId);
- if($auth){
- $map[] = ['work_type_mode', 'in', $auth];
- if($mode > 0){
- $map[] = ['work_type_mode', '=', $mode];
- }else{
- if($work_type_mode!=''){
- $map[] = ['work_type_mode','=',$work_type_mode];
- }
- }
- }else{
- $map[] = ['work_type_mode', '=', -1];
- }
- }else{
- if($mode > 0){
- $map[] = ['work_type_mode', '=', $mode];
- }else{
- if($work_type_mode!=''){
- $map[] = ['work_type_mode','=',$work_type_mode];
- }
- }
- }
- }
- $orderIds = Db::name('todo')
- ->where('todo_mode',4)
- ->where('org_id',$this->orgId)
- ->where('del',0)
- ->group('order_id')
- ->column('order_id');
- $map[] = ['id','in',$orderIds];
- $map = empty($map) ? true : $map;
- //数据查询
- $lists = db('orders')
- ->where($map)
- // ->whereOr($map6)
- ->limit($start, $length)
- ->order($order)
- ->select();
- foreach ($lists as $k => $v) {
- $lists[$k] = model('orders')->formatOrder($v);
- if ($turnoff && $level1 && $v['order_mode'] == 1 && $v['is_deal'] == 1) {
- $lists[$k]['order_mode_text'] = '已派发';
- }
- $lists[$k]['bh_nums'] = Db::name('todo')->where('order_id',$v['id'])->where('del',0)->where('todo_mode',4)->count();
- $gq = Db::name('todo')
- ->where('order_id',$v['id'])
- ->where('work_type_mode',1)
- ->where('todo_mode',2)
- ->where('pause',1)
- ->find();
- $lists[$k]['gq'] = $gq?'存在挂起':'';
- }
- //数据返回
- $totalCount = db('orders')->where($map)->count();
- }
- $totalPage = ceil($totalCount / $length);
- $result['page'] = $page;
- $result['total'] = $totalPage;
- $result['records'] = $totalCount;
- $result['rows'] = $lists;
- return json($result);
- }
- else {
- if($mode >0){
- $mode_name = $this->getTableField('work_type_mode', ['id' => $mode], 'name');
- }else{
- $mode_name = '';
- }
- $auths = [1,2,3,4,15,0];
- if(!is_admin($this->userId)){
- $auth = get_dispatch_auth($this->userId);
- if($auth){
- $auths = array_intersect($auths,$auth);
- if($mode > 0){
- $auths = array_intersect($auths,[$mode]);
- }
- }else{
- $auths = [];
- }
- }
- $this->assign('auths',$auths);
- $dep_list = (new \app\common\model\Dep())->getList();
- $order_type = (new \app\common\model\OrderType())->list();
- $order_mode = Db::name('order_mode')
- ->select();
- $this->assign('dep_list', $dep_list);
- $this->assign('order_type_list', $order_type);
- $this->assign('m_name', $mode_name);
- $this->assign('mode', $mode);
- $this->assign('order_mode_list', $order_mode);
- $this->assign('dispatch_type', check_two_dispatch($this->userId));
- $this->assign('orderType',$orderType);
- return $this->fetch('index/orders');
- }
- }
- //调度查看订单详情
- public function ordersDetail2($id) {
- if (!$id) {
- $this->error('参数错误');
- }
- $type = input('type/d',0);
- $this->assign('type', $type);
- $order = Db::name('orders')->where(['id' => $id])->find();
- $order = model('Orders')->formatOrder($order, 1);
- $order['images'] = !empty($order['images']) ? explode(',', $order['images']) : '';
- $this->assign('info', $order);
- $workTypeName = $this->getTableField('work_type_mode', ['id' => $order['work_type_mode']], 'name');
- $this->assign('meta_title', $workTypeName . '订单详情');
- $level2 = check_two_dispatch($this->userId);
- $level1 = check_is_dispatch($this->userId);
- $turnoff = two_dispatch_off($this->orgId);
- $this->assign('level1', $level1);
- $this->assign('level2', $level2);
- $this->assign('turnoff', $turnoff);
- $this->assign('dispatch_type', $level2);
- return $this->fetch();
- }
- public function searchMenu(){
- $menuName = input('menu_name');
- if($menuName){
- $map[] = ['title','like','%'.$menuName.'%'];
- }
- $map[] = ['del','=',0];
- $map[] = ['enable','=',1];
- $map[] = ['pid','=',500];
- $list = Db::name('menu')->where($map)->select();
- foreach ($list as $k=>$v){
- $list[$k]['url'] = url('index/indexsub1',['curmenu'=>500,'menuId'=>$v['id'],'ct'=>1]);
- }
- $this->success('','',$list);
- }
- public function indexsub(){
- $curmenu = input('curmenu',500);
- $menuId = input('menuId',0);
- $this->assign('curmenu',$curmenu);
- $this->assign('menuId',$menuId);
- $curmenuId = input('curmenuId',0);
- $this->assign('curmenuId',$curmenuId);
- $menuInfo = Db::name('menu')->where('id',$curmenu)->find();
- $menuTitle = $menuInfo['title'];
- $menuTitle1 = $menuTitle2 = '';
- if($curmenu != 500){
- $menuInfo1 = Db::name('menu')->where('pid',$menuInfo['id'])->find();
- if($menuInfo1){
- $menuTitle1 = $menuInfo1['title'];
- $menuInfo2 = Db::name('menu')->where('pid',$menuInfo1['id'])->where('del',0)->where('enable',1)->where('is_btn',0)->order(['sort'=>'asc','id'=>'asc'])->find();
- if($menuInfo2){
- $menuTitle2 = $menuInfo2['title'];
- }
- }
- if($menuId > 0){
- $menuInfo1 = Db::name('menu')->where('id',$menuId)->find();
- if($menuInfo1){
- $menuTitle1 = $menuInfo1['title'];
- $menuInfo2 = Db::name('menu')->where('pid',$menuInfo1['id'])->where('is_btn',0)->where('del',0)->where('enable',1)->order(['sort'=>'asc','id'=>'asc'])->find();
- if($menuInfo2){
- $menuTitle2 = $menuInfo2['title'];
- }
- }
- }
- }
- $this->assign('menuTitle',$menuTitle);
- $this->assign('menuTitle1',$menuTitle1);
- $this->assign('menuTitle2',$menuTitle2);
- $menus = model('Menu')->getMenuTree($this->rolesId,$this->orgId);
- $this->assign('menus',$menus);
- $userInfo = Db::name('user')
- ->where('id',$this->userId)
- ->find();
- $this->assign('userInfo',$userInfo);
- // 判断用户是否是调度
- $isDispatch = 0;
- if(check_is_dispatch($this->userId) || check_two_dispatch($this->userId)){
- $isDispatch = 1;
- }
- $this->assign('isDispatch',$isDispatch);
- $order = 0;
- // 判断用户是否是调度
- $level1 = check_is_dispatch($this->userId);
- $level2 = check_two_dispatch($this->userId);
- $level2onoff = two_dispatch_off($this->orgId);
- if(!$level1 && !$level2){
- $order = -1;
- }else{
- // 一级调度
- if($level1 || (!$level2onoff && $level2)){
- $map[] = ['org_id','=',$this->orgId];
- $map[] = ['del','=',0];
- $map[] = ['order_mode','=',1];
- if($level2onoff){
- $map[] = ['is_deal','=',0];
- }
- if(!is_admin($this->userId)){
- $auth = get_dispatch_auth($this->userId);
- if($auth){
- $map[] = ['work_type_mode', 'in', $auth];
- $where[] = ['o.work_type_mode', 'in', $auth];
- }else{
- $map[] = ['work_type_mode', '=', -1];
- $where[] = ['o.work_type_mode', '=', -1];
- }
- }
- $order = Db::name('orders')->where($map)->count();
- //$驳回的订单
- $where[] = ['o.del','=',0];
- $where[] = ['t.del','=',0];
- $bh = Db::name('orders')
- ->alias('o')
- ->join('todo t','t.order_id=o.id')
- ->where('t.todo_mode',4)
- ->where('t.org_id',$this->orgId)
- ->where('o.order_mode',4)
- ->where('o.org_id',$this->orgId)
- ->where($where)
- ->group('o.id')
- ->count();
- $order = $order + $bh;
- } else if($level2 && $level2onoff) { // 二级调度
- $rolesId = Db::name('user_roles')->where('user_id',$this->userId)->value('roles_id');
- if(!$rolesId){
- $order = 0;
- }else{
- $map[] = ['b.org_id','=',$this->orgId];
- $map[] = ['b.del','=',0];
- $map[] = ['b.order_mode','=',1];
- $map[] = ['b.is_deal','=',1];
- $map[] = ['a.roles_id','=',$rolesId];
- if(!is_admin($this->userId)){
- $auth = get_dispatch_auth($this->userId);
- if($auth){
- $map[] = ['b.work_type_mode', 'in', $auth];
- }else{
- $map[] = ['b.work_type_mode', '=', -1];
- }
- }
- $order = Db::name('dispatch_log')
- ->alias('a')
- ->join('orders b','b.id = a.order_id')
- ->where($map)
- ->field('a.*')
- ->count();
- }
- }
- }
- $complainCount = Db::name('complain')->where('del',0)->where('org_id',$this->orgId)->where('status',0)->where('order_id',0)->count();
- $hiddendangerCount = Db::name('hiddendanger')->where('del',0)->where('org_id',$this->orgId)->where('status',0)->where('order_id',0)->count();
- $endCount = $order+$complainCount+$hiddendangerCount;
- $this->assign('orderNums',$endCount);
- return $this->fetch();
- }
- public function indexsub1(){
- $curmenu = input('curmenu',500);
- $menuId = input('menuId',0);
- $ct = input('ct',0);
- $this->assign('curmenu',$curmenu);
- $this->assign('menuId',$menuId);
- $this->assign('ct',$ct);
- $menus = model('Menu')->getMenuTree($this->rolesId,$this->orgId);
- $this->assign('menus',$menus);
- $userInfo = Db::name('user')
- ->where('id',$this->userId)
- ->find();
- $this->assign('userInfo',$userInfo);
- $menuInfo = Db::name('menu')->where('id',$curmenu)->find();
- $menuTitle = $menuInfo['title'];
- $menuTitle1 = $menuTitle2 = '';
- if($curmenu == 500){
- $menuInfo1 = Db::name('menu')->where('id',$menuId)->find();
- if($menuInfo1){
- $menuTitle1 = $menuInfo1['title'];
- $menuInfo2 = Db::name('menu')->where('pid',$menuInfo1['id'])->where('del',0)->where('enable',1)->where('is_btn',0)->order(['sort'=>'asc','id'=>'asc'])->find();
- if($menuInfo2){
- $menuTitle2 = $menuInfo2['title'];
- }
- }
- }
- $this->assign('menuTitle',$menuTitle);
- $this->assign('menuTitle1',$menuTitle1);
- $this->assign('menuTitle2',$menuTitle2);
- // 判断用户是否是调度
- $isDispatch = 0;
- if(check_is_dispatch($this->userId) || check_two_dispatch($this->userId)){
- $isDispatch = 1;
- }
- $this->assign('isDispatch',$isDispatch);
- $order = 0;
- // 判断用户是否是调度
- $level1 = check_is_dispatch($this->userId);
- $level2 = check_two_dispatch($this->userId);
- $level2onoff = two_dispatch_off($this->orgId);
- if(!$level1 && !$level2){
- $order = -1;
- }else{
- // 一级调度
- if($level1 || (!$level2onoff && $level2)){
- $map[] = ['org_id','=',$this->orgId];
- $map[] = ['del','=',0];
- $map[] = ['order_mode','=',1];
- if($level2onoff){
- $map[] = ['is_deal','=',0];
- }
- if(!is_admin($this->userId)){
- $auth = get_dispatch_auth($this->userId);
- if($auth){
- $map[] = ['work_type_mode', 'in', $auth];
- $where[] = ['o.work_type_mode', 'in', $auth];
- }else{
- $map[] = ['work_type_mode', '=', -1];
- $where[] = ['o.work_type_mode', '=', -1];
- }
- }
- $order = Db::name('orders')->where($map)->count();
- //$驳回的订单
- $where[] = ['o.del','=',0];
- $where[] = ['t.del','=',0];
- $bh = Db::name('orders')
- ->alias('o')
- ->join('todo t','t.order_id=o.id')
- ->where('t.todo_mode',4)
- ->where('t.org_id',$this->orgId)
- ->where('o.order_mode',4)
- ->where('o.org_id',$this->orgId)
- ->where($where)
- ->group('o.id')
- ->count();
- $order = $order + $bh;
- } else if($level2 && $level2onoff) { // 二级调度
- $rolesId = Db::name('user_roles')->where('user_id',$this->userId)->value('roles_id');
- if(!$rolesId){
- $order = 0;
- }else{
- $map[] = ['b.org_id','=',$this->orgId];
- $map[] = ['b.del','=',0];
- $map[] = ['b.order_mode','=',1];
- $map[] = ['b.is_deal','=',1];
- $map[] = ['a.roles_id','=',$rolesId];
- if(!is_admin($this->userId)){
- $auth = get_dispatch_auth($this->userId);
- if($auth){
- $map[] = ['b.work_type_mode', 'in', $auth];
- }else{
- $map[] = ['b.work_type_mode', '=', -1];
- }
- }
- $order = Db::name('dispatch_log')
- ->alias('a')
- ->join('orders b','b.id = a.order_id')
- ->where($map)
- ->field('a.*')
- ->count();
- }
- }
- }
- $complainCount = Db::name('complain')->where('del',0)->where('org_id',$this->orgId)->where('status',0)->where('order_id',0)->count();
- $hiddendangerCount = Db::name('hiddendanger')->where('del',0)->where('org_id',$this->orgId)->where('status',0)->where('order_id',0)->count();
- $endCount = $order+$complainCount+$hiddendangerCount;
- $this->assign('orderNums',$endCount);
- $id = 500;
- $menus = model('Menu')->getMenuTree($this->rolesId,$this->orgId);
- $submenus = [];
- foreach ($menus as $k=>$v){
- if($v['id'] == $id){
- $submenus = $v['child'];
- break;
- }
- }
- $this->assign('submenus',$submenus);
- return $this->fetch();
- }
- public function menugroup($id = 0){
- if(request()->isPost()){
- $res = model('UserMenuGroup')->updates($this->userId);
- if($res){
- $this->success('操作成功');
- }else{
- $this->error(model('UserMenuGroup')->getError());
- }
- }else{
- if($id){
- $info = db('user_menu_group')->where('id',$id)->find();
- if($info){
- $info['menus'] = $info['menus']?explode(',',$info['menus']):[];
- }
- $this->assign('info',$info);
- }
- $id = 500;
- $menus = model('Menu')->getMenuTree($this->rolesId,$this->orgId);
- $submenus = [];
- foreach ($menus as $k=>$v){
- if($v['id'] == $id){
- $submenus = $v['child'];
- break;
- }
- }
- $this->assign('submenus',$submenus);
- return $this->fetch();
- }
- }
- public function menugroupdel(){
- $id = input('id',0);
- $ret = Db::name('user_menu_group')->where('id',$id)->where('user_id',$this->userId)->delete();
- if($ret){
- $this->success('操作成功');
- }else{
- $this->error('操作失败');
- }
- }
- public function def2(){
- $curmenu = input('curmenu',500);
- $this->assign('curmenu',$curmenu);
- $menuId = input('menuId',0);
- $this->assign('menuId',$menuId);
- $menuInfo = Db::name('menu')->where('id',$curmenu)->find();
- $menuTitle = $menuInfo['title'];
- $menuTitle1 = $menuTitle2 = '';
- if($curmenu == 500){
- $menuInfo1 = Db::name('menu')->where('pid',$menuInfo['id'])->find();
- if($menuInfo1){
- $menuTitle1 = $menuInfo1['title'];
- $menuInfo2 = Db::name('menu')->where('pid',$menuInfo1['id'])->where('is_btn',0)->order(['sort'=>'asc','id'=>'asc'])->find();
- if($menuInfo2){
- $menuTitle2 = $menuInfo2['title'];
- }
- }
- if($menuId > 0){
- $menuInfo1 = Db::name('menu')->where('id',$menuId)->find();
- if($menuInfo1){
- $menuTitle1 = $menuInfo1['title'];
- $menuInfo2 = Db::name('menu')->where('pid',$menuInfo1['id'])->where('is_btn',0)->where('del',0)->where('enable',1)->order(['sort'=>'asc','id'=>'asc'])->find();
- if($menuInfo2){
- $menuTitle2 = $menuInfo2['title'];
- }
- }
- }
- }
- $this->assign('menuTitle',$menuTitle);
- $this->assign('menuTitle1',$menuTitle1);
- $this->assign('menuTitle2',$menuTitle2);
- $menus = model('Menu')->getMenuTree($this->rolesId,$this->orgId);
- $this->assign('menus',$menus);
- $userInfo = Db::name('user')
- ->where('id',$this->userId)
- ->find();
- $this->assign('userInfo',$userInfo);
- // 判断用户是否是调度
- $isDispatch = 0;
- if(check_is_dispatch($this->userId) || check_two_dispatch($this->userId)){
- $isDispatch = 1;
- }
- $this->assign('isDispatch',$isDispatch);
- $order = 0;
- // 判断用户是否是调度
- $level1 = check_is_dispatch($this->userId);
- $level2 = check_two_dispatch($this->userId);
- $level2onoff = two_dispatch_off($this->orgId);
- if(!$level1 && !$level2){
- $order = -1;
- }else{
- // 一级调度
- if($level1 || (!$level2onoff && $level2)){
- $map[] = ['org_id','=',$this->orgId];
- $map[] = ['del','=',0];
- $map[] = ['order_mode','=',1];
- if($level2onoff){
- $map[] = ['is_deal','=',0];
- }
- if(!is_admin($this->userId)){
- $auth = get_dispatch_auth($this->userId);
- if($auth){
- $map[] = ['work_type_mode', 'in', $auth];
- $where[] = ['o.work_type_mode', 'in', $auth];
- }else{
- $map[] = ['work_type_mode', '=', -1];
- $where[] = ['o.work_type_mode', '=', -1];
- }
- }
- $order = Db::name('orders')->where($map)->count();
- //$驳回的订单
- $where[] = ['o.del','=',0];
- $where[] = ['t.del','=',0];
- $bh = Db::name('orders')
- ->alias('o')
- ->join('todo t','t.order_id=o.id')
- ->where('t.todo_mode',4)
- ->where('t.org_id',$this->orgId)
- ->where('o.order_mode',4)
- ->where('o.org_id',$this->orgId)
- ->where($where)
- ->group('o.id')
- ->count();
- $order = $order + $bh;
- } else if($level2 && $level2onoff) { // 二级调度
- $rolesId = Db::name('user_roles')->where('user_id',$this->userId)->value('roles_id');
- if(!$rolesId){
- $order = 0;
- }else{
- $map[] = ['b.org_id','=',$this->orgId];
- $map[] = ['b.del','=',0];
- $map[] = ['b.order_mode','=',1];
- $map[] = ['b.is_deal','=',1];
- $map[] = ['a.roles_id','=',$rolesId];
- if(!is_admin($this->userId)){
- $auth = get_dispatch_auth($this->userId);
- if($auth){
- $map[] = ['b.work_type_mode', 'in', $auth];
- }else{
- $map[] = ['b.work_type_mode', '=', -1];
- }
- }
- $order = Db::name('dispatch_log')
- ->alias('a')
- ->join('orders b','b.id = a.order_id')
- ->where($map)
- ->field('a.*')
- ->count();
- }
- }
- }
- $complainCount = Db::name('complain')->where('del',0)->where('org_id',$this->orgId)->where('status',0)->where('order_id',0)->count();
- $hiddendangerCount = Db::name('hiddendanger')->where('del',0)->where('org_id',$this->orgId)->where('status',0)->where('order_id',0)->count();
- $endCount = $order+$complainCount+$hiddendangerCount;
- $this->assign('orderNums',$endCount);
- return $this->fetch();
- }
- public function umenu(){
- $id = input('id/d',0);
- $info = Db::name('user_menu')->where('menu_id',$id)->where('user_id',$this->userId)->find();
- if($info){
- Db::name('user_menu')->where('id',$info['id'])->setInc('count',1);
- }else{
- Db::name('user_menu')->insert([
- 'user_id' => $this->userId,
- 'menu_id' => $id,
- 'count' => 1
- ]);
- }
- $this->success('操作成功');
- }
- }
|