0
0

Popup.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  1. <?php
  2. namespace app\api\controller\screen;
  3. use app\api\controller\screen\Index;
  4. use app\hander\HelpHander;
  5. use think\Db;
  6. use think\helper\Time;
  7. class Popup extends Index
  8. {
  9. // 项目大屏--员工实时在岗情况
  10. public function userPraise(){
  11. $allUids = model('WorkTypeMode')->getWorkerUserIds($this->orgId);
  12. $users = [];
  13. if($allUids){
  14. $users = Db::name('user')
  15. ->where('id','in',$allUids)
  16. ->order('score desc,id asc')
  17. ->field('id,real_name,score')
  18. ->limit(10)
  19. ->select();
  20. $users = $users?$users:[];
  21. }
  22. $data = [];
  23. foreach ($users as $k=>$v){
  24. $top = 'TOP'.($k+1);
  25. $data[$k]['top'] = $top;
  26. $data[$k]['name'] = $v['real_name'];
  27. $data[$k]['score'] = $v['score'];
  28. }
  29. HelpHander::success($data);
  30. }
  31. public function hotMate(){
  32. $map[] = ['tm.org_id','=',$this->orgId];
  33. $lists = Db::name('todo_mate_item')
  34. ->alias('tmi')
  35. ->join('todo_mate tm','tm.id = tmi.todo_mate_id')
  36. ->where($map)
  37. ->field('sum(total) as total,items_id')
  38. ->group('items_id')
  39. ->distinct(true)
  40. ->order('total desc')
  41. ->limit(10)
  42. ->select();
  43. $data = [];
  44. foreach ($lists as $k=>$v){
  45. $top = 'TOP'.($k+1);
  46. $name = Db::name('mate_goods')->where('id',$v['items_id'])->value('title');
  47. $data[$k]['top'] = $top;
  48. $data[$k]['name'] = $name ? $name :'';
  49. $data[$k]['count'] = $v['total'];
  50. }
  51. HelpHander::success($data);
  52. }
  53. public function hotDep(){
  54. $type = input('type/d',1);
  55. if(!in_array($type,[1,2])){
  56. HelpHander::error('参数错误');
  57. }
  58. if($type == 1){ // 运送
  59. $map[] = ['work_type_mode','=',3];
  60. $map[] = ['org_id','=',$this->orgId];
  61. $map[] = ['del','=',0];
  62. $lists = Db::name('orders')
  63. ->where($map)
  64. ->field('count(*) as count,dep_id')
  65. ->group('dep_id')
  66. ->distinct(true)
  67. ->order('count desc')
  68. ->limit(10)
  69. ->select();
  70. }else{ // 陪护
  71. $map[] = ['org_id','=',$this->orgId];
  72. $lists = Db::name('ph_orders')
  73. ->where($map)
  74. ->field('count(*) as count,dep_id')
  75. ->group('dep_id')
  76. ->distinct(true)
  77. ->order('count desc')
  78. ->limit(10)
  79. ->select();
  80. }
  81. $data = [];
  82. foreach ($lists as $k=>$v){
  83. $top = 'TOP'.($k+1);
  84. $depName = Db::name('dep')->where('id',$v['dep_id'])->value('title');
  85. $data[$k]['top'] = $top;
  86. $data[$k]['dep_name'] = $depName?$depName:'';
  87. $data[$k]['count'] = $v['count'];
  88. }
  89. HelpHander::success($data);
  90. }
  91. public function cateTodoCount(){
  92. //保洁
  93. $bjCount = Db::name('todo')
  94. ->where('del',0)
  95. ->where('create_yyyymmdd',date('Ymd'))
  96. ->where('work_type_mode',2)
  97. ->count();
  98. $bjCount2 = Db::name('todo')
  99. ->where('del',0)
  100. ->where('todo_mode',3)
  101. ->where('create_yyyymmdd',date('Ymd'))
  102. ->where('work_type_mode',2)
  103. ->count();
  104. //报修
  105. $bxCount = Db::name('todo')
  106. ->where('del',0)
  107. ->where('create_yyyymmdd',date('Ymd'))
  108. ->where('work_type_mode',1)
  109. ->count();
  110. $bxCount2 = Db::name('todo')
  111. ->where('del',0)
  112. ->where('todo_mode',3)
  113. ->where('create_yyyymmdd',date('Ymd'))
  114. ->where('work_type_mode',1)
  115. ->count();
  116. //隐患
  117. $yhCount = Db::name('todo')
  118. ->where('del',0)
  119. ->where('create_yyyymmdd',date('Ymd'))
  120. ->where('work_type_mode',4)
  121. ->count();
  122. $yhCount2 = Db::name('todo')
  123. ->where('del',0)
  124. ->where('todo_mode',3)
  125. ->where('create_yyyymmdd',date('Ymd'))
  126. ->where('work_type_mode',4)
  127. ->count();
  128. //运送
  129. $ysCount = Db::name('todo')
  130. ->where('del',0)
  131. ->where('create_yyyymmdd',date('Ymd'))
  132. ->where('work_type_mode',3)
  133. ->count();
  134. $ysCount2 = Db::name('todo')
  135. ->where('del',0)
  136. ->where('todo_mode',3)
  137. ->where('create_yyyymmdd',date('Ymd'))
  138. ->where('work_type_mode',3)
  139. ->count();
  140. //陪护
  141. $phCount = Db::name('ph_todo')
  142. ->where('create_time','>=',date('Y-m-d').' 00:00:00')
  143. ->where('create_time','<=',date('Y-m-d').' 23:59:59')
  144. ->count();
  145. $phCount2 = Db::name('ph_todo')
  146. ->where('create_time','>=',date('Y-m-d').' 00:00:00')
  147. ->where('create_time','<=',date('Y-m-d').' 23:59:59')
  148. ->where('status',2)
  149. ->count();
  150. $data = [
  151. ['name'=>'报修','num'=>$bxCount,'num1'=>$bxCount2],
  152. ['name'=>'保洁','num'=>$bjCount,'num1'=>$bjCount2],
  153. ['name'=>'运送','num'=>$ysCount,'num1'=>$ysCount2],
  154. ['name'=>'应急','num'=>$yhCount,'num1'=>$yhCount2],
  155. ['name'=>'陪护','num'=>$phCount,'num1'=>$phCount2],
  156. ];
  157. HelpHander::success($data);
  158. }
  159. public function orderCount(){
  160. $mode = input('mode/d',1);
  161. $type = input('type/d',1);
  162. if(!in_array($type,[1,2,3])||!in_array($mode,[1,2,3,4])){
  163. HelpHander::error('参数错误');
  164. }
  165. $date = [];
  166. $curDay = date('Y-m-d');
  167. if($type == 1){ // 日统计
  168. $date[] = '03';
  169. $date[] = '06';
  170. $date[] = '09';
  171. $date[] = '12';
  172. $date[] = '15';
  173. $date[] = '18';
  174. $date[] = '21';
  175. $date[] = '24';
  176. }else if($type == 2){ // 周统计
  177. $ms = Time::week();
  178. $start = $ms[0];
  179. $end = $ms[1] + 1;
  180. $date[] = date('Y-m-d',$start);
  181. $i = 1;
  182. while (($start + $i*24*60*60) < $end){
  183. $date[] = date('Y-m-d',$start + $i*24*60*60);
  184. $i++;
  185. }
  186. }else{ // 月统计
  187. $ms = Time::month();
  188. $start = $ms[0];
  189. $end = $ms[1] + 1;
  190. $i = 1;
  191. while (($start + $i*24*60*60) < $end){
  192. $date[] = date('Y-m-d',$start + $i*24*60*60);
  193. $i++;
  194. }
  195. }
  196. $d1 = [];
  197. $d2 = [];
  198. $d = [];
  199. $data = [];
  200. foreach ($date as $k=>$v){
  201. $map = [];
  202. $map[] = ['org_id','=',$this->orgId];
  203. $map[] = ['work_type_mode','=',$mode];
  204. $map[] = ['del','=',0];
  205. if($type == 1){ // 日统计
  206. if($k == 0){
  207. $s = $curDay.' 00:00:00';
  208. }else{
  209. $s = $curDay.' '.$date[$k-1].':00:00';
  210. }
  211. $e = $curDay.' '.$v.':00:00';
  212. $map[] = ['create_time','egt',$s];
  213. $map[] = ['create_time','lt',$e];
  214. $d[] = (int)$v;
  215. $data[$k]['name'] = $v;
  216. }else{
  217. $map[] = ['create_yyyymmdd','=',date('Ymd',strtotime($v))];
  218. $d[] = date('m-d',strtotime($v));
  219. $data[$k]['name'] = date('m-d',strtotime($v));
  220. }
  221. $order = Db::name('orders')->where($map)->count();
  222. $todo = Db::name('todo')->where($map)->count();
  223. $d1[] = $todo;
  224. $d2[] = $order;
  225. $data[$k]['order_num'] = $order;
  226. $data[$k]['todo_num'] = $todo;
  227. }
  228. // HelpHander::success(['d'=>$d,'d1'=>$d1,'d2'=>$d2]);
  229. HelpHander::success($data);
  230. }
  231. public function patrolRealTime(){
  232. $mode = input('mode');
  233. $page = input('page',1);
  234. $size = input('size',9);
  235. if(!in_array($mode,[1,2,3,4])){
  236. HelpHander::error('参数错误');
  237. }
  238. $lists = Db::name('patrol_record')
  239. ->field('create_time,user_id,patrol_addr_form_id,patrol_mode,is_normal,content as info,patrol_task_id,patrol_addr_id')
  240. ->where('patrol_mode',$mode)
  241. ->where('org_id',$this->orgId)
  242. ->page($page,$size)
  243. ->order('id desc')
  244. ->select();
  245. $data = [];
  246. foreach ($lists as $k=>$v){
  247. $addrForm = Db::name('patrol_addr_form')
  248. ->alias('a')
  249. ->join('patrol_task_addr b','b.patrol_form_id = a.id')
  250. ->where('b.id',$v['patrol_addr_form_id'])
  251. ->value('a.title');
  252. $modeTitle = Db::name('patrol_mode')
  253. ->where('id',$v['patrol_mode'])
  254. ->value('name');
  255. $user = Db::name('user')->where('id',$v['user_id'])->value('real_name');
  256. $is_normal = '无异常' ;
  257. if($v['is_normal'] == 1){
  258. $is_normal = '有异常' ;
  259. }
  260. $time = date('Y-m-d H:i',strtotime($v['create_time']));
  261. $content = '员工-'.$user.'完成'.$addrForm.$modeTitle.','.$is_normal;
  262. $data[$k]['time'] = $time;
  263. $data[$k]['content'] = $content;
  264. $data[$k]['info'] = $v['info'];
  265. $data[$k]['task_name'] = Db::name('patrol_task')->where('id',$v['patrol_task_id'])->value('title');
  266. $data[$k]['addr_name'] = Db::name('address')->where('id',$v['patrol_addr_id'])->value('title');
  267. }
  268. $count = Db::name('patrol_record')
  269. ->where('patrol_mode',$mode)
  270. ->where('org_id',$this->orgId)
  271. ->count();
  272. $dt = [
  273. 'list'=>$data,
  274. 'count'=>$count
  275. ];
  276. HelpHander::success($dt);
  277. }
  278. public function taskList(){
  279. $mode = input('mode/d',1);
  280. if(!in_array($mode,[1,2,3,4,5])){
  281. HelpHander::error('参数错误');
  282. }
  283. $data = [];
  284. if($mode == 5){
  285. $lists = Db::name('ph_orders')
  286. ->where('org_id',$this->orgId)
  287. ->where('status','in',[1,2])
  288. ->order('id desc')
  289. ->field('id,sn,cate_id,status,create_time,start,end,contact,phone')
  290. ->limit(20)
  291. ->select();
  292. foreach ($lists as $k=>$v){
  293. $cate = Db::name('cate')->where('id',$v['cate_id'])->value('title');
  294. $stxt = '新订单';
  295. $users = '';
  296. if($v['status'] == 2){
  297. $stxt = '服务中';
  298. $unames = Db::name('ph_todo')
  299. ->alias('t')
  300. ->join('worker w','t.worker_id = w.id')
  301. ->join('user u','u.id = w.user_id')
  302. ->where('t.order_id',$v['id'])
  303. ->where('t.status',1)
  304. ->column('real_name');
  305. $users = $unames?implode(',',$unames):'';
  306. }
  307. $data[$k]['status'] = $stxt;
  308. $data[$k]['sn'] = $v['sn'];
  309. $data[$k]['cate'] = $cate;
  310. $data[$k]['user'] = $users;
  311. $data[$k]['time'] = $v['create_time'];
  312. $data[$k]['st'] = $v['start'];
  313. $data[$k]['et'] = $v['end'];
  314. $data[$k]['contact'] = $v['contact'];
  315. $data[$k]['phone'] = $v['phone'];
  316. }
  317. }else{
  318. $lists = Db::name('orders')
  319. ->where('org_id',$this->orgId)
  320. ->where('order_mode','in',[1,4])
  321. ->where('work_type_mode',$mode)
  322. ->where('del',0)
  323. ->order('id desc')
  324. ->limit(20)
  325. ->field('id,order_mode,create_time,send_time,content,dep_id,sn,user_id')
  326. ->select();
  327. foreach ($lists as $k=>$v){
  328. $dep = Db::name('dep')->where('id',$v['dep_id'])->value('title');
  329. $status = Db::name('order_mode')->where('id',$v['order_mode'])->value('out_content');
  330. $userName = Db::name('user')->where('id',$v['user_id'])->value('real_name');
  331. if($mode == 1){ // 报修
  332. $type = Db::name('order_repair')
  333. ->alias('or')
  334. ->leftJoin('order_type ot','ot.id = or.type_id')
  335. ->where('or.order_id',$v['id'])
  336. ->value('title');
  337. // $data[] = [$status,$dep,$type?$type:'',$v['content'],$v['create_time']];
  338. $data[$k]['status'] = $status;
  339. $data[$k]['dep'] = $dep;
  340. $data[$k]['cate'] = $type?$type:'';
  341. $data[$k]['content'] = $v['content'];
  342. $data[$k]['time'] = $v['create_time'];
  343. $data[$k]['sn'] = $v['sn'];
  344. $data[$k]['user_name'] = $userName;
  345. $data[$k]['send_time'] = $v['send_time'];
  346. }else if($mode == 3){ //运送
  347. $convey = Db::name('order_convey')
  348. ->alias('oc')
  349. ->join('convey_cate cc','cc.id = oc.type')
  350. ->where('oc.order_id',$v['id'])
  351. ->field('oc.*,cc.title as cate_title')
  352. ->find();
  353. $start = Db::name('address')->where('id',$convey['start'])->value('title');
  354. $end = Db::name('address')->where('id',$convey['end'])->value('title');
  355. $todos = Db::name('todo')
  356. ->alias('t')
  357. ->join('user u','u.id = t.to_user_id')
  358. ->where('t.order_id',$v['id'])
  359. ->where('t.del',0)
  360. ->where('t.todo_mode','in',[1,2,3])
  361. ->field('t.confirm_time,u.real_name')
  362. ->select();
  363. $todos = $todos?$todos:[];
  364. $unames = [];
  365. $confirm = '';
  366. foreach ($todos as $tk=>$tv){
  367. $unames[] = $tv['real_name'];
  368. if(!$confirm){
  369. $confirm = $tv['confirm_time'];
  370. }
  371. }
  372. $un = $unames?implode(',',$unames):'';
  373. $send = $v['send_time']?date('H:i',strtotime($v['send_time'])):'';
  374. $xq = date('H:i',strtotime($convey['xq_time']));
  375. $confirm = $confirm?date('H:i',strtotime($confirm)):'';
  376. // $data[] = [$status,$convey['cate_title'],$start,$end,$xq,$un,$send,$confirm];
  377. $data[$k]['status'] = $status;
  378. $data[$k]['cate'] = $convey['cate_title'];
  379. $data[$k]['start'] = $start;
  380. $data[$k]['end'] = $end;
  381. $data[$k]['xq'] = $xq;
  382. $data[$k]['un'] = $un;
  383. $data[$k]['send'] = $send;
  384. $data[$k]['confirm'] = $confirm;
  385. $data[$k]['sn'] = $v['sn'];
  386. $data[$k]['user_name'] = $userName;
  387. $data[$k]['send_time'] = $v['send_time'];
  388. }else{ // 保洁,应急
  389. // $data[] = [$status,$dep,$v['content'],$v['create_time']];
  390. $data[$k]['status'] = $status;
  391. $data[$k]['dep'] = $dep;
  392. $data[$k]['content'] = $v['content'];
  393. $data[$k]['time'] = $v['create_time'];
  394. $data[$k]['sn'] = $v['sn'];
  395. $data[$k]['user_name'] = $userName;
  396. $data[$k]['send_time'] = $v['send_time'];
  397. }
  398. }
  399. }
  400. HelpHander::success($data);
  401. }
  402. public function wxTodoData(){
  403. $page = input('page',1);
  404. $size = input('size',9);
  405. $list = Db::name('todo')
  406. ->field('id,order_id,todo_mode,create_time,to_user_id,confirm_time,xy_time,wc_time,todo_content')
  407. ->where('org_id',$this->orgId)
  408. ->whereIn('todo_mode',[1,2,3])
  409. ->where('del',0)
  410. ->where('create_yyyymmdd','>=',date('Ymd',strtotime('-3 day')))
  411. ->where('create_yyyymmdd','<=',date('Ymd'))
  412. ->where('work_type_mode',1)
  413. ->page($page,$size)
  414. ->select();
  415. foreach ($list as $k=>$v){
  416. if($v['todo_mode'] == 1){
  417. $list[$k]['status'] = '新任务';
  418. }elseif ($v['todo_mode'] == 2){
  419. $list[$k]['status'] = '进行中';
  420. }elseif ($v['todo_mode'] == 3){
  421. $list[$k]['status'] = '已完成';
  422. }
  423. $repair = Db::name('order_type')
  424. ->alias('ot')
  425. ->field('ot.id,ot.title,ot.parent_id')
  426. ->join('order_repair or','or.type_id=ot.id')
  427. ->where('or.order_id',$v['order_id'])
  428. ->find();
  429. $list[$k]['cate_title'] = Db::name('order_type')->where('id',$repair['parent_id'])->value('title');
  430. $list[$k]['address'] = Db::name('address')
  431. ->alias('a')
  432. ->join('order_repair or','or.address_id=a.id')
  433. ->where('or.order_id',$v['order_id'])
  434. ->where('a.org_id',$this->orgId)
  435. ->value('a.title');
  436. $list[$k]['create_time'] = date('H:i',strtotime($v['create_time']));
  437. $list[$k]['confirm_time'] = $v['confirm_time']? date('H:i',strtotime($v['confirm_time'])):'';
  438. $list[$k]['user_name'] = Db::name('user')->where('id',$v['to_user_id'])->value('real_name');
  439. $list[$k]['xy_time'] = $v['xy_time'] ? round($v['xy_time']/60,1):'';
  440. $list[$k]['wc_time'] = $v['wc_time'] ? round($v['wc_time']/60,1):'';
  441. }
  442. $count = Db::name('todo')
  443. ->where('org_id',$this->orgId)
  444. ->whereIn('todo_mode',[1,2,3])
  445. ->where('del',0)
  446. ->where('create_yyyymmdd','>=',date('Ymd',strtotime('-3 day')))
  447. ->where('create_yyyymmdd','<=',date('Ymd'))
  448. ->where('work_type_mode',1)
  449. ->count();
  450. $data = [
  451. 'list'=>$list,
  452. 'count'=>$count,
  453. ];
  454. HelpHander::success($data);
  455. }
  456. public function patrolRecord(){
  457. $page = input('page',1);
  458. $size = input('size',9);
  459. $lists = Db::name('patrol_record')
  460. ->alias('a')
  461. ->join('patrol_task t','a.patrol_task_id = t.id')
  462. ->join('address b','a.patrol_addr_id = b.id')
  463. ->join('user c','a.user_id = c.id')
  464. ->where('a.create_yyyymmdd','>=',date('Ymd',strtotime('-3 day')))
  465. ->where('a.create_yyyymmdd','<=',date('Ymd'))
  466. ->where('a.org_id',$this->orgId)
  467. ->field('a.images,a.create_time,b.title as address,c.real_name as name,t.title as task_title,a.is_normal,a.content')
  468. ->page($page,$size)
  469. ->order('a.id desc')
  470. ->select();
  471. foreach ($lists as $k=>$v){
  472. $lists[$k]['is_normal_text'] = $v['is_normal'] == 0 ? '正常':'异常';
  473. }
  474. $count = Db::name('patrol_record')
  475. ->alias('a')
  476. ->join('patrol_task t','a.patrol_task_id = t.id')
  477. ->join('address b','a.patrol_addr_id = b.id')
  478. ->join('user c','a.user_id = c.id')
  479. ->where('a.create_yyyymmdd','>=',date('Ymd',strtotime('-3 day')))
  480. ->where('a.create_yyyymmdd','<=',date('Ymd'))
  481. ->where('a.org_id',$this->orgId)
  482. ->count();
  483. $data = [
  484. 'list'=>$lists,
  485. 'count'=>$count
  486. ];
  487. HelpHander::success($data);
  488. }
  489. }