Index_copy.php 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195
  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. $menus = model('Menu')->getMenuTree($this->rolesId,$this->orgId);
  9. $this->assign('menus',$menus);
  10. $userInfo = Db::name('user')
  11. ->where('id',$this->userId)
  12. ->find();
  13. $this->assign('userInfo',$userInfo);
  14. // 判断用户是否是调度
  15. $isDispatch = 0;
  16. if(check_is_dispatch($this->userId) || check_two_dispatch($this->userId)){
  17. $isDispatch = 1;
  18. }
  19. $this->assign('isDispatch',$isDispatch);
  20. $order = 0;
  21. // 判断用户是否是调度
  22. $level1 = check_is_dispatch($this->userId);
  23. $level2 = check_two_dispatch($this->userId);
  24. $level2onoff = two_dispatch_off($this->orgId);
  25. if(!$level1 && !$level2){
  26. $order = -1;
  27. }else{
  28. // 一级调度
  29. if($level1 || (!$level2onoff && $level2)){
  30. $map[] = ['org_id','=',$this->orgId];
  31. $map[] = ['del','=',0];
  32. $map[] = ['order_mode','=',1];
  33. if($level2onoff){
  34. $map[] = ['is_deal','=',0];
  35. }
  36. if(!is_admin($this->userId)){
  37. $auth = get_dispatch_auth($this->userId);
  38. if($auth){
  39. $map[] = ['work_type_mode', 'in', $auth];
  40. $where[] = ['o.work_type_mode', 'in', $auth];
  41. }else{
  42. $map[] = ['work_type_mode', '=', -1];
  43. $where[] = ['o.work_type_mode', '=', -1];
  44. }
  45. }
  46. $order = Db::name('orders')->where($map)->count();
  47. //$驳回的订单
  48. $where[] = ['o.del','=',0];
  49. $where[] = ['t.del','=',0];
  50. $bh = Db::name('orders')
  51. ->alias('o')
  52. ->join('todo t','t.order_id=o.id')
  53. ->where('t.todo_mode',4)
  54. ->where('t.org_id',$this->orgId)
  55. ->where('o.order_mode',4)
  56. ->where('o.org_id',$this->orgId)
  57. ->where($where)
  58. ->group('o.id')
  59. ->count();
  60. $order = $order + $bh;
  61. } else if($level2 && $level2onoff) { // 二级调度
  62. $rolesId = Db::name('user_roles')->where('user_id',$this->userId)->value('roles_id');
  63. if(!$rolesId){
  64. $order = 0;
  65. }else{
  66. $map[] = ['b.org_id','=',$this->orgId];
  67. $map[] = ['b.del','=',0];
  68. $map[] = ['b.order_mode','=',1];
  69. $map[] = ['b.is_deal','=',1];
  70. $map[] = ['a.roles_id','=',$rolesId];
  71. if(!is_admin($this->userId)){
  72. $auth = get_dispatch_auth($this->userId);
  73. if($auth){
  74. $map[] = ['b.work_type_mode', 'in', $auth];
  75. }else{
  76. $map[] = ['b.work_type_mode', '=', -1];
  77. }
  78. }
  79. $order = Db::name('dispatch_log')
  80. ->alias('a')
  81. ->join('orders b','b.id = a.order_id')
  82. ->where($map)
  83. ->field('a.*')
  84. ->count();
  85. }
  86. }
  87. }
  88. $complainCount = Db::name('complain')->where('del',0)->where('org_id',$this->orgId)->where('status',0)->where('order_id',0)->count();
  89. $hiddendangerCount = Db::name('hiddendanger')->where('del',0)->where('org_id',$this->orgId)->where('status',0)->where('order_id',0)->count();
  90. $endCount = $order+$complainCount+$hiddendangerCount;
  91. $this->assign('orderNums',$endCount);
  92. return $this->fetch();
  93. }
  94. public function ocount(){
  95. $order = 0;
  96. // 判断用户是否是调度
  97. $level1 = check_is_dispatch($this->userId);
  98. $level2 = check_two_dispatch($this->userId);
  99. $level2onoff = two_dispatch_off($this->orgId);
  100. if(!$level1 && !$level2){
  101. $order = -1;
  102. }else{
  103. // 一级调度
  104. if($level1 || (!$level2onoff && $level2)){
  105. $map[] = ['org_id','=',$this->orgId];
  106. $map[] = ['del','=',0];
  107. $map[] = ['order_mode','=',1];
  108. if($level2onoff){
  109. $map[] = ['is_deal','=',0];
  110. }
  111. if(!is_admin($this->userId)){
  112. $auth = get_dispatch_auth($this->userId);
  113. if($auth){
  114. $map[] = ['work_type_mode', 'in', $auth];
  115. $where[] = ['o.work_type_mode', 'in', $auth];
  116. }else{
  117. $map[] = ['work_type_mode', '=', -1];
  118. $where[] = ['work_type_mode', '=', -1];
  119. }
  120. }
  121. $order = Db::name('orders')->where($map)->count();
  122. //$驳回的订单
  123. $where[] = ['o.del','=',0];
  124. $where[] = ['t.del','=',0];
  125. $bh = Db::name('orders')
  126. ->alias('o')
  127. ->join('todo t','t.order_id=o.id')
  128. ->where('t.todo_mode',4)
  129. ->where('t.org_id',$this->orgId)
  130. ->where('o.order_mode',4)
  131. ->where('o.org_id',$this->orgId)
  132. ->where($where)
  133. ->group('o.id')
  134. ->count();
  135. $order = $order + $bh;
  136. } else if($level2 && $level2onoff) { // 二级调度
  137. $rolesId = Db::name('user_roles')->where('user_id',$this->userId)->value('roles_id');
  138. if(!$rolesId){
  139. $order = 0;
  140. }else{
  141. $map[] = ['b.org_id','=',$this->orgId];
  142. $map[] = ['b.del','=',0];
  143. $map[] = ['b.order_mode','=',1];
  144. $map[] = ['b.is_deal','=',1];
  145. $map[] = ['a.roles_id','=',$rolesId];
  146. if(!is_admin($this->userId)){
  147. $auth = get_dispatch_auth($this->userId);
  148. if($auth){
  149. $map[] = ['b.work_type_mode', 'in', $auth];
  150. }else{
  151. $map[] = ['b.work_type_mode', '=', -1];
  152. }
  153. }
  154. $order = Db::name('dispatch_log')
  155. ->alias('a')
  156. ->join('orders b','b.id = a.order_id')
  157. ->where($map)
  158. ->field('a.*')
  159. ->count();
  160. }
  161. }
  162. $complainCount = Db::name('complain')->where('del',0)->where('org_id',$this->orgId)->where('status',0)->where('order_id',0)->count();
  163. $hiddendangerCount = Db::name('hiddendanger')->where('del',0)->where('org_id',$this->orgId)->where('status',0)->where('order_id',0)->count();
  164. $endCount = $order+$complainCount+$hiddendangerCount;
  165. }
  166. $this->success('成功','',['count'=>$endCount]);
  167. }
  168. public function def(){
  169. // APP下载二维码
  170. $download = think_encrypt(url('h5/Index/download','',true,true));
  171. $this->assign('download',$download);
  172. // 小程序二维码
  173. $wxcode = Db::name('org')->where('id',$this->orgId)->value('wxqrcode');
  174. $this->assign('wxcode',$wxcode);
  175. // 陪护h5
  176. $phcode = think_encrypt(config("app.app_host").config('app.ph_url').'?orgId='.$this->orgId);
  177. $this->assign('phcode',$phcode);
  178. // 点餐h5
  179. $shopcode = think_encrypt(config('app.shop_url').'?orgId='.$this->orgId);
  180. $this->assign('shopcode',$shopcode);
  181. // 商城h5
  182. $xshopcode = think_encrypt(config('app.xshop_url').'?orgId='.$this->orgId);
  183. $this->assign('xshopcode',$xshopcode);
  184. //本月
  185. $month = date('Y-m');
  186. $sMonth = $month.'-1 00:00:00';
  187. $eMonth = $month.'31 23:59:59';
  188. //上月
  189. $tmp_year=substr($month,0,4);
  190. //切割出月份
  191. $tmp_mon =substr($month,5,2);
  192. $tmp_forwardmonth=mktime(0,0,0,$tmp_mon-1,1,$tmp_year);
  193. $lastMonth=date("Y-m",$tmp_forwardmonth);
  194. $sLastMonth = $lastMonth.'-1 00:00:00';
  195. $eLastMonth = $lastMonth.'31 23:59:59';
  196. $userNums = Db::name('user')
  197. ->alias('u')
  198. ->join('user_org uo','uo.user_id=u.id')
  199. ->where('uo.org_id',$this->orgId)
  200. ->where('u.del',0)
  201. ->where('u.enable',1)
  202. ->count();
  203. $monthUserNums = Db::name('user')
  204. ->alias('u')
  205. ->join('user_org uo','uo.user_id=u.id')
  206. ->where('uo.org_id',$this->orgId)
  207. ->where('u.del',0)
  208. ->where('u.enable',1)
  209. ->where('u.create_time','>=',$sMonth)
  210. ->where('u.create_time','<=',$eMonth)
  211. ->count();
  212. $lastMonthUserNums = Db::name('user')
  213. ->alias('u')
  214. ->join('user_org uo','uo.user_id=u.id')
  215. ->where('uo.org_id',$this->orgId)
  216. ->where('u.del',0)
  217. ->where('u.enable',1)
  218. ->where('u.create_time','>=',$sLastMonth)
  219. ->where('u.create_time','<=',$eLastMonth)
  220. ->count();
  221. $userLastNums = $monthUserNums-$lastMonthUserNums;
  222. $userCount = [
  223. 'userNums'=>$userNums,
  224. 'userLastNums'=>$userLastNums,
  225. ];
  226. $this->assign('userCount',$userCount);
  227. $monthOrderNums = Db::name('orders')
  228. ->where('org_id',$this->orgId)
  229. ->where('create_yyyymm',date('Ym'))
  230. ->where('del',0)
  231. ->count();
  232. $lastMonthOrderNums = Db::name('orders')
  233. ->where('org_id',$this->orgId)
  234. ->where('create_yyyymm',date('Ym',strtotime('-1 month')))
  235. ->where('del',0)
  236. ->count();
  237. $orderLastNums = $monthOrderNums -$lastMonthOrderNums;
  238. $orderCount = [
  239. 'orderNums'=>$monthOrderNums,
  240. 'orderLastNums'=>$orderLastNums,
  241. ];
  242. $this->assign('orderCount',$orderCount);
  243. $yearOrderNums = Db::name('orders')
  244. ->where('org_id',$this->orgId)
  245. ->where('create_yyyy',date('Y'))
  246. ->where('del',0)
  247. ->count();
  248. $lastYearOrderNums = Db::name('orders')
  249. ->where('org_id',$this->orgId)
  250. ->where('create_yyyy',date('Y',strtotime('-1 year')))
  251. ->where('del',0)
  252. ->count();
  253. $endYearOrderCount = $yearOrderNums - $lastYearOrderNums;
  254. if($lastYearOrderNums < 1){
  255. $orderLastYearNums = 100;
  256. }else{
  257. $orderLastYearNums = round($endYearOrderCount/$lastYearOrderNums,2)*100;
  258. }
  259. $orderYearCount = [
  260. 'orderYearNums'=>$yearOrderNums,
  261. 'orderLastYearNums'=>$orderLastYearNums,
  262. ];
  263. $this->assign('orderYearCount',$orderYearCount);
  264. $activeUserNums = Db::name('user')
  265. ->alias('u')
  266. ->join('user_org uo','uo.user_id=u.id')
  267. ->where('uo.org_id',$this->orgId)
  268. ->where('u.del',0)
  269. ->where('u.enable',1)
  270. ->where('u.last_login_time','>=',$sMonth)
  271. ->where('u.last_login_time','<=',$eMonth)
  272. ->count();
  273. $lastActiveUserNums = Db::name('user')
  274. ->alias('u')
  275. ->join('user_org uo','uo.user_id=u.id')
  276. ->where('uo.org_id',$this->orgId)
  277. ->where('u.del',0)
  278. ->where('u.enable',1)
  279. ->where('u.last_login_time','>=',$sLastMonth)
  280. ->where('u.last_login_time','<=',$eLastMonth)
  281. ->count();
  282. $activeUserLastNums = $activeUserNums-$lastActiveUserNums;
  283. $activeUserCount = [
  284. 'activeUserNums'=>$activeUserNums,
  285. 'activeUserLastNums'=>$activeUserLastNums,
  286. ];
  287. $this->assign('activeUserCount',$activeUserCount);
  288. $dayOrderNums1 = Db::name('orders')
  289. ->where('org_id',$this->orgId)
  290. ->where('del',0)
  291. ->where('order_mode',1)
  292. ->where('create_time','>=',date('Y-m-d').' 00:00:00')
  293. ->where('create_time','<=',date('Y-m-d').' 23:59:59')
  294. ->count();
  295. $dayOrderNums2 = Db::name('orders')
  296. ->where('org_id',$this->orgId)
  297. ->where('del',0)
  298. ->where('order_mode',4)
  299. ->where('create_time','>=',date('Y-m-d').' 00:00:00')
  300. ->where('create_time','<=',date('Y-m-d').' 23:59:59')
  301. ->count();
  302. $dayOrderNums3 = Db::name('orders')
  303. ->where('org_id',$this->orgId)
  304. ->where('del',0)
  305. ->where('order_mode',5)
  306. ->where('create_time','>=',date('Y-m-d').' 00:00:00')
  307. ->where('create_time','<=',date('Y-m-d').' 23:59:59')
  308. ->count();
  309. $dayOrderNums4 = Db::name('orders')
  310. ->where('org_id',$this->orgId)
  311. ->where('del',0)
  312. ->where('order_mode',6)
  313. ->where('create_time','>=',date('Y-m-d').' 00:00:00')
  314. ->where('create_time','<=',date('Y-m-d').' 23:59:59')
  315. ->count();
  316. $dayOrderNums5 = Db::name('orders')
  317. ->where('org_id',$this->orgId)
  318. ->where('del',0)
  319. ->where('order_mode',2)
  320. ->where('create_time','>=',date('Y-m-d').' 00:00:00')
  321. ->where('create_time','<=',date('Y-m-d').' 23:59:59')
  322. ->count();
  323. $dayOrderNums6 = Db::name('orders')
  324. ->where('org_id',$this->orgId)
  325. ->where('del',0)
  326. ->where('order_mode',3)
  327. ->where('create_time','>=',date('Y-m-d').' 00:00:00')
  328. ->where('create_time','<=',date('Y-m-d').' 23:59:59')
  329. ->count();
  330. $dayOrderCount =[
  331. 'count1'=> $dayOrderNums1,
  332. 'count2'=> $dayOrderNums2,
  333. 'count3'=> $dayOrderNums3,
  334. 'count4'=> $dayOrderNums4,
  335. 'count5'=> $dayOrderNums5,
  336. 'count6'=> $dayOrderNums6,
  337. ];
  338. $this->assign('dayOrderCount',$dayOrderCount);
  339. $mode = input('mode',1);
  340. $todoList = Db::name('todo')
  341. ->where('org_id',$this->orgId)
  342. ->where('del',0)
  343. ->where('work_type_mode',$mode)
  344. ->limit(11)
  345. ->order('id desc')
  346. ->select();
  347. foreach ($todoList as $k=>$v){
  348. $todoList[$k]['user_name'] = Db::name('user')->where('id',$v['to_user_id'])->value('real_name');
  349. $todoList[$k]['create_user_name'] = Db::name('user')->where('id',$v['create_user_id'])->value('real_name');
  350. $todoList[$k]['content'] = Db::name('orders')->where('id',$v['order_id'])->value('content');
  351. }
  352. $this->assign('mode',$mode);
  353. $this->assign('todoList',$todoList);
  354. $group = Db::name('attendance_group')
  355. ->where('del',0)
  356. ->where('org_id',$this->orgId)
  357. ->select();
  358. $groupsId = [];
  359. $groupsId2 = [];
  360. $week = date('w');
  361. foreach ($group as $k=>$v){
  362. $content = json_decode($v['content'],true);
  363. if($v['type'] == 1){
  364. foreach ($content['week'] as $kk=>$vv){
  365. if($vv['week'] == $week && $vv['class_id'] > 0){
  366. $groupsId[] = $v['id'];
  367. }
  368. }
  369. }
  370. if($v['type'] == 2){
  371. $groupClass = Db::name('attendance_group_class')
  372. ->where('group_id',$v['id'])
  373. ->where('org_id',$this->orgId)
  374. ->where('day',date('Y-m-d'))
  375. ->find();
  376. if($groupClass){
  377. $groupsId2[] = $v['id'];
  378. }
  379. }
  380. }
  381. $endGroupIds = array_unique(array_merge($groupsId,$groupsId2));
  382. $userCount = Db::name('attendance_group_user')
  383. ->where('org_id',$this->orgId)
  384. ->whereIn('group_id',$endGroupIds)
  385. ->count();
  386. $userIds = Db::name('attendance_group_user')
  387. ->where('org_id',$this->orgId)
  388. ->whereIn('group_id',$endGroupIds)
  389. ->column('user_id');
  390. $attendanceNums = 0;
  391. foreach ($userIds as $k=>$v){
  392. $attendanceRecord = Db::name('attendance_record')
  393. ->where('user_id',$v)
  394. ->where('org_id',$this->orgId)
  395. // ->where('status',1)
  396. ->where('create_time','>=',date('Y-m-d').' 00:00:00')
  397. ->where('create_time','<=',date('Y-m-d').' 23:59:59')
  398. ->select();
  399. $flag = 0;
  400. if($attendanceRecord){
  401. foreach ($attendanceRecord as $kk=>$vv){
  402. if($vv['status'] == 1){
  403. }else{
  404. $flag = 1;
  405. }
  406. }
  407. if($flag == 0){
  408. $attendanceNums +=1;
  409. }
  410. }
  411. }
  412. $attendanceNums3 = $userCount-$attendanceNums;
  413. $attendanceCount1 = [
  414. 'count1' => $userCount, //总人数
  415. 'count2' => $attendanceNums, //在职人数
  416. 'count3' => $attendanceNums3>0?$attendanceNums3:0, //缺勤人数
  417. 'bl' => $userCount>0?round($attendanceNums/$userCount,2)*100:0,
  418. 'bl2' => $userCount>0?round($attendanceNums3/$userCount,2)*100:0,
  419. ];
  420. $this->assign('attendanceCount1',$attendanceCount1);
  421. return $this->fetch();
  422. }
  423. public function todo(){
  424. $mode = input('mode',1);
  425. $todoList = Db::name('todo')
  426. ->where('org_id',$this->orgId)
  427. ->where('del',0)
  428. ->where('work_type_mode',$mode)
  429. ->limit(11)
  430. ->order('id desc')
  431. ->select();
  432. foreach ($todoList as $k=>$v){
  433. $todoList[$k]['work_type_mode_text'] = Db::name('work_type_mode')->where('id',$v['work_type_mode'])->value('name');
  434. $todoList[$k]['to_user_name'] = Db::name('user')->where('id',$v['to_user_id'])->value('real_name');
  435. $todoList[$k]['user_name'] = Db::name('user')->where('id',$v['create_user_id'])->value('real_name');
  436. $todoList[$k]['content'] = Db::name('orders')->where('id',$v['order_id'])->value('content');
  437. $todomode = Db::name('todo_mode')->where('id',$v['todo_mode'])->find();
  438. $todoList[$k]['todo_mode_text'] = $todomode?$todomode['in_content']:'';
  439. $todoList[$k]['todo_mode_color'] = $todomode?$todomode['color']:'';
  440. }
  441. //数据返回
  442. $totalCount = count($todoList);
  443. $totalPage = 1;
  444. $result['page'] = 1;
  445. $result['total'] = $totalPage;
  446. $result['records'] = $totalCount;
  447. $result['rows'] = $todoList;
  448. return json($result);
  449. }
  450. public function attendanceCount1(){
  451. $group = Db::name('attendance_group')
  452. ->where('del',0)
  453. ->where('org_id',$this->orgId)
  454. ->select();
  455. $groupsId = [];
  456. $groupsId2 = [];
  457. $week = date('w');
  458. foreach ($group as $k=>$v){
  459. $content = json_decode($v['content'],true);
  460. if($v['type'] == 1){
  461. foreach ($content['week'] as $kk=>$vv){
  462. if($vv['week'] == $week && $vv['class_id'] > 0){
  463. $groupsId[] = $v['id'];
  464. }
  465. }
  466. }
  467. if($v['type'] == 2){
  468. $groupClass = Db::name('attendance_group_class')
  469. ->where('group_id',$v['id'])
  470. ->where('org_id',$this->orgId)
  471. ->where('day',date('Y-m-d'))
  472. ->find();
  473. if($groupClass){
  474. $groupsId2[] = $v['id'];
  475. }
  476. }
  477. }
  478. $endGroupIds = array_unique(array_merge($groupsId,$groupsId2));
  479. $userCount = Db::name('attendance_group_user')
  480. ->where('org_id',$this->orgId)
  481. ->whereIn('group_id',$endGroupIds)
  482. ->count();
  483. $userIds = Db::name('attendance_group_user')
  484. ->where('org_id',$this->orgId)
  485. ->whereIn('group_id',$endGroupIds)
  486. ->column('user_id');
  487. $attendanceNums = 0;
  488. foreach ($userIds as $k=>$v){
  489. $attendanceRecord = Db::name('attendance_record')
  490. ->where('user_id',$v)
  491. ->where('org_id',$this->orgId)
  492. // ->where('status',1)
  493. ->where('create_time','>=',date('Y-m-d').' 00:00:00')
  494. ->where('create_time','<=',date('Y-m-d').' 23:59:59')
  495. ->select();
  496. $flag = 0;
  497. if($attendanceRecord){
  498. foreach ($attendanceRecord as $kk=>$vv){
  499. if($vv['status'] == 1){
  500. }else{
  501. $flag = 1;
  502. }
  503. }
  504. if($flag == 0){
  505. $attendanceNums +=1;
  506. }
  507. }
  508. }
  509. $attendanceNums3 = $userCount-$attendanceNums;
  510. $attendanceCount1 = [
  511. 'count1' => $userCount, //总人数
  512. 'count2' => $attendanceNums, //在职人数
  513. 'count3' => $attendanceNums3>0?$attendanceNums3:0, //缺勤人数
  514. 'bl' => $userCount>0?round($attendanceNums/$userCount,2)*100:0,
  515. 'bl2' => $userCount>0?round($attendanceNums3/$userCount,2)*100:0,
  516. ];
  517. $this->success('','',$attendanceCount1);
  518. }
  519. public function changeOrg(){
  520. if(request()->isAjax()){
  521. $id = input('id/d');
  522. $info = Db::name('org')->where('id',$id)->find();
  523. if($info['type'] != 2){
  524. $this->error('管理机构不能切换');
  525. }
  526. session('orgId',$info['id']);
  527. session('orgName',$info['name']);
  528. $this->success('切换成功');
  529. }else{
  530. $tree = model('Org')->getTreeByRoles($this->rolesId,$this->userId);
  531. $this->assign('tree',$tree);
  532. return $this->fetch();
  533. }
  534. }
  535. public function order(){
  536. // 判断用户是否是调度
  537. $level1 = check_is_dispatch($this->userId);
  538. $level2 = check_two_dispatch($this->userId);
  539. $level2onoff = two_dispatch_off($this->orgId);
  540. if(!$level1 && !$level2){
  541. $this->error('不是调度');
  542. }
  543. $order = 0;
  544. // 一级调度
  545. if($level1 || (!$level2onoff && $level2)){
  546. $map[] = ['org_id','=',$this->orgId];
  547. $map[] = ['del','=',0];
  548. $map[] = ['order_mode','=',1];
  549. if($level2onoff){
  550. $map[] = ['is_deal','=',0];
  551. }
  552. if(!is_admin($this->userId)){
  553. $auth = get_dispatch_auth($this->userId);
  554. if($auth){
  555. $map[] = ['work_type_mode', 'in', $auth];
  556. $where[] = ['o.work_type_mode', 'in', $auth];
  557. }else{
  558. $map[] = ['work_type_mode', '=', -1];
  559. $where[] = ['o.work_type_mode', '=', -1];
  560. }
  561. }
  562. $order = Db::name('orders')->where($map)->count();
  563. //$驳回的订单
  564. $where[] = ['o.del','=',0];
  565. $where[] = ['t.del','=',0];
  566. $bh = Db::name('orders')
  567. ->alias('o')
  568. ->join('todo t','t.order_id=o.id')
  569. ->where('t.todo_mode',4)
  570. ->where('t.org_id',$this->orgId)
  571. ->where('o.order_mode',4)
  572. ->where('o.org_id',$this->orgId)
  573. ->where($where)
  574. ->group('o.id')
  575. ->count();
  576. $order = $order + $bh;
  577. } else if($level2 && $level2onoff) { // 二级调度
  578. $rolesId = Db::name('user_roles')->where('user_id',$this->userId)->value('roles_id');
  579. if(!$rolesId){
  580. $this->error('无订单');
  581. }
  582. $map[] = ['b.org_id','=',$this->orgId];
  583. $map[] = ['b.del','=',0];
  584. $map[] = ['b.order_mode','=',1];
  585. $map[] = ['b.is_deal','=',1];
  586. $map[] = ['a.roles_id','=',$rolesId];
  587. if(!is_admin($this->userId)){
  588. $auth = get_dispatch_auth($this->userId);
  589. if($auth){
  590. $map[] = ['b.work_type_mode', 'in', $auth];
  591. }else{
  592. $map[] = ['b.work_type_mode', '=', -1];
  593. }
  594. }
  595. $order = Db::name('dispatch_log')
  596. ->alias('a')
  597. ->join('orders b','b.id = a.order_id')
  598. ->where($map)
  599. ->field('a.*')
  600. ->count();
  601. }
  602. $complainCount = Db::name('complain')->where('del',0)->where('org_id',$this->orgId)->where('status',0)->where('order_id',0)->count();
  603. $hiddendangerCount = Db::name('hiddendanger')->where('del',0)->where('org_id',$this->orgId)->where('status',0)->where('order_id',0)->count();
  604. $endCount = $order+$complainCount+$hiddendangerCount;
  605. if(!empty($endCount)){
  606. $this->success('','',$endCount);
  607. }else{
  608. $this->error('无订单');
  609. }
  610. }
  611. public function ordersList() {
  612. $orderType = input('orderType',1);
  613. $mode = input('mode', 0);
  614. $level1 = check_is_dispatch($this->userId);
  615. $level2 = check_two_dispatch($this->userId);
  616. $turnoff = two_dispatch_off($this->orgId);
  617. if (request()->isAjax()) {
  618. //分页参数
  619. $length = input('rows', 10, 'intval'); //每页条数
  620. $page = input('page', 1, 'intval'); //第几页
  621. $start = ($page - 1) * $length; //分页开始位置
  622. //排序
  623. $sortRow = input('sidx', 'id', 'trim'); //排序列
  624. $sort = input('sord', 'desc', 'trim'); //排序方式
  625. $order = $sortRow . ' ' . $sort;
  626. if($orderType == 1){
  627. $content = input('content', '', 'trim');
  628. if ($content) {
  629. $map[] = ['content', 'like', '%' . $content . '%'];
  630. }
  631. $dep_id = input('dep_id', '', 'trim');
  632. if ($dep_id != '') {
  633. $map[] = ['dep_id', '=', $dep_id];
  634. }
  635. $order_mode = input('order_mode', 1);
  636. $map6 = [];
  637. if ($order_mode != '') {
  638. if($level1 && $turnoff && $mode != 15){ // 一级调度且二级调度开关开着,品质整改例外
  639. if ($order_mode == 1) {
  640. $map[] = ['is_deal', '=', 0];
  641. }else if ($order_mode == 4) {
  642. $map6[] = ['is_deal', '=', 1];
  643. }
  644. }
  645. if($order_mode==100){//已挂起
  646. $gq = Db::name('todo')
  647. ->where('work_type_mode',1)
  648. ->where('todo_mode',2)
  649. ->where('pause',1)
  650. ->column('order_id');
  651. if(empty($gq)){
  652. $map[] = ['id', '=', -1];
  653. }else{
  654. $map[] = ['id', 'in', $gq];
  655. }
  656. }else{
  657. $map[] = ['order_mode', '=', $order_mode];
  658. }
  659. }
  660. $b = input('start', '', 'trim');
  661. $e = input('end', '', 'trim');
  662. if ($b) {
  663. $b = date('Ymd', strtotime($b));
  664. $map[] = ['create_yyyymmdd', '>=', $b];
  665. }
  666. if ($e) {
  667. $e = date('Ymd', strtotime($e));
  668. $map[] = ['create_yyyymmdd', '<=', $e];
  669. }
  670. $map[] = ['del', '=', 0];
  671. $map[] = ['org_id', '=', $this->orgId];
  672. if($mode==-1){
  673. $map[] = ['source_type', '=', 4];
  674. }
  675. $type = input('type', '', 'trim');
  676. $oids = [];
  677. if ($type != '') {
  678. $map1[] = ['parent_id', '=', $type];
  679. $type_id = Db::name('order_type')
  680. ->where($map1)
  681. ->where('org_id', $this->orgId)
  682. ->where('enable', 1)
  683. ->column('id');
  684. if (!empty($type_id)) {
  685. $map3[] = ['type_id', 'in', $type_id];
  686. $ids = Db::name('order_repair')
  687. ->where($map3)
  688. ->column('order_id');
  689. if (!empty($ids)) {
  690. $oids = $ids;
  691. }
  692. else {
  693. $oids = [];
  694. }
  695. }
  696. else {
  697. $oids = [];
  698. }
  699. }
  700. if($level2 && $turnoff){ // 二级调度
  701. $roles_id = Db::name('user_roles')
  702. ->where('user_id', $this->userId)
  703. ->value('roles_id');
  704. $ids = Db::name('dispatch_log')
  705. ->where('roles_id', $roles_id)
  706. ->whereOr('to_user_id', $this->userId)
  707. ->column('order_id');
  708. if (empty($ids)) {
  709. $map[] = ['id', '=', -1];
  710. } else {
  711. if($type != ''){
  712. $oids = array_intersect($oids,$ids);
  713. if($oids){
  714. $map[] = ['id', 'in', $oids];
  715. }else{
  716. $map[] = ['id', '=', -1];
  717. }
  718. }else{
  719. $map[] = ['id', 'in', $ids];
  720. }
  721. }
  722. }else{
  723. if($type != ''){
  724. if($oids){
  725. $map[] = ['id', 'in', $oids];
  726. }else{
  727. $map[] = ['id', '=', 0];
  728. }
  729. }
  730. }
  731. if($mode == 15){ // 品质检查,单独处理
  732. $map[] = ['work_type_mode','=',$mode];
  733. }else{
  734. $work_type_mode = input('work_type_mode','','trim');
  735. if(!is_admin($this->userId)){
  736. $auth = get_dispatch_auth($this->userId);
  737. if($auth){
  738. $map[] = ['work_type_mode', 'in', $auth];
  739. if($mode > 0){
  740. $map[] = ['work_type_mode', '=', $mode];
  741. }else{
  742. if($work_type_mode!=''){
  743. $map[] = ['work_type_mode','=',$work_type_mode];
  744. }
  745. }
  746. }else{
  747. $map[] = ['work_type_mode', '=', -1];
  748. }
  749. }else{
  750. if($mode > 0){
  751. $map[] = ['work_type_mode', '=', $mode];
  752. }else{
  753. if($work_type_mode!=''){
  754. $map[] = ['work_type_mode','=',$work_type_mode];
  755. }
  756. }
  757. }
  758. }
  759. $map = empty($map) ? true : $map;
  760. //数据查询
  761. $lists = db('orders')->where($map)
  762. ->whereOr($map6)
  763. ->limit($start, $length)->order($order)->select();
  764. foreach ($lists as $k => $v) {
  765. $lists[$k] = model('orders')->formatOrder($v);
  766. if ($turnoff && $level1 && $v['order_mode'] == 1 && $v['is_deal'] == 1) {
  767. $lists[$k]['order_mode_text'] = '已派发';
  768. }
  769. $lists[$k]['bh_nums'] = Db::name('todo')->where('order_id',$v['id'])->where('del',0)->where('todo_mode',4)->count();
  770. $gq = Db::name('todo')
  771. ->where('order_id',$v['id'])
  772. ->where('work_type_mode',1)
  773. ->where('todo_mode',2)
  774. ->where('pause',1)
  775. ->find();
  776. $lists[$k]['gq'] = $gq?'存在挂起':'';
  777. }
  778. //数据返回
  779. $totalCount = db('orders')->where($map)->count();
  780. }elseif($orderType == 2){
  781. $map[] = ['del','=',0];
  782. $map[] = ['org_id','=',$this->orgId];
  783. $hour = (new Config())->getConfig('org_complain_hour',$this->orgId);
  784. $hour = $hour>0?$hour:0;
  785. $endTime = date('Y-m-d H:i:s',time() - $hour*60*60);
  786. $type = input('type/d',0);
  787. if($hour > 0 && $type == 1){
  788. $map[] = ['create_time','<',$endTime];
  789. $map[] = ['status','=',0];
  790. }
  791. $from = input('from', '', 'trim');
  792. if ($from!='') {
  793. $map[] = ['from','=',$from];
  794. }
  795. $map[] = ['status','=',0];
  796. $map[] = ['order_id','=',0];
  797. $map= empty($map) ? true: $map;
  798. //数据查询
  799. $lists = db('complain')->where($map)
  800. ->limit($start,$length)->order($order)->select();
  801. foreach ($lists as $k=>$v){
  802. $lists[$k]['depName'] = Db::name('dep')
  803. ->where('id',$v['dep_id'])
  804. ->value('title');
  805. // $lists[$k]['fromName'] = model('Complain')->from[$v['from']];
  806. $lists[$k]['fromName'] = '';
  807. if($v['order_id'] > 0 && $v['bus_type'] != 0){
  808. if($v['to_from']){
  809. $lists[$k]['fromName'] = '一键呼叫';
  810. }else{
  811. $lists[$k]['fromName'] = '隐患';
  812. }
  813. }
  814. $lists[$k]['worktypemode'] = '';
  815. if($v['order_id'] > 0 && in_array($v['bus_type'],[0,1])){
  816. $worktype = Db::name('orders')
  817. ->alias('o')
  818. ->join('work_type_mode w','o.work_type_mode = w.id')
  819. ->where('o.id',$v['order_id'])
  820. ->value('w.name');
  821. $lists[$k]['worktypemode'] = $worktype?$worktype:'';
  822. }
  823. if($v['hide'] == 1){
  824. $lists[$k]['realName'] = '匿名';
  825. }else{
  826. $lists[$k]['realName'] = Db::name('user')
  827. ->where('id',$v['create_user_id'])
  828. ->value('real_name');
  829. }
  830. $orderMode = 0;
  831. if($v['order_id'] > 0){
  832. $orderMode = Db::name('orders')->where('id',$v['order_id'])->value('order_mode');
  833. }
  834. $lists[$k]['statusTxt'] = model('Complain')->formatStatus($v['status'],$v['order_id'],$v['id']);
  835. $lists[$k]['order_mode'] = $orderMode;
  836. if($v['create_time'] < $endTime && $v['status']==0){
  837. $lists[$k]['statusTxt'] = $lists[$k]['statusTxt'].'<span style="color:red;">(已超时)</span>';
  838. }
  839. }
  840. //数据返回
  841. $totalCount = db('complain')->where($map)->count();
  842. }elseif ($orderType == 3){
  843. $map[] = ['del','=',0];
  844. $map[] = ['org_id','=',$this->orgId];
  845. $map[] = ['status','=',0];
  846. $map[] = ['order_id','=',0];
  847. $from = input('from', '', 'trim');
  848. if ($from!='') {
  849. $map[] = ['from','=',$from];
  850. }
  851. $map= empty($map) ? true: $map;
  852. //数据查询
  853. $lists = db('hiddendanger')->where($map)
  854. ->limit($start,$length)->order($order)->select();
  855. foreach ($lists as $k=>$v){
  856. $lists[$k]['depName'] = Db::name('dep')
  857. ->where('id',$v['dep_id'])
  858. ->value('title');
  859. // $lists[$k]['fromName'] = model('Hiddendanger')->from[$v['from']];
  860. $lists[$k]['fromName'] = '';
  861. if($v['order_id'] > 0 && $v['bus_type'] != 0){
  862. if($v['to_from']){
  863. $lists[$k]['fromName'] = '一键呼叫';
  864. }else{
  865. $lists[$k]['fromName'] = '投诉';
  866. }
  867. }
  868. $lists[$k]['worktypemode'] = '';
  869. if($v['order_id'] > 0 && in_array($v['bus_type'],[0,1])){
  870. $worktype = Db::name('orders')
  871. ->alias('o')
  872. ->join('work_type_mode w','o.work_type_mode = w.id')
  873. ->where('o.id',$v['order_id'])
  874. ->value('w.name');
  875. $lists[$k]['worktypemode'] = $worktype?$worktype:'';
  876. }
  877. $lists[$k]['realName'] = Db::name('user')
  878. ->where('id',$v['create_user_id'])
  879. ->value('real_name');
  880. // $lists[$k]['statusTxt'] = $v['status']==1?'已处理':"未处理";
  881. $orderMode = 0;
  882. if($v['order_id'] > 0){
  883. $orderMode = Db::name('orders')->where('id',$v['order_id'])->value('order_mode');
  884. }
  885. $lists[$k]['statusTxt'] = model('Hiddendanger')->formatStatus($v['status'],$v['order_id'],$v['id']);
  886. $lists[$k]['order_mode'] = $orderMode;
  887. }
  888. //数据返回
  889. $totalCount = db('hiddendanger')->where($map)->count();
  890. }elseif($orderType == 4){
  891. $order_mode = input('order_mode', 4);
  892. $map6 = [];
  893. if ($order_mode != '') {
  894. if($level1 && $turnoff && $mode != 15){ // 一级调度且二级调度开关开着,品质整改例外
  895. if ($order_mode == 1) {
  896. $map[] = ['is_deal', '=', 0];
  897. }else if ($order_mode == 4) {
  898. $map6[] = ['is_deal', '=', 1];
  899. }
  900. }
  901. if($order_mode==100){//已挂起
  902. $gq = Db::name('todo')
  903. ->where('work_type_mode',1)
  904. ->where('todo_mode',2)
  905. ->where('pause',1)
  906. ->column('order_id');
  907. if(empty($gq)){
  908. $map[] = ['id', '=', -1];
  909. }else{
  910. $map[] = ['id', 'in', $gq];
  911. }
  912. }else{
  913. $map[] = ['order_mode', '=', $order_mode];
  914. }
  915. }
  916. $map[] = ['del', '=', 0];
  917. $map[] = ['org_id', '=', $this->orgId];
  918. if($mode==-1){
  919. $map[] = ['source_type', '=', 4];
  920. }
  921. $type = input('type', '', 'trim');
  922. $oids = [];
  923. if ($type != '') {
  924. $map1[] = ['parent_id', '=', $type];
  925. $type_id = Db::name('order_type')
  926. ->where($map1)
  927. ->where('org_id', $this->orgId)
  928. ->where('enable', 1)
  929. ->column('id');
  930. if (!empty($type_id)) {
  931. $map3[] = ['type_id', 'in', $type_id];
  932. $ids = Db::name('order_repair')
  933. ->where($map3)
  934. ->column('order_id');
  935. if (!empty($ids)) {
  936. $oids = $ids;
  937. }
  938. else {
  939. $oids = [];
  940. }
  941. }
  942. else {
  943. $oids = [];
  944. }
  945. }
  946. if($level2 && $turnoff){ // 二级调度
  947. $roles_id = Db::name('user_roles')
  948. ->where('user_id', $this->userId)
  949. ->value('roles_id');
  950. $ids = Db::name('dispatch_log')
  951. ->where('roles_id', $roles_id)
  952. ->whereOr('to_user_id', $this->userId)
  953. ->column('order_id');
  954. if (empty($ids)) {
  955. $map[] = ['id', '=', -1];
  956. } else {
  957. if($type != ''){
  958. $oids = array_intersect($oids,$ids);
  959. if($oids){
  960. $map[] = ['id', 'in', $oids];
  961. }else{
  962. $map[] = ['id', '=', -1];
  963. }
  964. }else{
  965. $map[] = ['id', 'in', $ids];
  966. }
  967. }
  968. }else{
  969. if($type != ''){
  970. if($oids){
  971. $map[] = ['id', 'in', $oids];
  972. }else{
  973. $map[] = ['id', '=', 0];
  974. }
  975. }
  976. }
  977. if($mode == 15){ // 品质检查,单独处理
  978. $map[] = ['work_type_mode','=',$mode];
  979. }else{
  980. $work_type_mode = input('work_type_mode','','trim');
  981. if(!is_admin($this->userId)){
  982. $auth = get_dispatch_auth($this->userId);
  983. if($auth){
  984. $map[] = ['work_type_mode', 'in', $auth];
  985. if($mode > 0){
  986. $map[] = ['work_type_mode', '=', $mode];
  987. }else{
  988. if($work_type_mode!=''){
  989. $map[] = ['work_type_mode','=',$work_type_mode];
  990. }
  991. }
  992. }else{
  993. $map[] = ['work_type_mode', '=', -1];
  994. }
  995. }else{
  996. if($mode > 0){
  997. $map[] = ['work_type_mode', '=', $mode];
  998. }else{
  999. if($work_type_mode!=''){
  1000. $map[] = ['work_type_mode','=',$work_type_mode];
  1001. }
  1002. }
  1003. }
  1004. }
  1005. $orderIds = Db::name('todo')
  1006. ->where('todo_mode',4)
  1007. ->where('org_id',$this->orgId)
  1008. ->where('del',0)
  1009. ->group('order_id')
  1010. ->column('order_id');
  1011. $map[] = ['id','in',$orderIds];
  1012. $map = empty($map) ? true : $map;
  1013. //数据查询
  1014. $lists = db('orders')
  1015. ->where($map)
  1016. // ->whereOr($map6)
  1017. ->limit($start, $length)
  1018. ->order($order)
  1019. ->select();
  1020. foreach ($lists as $k => $v) {
  1021. $lists[$k] = model('orders')->formatOrder($v);
  1022. if ($turnoff && $level1 && $v['order_mode'] == 1 && $v['is_deal'] == 1) {
  1023. $lists[$k]['order_mode_text'] = '已派发';
  1024. }
  1025. $lists[$k]['bh_nums'] = Db::name('todo')->where('order_id',$v['id'])->where('del',0)->where('todo_mode',4)->count();
  1026. $gq = Db::name('todo')
  1027. ->where('order_id',$v['id'])
  1028. ->where('work_type_mode',1)
  1029. ->where('todo_mode',2)
  1030. ->where('pause',1)
  1031. ->find();
  1032. $lists[$k]['gq'] = $gq?'存在挂起':'';
  1033. }
  1034. //数据返回
  1035. $totalCount = db('orders')->where($map)->count();
  1036. }
  1037. $totalPage = ceil($totalCount / $length);
  1038. $result['page'] = $page;
  1039. $result['total'] = $totalPage;
  1040. $result['records'] = $totalCount;
  1041. $result['rows'] = $lists;
  1042. return json($result);
  1043. }
  1044. else {
  1045. if($mode >0){
  1046. $mode_name = $this->getTableField('work_type_mode', ['id' => $mode], 'name');
  1047. }else{
  1048. $mode_name = '';
  1049. }
  1050. $auths = [1,2,3,4,15,0];
  1051. if(!is_admin($this->userId)){
  1052. $auth = get_dispatch_auth($this->userId);
  1053. if($auth){
  1054. $auths = array_intersect($auths,$auth);
  1055. if($mode > 0){
  1056. $auths = array_intersect($auths,[$mode]);
  1057. }
  1058. }else{
  1059. $auths = [];
  1060. }
  1061. }
  1062. $this->assign('auths',$auths);
  1063. $dep_list = (new \app\common\model\Dep())->getList();
  1064. $order_type = (new \app\common\model\OrderType())->list();
  1065. $order_mode = Db::name('order_mode')
  1066. ->select();
  1067. $this->assign('dep_list', $dep_list);
  1068. $this->assign('order_type_list', $order_type);
  1069. $this->assign('m_name', $mode_name);
  1070. $this->assign('mode', $mode);
  1071. $this->assign('order_mode_list', $order_mode);
  1072. $this->assign('dispatch_type', check_two_dispatch($this->userId));
  1073. $this->assign('orderType',$orderType);
  1074. return $this->fetch('index/orders');
  1075. }
  1076. }
  1077. //调度查看订单详情
  1078. public function ordersDetail2($id) {
  1079. if (!$id) {
  1080. $this->error('参数错误');
  1081. }
  1082. $type = input('type/d',0);
  1083. $this->assign('type', $type);
  1084. $order = Db::name('orders')->where(['id' => $id])->find();
  1085. $order = model('Orders')->formatOrder($order, 1);
  1086. $order['images'] = !empty($order['images']) ? explode(',', $order['images']) : '';
  1087. $this->assign('info', $order);
  1088. $workTypeName = $this->getTableField('work_type_mode', ['id' => $order['work_type_mode']], 'name');
  1089. $this->assign('meta_title', $workTypeName . '订单详情');
  1090. $level2 = check_two_dispatch($this->userId);
  1091. $level1 = check_is_dispatch($this->userId);
  1092. $turnoff = two_dispatch_off($this->orgId);
  1093. $this->assign('level1', $level1);
  1094. $this->assign('level2', $level2);
  1095. $this->assign('turnoff', $turnoff);
  1096. $this->assign('dispatch_type', $level2);
  1097. return $this->fetch();
  1098. }
  1099. }