PatrolStatistics.php 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059
  1. <?php
  2. namespace app\admin\controller;
  3. use function PHPSTORM_META\map;
  4. use think\App;
  5. use think\Db;
  6. class PatrolStatistics extends Auth {
  7. public function patrol() {
  8. $cur = date('Y-m-d');
  9. $start = input('start', date('Y-m-d', strtotime('' . $cur . ' -1 week')));
  10. $end = input('end', date('Y-m-d'));
  11. $start1 = $start . ' 00:00:00';
  12. $end1 = $end . ' 23:59:59';
  13. $type = input('type', 1);
  14. $list = $this->patrolData($start1, $end1, $type);
  15. $this->assign('type', $type);
  16. $this->assign('list', $list);
  17. $this->assign('start', $start);
  18. $this->assign('end', $end);
  19. return $this->fetch();
  20. }
  21. public function patrolData($start1, $end1, $type) {
  22. $map1[] = ['create_time', '>=', $start1];
  23. $map1[] = ['create_time', '<=', $end1];
  24. $map1[] = ['org_id', '=', $this->orgId];
  25. $list = Db::name('patrol_record')
  26. ->where($map1)
  27. ->where('patrol_mode', $type)
  28. ->group('patrol_addr_id')
  29. ->distinct(true)
  30. ->select();
  31. foreach ($list as $k => $v) {
  32. $list[$k]['title'] = Db::name('address')
  33. ->where('id', $v['patrol_addr_id'])
  34. ->value('title');
  35. $c = Db::name('patrol_record')
  36. ->where($map1)
  37. ->where('is_normal', 0)
  38. ->where('patrol_addr_id', $v['patrol_addr_id'])
  39. ->where('patrol_mode', $type)
  40. ->count();
  41. $list[$k]['count'] = $c ? $c : 0;
  42. $normal = Db::name('patrol_record')
  43. ->where($map1)
  44. ->where('is_normal', 1)
  45. ->where('patrol_addr_id', $v['patrol_addr_id'])
  46. ->where('patrol_mode', $type)
  47. ->count();
  48. $list[$k]['normal'] = $normal ? $normal : 0;
  49. }
  50. return $list;
  51. }
  52. public function patrolExport() {
  53. $cur = date('Y-m-d');
  54. $start = input('start', date('Y-m-d', strtotime('' . $cur . ' -1 week')));
  55. $end = input('end', date('Y-m-d'));
  56. $start1 = $start . ' 00:00:00';
  57. $end1 = $end . ' 23:59:59';
  58. $type = input('type', 1);
  59. $ret = $this->patrolData($start1, $end1, $type);
  60. include_once env('root_path') . '/extend/phpexcel/Classes/PHPExcel.php';
  61. //实例化PHPExcel类
  62. $objPHPExcel = new \PHPExcel();
  63. //激活当前的sheet表
  64. $objPHPExcel->setActiveSheetIndex(0);
  65. //设置表格头(即excel表格的第一行)
  66. $objPHPExcel->setActiveSheetIndex(0)
  67. ->setCellValue('A1', '智慧点')
  68. ->setCellValue('B1', '总数')
  69. ->setCellValue('C1', '总数(异常)');
  70. // 设置表格头水平居中
  71. $objPHPExcel->setActiveSheetIndex(0)->getStyle('A1')->getAlignment()
  72. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  73. $objPHPExcel->setActiveSheetIndex(0)->getStyle('B1')->getAlignment()
  74. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  75. $objPHPExcel->setActiveSheetIndex(0)->getStyle('C1')->getAlignment()
  76. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  77. //设置列水平居中
  78. $objPHPExcel->setActiveSheetIndex(0)->getStyle('A')->getAlignment()
  79. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  80. $objPHPExcel->setActiveSheetIndex(0)->getStyle('B')->getAlignment()
  81. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  82. $objPHPExcel->setActiveSheetIndex(0)->getStyle('C')->getAlignment()
  83. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  84. //设置单元格宽度
  85. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('A')->setWidth(10);
  86. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('B')->setWidth(20);
  87. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('C')->setWidth(20);
  88. //循环刚取出来的数组,将数据逐一添加到excel表格。
  89. for ($i = 0; $i < count($ret); $i++) {
  90. $objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 2), $ret[$i]['title']);
  91. $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $ret[$i]['count']);
  92. $objPHPExcel->getActiveSheet()->setCellValue('C' . ($i + 2), $ret[$i]['normal']);
  93. }
  94. $n = Db::name('patrol_mode')
  95. ->where('id', $type)
  96. ->value('name');
  97. //设置保存的Excel表格名称
  98. $filename = $n . '工作量统计分析_' . date('YmdHis', time()) . '.xls';
  99. //设置当前激活的sheet表格名称
  100. $objPHPExcel->getActiveSheet()->setTitle($n . '工作量统计分析');
  101. //设置浏览器窗口下载表格
  102. ob_end_clean();
  103. header("Content-Type: application/force-download");
  104. header("Content-Type: application/octet-stream");
  105. header("Content-Type: application/download");
  106. header('Content-Disposition:inline;filename="' . $filename);
  107. //生成excel文件
  108. $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
  109. //下载文件在浏览器窗口
  110. return $objWriter->save('php://output');
  111. }
  112. public function work() {
  113. $cur = date('Y-m-d');
  114. $start = input('start', date('Y-m-d', strtotime('' . $cur . ' -1 week')));
  115. $end = input('end', date('Y-m-d'));
  116. $start1 = $start . ' 00:00:00';
  117. $end1 = $end . ' 23:59:59';
  118. $type = input('type', 1);
  119. $list = $this->workData($start1, $end1, $type);
  120. $this->assign('type', $type);
  121. $this->assign('list', $list);
  122. $this->assign('start', $start);
  123. $this->assign('end', $end);
  124. return $this->fetch();
  125. }
  126. public function workData($start1, $end1, $type) {
  127. $map1[] = ['create_time', '>=', $start1];
  128. $map1[] = ['create_time', '<=', $end1];
  129. $map1[] = ['org_id', '=', $this->orgId];
  130. $list = Db::name('patrol_record')
  131. ->where($map1)
  132. ->where('patrol_mode', $type)
  133. ->group('user_id')
  134. ->distinct(true)
  135. ->select();
  136. foreach ($list as $k => $v) {
  137. $list[$k]['title'] = Db::name('user')
  138. ->where('id', $v['user_id'])
  139. ->value('real_name');
  140. $c = Db::name('patrol_record')
  141. ->where($map1)
  142. ->where('user_id', $v['user_id'])
  143. ->where('patrol_mode', $type)
  144. ->count();
  145. $list[$k]['count'] = $c ? $c : 0;
  146. $c1 = Db::name('patrol_record')
  147. ->where($map1)
  148. ->where('user_id', $v['user_id'])
  149. ->where('patrol_mode', $type)
  150. ->where('is_normal', 0)
  151. ->count();
  152. $list[$k]['count1'] = $c1 ? $c1 : 0;
  153. $c2 = Db::name('patrol_record')
  154. ->where($map1)
  155. ->where('user_id', $v['user_id'])
  156. ->where('patrol_mode', $type)
  157. ->where('is_normal', 1)
  158. ->count();
  159. $list[$k]['count2'] = $c2 ? $c2 : 0;
  160. $taskCount = Db::name('patrol_task_user')
  161. ->alias('a')
  162. ->join('patrol_task b','a.patrol_task_id=b.id')
  163. ->where('a.user_id',$v['user_id'])
  164. ->where('b.org_id',$this->orgId)
  165. ->where('b.status','<>',6)
  166. ->where('b.start_time','>=',$start1)
  167. ->where('b.end_time','<=',$end1)
  168. ->where('b.patrol_mode','=',$type)
  169. ->count();
  170. $ywcCount = Db::name('patrol_task_user')
  171. ->alias('a')
  172. ->join('patrol_task b','a.patrol_task_id=b.id')
  173. ->where('a.user_id',$v['user_id'])
  174. ->where('b.org_id',$this->orgId)
  175. ->where('b.status','=',2)
  176. ->where('b.start_time','>=',$start1)
  177. ->where('b.end_time','<=',$end1)
  178. ->where('b.patrol_mode','=',$type)
  179. ->count();
  180. $wcl = $taskCount>0?round($ywcCount/$taskCount,2)*100:0;
  181. $wcl = $wcl.'%';
  182. $list[$k]['wcl'] = $wcl;
  183. $list[$k]['count3'] = $ywcCount;
  184. $list[$k]['count4'] = $taskCount;
  185. }
  186. return $list;
  187. }
  188. public function workList(){
  189. $user_id = input('user_id','','trim');
  190. if($user_id!=''){
  191. $map[] = ['user_id','=',$user_id];
  192. }
  193. $is_normal = input('is_normal','','trim');
  194. if($is_normal!==''){
  195. $map[] = ['is_normal','=',$is_normal];
  196. }
  197. $type = input('type','','trim');
  198. if($type != ''){
  199. $map[] = ['patrol_mode','=',$type];
  200. }
  201. $start = input('start',date('Y-m-d', strtotime('' . date('Y-m-d') . ' -1 week')));
  202. if($start != ''){
  203. $map[] = ['create_time','>=',$start.' 00:00:00'];
  204. }
  205. $end = input('end', date('Y-m-d'));
  206. if($end != ''){
  207. $map[] = ['create_time','<=',$end.' 23:59:59'];
  208. }
  209. if(request()->isAjax()){
  210. //分页参数
  211. $length = input('rows',10,'intval'); //每页条数
  212. $page = input('page',1,'intval'); //第几页
  213. $start = ($page - 1) * $length; //分页开始位置
  214. //排序
  215. $sortRow = input('sidx','sort','trim'); //排序列
  216. $sort = input('sord','asc','trim'); //排序方式
  217. $order = $sortRow.' '.$sort.' ,id desc';
  218. $map[] = ['org_id','=',$this->orgId];
  219. $map= empty($map) ? true: $map;
  220. //数据查询
  221. $lists = Db::name('patrol_record')
  222. ->where($map)
  223. ->limit($start,$length)
  224. ->order($order)
  225. ->select();
  226. foreach ($lists as $k=>$v){
  227. $lists[$k]['address_title'] = Db::name('address')
  228. ->where('id', $v['patrol_addr_id'])
  229. ->value('title');
  230. $lists[$k]['task_user'] = Db::name('user')
  231. ->where('id', $v['user_id'])->value('real_name');
  232. $lists[$k]['task_title'] = Db::name('patrol_task')
  233. ->where('id', $v['patrol_task_id'])
  234. ->value('title');
  235. }
  236. //数据返回
  237. $totalCount = Db::name('patrol_record')->where($map)->count();
  238. $totalPage = ceil($totalCount/$length);
  239. $result['page'] = $page;
  240. $result['total'] = $totalPage;
  241. $result['records'] = $totalCount;
  242. $result['rows'] = $lists;
  243. return json($result);
  244. }else{
  245. $type = input('type',1);
  246. $t = Db::name('patrol_mode')
  247. ->where('id',$type)
  248. ->value('name');
  249. $this->assign('is_normal',$is_normal);
  250. $this->assign('type',$type);
  251. $this->assign('start',$start);
  252. $this->assign('end',$end);
  253. $this->assign('user_id',$user_id);
  254. $this->assign('meta_title',$t.'人员工作量统计');
  255. return $this->fetch();
  256. }
  257. }
  258. public function workList1(){
  259. $user_id = input('user_id','','trim');
  260. if($user_id!=''){
  261. $map[] = ['a.user_id','=',$user_id];
  262. }
  263. $is_normal = input('is_normal','','trim');
  264. if($is_normal!==''){
  265. if($is_normal==1){//总数
  266. $map[] = ['b.status','<>',6];
  267. }
  268. if($is_normal==2){//已完成
  269. $map[] = ['b.status','=',2];
  270. }
  271. }
  272. $type = input('type','','trim');
  273. if($type != ''){
  274. $map[] = ['b.patrol_mode','=',$type];
  275. }
  276. $start = input('start',date('Y-m-d', strtotime('' . date('Y-m-d') . ' -1 week')));
  277. if($start != ''){
  278. $map[] = ['b.start_time','>=',$start.' 00:00:00'];
  279. }
  280. $end = input('end', date('Y-m-d'));
  281. if($end != ''){
  282. $map[] = ['b.end_time','<=',$end.' 23:59:59'];
  283. }
  284. if(request()->isAjax()){
  285. //分页参数
  286. $length = input('rows',10,'intval'); //每页条数
  287. $page = input('page',1,'intval'); //第几页
  288. $start = ($page - 1) * $length; //分页开始位置
  289. $map[] = ['b.org_id','=',$this->orgId];
  290. $map= empty($map) ? true: $map;
  291. //数据查询
  292. $lists = Db::name('patrol_task_user')
  293. ->alias('a')
  294. ->join('patrol_task b','a.patrol_task_id=b.id')
  295. ->field('b.*,a.user_id')
  296. ->where($map)
  297. ->limit($start,$length)
  298. ->order('b.id','desc')
  299. ->select();
  300. foreach ($lists as $k=>$v){
  301. $lists[$k]['task_user'] = Db::name('user')
  302. ->where('id', $v['user_id'])->value('real_name');
  303. }
  304. //数据返回
  305. $totalCount = Db::name('patrol_task_user')
  306. ->alias('a')
  307. ->join('patrol_task b','a.patrol_task_id=b.id')->where($map)->count();
  308. $totalPage = ceil($totalCount/$length);
  309. $result['page'] = $page;
  310. $result['total'] = $totalPage;
  311. $result['records'] = $totalCount;
  312. $result['rows'] = $lists;
  313. return json($result);
  314. }else{
  315. $type = input('type',1);
  316. $t = Db::name('patrol_mode')
  317. ->where('id',$type)
  318. ->value('name');
  319. $this->assign('is_normal',$is_normal);
  320. $this->assign('type',$type);
  321. $this->assign('start',$start);
  322. $this->assign('end',$end);
  323. $this->assign('user_id',$user_id);
  324. $this->assign('meta_title',$t.'人员工作量统计');
  325. return $this->fetch();
  326. }
  327. }
  328. public function workExport() {
  329. $cur = date('Y-m-d');
  330. $start = input('start', date('Y-m-d', strtotime('' . $cur . ' -1 week')));
  331. $end = input('end', date('Y-m-d'));
  332. $start1 = $start . ' 00:00:00';
  333. $end1 = $end . ' 23:59:59';
  334. $type = input('type', 1);
  335. $ret = $this->workData($start1, $end1, $type);
  336. include_once env('root_path') . '/extend/phpexcel/Classes/PHPExcel.php';
  337. //实例化PHPExcel类
  338. $objPHPExcel = new \PHPExcel();
  339. //激活当前的sheet表
  340. $objPHPExcel->setActiveSheetIndex(0);
  341. //设置表格头(即excel表格的第一行)
  342. $objPHPExcel->setActiveSheetIndex(0)
  343. ->setCellValue('A1', 'ID')
  344. ->setCellValue('B1', '姓名')
  345. ->setCellValue('C1', '工作记录(总数)')
  346. ->setCellValue('D1', '工作记录(正常)')
  347. ->setCellValue('E1', '工作记录(异常)')
  348. ->setCellValue('F1', '完成率')
  349. ->setCellValue('G1', '需要完成')
  350. ->setCellValue('H1', '已完成');
  351. // 设置表格头水平居中
  352. $objPHPExcel->setActiveSheetIndex(0)->getStyle('A1')->getAlignment()
  353. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  354. $objPHPExcel->setActiveSheetIndex(0)->getStyle('B1')->getAlignment()
  355. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  356. $objPHPExcel->setActiveSheetIndex(0)->getStyle('C1')->getAlignment()
  357. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  358. //设置列水平居中
  359. $objPHPExcel->setActiveSheetIndex(0)->getStyle('A')->getAlignment()
  360. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  361. $objPHPExcel->setActiveSheetIndex(0)->getStyle('B')->getAlignment()
  362. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  363. $objPHPExcel->setActiveSheetIndex(0)->getStyle('C')->getAlignment()
  364. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  365. //设置单元格宽度
  366. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('A')->setWidth(10);
  367. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('B')->setWidth(20);
  368. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('C')->setWidth(20);
  369. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('D')->setWidth(20);
  370. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('E')->setWidth(20);
  371. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('F')->setWidth(20);
  372. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('G')->setWidth(20);
  373. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('H')->setWidth(20);
  374. //循环刚取出来的数组,将数据逐一添加到excel表格。
  375. for ($i = 0; $i < count($ret); $i++) {
  376. $objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 2), $ret[$i]['id']);
  377. $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $ret[$i]['title']);
  378. $objPHPExcel->getActiveSheet()->setCellValue('C' . ($i + 2), $ret[$i]['count']);
  379. $objPHPExcel->getActiveSheet()->setCellValue('D' . ($i + 2), $ret[$i]['count1']);
  380. $objPHPExcel->getActiveSheet()->setCellValue('E' . ($i + 2), $ret[$i]['count2']);
  381. $objPHPExcel->getActiveSheet()->setCellValue('F' . ($i + 2), $ret[$i]['wcl']);
  382. $objPHPExcel->getActiveSheet()->setCellValue('G' . ($i + 2), $ret[$i]['count4']);
  383. $objPHPExcel->getActiveSheet()->setCellValue('H' . ($i + 2), $ret[$i]['count3']);
  384. }
  385. $n = Db::name('patrol_mode')
  386. ->where('id', $type)
  387. ->value('name');
  388. //设置保存的Excel表格名称
  389. $filename = $n . '人员工作量统计_' . date('YmdHis', time()) . '.xls';
  390. //设置当前激活的sheet表格名称
  391. $objPHPExcel->getActiveSheet()->setTitle($n . '人员工作量统计');
  392. //设置浏览器窗口下载表格
  393. ob_end_clean();
  394. header("Content-Type: application/force-download");
  395. header("Content-Type: application/octet-stream");
  396. header("Content-Type: application/download");
  397. header('Content-Disposition:inline;filename="' . $filename);
  398. //生成excel文件
  399. $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
  400. //下载文件在浏览器窗口
  401. return $objWriter->save('php://output');
  402. }
  403. public function patrolList(){
  404. $patrol_addr_id = input('patrol_addr_id','','trim');
  405. if($patrol_addr_id!=''){
  406. $map[] = ['patrol_addr_id','=',$patrol_addr_id];
  407. }
  408. $is_normal = input('is_normal','','trim');
  409. if($is_normal!==''){
  410. $map[] = ['is_normal','=',$is_normal];
  411. }
  412. $type = input('type','','trim');
  413. if($type != ''){
  414. $map[] = ['patrol_mode','=',$type];
  415. }
  416. $start = input('start',date('Y-m-d', strtotime('' . date('Y-m-d') . ' -1 week')));
  417. if($start != ''){
  418. $map[] = ['create_time','>=',$start.' 00:00:00'];
  419. }
  420. $end = input('end', date('Y-m-d'));
  421. if($end != ''){
  422. $map[] = ['create_time','<=',$end.' 23:59:59'];
  423. }
  424. if(request()->isAjax()){
  425. //分页参数
  426. $length = input('rows',10,'intval'); //每页条数
  427. $page = input('page',1,'intval'); //第几页
  428. $start = ($page - 1) * $length; //分页开始位置
  429. //排序
  430. $sortRow = input('sidx','sort','trim'); //排序列
  431. $sort = input('sord','asc','trim'); //排序方式
  432. $order = $sortRow.' '.$sort.' ,id desc';
  433. $map[] = ['org_id','=',$this->orgId];
  434. $map= empty($map) ? true: $map;
  435. //数据查询
  436. $lists = Db::name('patrol_record')
  437. ->where($map)
  438. ->limit($start,$length)
  439. ->order($order)
  440. ->select();
  441. foreach ($lists as $k=>$v){
  442. $lists[$k]['address_title'] = Db::name('address')
  443. ->where('id', $v['patrol_addr_id'])
  444. ->value('title');
  445. $lists[$k]['task_user'] = Db::name('user')
  446. ->where('id', $v['user_id'])->value('real_name');
  447. $lists[$k]['task_title'] = Db::name('patrol_task')
  448. ->where('id', $v['patrol_task_id'])
  449. ->value('title');
  450. }
  451. //数据返回
  452. $totalCount = Db::name('patrol_record')->where($map)->count();
  453. $totalPage = ceil($totalCount/$length);
  454. $result['page'] = $page;
  455. $result['total'] = $totalPage;
  456. $result['records'] = $totalCount;
  457. $result['rows'] = $lists;
  458. return json($result);
  459. }else{
  460. $type = input('type',1);
  461. $t = Db::name('patrol_mode')
  462. ->where('id',$type)
  463. ->value('name');
  464. $this->assign('is_normal',$is_normal);
  465. $this->assign('type',$type);
  466. $this->assign('start',$start);
  467. $this->assign('end',$end);
  468. $this->assign('patrol_addr_id',$patrol_addr_id);
  469. $this->assign('meta_title',$t.'检查记录');
  470. return $this->fetch();
  471. }
  472. }
  473. public function orgList(){
  474. $sday = input('sday',date('Y-m-d',strtotime('-7 day')));
  475. $day = input('day',date('Y-m-d'));
  476. $patrolMode = input('patrolMode',2);
  477. $title = input('title','','trim');
  478. $lists = $this->orgListData($sday,$day,$patrolMode,$title);
  479. $this->assign('lists',$lists);
  480. $modeList = Db::name('patrol_mode')->select();
  481. foreach ($modeList as $k=>$v){
  482. if($v['id'] == 1){
  483. $modeList[$k]['name'] = '安保巡更';
  484. }elseif($v['id'] == 2){
  485. $modeList[$k]['name'] = '保洁巡视';
  486. }elseif($v['id'] == 3){
  487. $modeList[$k]['name'] = '总部巡查';
  488. }elseif($v['id'] == 4){
  489. $modeList[$k]['name'] = '设备巡检';
  490. }
  491. }
  492. $this->assign('modeList',$modeList);
  493. $this->assign('patrolMode',$patrolMode);
  494. $this->assign('title',$title);
  495. $this->assign('day',$day);
  496. $this->assign('sday',$sday);
  497. return $this->fetch();
  498. }
  499. public function orgListData($sday,$day,$patrolMode,$title){
  500. if($title !=''){
  501. $map[] = ['name','like','%'.$title.'%'];
  502. }
  503. $map[] = ['del','=',0];
  504. $lists = Db::name('org')
  505. ->where('type',1)
  506. ->where('enable',1)
  507. ->where($map)
  508. ->where('parent_id',1)
  509. ->field('id,name')
  510. ->select();
  511. $data = [];
  512. foreach ($lists as $k=>$v){
  513. $orgs = model('org')->getAllNextId($v['id']);
  514. $orgList = Db::name('org')
  515. ->where('del',0)
  516. ->where('enable',1)
  517. ->where('type',2)
  518. ->whereIn('id',$orgs)
  519. ->field('id,name')
  520. ->select();
  521. foreach ($orgList as $kk=>$vv){
  522. $count = Db::name('patrol_task')
  523. ->where('org_id',$vv['id'])
  524. ->where('create_yyyymmdd','>=',date('Ymd',strtotime($sday)))
  525. ->where('create_yyyymmdd','<=',date('Ymd',strtotime($day)))
  526. ->where('del',0)
  527. ->where('patrol_mode',$patrolMode)
  528. ->count();
  529. $status0 = Db::name('patrol_task')
  530. ->where('org_id',$vv['id'])
  531. ->where('create_yyyymmdd','>=',date('Ymd',strtotime($sday)))
  532. ->where('create_yyyymmdd','<=',date('Ymd',strtotime($day)))
  533. ->where('del',0)
  534. ->where('patrol_mode',$patrolMode)
  535. ->where('status',0)
  536. ->count();
  537. $status1 = Db::name('patrol_task')
  538. ->where('org_id',$vv['id'])
  539. ->where('create_yyyymmdd','>=',date('Ymd',strtotime($sday)))
  540. ->where('create_yyyymmdd','<=',date('Ymd',strtotime($day)))
  541. ->where('del',0)
  542. ->where('patrol_mode',$patrolMode)
  543. ->where('status',1)
  544. ->count();
  545. $status2 = Db::name('patrol_task')
  546. ->where('org_id',$vv['id'])
  547. ->where('create_yyyymmdd','>=',date('Ymd',strtotime($sday)))
  548. ->where('create_yyyymmdd','<=',date('Ymd',strtotime($day)))
  549. ->where('del',0)
  550. ->where('patrol_mode',$patrolMode)
  551. ->where('status',2)
  552. ->count();
  553. $status3 = Db::name('patrol_task')
  554. ->where('org_id',$vv['id'])
  555. ->where('create_yyyymmdd','>=',date('Ymd',strtotime($sday)))
  556. ->where('create_yyyymmdd','<=',date('Ymd',strtotime($day)))
  557. ->where('del',0)
  558. ->where('patrol_mode',$patrolMode)
  559. ->where('status','=',3)
  560. ->count();
  561. $prInfo = Db::name('patrol_record')
  562. ->alias('pr')
  563. ->join('patrol_task pt','pt.id=pr.patrol_task_id')
  564. ->join('user u','u.id=pr.user_id')
  565. ->where('pt.org_id',$vv['id'])
  566. ->where('pt.create_yyyymmdd','>=',date('Ymd',strtotime($sday)))
  567. ->where('pt.create_yyyymmdd','<=',date('Ymd',strtotime($day)))
  568. ->where('pt.del',0)
  569. ->where('pt.patrol_mode',$patrolMode)
  570. ->where('pt.status','=',2)
  571. ->field('u.real_name,pr.create_time')
  572. ->order('pr.id desc')
  573. ->find();
  574. $endTaskTime = $prInfo?$prInfo['create_time']:'';
  575. $user = $prInfo?$prInfo['real_name'] :'';
  576. $data[] = [
  577. 'area_name'=> $kk==0 ?$v['name']:'',
  578. 'org_name'=>$vv['name'],
  579. 'org_num'=>count($orgList),
  580. 'count'=>$count,
  581. 'status0'=>$status0,
  582. 'status1'=>$status1,
  583. 'status2'=>$status2,
  584. 'status3'=>$status3,
  585. 'mode'=>$patrolMode,
  586. 'sday'=>$sday,
  587. 'day'=>$day,
  588. 'end_task_time'=>$endTaskTime,
  589. 'user_name'=>$user,
  590. 'org_id'=>$vv['id'],
  591. ];
  592. }
  593. }
  594. return $data;
  595. }
  596. public function orgListExport(){
  597. $sday = input('sday',date('Y-m-d',strtotime('-7 day')));
  598. $day = input('day',date('Y-m-d'));
  599. $patrolMode = input('patrolMode',1);
  600. $title = input('title','','trim');
  601. $lists = $this->orgListData($sday,$day,$patrolMode,$title);
  602. set_time_limit(0);
  603. ini_set("memory_limit", "1024M");
  604. $n = Db::name('patrol_mode')
  605. ->where('id', $patrolMode)
  606. ->value('name');
  607. $title = $day.'-'. $n.'各项目统计';
  608. header("Content-type: application/vnd.ms-excel");
  609. header("Content-Type: application/force-download");
  610. header("Content-Disposition: attachment; filename=".$title.".xls");
  611. header('Expires:0');
  612. header('Pragma:public');
  613. $res = '';
  614. $res.='<table style="border-top: 1px solid #ddd;border-left: 1px solid #ddd;border-spacing: 0;">';
  615. $res.='<tr style="background: #ffffff;">';
  616. $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">区域名称</th>';
  617. $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">项目名称</th>';
  618. $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">任务数</th>';
  619. $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">未执行</th>';
  620. $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">执行中</th>';
  621. $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">已完成</th>';
  622. $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">未完成</th>';
  623. $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">最近任务完成时间</th>';
  624. $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">完成人员</th>';
  625. $res.='</tr>';
  626. foreach ($lists as $k=>$v){
  627. $res.='<tr style="background: #ffffff;">';
  628. if($v['area_name']){
  629. $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd" rowspan="'.$v['org_num'].'">'.$v['area_name'].'</td>';
  630. }
  631. $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v['org_name'].'</td>';
  632. $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v['count'].'</td>';
  633. $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v['status0'].'</td>';
  634. $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v['status1'].'</td>';
  635. $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v['status2'].'</td>';
  636. $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v['status3'].'</td>';
  637. $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v['end_task_time'].'</td>';
  638. $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v['user_name'].'</td>';
  639. $res.='</tr>';
  640. }
  641. echo $res;
  642. }
  643. public function orgListCopy(){
  644. if(request()->isAjax()){
  645. //分页参数
  646. $length = input('rows',10,'intval'); //每页条数
  647. $page = input('page',1,'intval'); //第几页
  648. $start = ($page - 1) * $length; //分页开始位置
  649. //排序
  650. $sortRow = input('sidx','id','trim'); //排序列
  651. $sort = input('sord','desc','trim'); //排序方式
  652. $order = $sortRow.' '.$sort;
  653. $day = input('day',date('Y-m-d'));
  654. $patrolMode = input('patrolMode',1);
  655. $lists = Db::name('org')
  656. ->where('type',2)
  657. ->where('enable',1)
  658. ->where('del',0)
  659. ->field('id,name')
  660. ->limit($start,$length)
  661. ->order($order)
  662. ->select();
  663. foreach ($lists as $k=>$v){
  664. $lists[$k]['count'] = Db::name('patrol_task')
  665. ->where('org_id',$v['id'])
  666. ->where('create_yyyymmdd',date('Ymd',strtotime($day)))
  667. ->where('del',0)
  668. ->where('patrol_mode',$patrolMode)
  669. ->count();
  670. $lists[$k]['status0'] = Db::name('patrol_task')
  671. ->where('org_id',$v['id'])
  672. ->where('create_yyyymmdd',date('Ymd',strtotime($day)))
  673. ->where('del',0)
  674. ->where('patrol_mode',$patrolMode)
  675. ->where('status',0)
  676. ->count();
  677. $lists[$k]['status1'] = Db::name('patrol_task')
  678. ->where('org_id',$v['id'])
  679. ->where('create_yyyymmdd',date('Ymd',strtotime($day)))
  680. ->where('del',0)
  681. ->where('patrol_mode',$patrolMode)
  682. ->where('status',1)
  683. ->count();
  684. $lists[$k]['status2'] = Db::name('patrol_task')
  685. ->where('org_id',$v['id'])
  686. ->where('create_yyyymmdd',date('Ymd',strtotime($day)))
  687. ->where('del',0)
  688. ->where('patrol_mode',$patrolMode)
  689. ->where('status',2)
  690. ->count();
  691. $lists[$k]['status3'] = Db::name('patrol_task')
  692. ->where('org_id',$v['id'])
  693. ->where('create_yyyymmdd',date('Ymd',strtotime($day)))
  694. ->where('del',0)
  695. ->where('patrol_mode',$patrolMode)
  696. ->where('status','=',3)
  697. ->count();
  698. $lists[$k]['mode'] = $patrolMode;
  699. $lists[$k]['day'] = $day;
  700. }
  701. //数据返回
  702. $totalCount = Db::name('org')
  703. ->where('type',2)
  704. ->where('enable',1)
  705. ->where('del',0)
  706. ->count();
  707. $totalPage = ceil($totalCount/$length);
  708. $result['page'] = $page;
  709. $result['total'] = $totalPage;
  710. $result['records'] = $totalCount;
  711. $result['rows'] = $lists;
  712. return json($result);
  713. }else{
  714. $modeList = Db::name('patrol_mode')->select();
  715. $this->assign('modeList',$modeList);
  716. $this->assign('day',input('day',date('Y-m-d')));
  717. return $this->fetch();
  718. }
  719. }
  720. public function patrolTaskList(){
  721. $sday = input('sday');
  722. $day = input('day');
  723. $mode = input('mode');
  724. $status = input('status');
  725. $orgId= input('orgId');
  726. if(request()->isAjax()){
  727. //分页参数
  728. $length = input('rows',10,'intval'); //每页条数
  729. $page = input('page',1,'intval'); //第几页
  730. $start = ($page - 1) * $length; //分页开始位置
  731. //排序
  732. $sortRow = input('sidx','sort','trim'); //排序列
  733. $sort = input('sord','asc','trim'); //排序方式
  734. $order = $sortRow.' '.$sort.' ,id desc';
  735. if($status > -1){
  736. $map[] = ['status','=',$status];
  737. }
  738. $map[] = ['create_yyyymmdd','>=',date('Ymd',strtotime($sday))];
  739. $map[] = ['create_yyyymmdd','<=',date('Ymd',strtotime($day))];
  740. $map[] = ['org_id','=',$orgId];
  741. $map[] = ['patrol_mode','=',$mode];
  742. $map[] = ['del','=',0];
  743. $map= empty($map) ? true: $map;
  744. //数据查询
  745. $lists = Db::name('patrol_task')
  746. ->where($map)
  747. ->limit($start,$length)
  748. ->order($order)
  749. ->select();
  750. foreach ($lists as $k=>$v){
  751. $lists[$k]['start_time'] = date('Y-m-d H:i',strtotime($v['start_time']));
  752. $lists[$k]['end_time'] = date('Y-m-d H:i',strtotime($v['end_time']));
  753. $taskUser=Db::name('patrol_task_user')
  754. ->alias('ptu')
  755. ->field('u.real_name')
  756. ->join('user u','u.id=ptu.user_id')
  757. ->where('ptu.patrol_task_id',$v['id'])
  758. ->column('real_name');
  759. $lists[$k]['task_user']=$taskUser?implode(',',$taskUser):'';
  760. }
  761. //数据返回
  762. $totalCount = Db::name('patrol_task')->where($map)->count();
  763. $totalPage = ceil($totalCount/$length);
  764. $result['page'] = $page;
  765. $result['total'] = $totalPage;
  766. $result['records'] = $totalCount;
  767. $result['rows'] = $lists;
  768. return json($result);
  769. }else{
  770. $this->assign('day',$day);
  771. $this->assign('sday',$sday);
  772. $this->assign('mode',$mode);
  773. $this->assign('status',$status);
  774. $this->assign('orgId',$orgId);
  775. return $this->fetch();
  776. }
  777. }
  778. public function orgOver(){
  779. $start = input('start', '');
  780. $end = input('end','');
  781. $mode = input('mode',2);
  782. if($start){
  783. $map[] = ['create_yyyymmdd','>=',date('Ymd',strtotime($start))];
  784. }
  785. if($end){
  786. $map[] = ['create_yyyymmdd','<=',date('Ymd',strtotime($end))];
  787. }
  788. $map[] = ['del','=',0];
  789. $list = Db::name('org')
  790. ->where('del',0)
  791. ->where('enable',1)
  792. ->where('type',2)
  793. ->select();
  794. $y = $y1 = $y2 = [];
  795. foreach ($list as $k=>$v){
  796. $list[$k]['y'] = Db::name('patrol_task')
  797. ->where($map)
  798. ->where('org_id',$v['id'])
  799. ->where('patrol_mode',$mode)
  800. ->count();
  801. $list[$k]['y1'] = Db::name('patrol_task')
  802. ->where($map)
  803. ->where('org_id',$v['id'])
  804. ->where('patrol_mode',$mode)
  805. ->where('status',2)
  806. ->count();
  807. $list[$k]['y2'] = Db::name('patrol_task')
  808. ->where($map)
  809. ->where('org_id',$v['id'])
  810. ->where('patrol_mode',$mode)
  811. ->where('status',3)
  812. ->count();
  813. }
  814. $list = list_sort_by($list,'y','asc');
  815. $this->assign('x',array_column($list,'name'));
  816. $this->assign('y',array_column($list,'y'));
  817. $this->assign('y1',array_column($list,'y1'));
  818. $this->assign('y2',array_column($list,'y2'));
  819. $modeList = Db::name('patrol_mode')->select();
  820. foreach ($modeList as $k=>$v){
  821. if($v['id'] == 1){
  822. $modeList[$k]['name'] = '安保巡更';
  823. }elseif($v['id'] == 2){
  824. $modeList[$k]['name'] = '保洁巡视';
  825. }elseif($v['id'] == 3){
  826. $modeList[$k]['name'] = '总部巡查';
  827. }elseif($v['id'] == 4){
  828. $modeList[$k]['name'] = '设备巡检';
  829. }
  830. }
  831. $this->assign('modeList',$modeList);
  832. $this->assign('mode', $mode);
  833. $this->assign('start', $start);
  834. $this->assign('end', $end);
  835. return $this->fetch();
  836. }
  837. public function areaDay(){
  838. $map[] = ['del','=',0];
  839. $map[] = ['create_yyyymmdd','=',date('Ymd')];
  840. $list = Db::name('org')
  841. ->field('id,name')
  842. ->where('del',0)
  843. ->where('enable',1)
  844. ->where('type',1)
  845. ->where('parent_id',1)
  846. ->select();
  847. foreach ($list as $k=>$v){
  848. $orgs = model('org')->getAllNextId($v['id']);
  849. // $y = Db::name('patrol_task')
  850. // ->where($map)
  851. // ->whereIn('org_id',$orgs)
  852. // ->where('patrol_mode',2)
  853. // ->count();
  854. $y1 = Db::name('patrol_task')
  855. ->where($map)
  856. ->whereIn('org_id',$orgs)
  857. ->where('patrol_mode',2)
  858. ->where('status',2)
  859. ->count();
  860. $list[$k]['value'] = $y1;
  861. }
  862. $this->assign('list',$list);
  863. return $this->fetch();
  864. }
  865. public function ztqk(){
  866. $map[] = ['del','=',0];
  867. $map[] = ['create_yyyymmdd','=',date('Ymd')];
  868. $list = Db::name('org')
  869. ->field('id,name')
  870. ->where('del',0)
  871. ->where('enable',1)
  872. ->where('type',1)
  873. ->where('parent_id',1)
  874. ->select();
  875. foreach ($list as $k=>$v){
  876. $orgs = model('org')->getAllNextId($v['id']);
  877. // $y = Db::name('patrol_task')
  878. // ->where($map)
  879. // ->whereIn('org_id',$orgs)
  880. // ->where('patrol_mode',2)
  881. // ->count();
  882. $y1 = Db::name('patrol_task')
  883. ->where($map)
  884. ->whereIn('org_id',$orgs)
  885. ->where('patrol_mode',2)
  886. ->where('status',2)
  887. ->count();
  888. $list[$k]['value'] = $y1;
  889. }
  890. $this->assign('list',$list);
  891. $month = [];
  892. for ($i=1;$i<=12;$i++){
  893. $t = $i;
  894. if($i< 10){
  895. $t = '0'.$i;
  896. }
  897. $month[] = $t;
  898. }
  899. $year = date('Y');
  900. $y = [];
  901. foreach ($month as $k=>$v){
  902. $y[] = Db::name('patrol_task')
  903. ->where('create_yyyymm',$year.$v)
  904. ->whereIn('org_id',$this->orgId)
  905. ->where('patrol_mode',2)
  906. ->where('status',2)
  907. ->count();
  908. }
  909. $this->assign('x',$month);
  910. $this->assign('y',$y);
  911. return $this->fetch();
  912. }
  913. public function monthOver(){
  914. $month = [];
  915. for ($i=1;$i<=12;$i++){
  916. $t = $i;
  917. if($i< 10){
  918. $t = '0'.$i;
  919. }
  920. $month[] = $t;
  921. }
  922. $year = date('Y');
  923. $y = [];
  924. foreach ($month as $k=>$v){
  925. $y[] = Db::name('patrol_task')
  926. ->where('create_yyyymm',$year.$v)
  927. ->whereIn('org_id',$this->orgId)
  928. ->where('patrol_mode',2)
  929. ->where('status',2)
  930. ->count();
  931. }
  932. $this->assign('x',$month);
  933. $this->assign('y',$y);
  934. return $this->fetch();
  935. }
  936. }