Index.php 64 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\model\Config;
  4. use think\Db;
  5. class Index extends Auth
  6. {
  7. public function index(){
  8. $userInfo = Db::name('user')
  9. ->where('id',$this->userId)
  10. ->find();
  11. $this->assign('userInfo',$userInfo);
  12. // 判断用户是否是调度
  13. $isDispatch = 0;
  14. if(check_is_dispatch($this->userId) || check_two_dispatch($this->userId)){
  15. $isDispatch = 1;
  16. }
  17. $this->assign('isDispatch',$isDispatch);
  18. $order = 0;
  19. // 判断用户是否是调度
  20. $level1 = check_is_dispatch($this->userId);
  21. $level2 = check_two_dispatch($this->userId);
  22. $level2onoff = two_dispatch_off($this->orgId);
  23. if(!$level1 && !$level2){
  24. $order = -1;
  25. }else{
  26. // 一级调度
  27. if($level1 || (!$level2onoff && $level2)){
  28. $map[] = ['org_id','=',$this->orgId];
  29. $map[] = ['del','=',0];
  30. $map[] = ['order_mode','=',1];
  31. if($level2onoff){
  32. $map[] = ['is_deal','=',0];
  33. }
  34. if(!is_admin($this->userId)){
  35. $auth = get_dispatch_auth($this->userId);
  36. if($auth){
  37. $map[] = ['work_type_mode', 'in', $auth];
  38. $where[] = ['o.work_type_mode', 'in', $auth];
  39. }else{
  40. $map[] = ['work_type_mode', '=', -1];
  41. $where[] = ['o.work_type_mode', '=', -1];
  42. }
  43. }
  44. $order = Db::name('orders')->where($map)->count();
  45. //$驳回的订单
  46. $where[] = ['o.del','=',0];
  47. $where[] = ['t.del','=',0];
  48. $bh = Db::name('orders')
  49. ->alias('o')
  50. ->join('todo t','t.order_id=o.id')
  51. ->where('t.todo_mode',4)
  52. ->where('t.org_id',$this->orgId)
  53. ->where('o.order_mode',4)
  54. ->where('o.org_id',$this->orgId)
  55. ->where($where)
  56. ->group('o.id')
  57. ->count();
  58. $order = $order + $bh;
  59. } else if($level2 && $level2onoff) { // 二级调度
  60. $rolesId = Db::name('user_roles')->where('user_id',$this->userId)->value('roles_id');
  61. if(!$rolesId){
  62. $order = 0;
  63. }else{
  64. $map[] = ['b.org_id','=',$this->orgId];
  65. $map[] = ['b.del','=',0];
  66. $map[] = ['b.order_mode','=',1];
  67. $map[] = ['b.is_deal','=',1];
  68. $map[] = ['a.roles_id','=',$rolesId];
  69. if(!is_admin($this->userId)){
  70. $auth = get_dispatch_auth($this->userId);
  71. if($auth){
  72. $map[] = ['b.work_type_mode', 'in', $auth];
  73. }else{
  74. $map[] = ['b.work_type_mode', '=', -1];
  75. }
  76. }
  77. $order = Db::name('dispatch_log')
  78. ->alias('a')
  79. ->join('orders b','b.id = a.order_id')
  80. ->where($map)
  81. ->field('a.*')
  82. ->count();
  83. }
  84. }
  85. }
  86. $complainCount = Db::name('complain')->where('del',0)->where('org_id',$this->orgId)->where('status',0)->where('order_id',0)->count();
  87. $hiddendangerCount = Db::name('hiddendanger')->where('del',0)->where('org_id',$this->orgId)->where('status',0)->where('order_id',0)->count();
  88. $endCount = $order+$complainCount+$hiddendangerCount;
  89. $this->assign('orderNums',$endCount);
  90. //今日看板
  91. $dayOrderNums1 = Db::name('orders')
  92. ->where('org_id',$this->orgId)
  93. ->where('del',0)
  94. ->where('order_mode',1)
  95. ->where('create_time','>=',date('Y-m-d').' 00:00:00')
  96. ->where('create_time','<=',date('Y-m-d').' 23:59:59')
  97. ->count();
  98. $dayOrderNums2 = Db::name('orders')
  99. ->where('org_id',$this->orgId)
  100. ->where('del',0)
  101. ->where('order_mode',4)
  102. ->where('create_time','>=',date('Y-m-d').' 00:00:00')
  103. ->where('create_time','<=',date('Y-m-d').' 23:59:59')
  104. ->count();
  105. $dayOrderNums3 = Db::name('orders')
  106. ->where('org_id',$this->orgId)
  107. ->where('del',0)
  108. ->where('order_mode',5)
  109. ->where('create_time','>=',date('Y-m-d').' 00:00:00')
  110. ->where('create_time','<=',date('Y-m-d').' 23:59:59')
  111. ->count();
  112. $dayOrderNums4 = Db::name('orders')
  113. ->where('org_id',$this->orgId)
  114. ->where('del',0)
  115. ->where('order_mode',6)
  116. ->where('create_time','>=',date('Y-m-d').' 00:00:00')
  117. ->where('create_time','<=',date('Y-m-d').' 23:59:59')
  118. ->count();
  119. $dayOrderNums5 = Db::name('orders')
  120. ->where('org_id',$this->orgId)
  121. ->where('del',0)
  122. ->where('order_mode',2)
  123. ->where('create_time','>=',date('Y-m-d').' 00:00:00')
  124. ->where('create_time','<=',date('Y-m-d').' 23:59:59')
  125. ->count();
  126. $dayOrderNums6 = Db::name('orders')
  127. ->where('org_id',$this->orgId)
  128. ->where('del',0)
  129. ->where('order_mode',3)
  130. ->where('create_time','>=',date('Y-m-d').' 00:00:00')
  131. ->where('create_time','<=',date('Y-m-d').' 23:59:59')
  132. ->count();
  133. $dayOrderCount =[
  134. 'count1'=> $dayOrderNums1,
  135. 'count2'=> $dayOrderNums2,
  136. 'count3'=> $dayOrderNums3,
  137. 'count4'=> $dayOrderNums4,
  138. 'count5'=> $dayOrderNums5,
  139. 'count6'=> $dayOrderNums6,
  140. ];
  141. $this->assign('dayOrderCount',$dayOrderCount);
  142. $notice = Db::name('notice')
  143. ->where('org_id',$this->orgId)
  144. ->where('del',0)
  145. ->where('user_id',$this->userId)
  146. ->field('id,title,create_time,content')
  147. ->order('id desc')
  148. ->limit(2)
  149. ->select();
  150. $this->assign('notice',$notice);
  151. //常用模块
  152. $module = Db::name('user_menu')->where('user_id',$this->userId)->order('count desc')->select();
  153. $id = 500;
  154. $menus = model('Menu')->getMenuTree($this->rolesId,$this->orgId);
  155. $this->assign('menus',$menus);
  156. $submenus = [];
  157. foreach ($menus as $k=>$v){
  158. if($v['id'] == $id){
  159. $submenus = $v['child'];
  160. break;
  161. }
  162. }
  163. $lists11 = [];
  164. foreach ($submenus as $k=>$v){
  165. // if(!$v['url']){
  166. // $v['url'] = url('Index/submenu',['id'=>$v['id'],'t'=>1]);
  167. // }
  168. $lists11[] = $v;
  169. }
  170. $this->assign('submenus',$submenus);
  171. $limit = 6;
  172. $modules = [];
  173. foreach ($module as $k=>$v){
  174. foreach ($lists11 as $kk=>$vv){
  175. if(count($modules) == $limit){
  176. continue;
  177. }
  178. if($vv['id'] == $v['menu_id']){
  179. $v['title'] = $vv['title'];
  180. $v['url'] = $vv['url'];
  181. $v['img'] = $vv['img'];
  182. $v['des'] = $vv['des'];
  183. $modules[] = $v;
  184. break;
  185. }
  186. }
  187. }
  188. $this->assign('module',$modules);
  189. $userEndMenu = $submenus;
  190. $threeMenu = model('Menu')->getMenuTree1($this->rolesId,$this->orgId,'');
  191. $this->assign('userEndMenu',$userEndMenu);
  192. $authMenuIds = array_column($threeMenu,'id');
  193. //固定模块
  194. $fixedModule = Db::name('menu')
  195. ->where('id',500)
  196. ->where('del',0)
  197. ->find();
  198. $fixedModule1 = Db::name('menu')
  199. ->where('id',1)
  200. ->where('del',0)
  201. ->find();
  202. $fixedModule2 = Db::name('menu')
  203. ->where('id',144)
  204. ->where('del',0)
  205. ->find();
  206. $fixedModule3 = Db::name('menu')
  207. ->where('id',163)
  208. ->where('del',0)
  209. ->find();
  210. $fixedModule4 = Db::name('menu')
  211. ->where('id',28)
  212. ->where('del',0)
  213. ->find();
  214. $fixedModuleAuth = $fixedModuleAuth1 = $fixedModuleAuth2 = $fixedModuleAuth3 = $fixedModuleAuth4 = 0 ;
  215. if(in_array($fixedModule['id'],$authMenuIds)){
  216. $fixedModuleAuth = 1 ;
  217. }
  218. if(in_array($fixedModule1['id'],$authMenuIds)){
  219. $fixedModuleAuth1 = 1 ;
  220. }
  221. if(in_array($fixedModule2['id'],$authMenuIds)){
  222. $fixedModuleAuth2 = 1 ;
  223. }
  224. if(in_array($fixedModule3['id'],$authMenuIds)){
  225. $fixedModuleAuth3 = 1 ;
  226. }
  227. if(in_array($fixedModule4['id'],$authMenuIds)){
  228. $fixedModuleAuth4 = 1 ;
  229. }
  230. $this->assign('fixedModule',$fixedModule);
  231. $this->assign('fixedModule1',$fixedModule1);
  232. $this->assign('fixedModule2',$fixedModule2);
  233. $this->assign('fixedModule3',$fixedModule3);
  234. $this->assign('fixedModule4',$fixedModule4);
  235. $this->assign('fixedModuleAuth',$fixedModuleAuth);
  236. $this->assign('fixedModuleAuth1',$fixedModuleAuth1);
  237. $this->assign('fixedModuleAuth2',$fixedModuleAuth2);
  238. $this->assign('fixedModuleAuth3',$fixedModuleAuth3);
  239. $this->assign('fixedModuleAuth4',$fixedModuleAuth4);
  240. // APP下载二维码
  241. $download = think_encrypt(url('h5/Index/download','',true,true));
  242. $this->assign('download',$download);
  243. // 小程序二维码
  244. $wxcode = Db::name('org')->where('id',$this->orgId)->value('wxqrcode');
  245. $this->assign('wxcode',$wxcode);
  246. // 陪护h5
  247. $phcode = think_encrypt(config('app.ph_url').'?orgId='.$this->orgId);
  248. $this->assign('phcode',$phcode);
  249. // 点餐h5
  250. $shopcode = think_encrypt(config('app.shop_url').'?orgId='.$this->orgId);
  251. $this->assign('shopcode',$shopcode);
  252. // 商城h5
  253. $xshopcode = think_encrypt(config('app.xshop_url').'?orgId='.$this->orgId);
  254. $this->assign('xshopcode',$xshopcode);
  255. return $this->fetch();
  256. }
  257. public function ocount(){
  258. $order = 0;
  259. // 判断用户是否是调度
  260. $level1 = check_is_dispatch($this->userId);
  261. $level2 = check_two_dispatch($this->userId);
  262. $level2onoff = two_dispatch_off($this->orgId);
  263. if(!$level1 && !$level2){
  264. $order = -1;
  265. }else{
  266. // 一级调度
  267. if($level1 || (!$level2onoff && $level2)){
  268. $map[] = ['org_id','=',$this->orgId];
  269. $map[] = ['del','=',0];
  270. $map[] = ['order_mode','=',1];
  271. if($level2onoff){
  272. $map[] = ['is_deal','=',0];
  273. }
  274. if(!is_admin($this->userId)){
  275. $auth = get_dispatch_auth($this->userId);
  276. if($auth){
  277. $map[] = ['work_type_mode', 'in', $auth];
  278. $where[] = ['o.work_type_mode', 'in', $auth];
  279. }else{
  280. $map[] = ['work_type_mode', '=', -1];
  281. $where[] = ['work_type_mode', '=', -1];
  282. }
  283. }
  284. $order = Db::name('orders')->where($map)->count();
  285. //$驳回的订单
  286. $where[] = ['o.del','=',0];
  287. $where[] = ['t.del','=',0];
  288. $bh = Db::name('orders')
  289. ->alias('o')
  290. ->join('todo t','t.order_id=o.id')
  291. ->where('t.todo_mode',4)
  292. ->where('t.org_id',$this->orgId)
  293. ->where('o.order_mode',4)
  294. ->where('o.org_id',$this->orgId)
  295. ->where($where)
  296. ->group('o.id')
  297. ->count();
  298. $order = $order + $bh;
  299. } else if($level2 && $level2onoff) { // 二级调度
  300. $rolesId = Db::name('user_roles')->where('user_id',$this->userId)->value('roles_id');
  301. if(!$rolesId){
  302. $order = 0;
  303. }else{
  304. $map[] = ['b.org_id','=',$this->orgId];
  305. $map[] = ['b.del','=',0];
  306. $map[] = ['b.order_mode','=',1];
  307. $map[] = ['b.is_deal','=',1];
  308. $map[] = ['a.roles_id','=',$rolesId];
  309. if(!is_admin($this->userId)){
  310. $auth = get_dispatch_auth($this->userId);
  311. if($auth){
  312. $map[] = ['b.work_type_mode', 'in', $auth];
  313. }else{
  314. $map[] = ['b.work_type_mode', '=', -1];
  315. }
  316. }
  317. $order = Db::name('dispatch_log')
  318. ->alias('a')
  319. ->join('orders b','b.id = a.order_id')
  320. ->where($map)
  321. ->field('a.*')
  322. ->count();
  323. }
  324. }
  325. $complainCount = Db::name('complain')->where('del',0)->where('org_id',$this->orgId)->where('status',0)->where('order_id',0)->count();
  326. $hiddendangerCount = Db::name('hiddendanger')->where('del',0)->where('org_id',$this->orgId)->where('status',0)->where('order_id',0)->count();
  327. $endCount = $order+$complainCount+$hiddendangerCount;
  328. }
  329. $this->success('成功','',['count'=>$endCount]);
  330. }
  331. public function def(){
  332. $id = 500;
  333. $menus = model('Menu')->getMenuTree($this->rolesId,$this->orgId);
  334. $submenus = [];
  335. foreach ($menus as $k=>$v){
  336. if($v['id'] == $id){
  337. $submenus = $v['child'];
  338. break;
  339. }
  340. }
  341. $lists = [];
  342. foreach ($submenus as $k=>$v){
  343. if(!$v['url']){
  344. // $v['url'] = url('Index/indexsub',['id'=>$v['id'],'t'=>1]);
  345. }
  346. $lists[] = $v;
  347. }
  348. $this->assign('lists',$lists);
  349. // 获取常用模块
  350. $cys = Db::name('user_menu')
  351. ->where('user_id',$this->userId)
  352. ->order('count desc,id asc')
  353. ->select();
  354. $cys = $cys?$cys:[];
  355. $ncys = [];
  356. foreach ($cys as $k=>$v){
  357. foreach ($lists as $kk=>$vv){
  358. if(count($ncys) == 5){
  359. continue;
  360. }
  361. if($vv['id'] == $v['menu_id']){
  362. $v['title'] = $vv['title'];
  363. $v['url'] = $vv['url'];
  364. $v['img'] = $vv['img'];
  365. $v['des'] = $vv['des'];
  366. $ncys[] = $v;
  367. break;
  368. }
  369. }
  370. }
  371. $this->assign('cys',$ncys);
  372. // 自定义模块
  373. $usermenus = Db::name('user_menu_group')->where('user_id',$this->userId)->order('sort asc,id asc')->select();
  374. $usermenus = $usermenus?$usermenus:[];
  375. $groupMenuList = $usermenus;
  376. $allmenus = [];
  377. foreach ($usermenus as $k=>$v){
  378. $menus = [];
  379. if($v['menus']){
  380. $menuids = explode(',',$v['menus']);
  381. $allmenus = array_merge($allmenus,$menuids);
  382. foreach ($lists as $kk=>$vv){
  383. if(in_array($vv['id'],$menuids)){
  384. $menus[] = $vv;
  385. }
  386. }
  387. }
  388. $usermenus[$k]['menus'] = $menus;
  389. }
  390. $menus = [];
  391. foreach ($lists as $kk=>$vv){
  392. if(!$allmenus || !in_array($vv['id'],$allmenus)){
  393. $menus[] = $vv;
  394. }
  395. }
  396. $usermenus[] = [
  397. 'id' => 0,
  398. 'title' => '综合模块',
  399. 'menus' => $menus
  400. ];
  401. $arr[] = [
  402. 'id'=>0,
  403. 'title'=>'综合模块',
  404. ];
  405. $this->assign('usermenusgroup',array_merge($arr,$groupMenuList));
  406. $this->assign('usermenus',$usermenus);
  407. $menuInfo = Db::name('menu')->where('id',$id)->find();
  408. $menuTitle = $menuInfo['title'];
  409. $menuTitle1 = $menuTitle2 = '';
  410. // if($menuInfo){
  411. // $menuInfo1 = Db::name('menu')->where('pid',$menuInfo['id'])->find();
  412. // if($menuInfo1){
  413. // $menuTitle1 = $menuInfo1['title'];
  414. // $menuInfo2 = Db::name('menu')->where('pid',$menuInfo1['id'])->find();
  415. // if($menuInfo2){
  416. // $menuTitle2 = $menuInfo2['title'];
  417. // }
  418. // }
  419. // }
  420. $this->assign('menuTitle',$menuTitle);
  421. $this->assign('menuTitle1',$menuTitle1);
  422. $this->assign('menuTitle2',$menuTitle2);
  423. return $this->fetch();
  424. }
  425. public function todo(){
  426. $mode = input('mode',1);
  427. $todoList = Db::name('todo')
  428. ->where('org_id',$this->orgId)
  429. ->where('del',0)
  430. ->where('work_type_mode',$mode)
  431. ->limit(11)
  432. ->order('id desc')
  433. ->select();
  434. foreach ($todoList as $k=>$v){
  435. $todoList[$k]['work_type_mode_text'] = Db::name('work_type_mode')->where('id',$v['work_type_mode'])->value('name');
  436. $todoList[$k]['to_user_name'] = Db::name('user')->where('id',$v['to_user_id'])->value('real_name');
  437. $todoList[$k]['user_name'] = Db::name('user')->where('id',$v['create_user_id'])->value('real_name');
  438. $todoList[$k]['content'] = Db::name('orders')->where('id',$v['order_id'])->value('content');
  439. $todomode = Db::name('todo_mode')->where('id',$v['todo_mode'])->find();
  440. $todoList[$k]['todo_mode_text'] = $todomode?$todomode['in_content']:'';
  441. $todoList[$k]['todo_mode_color'] = $todomode?$todomode['color']:'';
  442. }
  443. //数据返回
  444. $totalCount = count($todoList);
  445. $totalPage = 1;
  446. $result['page'] = 1;
  447. $result['total'] = $totalPage;
  448. $result['records'] = $totalCount;
  449. $result['rows'] = $todoList;
  450. return json($result);
  451. }
  452. public function attendanceCount1(){
  453. $group = Db::name('attendance_group')
  454. ->where('del',0)
  455. ->where('org_id',$this->orgId)
  456. ->select();
  457. $groupsId = [];
  458. $groupsId2 = [];
  459. $week = date('w');
  460. foreach ($group as $k=>$v){
  461. $content = json_decode($v['content'],true);
  462. if($v['type'] == 1){
  463. foreach ($content['week'] as $kk=>$vv){
  464. if($vv['week'] == $week && $vv['class_id'] > 0){
  465. $groupsId[] = $v['id'];
  466. }
  467. }
  468. }
  469. if($v['type'] == 2){
  470. $groupClass = Db::name('attendance_group_class')
  471. ->where('group_id',$v['id'])
  472. ->where('org_id',$this->orgId)
  473. ->where('day',date('Y-m-d'))
  474. ->find();
  475. if($groupClass){
  476. $groupsId2[] = $v['id'];
  477. }
  478. }
  479. }
  480. $endGroupIds = array_unique(array_merge($groupsId,$groupsId2));
  481. $userCount = Db::name('attendance_group_user')
  482. ->where('org_id',$this->orgId)
  483. ->whereIn('group_id',$endGroupIds)
  484. ->count();
  485. $userIds = Db::name('attendance_group_user')
  486. ->where('org_id',$this->orgId)
  487. ->whereIn('group_id',$endGroupIds)
  488. ->column('user_id');
  489. $attendanceNums = 0;
  490. foreach ($userIds as $k=>$v){
  491. $attendanceRecord = Db::name('attendance_record')
  492. ->where('user_id',$v)
  493. ->where('org_id',$this->orgId)
  494. // ->where('status',1)
  495. ->where('create_time','>=',date('Y-m-d').' 00:00:00')
  496. ->where('create_time','<=',date('Y-m-d').' 23:59:59')
  497. ->select();
  498. $flag = 0;
  499. if($attendanceRecord){
  500. foreach ($attendanceRecord as $kk=>$vv){
  501. if($vv['status'] == 1){
  502. }else{
  503. $flag = 1;
  504. }
  505. }
  506. if($flag == 0){
  507. $attendanceNums +=1;
  508. }
  509. }
  510. }
  511. $attendanceNums3 = $userCount-$attendanceNums;
  512. $attendanceCount1 = [
  513. 'count1' => $userCount, //总人数
  514. 'count2' => $attendanceNums, //在职人数
  515. 'count3' => $attendanceNums3>0?$attendanceNums3:0, //缺勤人数
  516. 'bl' => $userCount>0?round($attendanceNums/$userCount,2)*100:0,
  517. 'bl2' => $userCount>0?round($attendanceNums3/$userCount,2)*100:0,
  518. ];
  519. $this->success('','',$attendanceCount1);
  520. }
  521. public function changeOrg(){
  522. if(request()->isAjax()){
  523. $id = input('id/d');
  524. $info = Db::name('org')->where('id',$id)->find();
  525. if($info['type'] != 2){
  526. $this->error('管理机构不能切换');
  527. }
  528. session('orgId',$info['id']);
  529. session('orgName',$info['name']);
  530. $this->success('切换成功');
  531. }else{
  532. $tree = model('Org')->getTreeByRoles($this->rolesId,$this->userId);
  533. $this->assign('tree',$tree);
  534. return $this->fetch();
  535. }
  536. }
  537. public function order(){
  538. // 判断用户是否是调度
  539. $level1 = check_is_dispatch($this->userId);
  540. $level2 = check_two_dispatch($this->userId);
  541. $level2onoff = two_dispatch_off($this->orgId);
  542. if(!$level1 && !$level2){
  543. $this->error('不是调度');
  544. }
  545. $order = 0;
  546. // 一级调度
  547. if($level1 || (!$level2onoff && $level2)){
  548. $map[] = ['org_id','=',$this->orgId];
  549. $map[] = ['del','=',0];
  550. $map[] = ['order_mode','=',1];
  551. if($level2onoff){
  552. $map[] = ['is_deal','=',0];
  553. }
  554. if(!is_admin($this->userId)){
  555. $auth = get_dispatch_auth($this->userId);
  556. if($auth){
  557. $map[] = ['work_type_mode', 'in', $auth];
  558. $where[] = ['o.work_type_mode', 'in', $auth];
  559. }else{
  560. $map[] = ['work_type_mode', '=', -1];
  561. $where[] = ['o.work_type_mode', '=', -1];
  562. }
  563. }
  564. $order = Db::name('orders')->where($map)->count();
  565. //$驳回的订单
  566. $where[] = ['o.del','=',0];
  567. $where[] = ['t.del','=',0];
  568. $bh = Db::name('orders')
  569. ->alias('o')
  570. ->join('todo t','t.order_id=o.id')
  571. ->where('t.todo_mode',4)
  572. ->where('t.org_id',$this->orgId)
  573. ->where('o.order_mode',4)
  574. ->where('o.org_id',$this->orgId)
  575. ->where($where)
  576. ->group('o.id')
  577. ->count();
  578. $order = $order + $bh;
  579. } else if($level2 && $level2onoff) { // 二级调度
  580. $rolesId = Db::name('user_roles')->where('user_id',$this->userId)->value('roles_id');
  581. if(!$rolesId){
  582. $this->error('无订单');
  583. }
  584. $map[] = ['b.org_id','=',$this->orgId];
  585. $map[] = ['b.del','=',0];
  586. $map[] = ['b.order_mode','=',1];
  587. $map[] = ['b.is_deal','=',1];
  588. $map[] = ['a.roles_id','=',$rolesId];
  589. if(!is_admin($this->userId)){
  590. $auth = get_dispatch_auth($this->userId);
  591. if($auth){
  592. $map[] = ['b.work_type_mode', 'in', $auth];
  593. }else{
  594. $map[] = ['b.work_type_mode', '=', -1];
  595. }
  596. }
  597. $order = Db::name('dispatch_log')
  598. ->alias('a')
  599. ->join('orders b','b.id = a.order_id')
  600. ->where($map)
  601. ->field('a.*')
  602. ->count();
  603. }
  604. $complainCount = Db::name('complain')->where('del',0)->where('org_id',$this->orgId)->where('status',0)->where('order_id',0)->count();
  605. $hiddendangerCount = Db::name('hiddendanger')->where('del',0)->where('org_id',$this->orgId)->where('status',0)->where('order_id',0)->count();
  606. $endCount = $order+$complainCount+$hiddendangerCount;
  607. if(!empty($endCount)){
  608. $this->success('','',$endCount);
  609. }else{
  610. $this->error('无订单');
  611. }
  612. }
  613. public function ordersList() {
  614. $orderType = input('orderType',1);
  615. $mode = input('mode', 0);
  616. $level1 = check_is_dispatch($this->userId);
  617. $level2 = check_two_dispatch($this->userId);
  618. $turnoff = two_dispatch_off($this->orgId);
  619. if (request()->isAjax()) {
  620. //分页参数
  621. $length = input('rows', 10, 'intval'); //每页条数
  622. $page = input('page', 1, 'intval'); //第几页
  623. $start = ($page - 1) * $length; //分页开始位置
  624. //排序
  625. $sortRow = input('sidx', 'id', 'trim'); //排序列
  626. $sort = input('sord', 'desc', 'trim'); //排序方式
  627. $order = $sortRow . ' ' . $sort;
  628. if($orderType == 1){
  629. $content = input('content', '', 'trim');
  630. if ($content) {
  631. $map[] = ['content', 'like', '%' . $content . '%'];
  632. }
  633. $dep_id = input('dep_id', '', 'trim');
  634. if ($dep_id != '') {
  635. $map[] = ['dep_id', '=', $dep_id];
  636. }
  637. $order_mode = input('order_mode', 1);
  638. $map6 = [];
  639. if ($order_mode != '') {
  640. if($level1 && $turnoff && $mode != 15){ // 一级调度且二级调度开关开着,品质整改例外
  641. if ($order_mode == 1) {
  642. $map[] = ['is_deal', '=', 0];
  643. }else if ($order_mode == 4) {
  644. $map6[] = ['is_deal', '=', 1];
  645. }
  646. }
  647. if($order_mode==100){//已挂起
  648. $gq = Db::name('todo')
  649. ->where('work_type_mode',1)
  650. ->where('todo_mode',2)
  651. ->where('pause',1)
  652. ->column('order_id');
  653. if(empty($gq)){
  654. $map[] = ['id', '=', -1];
  655. }else{
  656. $map[] = ['id', 'in', $gq];
  657. }
  658. }else{
  659. $map[] = ['order_mode', '=', $order_mode];
  660. }
  661. }
  662. $b = input('start', '', 'trim');
  663. $e = input('end', '', 'trim');
  664. if ($b) {
  665. $b = date('Ymd', strtotime($b));
  666. $map[] = ['create_yyyymmdd', '>=', $b];
  667. }
  668. if ($e) {
  669. $e = date('Ymd', strtotime($e));
  670. $map[] = ['create_yyyymmdd', '<=', $e];
  671. }
  672. $map[] = ['del', '=', 0];
  673. $map[] = ['org_id', '=', $this->orgId];
  674. if($mode==-1){
  675. $map[] = ['source_type', '=', 4];
  676. }
  677. $type = input('type', '', 'trim');
  678. $oids = [];
  679. if ($type != '') {
  680. $map1[] = ['parent_id', '=', $type];
  681. $type_id = Db::name('order_type')
  682. ->where($map1)
  683. ->where('org_id', $this->orgId)
  684. ->where('enable', 1)
  685. ->column('id');
  686. if (!empty($type_id)) {
  687. $map3[] = ['type_id', 'in', $type_id];
  688. $ids = Db::name('order_repair')
  689. ->where($map3)
  690. ->column('order_id');
  691. if (!empty($ids)) {
  692. $oids = $ids;
  693. }
  694. else {
  695. $oids = [];
  696. }
  697. }
  698. else {
  699. $oids = [];
  700. }
  701. }
  702. if($level2 && $turnoff){ // 二级调度
  703. $roles_id = Db::name('user_roles')
  704. ->where('user_id', $this->userId)
  705. ->value('roles_id');
  706. $ids = Db::name('dispatch_log')
  707. ->where('roles_id', $roles_id)
  708. ->whereOr('to_user_id', $this->userId)
  709. ->column('order_id');
  710. if (empty($ids)) {
  711. $map[] = ['id', '=', -1];
  712. } else {
  713. if($type != ''){
  714. $oids = array_intersect($oids,$ids);
  715. if($oids){
  716. $map[] = ['id', 'in', $oids];
  717. }else{
  718. $map[] = ['id', '=', -1];
  719. }
  720. }else{
  721. $map[] = ['id', 'in', $ids];
  722. }
  723. }
  724. }else{
  725. if($type != ''){
  726. if($oids){
  727. $map[] = ['id', 'in', $oids];
  728. }else{
  729. $map[] = ['id', '=', 0];
  730. }
  731. }
  732. }
  733. if($mode == 15){ // 品质检查,单独处理
  734. $map[] = ['work_type_mode','=',$mode];
  735. }else{
  736. $work_type_mode = input('work_type_mode','','trim');
  737. if(!is_admin($this->userId)){
  738. $auth = get_dispatch_auth($this->userId);
  739. if($auth){
  740. $map[] = ['work_type_mode', 'in', $auth];
  741. if($mode > 0){
  742. $map[] = ['work_type_mode', '=', $mode];
  743. }else{
  744. if($work_type_mode!=''){
  745. $map[] = ['work_type_mode','=',$work_type_mode];
  746. }
  747. }
  748. }else{
  749. $map[] = ['work_type_mode', '=', -1];
  750. }
  751. }else{
  752. if($mode > 0){
  753. $map[] = ['work_type_mode', '=', $mode];
  754. }else{
  755. if($work_type_mode!=''){
  756. $map[] = ['work_type_mode','=',$work_type_mode];
  757. }
  758. }
  759. }
  760. }
  761. $map = empty($map) ? true : $map;
  762. //数据查询
  763. $lists = db('orders')->where($map)
  764. ->whereOr($map6)
  765. ->limit($start, $length)->order($order)->select();
  766. foreach ($lists as $k => $v) {
  767. $lists[$k] = model('orders')->formatOrder($v);
  768. if ($turnoff && $level1 && $v['order_mode'] == 1 && $v['is_deal'] == 1) {
  769. $lists[$k]['order_mode_text'] = '已派发';
  770. }
  771. $lists[$k]['bh_nums'] = Db::name('todo')->where('order_id',$v['id'])->where('del',0)->where('todo_mode',4)->count();
  772. $gq = Db::name('todo')
  773. ->where('order_id',$v['id'])
  774. ->where('work_type_mode',1)
  775. ->where('todo_mode',2)
  776. ->where('pause',1)
  777. ->find();
  778. $lists[$k]['gq'] = $gq?'存在挂起':'';
  779. }
  780. //数据返回
  781. $totalCount = db('orders')->where($map)->count();
  782. }elseif($orderType == 2){
  783. $map[] = ['del','=',0];
  784. $map[] = ['org_id','=',$this->orgId];
  785. $hour = (new Config())->getConfig('org_complain_hour',$this->orgId);
  786. $hour = $hour>0?$hour:0;
  787. $endTime = date('Y-m-d H:i:s',time() - $hour*60*60);
  788. $type = input('type/d',0);
  789. if($hour > 0 && $type == 1){
  790. $map[] = ['create_time','<',$endTime];
  791. $map[] = ['status','=',0];
  792. }
  793. $from = input('from', '', 'trim');
  794. if ($from!='') {
  795. $map[] = ['from','=',$from];
  796. }
  797. $map[] = ['status','=',0];
  798. $map[] = ['order_id','=',0];
  799. $map= empty($map) ? true: $map;
  800. //数据查询
  801. $lists = db('complain')->where($map)
  802. ->limit($start,$length)->order($order)->select();
  803. foreach ($lists as $k=>$v){
  804. $lists[$k]['depName'] = Db::name('dep')
  805. ->where('id',$v['dep_id'])
  806. ->value('title');
  807. // $lists[$k]['fromName'] = model('Complain')->from[$v['from']];
  808. $lists[$k]['fromName'] = '';
  809. if($v['order_id'] > 0 && $v['bus_type'] != 0){
  810. if($v['to_from']){
  811. $lists[$k]['fromName'] = '一键呼叫';
  812. }else{
  813. $lists[$k]['fromName'] = '隐患';
  814. }
  815. }
  816. $lists[$k]['worktypemode'] = '';
  817. if($v['order_id'] > 0 && in_array($v['bus_type'],[0,1])){
  818. $worktype = Db::name('orders')
  819. ->alias('o')
  820. ->join('work_type_mode w','o.work_type_mode = w.id')
  821. ->where('o.id',$v['order_id'])
  822. ->value('w.name');
  823. $lists[$k]['worktypemode'] = $worktype?$worktype:'';
  824. }
  825. if($v['hide'] == 1){
  826. $lists[$k]['realName'] = '匿名';
  827. }else{
  828. $lists[$k]['realName'] = Db::name('user')
  829. ->where('id',$v['create_user_id'])
  830. ->value('real_name');
  831. }
  832. $orderMode = 0;
  833. if($v['order_id'] > 0){
  834. $orderMode = Db::name('orders')->where('id',$v['order_id'])->value('order_mode');
  835. }
  836. $lists[$k]['statusTxt'] = model('Complain')->formatStatus($v['status'],$v['order_id'],$v['id']);
  837. $lists[$k]['order_mode'] = $orderMode;
  838. if($v['create_time'] < $endTime && $v['status']==0){
  839. $lists[$k]['statusTxt'] = $lists[$k]['statusTxt'].'<span style="color:red;">(已超时)</span>';
  840. }
  841. }
  842. //数据返回
  843. $totalCount = db('complain')->where($map)->count();
  844. }elseif ($orderType == 3){
  845. $map[] = ['del','=',0];
  846. $map[] = ['org_id','=',$this->orgId];
  847. $map[] = ['status','=',0];
  848. $map[] = ['order_id','=',0];
  849. $from = input('from', '', 'trim');
  850. if ($from!='') {
  851. $map[] = ['from','=',$from];
  852. }
  853. $map= empty($map) ? true: $map;
  854. //数据查询
  855. $lists = db('hiddendanger')->where($map)
  856. ->limit($start,$length)->order($order)->select();
  857. foreach ($lists as $k=>$v){
  858. $lists[$k]['depName'] = Db::name('dep')
  859. ->where('id',$v['dep_id'])
  860. ->value('title');
  861. // $lists[$k]['fromName'] = model('Hiddendanger')->from[$v['from']];
  862. $lists[$k]['fromName'] = '';
  863. if($v['order_id'] > 0 && $v['bus_type'] != 0){
  864. if($v['to_from']){
  865. $lists[$k]['fromName'] = '一键呼叫';
  866. }else{
  867. $lists[$k]['fromName'] = '投诉';
  868. }
  869. }
  870. $lists[$k]['worktypemode'] = '';
  871. if($v['order_id'] > 0 && in_array($v['bus_type'],[0,1])){
  872. $worktype = Db::name('orders')
  873. ->alias('o')
  874. ->join('work_type_mode w','o.work_type_mode = w.id')
  875. ->where('o.id',$v['order_id'])
  876. ->value('w.name');
  877. $lists[$k]['worktypemode'] = $worktype?$worktype:'';
  878. }
  879. $lists[$k]['realName'] = Db::name('user')
  880. ->where('id',$v['create_user_id'])
  881. ->value('real_name');
  882. // $lists[$k]['statusTxt'] = $v['status']==1?'已处理':"未处理";
  883. $orderMode = 0;
  884. if($v['order_id'] > 0){
  885. $orderMode = Db::name('orders')->where('id',$v['order_id'])->value('order_mode');
  886. }
  887. $lists[$k]['statusTxt'] = model('Hiddendanger')->formatStatus($v['status'],$v['order_id'],$v['id']);
  888. $lists[$k]['order_mode'] = $orderMode;
  889. }
  890. //数据返回
  891. $totalCount = db('hiddendanger')->where($map)->count();
  892. }elseif($orderType == 4){
  893. $order_mode = input('order_mode', 4);
  894. $map6 = [];
  895. if ($order_mode != '') {
  896. if($level1 && $turnoff && $mode != 15){ // 一级调度且二级调度开关开着,品质整改例外
  897. if ($order_mode == 1) {
  898. $map[] = ['is_deal', '=', 0];
  899. }else if ($order_mode == 4) {
  900. $map6[] = ['is_deal', '=', 1];
  901. }
  902. }
  903. if($order_mode==100){//已挂起
  904. $gq = Db::name('todo')
  905. ->where('work_type_mode',1)
  906. ->where('todo_mode',2)
  907. ->where('pause',1)
  908. ->column('order_id');
  909. if(empty($gq)){
  910. $map[] = ['id', '=', -1];
  911. }else{
  912. $map[] = ['id', 'in', $gq];
  913. }
  914. }else{
  915. $map[] = ['order_mode', '=', $order_mode];
  916. }
  917. }
  918. $map[] = ['del', '=', 0];
  919. $map[] = ['org_id', '=', $this->orgId];
  920. if($mode==-1){
  921. $map[] = ['source_type', '=', 4];
  922. }
  923. $type = input('type', '', 'trim');
  924. $oids = [];
  925. if ($type != '') {
  926. $map1[] = ['parent_id', '=', $type];
  927. $type_id = Db::name('order_type')
  928. ->where($map1)
  929. ->where('org_id', $this->orgId)
  930. ->where('enable', 1)
  931. ->column('id');
  932. if (!empty($type_id)) {
  933. $map3[] = ['type_id', 'in', $type_id];
  934. $ids = Db::name('order_repair')
  935. ->where($map3)
  936. ->column('order_id');
  937. if (!empty($ids)) {
  938. $oids = $ids;
  939. }
  940. else {
  941. $oids = [];
  942. }
  943. }
  944. else {
  945. $oids = [];
  946. }
  947. }
  948. if($level2 && $turnoff){ // 二级调度
  949. $roles_id = Db::name('user_roles')
  950. ->where('user_id', $this->userId)
  951. ->value('roles_id');
  952. $ids = Db::name('dispatch_log')
  953. ->where('roles_id', $roles_id)
  954. ->whereOr('to_user_id', $this->userId)
  955. ->column('order_id');
  956. if (empty($ids)) {
  957. $map[] = ['id', '=', -1];
  958. } else {
  959. if($type != ''){
  960. $oids = array_intersect($oids,$ids);
  961. if($oids){
  962. $map[] = ['id', 'in', $oids];
  963. }else{
  964. $map[] = ['id', '=', -1];
  965. }
  966. }else{
  967. $map[] = ['id', 'in', $ids];
  968. }
  969. }
  970. }else{
  971. if($type != ''){
  972. if($oids){
  973. $map[] = ['id', 'in', $oids];
  974. }else{
  975. $map[] = ['id', '=', 0];
  976. }
  977. }
  978. }
  979. if($mode == 15){ // 品质检查,单独处理
  980. $map[] = ['work_type_mode','=',$mode];
  981. }else{
  982. $work_type_mode = input('work_type_mode','','trim');
  983. if(!is_admin($this->userId)){
  984. $auth = get_dispatch_auth($this->userId);
  985. if($auth){
  986. $map[] = ['work_type_mode', 'in', $auth];
  987. if($mode > 0){
  988. $map[] = ['work_type_mode', '=', $mode];
  989. }else{
  990. if($work_type_mode!=''){
  991. $map[] = ['work_type_mode','=',$work_type_mode];
  992. }
  993. }
  994. }else{
  995. $map[] = ['work_type_mode', '=', -1];
  996. }
  997. }else{
  998. if($mode > 0){
  999. $map[] = ['work_type_mode', '=', $mode];
  1000. }else{
  1001. if($work_type_mode!=''){
  1002. $map[] = ['work_type_mode','=',$work_type_mode];
  1003. }
  1004. }
  1005. }
  1006. }
  1007. $orderIds = Db::name('todo')
  1008. ->where('todo_mode',4)
  1009. ->where('org_id',$this->orgId)
  1010. ->where('del',0)
  1011. ->group('order_id')
  1012. ->column('order_id');
  1013. $map[] = ['id','in',$orderIds];
  1014. $map = empty($map) ? true : $map;
  1015. //数据查询
  1016. $lists = db('orders')
  1017. ->where($map)
  1018. // ->whereOr($map6)
  1019. ->limit($start, $length)
  1020. ->order($order)
  1021. ->select();
  1022. foreach ($lists as $k => $v) {
  1023. $lists[$k] = model('orders')->formatOrder($v);
  1024. if ($turnoff && $level1 && $v['order_mode'] == 1 && $v['is_deal'] == 1) {
  1025. $lists[$k]['order_mode_text'] = '已派发';
  1026. }
  1027. $lists[$k]['bh_nums'] = Db::name('todo')->where('order_id',$v['id'])->where('del',0)->where('todo_mode',4)->count();
  1028. $gq = Db::name('todo')
  1029. ->where('order_id',$v['id'])
  1030. ->where('work_type_mode',1)
  1031. ->where('todo_mode',2)
  1032. ->where('pause',1)
  1033. ->find();
  1034. $lists[$k]['gq'] = $gq?'存在挂起':'';
  1035. }
  1036. //数据返回
  1037. $totalCount = db('orders')->where($map)->count();
  1038. }
  1039. $totalPage = ceil($totalCount / $length);
  1040. $result['page'] = $page;
  1041. $result['total'] = $totalPage;
  1042. $result['records'] = $totalCount;
  1043. $result['rows'] = $lists;
  1044. return json($result);
  1045. }
  1046. else {
  1047. if($mode >0){
  1048. $mode_name = $this->getTableField('work_type_mode', ['id' => $mode], 'name');
  1049. }else{
  1050. $mode_name = '';
  1051. }
  1052. $auths = [1,2,3,4,15,0];
  1053. if(!is_admin($this->userId)){
  1054. $auth = get_dispatch_auth($this->userId);
  1055. if($auth){
  1056. $auths = array_intersect($auths,$auth);
  1057. if($mode > 0){
  1058. $auths = array_intersect($auths,[$mode]);
  1059. }
  1060. }else{
  1061. $auths = [];
  1062. }
  1063. }
  1064. $this->assign('auths',$auths);
  1065. $dep_list = (new \app\common\model\Dep())->getList();
  1066. $order_type = (new \app\common\model\OrderType())->list();
  1067. $order_mode = Db::name('order_mode')
  1068. ->select();
  1069. $this->assign('dep_list', $dep_list);
  1070. $this->assign('order_type_list', $order_type);
  1071. $this->assign('m_name', $mode_name);
  1072. $this->assign('mode', $mode);
  1073. $this->assign('order_mode_list', $order_mode);
  1074. $this->assign('dispatch_type', check_two_dispatch($this->userId));
  1075. $this->assign('orderType',$orderType);
  1076. return $this->fetch('index/orders');
  1077. }
  1078. }
  1079. //调度查看订单详情
  1080. public function ordersDetail2($id) {
  1081. if (!$id) {
  1082. $this->error('参数错误');
  1083. }
  1084. $type = input('type/d',0);
  1085. $this->assign('type', $type);
  1086. $order = Db::name('orders')->where(['id' => $id])->find();
  1087. $order = model('Orders')->formatOrder($order, 1);
  1088. $order['images'] = !empty($order['images']) ? explode(',', $order['images']) : '';
  1089. $this->assign('info', $order);
  1090. $workTypeName = $this->getTableField('work_type_mode', ['id' => $order['work_type_mode']], 'name');
  1091. $this->assign('meta_title', $workTypeName . '订单详情');
  1092. $level2 = check_two_dispatch($this->userId);
  1093. $level1 = check_is_dispatch($this->userId);
  1094. $turnoff = two_dispatch_off($this->orgId);
  1095. $this->assign('level1', $level1);
  1096. $this->assign('level2', $level2);
  1097. $this->assign('turnoff', $turnoff);
  1098. $this->assign('dispatch_type', $level2);
  1099. return $this->fetch();
  1100. }
  1101. public function searchMenu(){
  1102. $menuName = input('menu_name');
  1103. if($menuName){
  1104. $map[] = ['title','like','%'.$menuName.'%'];
  1105. }
  1106. $map[] = ['del','=',0];
  1107. $map[] = ['enable','=',1];
  1108. $map[] = ['pid','=',500];
  1109. $list = Db::name('menu')->where($map)->select();
  1110. foreach ($list as $k=>$v){
  1111. $list[$k]['url'] = url('index/indexsub1',['curmenu'=>500,'menuId'=>$v['id'],'ct'=>1]);
  1112. }
  1113. $this->success('','',$list);
  1114. }
  1115. public function indexsub(){
  1116. $curmenu = input('curmenu',500);
  1117. $menuId = input('menuId',0);
  1118. $this->assign('curmenu',$curmenu);
  1119. $this->assign('menuId',$menuId);
  1120. $curmenuId = input('curmenuId',0);
  1121. $this->assign('curmenuId',$curmenuId);
  1122. $menuInfo = Db::name('menu')->where('id',$curmenu)->find();
  1123. $menuTitle = $menuInfo['title'];
  1124. $menuTitle1 = $menuTitle2 = '';
  1125. if($curmenu != 500){
  1126. $menuInfo1 = Db::name('menu')->where('pid',$menuInfo['id'])->find();
  1127. if($menuInfo1){
  1128. $menuTitle1 = $menuInfo1['title'];
  1129. $menuInfo2 = Db::name('menu')->where('pid',$menuInfo1['id'])->where('del',0)->where('enable',1)->where('is_btn',0)->order(['sort'=>'asc','id'=>'asc'])->find();
  1130. if($menuInfo2){
  1131. $menuTitle2 = $menuInfo2['title'];
  1132. }
  1133. }
  1134. if($menuId > 0){
  1135. $menuInfo1 = Db::name('menu')->where('id',$menuId)->find();
  1136. if($menuInfo1){
  1137. $menuTitle1 = $menuInfo1['title'];
  1138. $menuInfo2 = Db::name('menu')->where('pid',$menuInfo1['id'])->where('is_btn',0)->where('del',0)->where('enable',1)->order(['sort'=>'asc','id'=>'asc'])->find();
  1139. if($menuInfo2){
  1140. $menuTitle2 = $menuInfo2['title'];
  1141. }
  1142. }
  1143. }
  1144. }
  1145. $this->assign('menuTitle',$menuTitle);
  1146. $this->assign('menuTitle1',$menuTitle1);
  1147. $this->assign('menuTitle2',$menuTitle2);
  1148. $menus = model('Menu')->getMenuTree($this->rolesId,$this->orgId);
  1149. $this->assign('menus',$menus);
  1150. $userInfo = Db::name('user')
  1151. ->where('id',$this->userId)
  1152. ->find();
  1153. $this->assign('userInfo',$userInfo);
  1154. // 判断用户是否是调度
  1155. $isDispatch = 0;
  1156. if(check_is_dispatch($this->userId) || check_two_dispatch($this->userId)){
  1157. $isDispatch = 1;
  1158. }
  1159. $this->assign('isDispatch',$isDispatch);
  1160. $order = 0;
  1161. // 判断用户是否是调度
  1162. $level1 = check_is_dispatch($this->userId);
  1163. $level2 = check_two_dispatch($this->userId);
  1164. $level2onoff = two_dispatch_off($this->orgId);
  1165. if(!$level1 && !$level2){
  1166. $order = -1;
  1167. }else{
  1168. // 一级调度
  1169. if($level1 || (!$level2onoff && $level2)){
  1170. $map[] = ['org_id','=',$this->orgId];
  1171. $map[] = ['del','=',0];
  1172. $map[] = ['order_mode','=',1];
  1173. if($level2onoff){
  1174. $map[] = ['is_deal','=',0];
  1175. }
  1176. if(!is_admin($this->userId)){
  1177. $auth = get_dispatch_auth($this->userId);
  1178. if($auth){
  1179. $map[] = ['work_type_mode', 'in', $auth];
  1180. $where[] = ['o.work_type_mode', 'in', $auth];
  1181. }else{
  1182. $map[] = ['work_type_mode', '=', -1];
  1183. $where[] = ['o.work_type_mode', '=', -1];
  1184. }
  1185. }
  1186. $order = Db::name('orders')->where($map)->count();
  1187. //$驳回的订单
  1188. $where[] = ['o.del','=',0];
  1189. $where[] = ['t.del','=',0];
  1190. $bh = Db::name('orders')
  1191. ->alias('o')
  1192. ->join('todo t','t.order_id=o.id')
  1193. ->where('t.todo_mode',4)
  1194. ->where('t.org_id',$this->orgId)
  1195. ->where('o.order_mode',4)
  1196. ->where('o.org_id',$this->orgId)
  1197. ->where($where)
  1198. ->group('o.id')
  1199. ->count();
  1200. $order = $order + $bh;
  1201. } else if($level2 && $level2onoff) { // 二级调度
  1202. $rolesId = Db::name('user_roles')->where('user_id',$this->userId)->value('roles_id');
  1203. if(!$rolesId){
  1204. $order = 0;
  1205. }else{
  1206. $map[] = ['b.org_id','=',$this->orgId];
  1207. $map[] = ['b.del','=',0];
  1208. $map[] = ['b.order_mode','=',1];
  1209. $map[] = ['b.is_deal','=',1];
  1210. $map[] = ['a.roles_id','=',$rolesId];
  1211. if(!is_admin($this->userId)){
  1212. $auth = get_dispatch_auth($this->userId);
  1213. if($auth){
  1214. $map[] = ['b.work_type_mode', 'in', $auth];
  1215. }else{
  1216. $map[] = ['b.work_type_mode', '=', -1];
  1217. }
  1218. }
  1219. $order = Db::name('dispatch_log')
  1220. ->alias('a')
  1221. ->join('orders b','b.id = a.order_id')
  1222. ->where($map)
  1223. ->field('a.*')
  1224. ->count();
  1225. }
  1226. }
  1227. }
  1228. $complainCount = Db::name('complain')->where('del',0)->where('org_id',$this->orgId)->where('status',0)->where('order_id',0)->count();
  1229. $hiddendangerCount = Db::name('hiddendanger')->where('del',0)->where('org_id',$this->orgId)->where('status',0)->where('order_id',0)->count();
  1230. $endCount = $order+$complainCount+$hiddendangerCount;
  1231. $this->assign('orderNums',$endCount);
  1232. return $this->fetch();
  1233. }
  1234. public function indexsub1(){
  1235. $curmenu = input('curmenu',500);
  1236. $menuId = input('menuId',0);
  1237. $ct = input('ct',0);
  1238. $this->assign('curmenu',$curmenu);
  1239. $this->assign('menuId',$menuId);
  1240. $this->assign('ct',$ct);
  1241. $menus = model('Menu')->getMenuTree($this->rolesId,$this->orgId);
  1242. $this->assign('menus',$menus);
  1243. $userInfo = Db::name('user')
  1244. ->where('id',$this->userId)
  1245. ->find();
  1246. $this->assign('userInfo',$userInfo);
  1247. $menuInfo = Db::name('menu')->where('id',$curmenu)->find();
  1248. $menuTitle = $menuInfo['title'];
  1249. $menuTitle1 = $menuTitle2 = '';
  1250. if($curmenu == 500){
  1251. $menuInfo1 = Db::name('menu')->where('id',$menuId)->find();
  1252. if($menuInfo1){
  1253. $menuTitle1 = $menuInfo1['title'];
  1254. $menuInfo2 = Db::name('menu')->where('pid',$menuInfo1['id'])->where('del',0)->where('enable',1)->where('is_btn',0)->order(['sort'=>'asc','id'=>'asc'])->find();
  1255. if($menuInfo2){
  1256. $menuTitle2 = $menuInfo2['title'];
  1257. }
  1258. }
  1259. }
  1260. $this->assign('menuTitle',$menuTitle);
  1261. $this->assign('menuTitle1',$menuTitle1);
  1262. $this->assign('menuTitle2',$menuTitle2);
  1263. // 判断用户是否是调度
  1264. $isDispatch = 0;
  1265. if(check_is_dispatch($this->userId) || check_two_dispatch($this->userId)){
  1266. $isDispatch = 1;
  1267. }
  1268. $this->assign('isDispatch',$isDispatch);
  1269. $order = 0;
  1270. // 判断用户是否是调度
  1271. $level1 = check_is_dispatch($this->userId);
  1272. $level2 = check_two_dispatch($this->userId);
  1273. $level2onoff = two_dispatch_off($this->orgId);
  1274. if(!$level1 && !$level2){
  1275. $order = -1;
  1276. }else{
  1277. // 一级调度
  1278. if($level1 || (!$level2onoff && $level2)){
  1279. $map[] = ['org_id','=',$this->orgId];
  1280. $map[] = ['del','=',0];
  1281. $map[] = ['order_mode','=',1];
  1282. if($level2onoff){
  1283. $map[] = ['is_deal','=',0];
  1284. }
  1285. if(!is_admin($this->userId)){
  1286. $auth = get_dispatch_auth($this->userId);
  1287. if($auth){
  1288. $map[] = ['work_type_mode', 'in', $auth];
  1289. $where[] = ['o.work_type_mode', 'in', $auth];
  1290. }else{
  1291. $map[] = ['work_type_mode', '=', -1];
  1292. $where[] = ['o.work_type_mode', '=', -1];
  1293. }
  1294. }
  1295. $order = Db::name('orders')->where($map)->count();
  1296. //$驳回的订单
  1297. $where[] = ['o.del','=',0];
  1298. $where[] = ['t.del','=',0];
  1299. $bh = Db::name('orders')
  1300. ->alias('o')
  1301. ->join('todo t','t.order_id=o.id')
  1302. ->where('t.todo_mode',4)
  1303. ->where('t.org_id',$this->orgId)
  1304. ->where('o.order_mode',4)
  1305. ->where('o.org_id',$this->orgId)
  1306. ->where($where)
  1307. ->group('o.id')
  1308. ->count();
  1309. $order = $order + $bh;
  1310. } else if($level2 && $level2onoff) { // 二级调度
  1311. $rolesId = Db::name('user_roles')->where('user_id',$this->userId)->value('roles_id');
  1312. if(!$rolesId){
  1313. $order = 0;
  1314. }else{
  1315. $map[] = ['b.org_id','=',$this->orgId];
  1316. $map[] = ['b.del','=',0];
  1317. $map[] = ['b.order_mode','=',1];
  1318. $map[] = ['b.is_deal','=',1];
  1319. $map[] = ['a.roles_id','=',$rolesId];
  1320. if(!is_admin($this->userId)){
  1321. $auth = get_dispatch_auth($this->userId);
  1322. if($auth){
  1323. $map[] = ['b.work_type_mode', 'in', $auth];
  1324. }else{
  1325. $map[] = ['b.work_type_mode', '=', -1];
  1326. }
  1327. }
  1328. $order = Db::name('dispatch_log')
  1329. ->alias('a')
  1330. ->join('orders b','b.id = a.order_id')
  1331. ->where($map)
  1332. ->field('a.*')
  1333. ->count();
  1334. }
  1335. }
  1336. }
  1337. $complainCount = Db::name('complain')->where('del',0)->where('org_id',$this->orgId)->where('status',0)->where('order_id',0)->count();
  1338. $hiddendangerCount = Db::name('hiddendanger')->where('del',0)->where('org_id',$this->orgId)->where('status',0)->where('order_id',0)->count();
  1339. $endCount = $order+$complainCount+$hiddendangerCount;
  1340. $this->assign('orderNums',$endCount);
  1341. $id = 500;
  1342. $menus = model('Menu')->getMenuTree($this->rolesId,$this->orgId);
  1343. $submenus = [];
  1344. foreach ($menus as $k=>$v){
  1345. if($v['id'] == $id){
  1346. $submenus = $v['child'];
  1347. break;
  1348. }
  1349. }
  1350. $this->assign('submenus',$submenus);
  1351. return $this->fetch();
  1352. }
  1353. public function menugroup($id = 0){
  1354. if(request()->isPost()){
  1355. $res = model('UserMenuGroup')->updates($this->userId);
  1356. if($res){
  1357. $this->success('操作成功');
  1358. }else{
  1359. $this->error(model('UserMenuGroup')->getError());
  1360. }
  1361. }else{
  1362. if($id){
  1363. $info = db('user_menu_group')->where('id',$id)->find();
  1364. if($info){
  1365. $info['menus'] = $info['menus']?explode(',',$info['menus']):[];
  1366. }
  1367. $this->assign('info',$info);
  1368. }
  1369. $id = 500;
  1370. $menus = model('Menu')->getMenuTree($this->rolesId,$this->orgId);
  1371. $submenus = [];
  1372. foreach ($menus as $k=>$v){
  1373. if($v['id'] == $id){
  1374. $submenus = $v['child'];
  1375. break;
  1376. }
  1377. }
  1378. $this->assign('submenus',$submenus);
  1379. return $this->fetch();
  1380. }
  1381. }
  1382. public function menugroupdel(){
  1383. $id = input('id',0);
  1384. $ret = Db::name('user_menu_group')->where('id',$id)->where('user_id',$this->userId)->delete();
  1385. if($ret){
  1386. $this->success('操作成功');
  1387. }else{
  1388. $this->error('操作失败');
  1389. }
  1390. }
  1391. public function def2(){
  1392. $curmenu = input('curmenu',500);
  1393. $this->assign('curmenu',$curmenu);
  1394. $menuId = input('menuId',0);
  1395. $this->assign('menuId',$menuId);
  1396. $menuInfo = Db::name('menu')->where('id',$curmenu)->find();
  1397. $menuTitle = $menuInfo['title'];
  1398. $menuTitle1 = $menuTitle2 = '';
  1399. if($curmenu == 500){
  1400. $menuInfo1 = Db::name('menu')->where('pid',$menuInfo['id'])->find();
  1401. if($menuInfo1){
  1402. $menuTitle1 = $menuInfo1['title'];
  1403. $menuInfo2 = Db::name('menu')->where('pid',$menuInfo1['id'])->where('is_btn',0)->order(['sort'=>'asc','id'=>'asc'])->find();
  1404. if($menuInfo2){
  1405. $menuTitle2 = $menuInfo2['title'];
  1406. }
  1407. }
  1408. if($menuId > 0){
  1409. $menuInfo1 = Db::name('menu')->where('id',$menuId)->find();
  1410. if($menuInfo1){
  1411. $menuTitle1 = $menuInfo1['title'];
  1412. $menuInfo2 = Db::name('menu')->where('pid',$menuInfo1['id'])->where('is_btn',0)->where('del',0)->where('enable',1)->order(['sort'=>'asc','id'=>'asc'])->find();
  1413. if($menuInfo2){
  1414. $menuTitle2 = $menuInfo2['title'];
  1415. }
  1416. }
  1417. }
  1418. }
  1419. $this->assign('menuTitle',$menuTitle);
  1420. $this->assign('menuTitle1',$menuTitle1);
  1421. $this->assign('menuTitle2',$menuTitle2);
  1422. $menus = model('Menu')->getMenuTree($this->rolesId,$this->orgId);
  1423. $this->assign('menus',$menus);
  1424. $userInfo = Db::name('user')
  1425. ->where('id',$this->userId)
  1426. ->find();
  1427. $this->assign('userInfo',$userInfo);
  1428. // 判断用户是否是调度
  1429. $isDispatch = 0;
  1430. if(check_is_dispatch($this->userId) || check_two_dispatch($this->userId)){
  1431. $isDispatch = 1;
  1432. }
  1433. $this->assign('isDispatch',$isDispatch);
  1434. $order = 0;
  1435. // 判断用户是否是调度
  1436. $level1 = check_is_dispatch($this->userId);
  1437. $level2 = check_two_dispatch($this->userId);
  1438. $level2onoff = two_dispatch_off($this->orgId);
  1439. if(!$level1 && !$level2){
  1440. $order = -1;
  1441. }else{
  1442. // 一级调度
  1443. if($level1 || (!$level2onoff && $level2)){
  1444. $map[] = ['org_id','=',$this->orgId];
  1445. $map[] = ['del','=',0];
  1446. $map[] = ['order_mode','=',1];
  1447. if($level2onoff){
  1448. $map[] = ['is_deal','=',0];
  1449. }
  1450. if(!is_admin($this->userId)){
  1451. $auth = get_dispatch_auth($this->userId);
  1452. if($auth){
  1453. $map[] = ['work_type_mode', 'in', $auth];
  1454. $where[] = ['o.work_type_mode', 'in', $auth];
  1455. }else{
  1456. $map[] = ['work_type_mode', '=', -1];
  1457. $where[] = ['o.work_type_mode', '=', -1];
  1458. }
  1459. }
  1460. $order = Db::name('orders')->where($map)->count();
  1461. //$驳回的订单
  1462. $where[] = ['o.del','=',0];
  1463. $where[] = ['t.del','=',0];
  1464. $bh = Db::name('orders')
  1465. ->alias('o')
  1466. ->join('todo t','t.order_id=o.id')
  1467. ->where('t.todo_mode',4)
  1468. ->where('t.org_id',$this->orgId)
  1469. ->where('o.order_mode',4)
  1470. ->where('o.org_id',$this->orgId)
  1471. ->where($where)
  1472. ->group('o.id')
  1473. ->count();
  1474. $order = $order + $bh;
  1475. } else if($level2 && $level2onoff) { // 二级调度
  1476. $rolesId = Db::name('user_roles')->where('user_id',$this->userId)->value('roles_id');
  1477. if(!$rolesId){
  1478. $order = 0;
  1479. }else{
  1480. $map[] = ['b.org_id','=',$this->orgId];
  1481. $map[] = ['b.del','=',0];
  1482. $map[] = ['b.order_mode','=',1];
  1483. $map[] = ['b.is_deal','=',1];
  1484. $map[] = ['a.roles_id','=',$rolesId];
  1485. if(!is_admin($this->userId)){
  1486. $auth = get_dispatch_auth($this->userId);
  1487. if($auth){
  1488. $map[] = ['b.work_type_mode', 'in', $auth];
  1489. }else{
  1490. $map[] = ['b.work_type_mode', '=', -1];
  1491. }
  1492. }
  1493. $order = Db::name('dispatch_log')
  1494. ->alias('a')
  1495. ->join('orders b','b.id = a.order_id')
  1496. ->where($map)
  1497. ->field('a.*')
  1498. ->count();
  1499. }
  1500. }
  1501. }
  1502. $complainCount = Db::name('complain')->where('del',0)->where('org_id',$this->orgId)->where('status',0)->where('order_id',0)->count();
  1503. $hiddendangerCount = Db::name('hiddendanger')->where('del',0)->where('org_id',$this->orgId)->where('status',0)->where('order_id',0)->count();
  1504. $endCount = $order+$complainCount+$hiddendangerCount;
  1505. $this->assign('orderNums',$endCount);
  1506. return $this->fetch();
  1507. }
  1508. public function umenu(){
  1509. $id = input('id/d',0);
  1510. $info = Db::name('user_menu')->where('menu_id',$id)->where('user_id',$this->userId)->find();
  1511. if($info){
  1512. Db::name('user_menu')->where('id',$info['id'])->setInc('count',1);
  1513. }else{
  1514. Db::name('user_menu')->insert([
  1515. 'user_id' => $this->userId,
  1516. 'menu_id' => $id,
  1517. 'count' => 1
  1518. ]);
  1519. }
  1520. $this->success('操作成功');
  1521. }
  1522. }