Location.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <?php
  2. namespace app\admin\controller;
  3. use app\watch\controller\Api;
  4. use think\App;
  5. use think\Db;
  6. class Location extends Auth
  7. {
  8. protected $lx = 'http://manager.aiqiangua.com:8080/organS2/themes/default/images/loc2.png';
  9. protected $zx = 'http://manager.aiqiangua.com:8080/organS2/themes/default/images/loc.png';
  10. public function __construct(App $app) {
  11. parent::__construct($app);
  12. $this->api = new Api($this->app);
  13. }
  14. public function index(){
  15. if(request()->post()){
  16. $length = input('rows',10,'intval'); //每页条数
  17. $page = input('page',1,'intval'); //第几页
  18. $start = ($page - 1) * $length; //分页开始位置
  19. $map[] =['del','=',0];
  20. $map[] =['org_id','=',cur_org_id()];
  21. $map= empty($map) ? true: $map;
  22. $lists = Db::name('bracelet_device')
  23. ->where($map)->limit($start,$length)
  24. ->select();
  25. $deviceInfo = [];
  26. foreach ($lists as $k=>$v){
  27. $a = $this->api->getDevice($v['imei']);
  28. if(!$a['success']) $this->error($v['imei'].$a['error_desc']);
  29. $deviceInfo[] = $a['obj'];
  30. }
  31. $totalCount = Db::name('bracelet_device')
  32. ->where($map)
  33. ->count();
  34. $totalPage = ceil($totalCount/$length);
  35. $data = [];
  36. $ydw = [];
  37. $wdw = [];
  38. $onlineNumber = 0;
  39. foreach ($deviceInfo as $k=>$v){
  40. if(!empty($v['last_address'])){
  41. $a = [
  42. 'lonLat'=>[$v['last_location']['coordinates'][0],$v['last_location']['coordinates'][1]],
  43. 'imeI'=>$v['_id'],
  44. 'name'=>$v['name'],
  45. 'lon'=>$v['last_location']['coordinates'][0],
  46. 'lat'=>$v['last_location']['coordinates'][1],
  47. 'address'=>$v['last_address'],
  48. 'updated_at'=>nDate($v['location_updated_at']['$date']),
  49. 'icon'=>$v['online']?$this->zx:$this->lx
  50. ];
  51. $ydw[] = [
  52. 'imeI'=>$v['_id'],
  53. 'name'=>$v['name'],
  54. 'online'=>$v['online']?'在线':'离线',
  55. ];
  56. if($v['online']){
  57. $onlineNumber++;
  58. }
  59. }else{
  60. $wdw[] = [
  61. 'imeI'=>$v['_id'],
  62. 'name'=>$v['name'],
  63. ];
  64. }
  65. }
  66. $data['data'][] = $a;
  67. $data['online_numbers'] =$onlineNumber;
  68. $lpage['page_count'] = $totalPage;
  69. $lpage['total'] = $totalCount;
  70. $lastPage = $page+1;
  71. $proPage = $page-1;
  72. $a1 = '<a href="javascript:;" style="color:black;">&nbsp;&nbsp;当前第'.$page.'页&nbsp;&nbsp;</a>';
  73. $a3 = '<a href="javascript:;" style="color:black;">&nbsp;&nbsp;共'.$lpage['total'].'条</a>';
  74. if($page==1 && $lpage['page_count'] <=1){
  75. $a0 = '<a style="color:black;" href="javascript:;">上一页&nbsp;&nbsp;|</a>';
  76. $a2 = '<a style="color:black;" href="javascript:;">|&nbsp;&nbsp;下一页&nbsp;&nbsp;|</a>';
  77. }else if ($page==1 && $lpage['page_count'] >1){
  78. $a0 = '<a style="color:black;" href="javascript:;">上一页&nbsp;&nbsp;|</a>';
  79. $a2 = '<a style="color:black;" onclick="setPage('.$lastPage.')" href="javascript:;">|&nbsp;&nbsp;下一页&nbsp;&nbsp;|</a>';
  80. }else if ($page > 1 && $lpage['page_count'] <=1){
  81. $a0 = '<a style="color:black;" onclick="setPage('.$proPage.')" href="javascript:;">上一页&nbsp;&nbsp;|</a>';
  82. $a2 = '<a style="color:black;" href="javascript:;">|&nbsp;&nbsp;下一页&nbsp;&nbsp;|</a>';
  83. }else if ($page > 1 && $lpage['page_count'] >1){
  84. $a0 = '<a style="color:black;" onclick="setPage('.$proPage.')" href="javascript:;">上一页&nbsp;&nbsp;|</a>';
  85. $a2 = '<a style="color:black;" onclick="setPage('.$lastPage.')" href="javascript:;">|&nbsp;&nbsp;下一页&nbsp;&nbsp;|</a>';
  86. }
  87. $data['page'] = $a0.$a1.$a2.$a3;
  88. $ydwTxt ='';
  89. $wdwTxt ='';
  90. if(!empty($ydw)){
  91. foreach ($ydw as $v){
  92. $ydwTxt.='<li>'.$v['imeI'].'['.$v['name'].']['.$v['online'].']</li>';
  93. }
  94. }
  95. if(!empty($wdw)){
  96. foreach ($wdw as $v){
  97. $wdwTxt.='<li>'.$v['imeI'].'['.$v['name'].']</li>';
  98. }
  99. }
  100. $data['ydw'] = $ydwTxt;
  101. $data['wdw'] = $wdwTxt;
  102. $this->success('获取成功','',$data);
  103. }else{
  104. $this->assign('gdKey',config('app.gdmap'));
  105. return $this->fetch();
  106. }
  107. }
  108. public function getSosNum(){
  109. $count = Db::name('sos_data')
  110. ->where('org_id',cur_org_id())
  111. ->count();
  112. $this->success('操作成功','',$count);
  113. }
  114. public function getSosList(){
  115. if(request()->isAjax()){
  116. //分页参数
  117. $length = input('rows',10,'intval'); //每页条数
  118. $page = 1; //第几页
  119. $start = ($page - 1) * $length; //分页开始位置
  120. $map[] = ['org_id','=',cur_org_id()];
  121. $list = Db::name('sos_data')->where($map)
  122. ->limit($start,$length)->order('id','desc')
  123. ->select();
  124. foreach ($list as $k=>&$v){
  125. $v['created_at'] = $v['time_begin'];
  126. }
  127. $totalCount = Db::name('sos_data')->where($map)->count();
  128. $totalPage = ceil($totalCount/$length);
  129. $result['page'] = $page;
  130. $result['total'] = $totalPage;
  131. $result['records'] = $totalCount;
  132. $result['rows'] = $list;
  133. Db::name('sos_data')
  134. ->whereIn('id',array_column($list,'id'))
  135. ->delete();
  136. return json($result);
  137. }else{
  138. return $this->fetch();
  139. }
  140. }
  141. }