Patrol.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742
  1. <?php
  2. namespace app\api\controller\screen;
  3. use app\common\model\User;
  4. use app\hander\HelpHander;
  5. use app\api\controller\screen\Index;
  6. use think\Db;
  7. class Patrol extends Index
  8. {
  9. public function patrolNums(){
  10. $mode = input('mode');
  11. if(!in_array($mode,[1,2,3,4])){
  12. HelpHander::error('参数错误');
  13. }
  14. if($mode == 1){
  15. $c = 3;
  16. }elseif ($mode == 2){
  17. $c = 4;
  18. }elseif ($mode == 3){
  19. $c = 5;
  20. }elseif ($mode == 4){
  21. $c = 6;
  22. }
  23. $addr = Db::name('address')
  24. ->where('del',0)
  25. ->where('enable',1)
  26. ->where('org_id',$this->orgId)
  27. ->where('','exp',Db::raw("FIND_IN_SET($c,types)"))
  28. ->count('id');
  29. $user = Db::name('patrol_task_user')
  30. ->alias('ptu')
  31. ->join('patrol_task pt','pt.id=ptu.patrol_task_id')
  32. ->join('user u','u.id=ptu.user_id')
  33. ->where('pt.del',0)
  34. ->where('pt.org_id',$this->orgId)
  35. ->where('pt.patrol_mode',$mode)
  36. ->where('pt.status','in',[0,1,2,3])
  37. ->where('u.del',0)
  38. ->group('ptu.user_id')
  39. ->count();
  40. $task = Db::name('patrol_task')->where('org_id',$this->orgId)->where('del',0)->where('patrol_mode',$mode)->count();
  41. $data = [
  42. 'addrCount'=>$addr,
  43. 'userCount'=>$user,
  44. 'taskCount'=>$task,
  45. ];
  46. HelpHander::success($data);
  47. }
  48. //最新的一条巡更内容
  49. public function patrolPath(){
  50. $mode = input('mode');
  51. if(!in_array($mode,[1,2,3,4])){
  52. HelpHander::error('参数错误');
  53. }
  54. $record = Db::name('patrol_record')
  55. ->alias('pr')
  56. ->field('pr.*')
  57. ->join('patrol_task pt','pt.id=pr.patrol_task_id')
  58. ->where('pr.org_id',$this->orgId)
  59. ->where('pt.patrol_mode',$mode)
  60. ->where('pt.del',0)
  61. ->where('pt.status',1)
  62. ->order('pr.id desc')
  63. ->find();
  64. $addrList =[];
  65. if(isset($record) && !empty($record)){
  66. $record['addr'] = Db::name('address')->where('id',$record['patrol_addr_id'])->value('title');
  67. $record['user'] = Db::name('user')->where('id',$record['user_id'])->value('real_name');
  68. $record['task'] = Db::name('patrol_task')->where('id',$record['patrol_task_id'])->value('title');
  69. $addrList = Db::name('patrol_task_addr')
  70. ->alias('pta')
  71. ->field('a.id,a.title')
  72. ->join('patrol_addr_form paf','paf.id=pta.patrol_form_id')
  73. ->join('address a','a.id=paf.patrol_addr_id')
  74. ->where('pta.patrol_task_id',$record['patrol_task_id'])
  75. ->where('a.del',0)
  76. ->select();
  77. if($addrList){
  78. foreach ($addrList as $k=>$v){
  79. $addrList[$k]['nums'] = Db::name('patrol_record')
  80. ->where('org_id',$this->orgId)
  81. ->where('patrol_addr_id',$v['id'])
  82. ->count();
  83. $active = 0;
  84. if($v['id'] == $record['patrol_addr_id']){
  85. $active = 1;
  86. }
  87. $addrList[$k]['active'] = $active;
  88. $times = Db::name('patrol_record')
  89. ->field('create_time')
  90. ->where('org_id',$this->orgId)
  91. ->where('patrol_addr_id',$v['id'])
  92. ->select();
  93. $eDate = '无';
  94. foreach ($times as $kk=>$vv){
  95. $date = isset($times[1]['create_time'])&&!empty($times[1]['create_time'])?$times[1]['create_time']:'';
  96. $eDate = !empty($date)?date('H:i',strtotime($date)):'无';
  97. }
  98. $addrList[$k]['time'] = $eDate;
  99. }
  100. }
  101. }
  102. $data = [
  103. 'record' => $record,
  104. 'addrList' => $addrList,
  105. ];
  106. HelpHander::success($data);
  107. }
  108. //实时信息总览
  109. public function patrolRealTime(){
  110. $mode = input('mode');
  111. if(!in_array($mode,[1,2,3,4])){
  112. HelpHander::error('参数错误');
  113. }
  114. $lists = Db::name('patrol_record')
  115. ->where('patrol_mode',$mode)
  116. ->where('org_id',$this->orgId)
  117. ->order('id desc')
  118. ->limit(20)
  119. ->select();
  120. $data = [];
  121. foreach ($lists as $k=>$v){
  122. $addrForm = Db::name('patrol_addr_form')
  123. ->alias('a')
  124. ->join('patrol_task_addr b','b.patrol_form_id = a.id')
  125. ->where('b.id',$v['patrol_addr_form_id'])
  126. ->value('a.title');
  127. $mode = Db::name('patrol_mode')
  128. ->where('id',$v['patrol_mode'])
  129. ->value('name');
  130. $user = Db::name('user')->where('id',$v['user_id'])->value('real_name');
  131. $is_normal = '无异常' ;
  132. // if($v['is_normal'] == 1){
  133. // $is_normal = '有异常' ;
  134. // }
  135. $isno = 1;
  136. $checkJson = json_decode($v['check_json'],true);
  137. foreach ($checkJson as $kk=>$vv) {
  138. if (isset($vv['forms'])) {
  139. foreach ($vv['forms'] as $kkk => $vvv) {
  140. if (isset($vvv['status']) && $vvv['status'] == 0 && $isno == 1) {
  141. $is_normal = '有异常';
  142. $isno = 0;
  143. break;
  144. }
  145. }
  146. }
  147. }
  148. $time = date('Y-m-d H:i',strtotime($v['create_time']));
  149. $content = '员工-'.$user.'完成'.$addrForm.$mode.','.$is_normal;
  150. $data[$k][] = $time;
  151. $data[$k][] = $content;
  152. }
  153. HelpHander::success($data);
  154. }
  155. //异常地点数据总览
  156. public function patrolNormalAddr(){
  157. $mode = input('mode');
  158. if(!in_array($mode,[1,2,3,4])){
  159. HelpHander::error('参数错误');
  160. }
  161. $lists = Db::name('patrol_record')
  162. ->where('org_id',$this->orgId)
  163. // ->where('is_normal',1)
  164. ->where('patrol_mode',$mode)
  165. ->order('id desc')
  166. ->limit(20)
  167. ->select();
  168. $data = [];
  169. foreach ($lists as $k=>$v){
  170. $addr = Db::name('address')->where('id',$v['patrol_addr_id'])
  171. ->value('title');
  172. $user = Db::name('user')->where('id',$v['user_id'])->value('real_name');
  173. $is_normal = '正常' ;
  174. // if($v['is_normal'] == 1){
  175. // $is_normal = '异常' ;
  176. // }
  177. $isno = 1;
  178. $checkJson = json_decode($v['check_json'],true);
  179. foreach ($checkJson as $kk=>$vv) {
  180. if (isset($vv['forms'])) {
  181. foreach ($vv['forms'] as $kkk => $vvv) {
  182. if (isset($vvv['status']) && $vvv['status'] == 0 && $isno == 1) {
  183. $is_normal = '异常';
  184. $isno = 0;
  185. break;
  186. }
  187. }
  188. }
  189. }
  190. $data[$k][] = $addr;
  191. $data[$k][] = $user;
  192. $data[$k][] = $v['create_time'];
  193. $data[$k][] = $is_normal;
  194. $data[$k][] = $v['content'];
  195. }
  196. HelpHander::success($data);
  197. }
  198. //获取今天最新一条巡更记录
  199. public function newestRecord(){
  200. $info = Db::name('patrol_record')
  201. ->alias('a')
  202. ->join('patrol_task t','a.patrol_task_id = t.id')
  203. ->join('address b','a.patrol_addr_id = b.id')
  204. ->join('user c','a.user_id = c.id')
  205. ->where('a.create_yyyymmdd',date('Ymd'))
  206. ->where('a.org_id',$this->orgId)
  207. ->field('a.images,a.create_time,b.title as address,c.real_name as name,t.title as content')
  208. ->order('a.id desc')
  209. ->find();
  210. $img = $info['images']?(explode(',',$info['images']))[0]:'';
  211. if(!$info){
  212. HelpHander::error('错误');
  213. }
  214. $info['img'] = $img;
  215. HelpHander::success($info);
  216. }
  217. // 可视化轨迹展示
  218. public function patrolRecord(){
  219. $lists = Db::name('patrol_record')
  220. ->alias('a')
  221. ->join('patrol_task t','a.patrol_task_id = t.id')
  222. ->join('address b','a.patrol_addr_id = b.id')
  223. ->join('user c','a.user_id = c.id')
  224. // ->where('a.create_yyyymmdd',date('Ymd'))
  225. ->where('a.org_id',$this->orgId)
  226. ->field('a.images,a.create_time,b.title as address,c.real_name as name,a.content')
  227. ->order('a.id desc')
  228. ->limit(20)
  229. ->select();
  230. $lists = $lists?$lists:[];
  231. $imgs = [];
  232. $record = [];
  233. foreach ($lists as $k=>$v){
  234. $img = $v['images']?(explode(',',$v['images']))[0]:'';
  235. if($img && count($imgs) < 3){
  236. $imgs[] = [
  237. 'title' => $v['address'],
  238. 'img' => $img
  239. ];
  240. }
  241. $record[] = [$v['address'],$v['create_time'],$v['name'],$v['content']];
  242. }
  243. HelpHander::success(['imgs' => $imgs,'lists' => $record]);
  244. }
  245. // 巡更任务数据统计 当天及30天异常数量
  246. public function addrRecord(){
  247. //先取30内的巡更地点
  248. $curDay = date('Ymd');
  249. $start = date('Ymd',strtotime(date('Y-m-d')) - 29*24*60*60);
  250. $lists = Db::name('patrol_record')
  251. ->alias('pr')
  252. ->join('address a','a.id = pr.patrol_addr_id')
  253. ->where('pr.org_id',$this->orgId)
  254. ->where('pr.patrol_mode',1)
  255. ->where('pr.create_yyyymmdd','<=',$curDay)
  256. ->where('pr.create_yyyymmdd','>=',$start)
  257. ->field('a.id,a.title')
  258. ->group('pr.patrol_addr_id')
  259. ->distinct(true)
  260. ->select();
  261. $titles = [];
  262. $y1 = [];
  263. $y2 = [];
  264. foreach ($lists as $k=>$v){
  265. $titles[] = $v['title'];
  266. $count1 = Db::name('patrol_record')
  267. ->where('org_id',$this->orgId)
  268. ->where('patrol_mode',1)
  269. ->where('create_yyyymmdd','=',$curDay)
  270. ->count();
  271. $y1[] = $count1;
  272. $count2 = Db::name('patrol_record')
  273. ->where('org_id',$this->orgId)
  274. ->where('patrol_mode',1)
  275. ->where('is_normal',1)
  276. ->where('create_yyyymmdd','<=',$curDay)
  277. ->where('create_yyyymmdd','>=',$start)
  278. ->count();
  279. $y2[] = $count2;
  280. }
  281. HelpHander::success(['titles' => $titles,'y1' => $y1,'y2' => $y2]);
  282. }
  283. //巡*图片
  284. public function patrolImg(){
  285. $data = Db::name('patrol_record')
  286. ->field('images')
  287. ->where('images','<>','')
  288. ->where('org_id',$this->orgId)
  289. ->limit(30)
  290. ->order('id desc')
  291. ->select();
  292. foreach ($data as $k=>$v){
  293. $img = explode(',',$v['images']);
  294. if($img){
  295. $data[$k]['images'] = $img[0];
  296. }
  297. }
  298. if(count($data)>3){
  299. $key = array_rand($data,4);
  300. $list[] = $data[$key[0]];
  301. $list[] = $data[$key[1]];
  302. $list[] = $data[$key[2]];
  303. $list[] = $data[$key[3]];
  304. }
  305. $eList = isset($list)?$list:$data;
  306. HelpHander::success($eList);
  307. }
  308. //
  309. public function patrolRecordCount(){
  310. $dlist = [
  311. date('Y-m-d',strtotime('-6 days')),
  312. date('Y-m-d',strtotime('-5 days')),
  313. date('Y-m-d',strtotime('-4 days')),
  314. date('Y-m-d',strtotime('-3 days')),
  315. date('Y-m-d',strtotime('-2 days')),
  316. date('Y-m-d',strtotime('-1 days')),
  317. date('Y-m-d'),
  318. ];
  319. $date = [];
  320. $yCount = [];
  321. $y2Count = [];
  322. $y3Count = [];
  323. $y4Count = [];
  324. foreach ($dlist as $k=>$v){
  325. $tt = date('Ymd',strtotime($v));
  326. $count = Db::name('patrol_record')
  327. ->where('create_yyyymmdd',$tt)
  328. ->where('org_id',$this->orgId)
  329. ->where('patrol_mode',4)
  330. ->count();
  331. $count2 =Db::name('patrol_record')
  332. ->where('create_yyyymmdd',$tt)
  333. ->where('org_id',$this->orgId)
  334. ->where('patrol_mode',2)
  335. ->count();
  336. $count3 =Db::name('patrol_record')
  337. ->where('create_yyyymmdd',$tt)
  338. ->where('patrol_mode',3)
  339. ->where('org_id',$this->orgId)
  340. ->count();
  341. $count4 =Db::name('patrol_record')
  342. ->where('create_yyyymmdd',$tt)
  343. ->where('patrol_mode',1)
  344. ->count();
  345. $date[] = date('m-d',strtotime($v));
  346. $yCount[] = $count;
  347. $y2Count[] = $count2;
  348. $y3Count[] = $count3;
  349. $y4Count[] = $count4;
  350. }
  351. $data = [
  352. 'date'=>$date,
  353. 'count1'=>$yCount,
  354. 'count2'=>$y2Count,
  355. 'count3'=>$y3Count,
  356. 'count4'=>$y4Count,
  357. ];
  358. HelpHander::success($data);
  359. }
  360. public function countData(){
  361. $task = Db::name('patrol_task')
  362. ->where('org_id',$this->orgId)
  363. ->where('del',0)
  364. ->where('patrol_mode',2)
  365. ->where('create_yyyymmdd',date('Ymd'))
  366. ->count();
  367. $task1 = Db::name('patrol_task')
  368. ->where('org_id',$this->orgId)
  369. ->where('del',0)
  370. ->where('patrol_mode',2)
  371. ->where('create_yyyymmdd',date('Ymd'))
  372. ->where('status',2)
  373. ->count();
  374. $task2 = Db::name('patrol_task')
  375. ->where('org_id',$this->orgId)
  376. ->where('del',0)
  377. ->where('patrol_mode',2)
  378. ->where('create_yyyymmdd',date('Ymd'))
  379. ->where('status',0)
  380. ->count();
  381. $task3 = Db::name('patrol_task')
  382. ->where('org_id',$this->orgId)
  383. ->where('del',0)
  384. ->where('patrol_mode',2)
  385. ->where('create_yyyymmdd',date('Ymd'))
  386. ->where('status',1)
  387. ->count();
  388. $bl = '0';
  389. if($task > 0 ){
  390. $bl = round($task1/$task*100,1);
  391. }
  392. //$addrCount = model('Address')->getListByTypeCount(4,$this->orgId);
  393. $addrCount = Db::name('patrol_task')
  394. ->alias('pr')
  395. ->leftJoin('patrol_task_addr b','pr.id=b.patrol_task_id')
  396. ->where('pr.org_id',$this->orgId)
  397. ->where('pr.del',0)
  398. ->where('pr.patrol_mode',2)
  399. ->where('pr.create_yyyymmdd',date('Ymd'))
  400. ->group('b.address_id')
  401. ->count();
  402. $fg = Db::name('patrol_record')
  403. ->alias('pr')
  404. ->join('address a','a.id=pr.patrol_addr_id')
  405. ->where('pr.org_id',$this->orgId)
  406. ->where('a.del',0)
  407. ->where('a.enable',1)
  408. ->where('pr.patrol_mode',2)
  409. ->where('pr.create_yyyymmdd',date('Ymd'))
  410. ->group('pr.patrol_addr_id')
  411. ->count();
  412. $fgbl = '0';
  413. if($addrCount > 0 ){
  414. $fgbl = round($fg/$addrCount*100,1);
  415. }
  416. $data = [
  417. 'task'=>$task,
  418. 'task1'=>$task1,
  419. 'task2'=>$task2,
  420. 'task3'=>$task3,
  421. 'bl'=>$bl,
  422. 'addr'=>$addrCount,
  423. 'addr1'=>$fg,
  424. 'addrbl'=>$fgbl,
  425. ];
  426. HelpHander::success($data);
  427. }
  428. public function bjxsMonthData(){
  429. $mode = input('mode',2);
  430. $year = date('Y');
  431. $month = date('m');
  432. $t = date('t',time());
  433. $x = $dayList = [];
  434. for ($i=1;$i<=$t;$i++){
  435. $d = $i;
  436. if($i < 10){
  437. $d = '0'.$i;
  438. }
  439. $dayList[] = $year.$month.$d;
  440. $x[] = $month.'-'.$d;
  441. }
  442. $y = $y1 = $y2 = [];
  443. foreach ($dayList as $k=>$v){
  444. $count = Db::name('patrol_task')
  445. ->where('del',0)
  446. ->where('org_id',$this->orgId)
  447. ->where('patrol_mode',$mode)
  448. ->where('create_yyyymmdd',$v)
  449. ->count();
  450. $wc = Db::name('patrol_task')
  451. ->where('del',0)
  452. ->where('org_id',$this->orgId)
  453. ->where('patrol_mode',$mode)
  454. ->where('create_yyyymmdd',$v)
  455. ->where('status',2)
  456. ->count();
  457. $bl = 0 ;
  458. if($count > 0){
  459. $bl = round($wc/$count*100,1);
  460. }
  461. $y[] = $bl;
  462. $y1[] = $count;
  463. $y2[] = $wc;
  464. }
  465. HelpHander::success(['x'=>$x,'y'=>$y,'y1'=>$y1,'y2'=>$y2]);
  466. }
  467. public function bjxsTaskRecord(){
  468. $mode = input('mode',2);
  469. $record = Db::name('patrol_record')
  470. ->where('org_id',$this->orgId)
  471. ->where('patrol_mode',$mode)
  472. ->where('create_yyyymmdd',date('Ymd'))
  473. ->order('id desc')
  474. ->limit(20)
  475. ->select();
  476. $rList = [];
  477. foreach ($record as $k=>$v){
  478. $task = Db::name('patrol_task')->where('id',$v['patrol_task_id'])->value('title');
  479. $addr = Db::name('address')->where('id',$v['patrol_addr_id'])->value('title');
  480. $status = $v['is_normal'] == 0 ? '正常':'异常';
  481. $user = Db::name('user')->where('id',$v['user_id'])->value('real_name');
  482. $time = date('H:i',strtotime($v['create_time']));
  483. $rList[] =[$v['id'],$task,$addr,$status,$user,$time];
  484. }
  485. $task = Db::name('patrol_task')
  486. ->where('del',0)
  487. ->where('org_id',$this->orgId)
  488. ->where('patrol_mode',$mode)
  489. ->where('create_yyyymmdd',date('Ymd'))
  490. ->where('status','in',[0,1,2,3])
  491. ->order('id desc')
  492. ->limit(20)
  493. ->select();
  494. $tList = [];
  495. foreach ($task as $k=>$v){
  496. $users = Db::name('patrol_task_user')
  497. ->alias('ptu')
  498. ->join('user u','u.id=ptu.user_id')
  499. ->where('ptu.patrol_task_id',$v['id'])
  500. ->where('u.del',0)
  501. ->column('u.real_name');
  502. $userNames = $users ? implode(',',$users):'';
  503. $st = date('H:i',strtotime($v['start_time']));
  504. $et = date('H:i',strtotime($v['end_time']));
  505. $statusTxt = $remark = '';
  506. if($v['status'] == 0){
  507. $statusTxt = '未执行';
  508. $etime = strtotime($v['end_time']);
  509. $time = time();
  510. $xctime = $etime - $time;
  511. $fz = round($xctime/60);
  512. // if($fz > 0 && $fz < 10){
  513. // $remark = '<span style="color:#FF3939 ">'.$fz.'分钟后超时</span>';
  514. // }
  515. // if($fz > 10 && $fz < 30){
  516. // $remark = '<span style="color:#FF9600 ">'.$fz.'分钟后超时</span>';
  517. // }
  518. // if($fz > 30){
  519. // $remark = '<span style="color:#FFFC1E ">'.$fz.'分钟后超时</span>';
  520. // }
  521. // if($fz <0){
  522. // $remark = '<span style="color: red">已超时</span>';
  523. // }
  524. }elseif ($v['status'] == 1){
  525. $statusTxt = '执行中';
  526. }elseif ($v['status'] == 2){
  527. $statusTxt = '已完成';
  528. }elseif ($v['status'] == 3){
  529. $statusTxt = '未完成';
  530. }
  531. $tList[] = [$v['id'],$v['title'],$userNames,$st,$et,$statusTxt];
  532. }
  533. $wzz = Db::name('patrol_task')
  534. ->where('del',0)
  535. ->where('org_id',$this->orgId)
  536. ->where('patrol_mode',$mode)
  537. ->where('create_yyyymmdd',date('Ymd'))
  538. ->where('status',0)
  539. ->count();
  540. $zxz = Db::name('patrol_task')
  541. ->where('del',0)
  542. ->where('org_id',$this->orgId)
  543. ->where('patrol_mode',$mode)
  544. ->where('create_yyyymmdd',date('Ymd'))
  545. ->where('status',1)
  546. ->count();
  547. $wwc = Db::name('patrol_task')
  548. ->where('del',0)
  549. ->where('org_id',$this->orgId)
  550. ->where('patrol_mode',$mode)
  551. ->where('create_yyyymmdd',date('Ymd'))
  552. ->where('status',3)
  553. ->count();
  554. $data = [
  555. 'rlist'=>$rList,
  556. 'tlist'=>$tList,
  557. 'wzz'=>$wzz,
  558. 'zxz'=>$zxz,
  559. 'wwc'=>$wwc,
  560. ];
  561. HelpHander::success($data);
  562. }
  563. public function patrolImg2(){
  564. $mode = input('mode',2);
  565. $data = Db::name('patrol_record')
  566. ->field('images,patrol_addr_id')
  567. ->where('images','<>','')
  568. ->where('org_id',$this->orgId)
  569. ->where('patrol_mode',$mode)
  570. ->limit(30)
  571. ->order('id desc')
  572. ->select();
  573. foreach ($data as $k=>$v){
  574. $img = explode(',',$v['images']);
  575. if($img){
  576. $data[$k]['images'] = $img[0];
  577. }
  578. $data[$k]['addr'] = Db::name('address')->where('id',$v['patrol_addr_id'])->value('title');
  579. }
  580. if(count($data)>6){
  581. $key = array_rand($data,6);
  582. $list[] = $data[$key[0]];
  583. $list[] = $data[$key[1]];
  584. $list[] = $data[$key[2]];
  585. $list[] = $data[$key[3]];
  586. $list[] = $data[$key[4]];
  587. $list[] = $data[$key[5]];
  588. }
  589. $eList = isset($list)?$list:$data;
  590. HelpHander::success($eList);
  591. }
  592. public function zgImg(){
  593. $orders = Db::name('orders')
  594. ->alias('a')
  595. ->join('todo b','a.id=b.order_id')
  596. ->field('a.images as oImages,b.images as tImages,a.create_time,b.done_time')
  597. ->where('a.images','<>','')
  598. ->where('b.images','<>','')
  599. ->where('a.org_id',$this->orgId)
  600. ->where('a.del',0)
  601. ->where('a.work_type_mode',2)
  602. ->where('a.order_mode','in',[5,6])
  603. ->limit(30)
  604. ->order('a.id desc')
  605. ->select();
  606. $img = [];
  607. foreach ($orders as $k=>$v){
  608. $oImages = explode(',',$v['oImages']);
  609. $tImages = explode(',',$v['tImages']);
  610. $img[$k]= ['img'=>[$oImages[0],$tImages[0]],'time'=>[date('Y-m-d H:i',strtotime($v['create_time'])),date('Y-m-d H:i',strtotime($v['done_time']))]];
  611. }
  612. $list = [];
  613. if(count($img)>3){
  614. $key = array_rand($img,3);
  615. foreach ($key as $k=>$v){
  616. $list[] =['images'=>$img[$v]['img'],'time'=>$img[$v]['time']];
  617. }
  618. }else{
  619. foreach ($img as $k=>$v){
  620. $list[] =['images'=>$v['img'],'time'=>$v['time']];
  621. }
  622. }
  623. $eList = $list;
  624. HelpHander::success($eList);
  625. }
  626. public function zgImgbak(){
  627. $orders = Db::name('orders')
  628. ->field('images')
  629. ->where('images','<>','')
  630. ->where('org_id',$this->orgId)
  631. ->where('del',0)
  632. ->where('work_type_mode',2)
  633. ->limit(10)
  634. ->order('id desc')
  635. ->select();
  636. foreach ($orders as $k=>$v){
  637. $img = explode(',',$v['images']);
  638. if($img){
  639. $orders[$k]['images'] = $img[0];
  640. }
  641. }
  642. $todo = Db::name('todo')
  643. ->field('images')
  644. ->where('images','<>','')
  645. ->where('org_id',$this->orgId)
  646. ->where('del',0)
  647. ->where('work_type_mode',2)
  648. ->limit(10)
  649. ->order('id desc')
  650. ->select();
  651. foreach ($todo as $k=>$v){
  652. $img = explode(',',$v['images']);
  653. if($img){
  654. $todo[$k]['images'] = $img[0];
  655. }
  656. }
  657. $data = array_merge($orders,$todo);
  658. if(count($data)>3){
  659. $key = array_rand($data,3);
  660. $list[] = $data[$key[0]];
  661. $list[] = $data[$key[1]];
  662. $list[] = $data[$key[2]];
  663. }
  664. $eList = isset($list)?$list:$data;
  665. HelpHander::success($eList);
  666. }
  667. }