0
0

Bracelet.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <?php
  2. namespace app\admin\controller;
  3. use app\watch\controller\Api;
  4. use think\App;
  5. use think\Db;
  6. use think\Exception;
  7. class Bracelet extends Auth
  8. {
  9. protected $sex = [
  10. '未知',
  11. '男',
  12. '女'
  13. ];
  14. public function __construct(App $app) {
  15. parent::__construct($app);
  16. $this->api=new Api($this->app);
  17. }
  18. public function index(){
  19. if(request()->isAjax()){
  20. //分页参数
  21. $length = input('rows',10,'intval'); //每页条数
  22. $page = input('page',1,'intval'); //第几页
  23. $start = ($page - 1) * $length; //分页开始位置
  24. //排序
  25. $sortRow = input('sidx','id','trim'); //排序列
  26. $sort = input('sord','desc','trim'); //排序方式
  27. $order = $sortRow.' '.$sort;
  28. $title = input('name','','trim');
  29. if($title){
  30. $map[] = ['nickname','like','%'.$title.'%'];
  31. }
  32. $map[] = ['org_id','=',$this->orgId];
  33. $map[] = ['del','=',0];
  34. $map= empty($map) ? true: $map;
  35. //数据查询
  36. $lists = Db::name('bracelet_device')
  37. ->where($map)->limit($start,$length)->order($order)
  38. ->select();
  39. foreach ($lists as $k=>$v){
  40. $lists[$k]['sex'] =$v['sex']==0?'位置':($v['sex']==1?'男':'女');
  41. $watch = new Api($this->app);
  42. $info = $watch->getDevice($v['imei']);
  43. if(!$info['success']) $this->error($v['imei'].$info['error_desc']);
  44. $lists[$k]['online'] = $info['obj']['online']?'在线':'离线';
  45. $lists[$k]['jk'] = '';
  46. $lists[$k]['icon'] = '';
  47. }
  48. //数据返回
  49. $totalCount = Db::name('bracelet_device')->where($map)->count();
  50. $totalPage = ceil($totalCount/$length);
  51. $result['page'] = $page;
  52. $result['total'] = $totalPage;
  53. $result['records'] = $totalCount;
  54. $result['rows'] = $lists;
  55. return json($result);
  56. }else{
  57. return $this->fetch();
  58. }
  59. }
  60. /**
  61. * 新增/编辑
  62. */
  63. public function add($id=0)
  64. {
  65. if (request()->isPost()) {
  66. $model = new \app\common\model\Bracelet();
  67. $res = $model->saves();
  68. if ($res) {
  69. $this->success('操作成功', url('index'));
  70. } else {
  71. $this->error($model->getError());
  72. }
  73. } else {
  74. $meta_title = '新增设备';
  75. if ($id) {
  76. $info = Db::name('bracelet_device')
  77. ->where('id', $id)->find();
  78. $this->assign('info', $info);
  79. $meta_title = '编辑设备';
  80. }
  81. $this->assign('sex', $this->sex);
  82. $this->assign('meta_title', $meta_title);
  83. return $this->fetch();
  84. }
  85. }
  86. /**
  87. * 删除
  88. * @param int $id
  89. */
  90. public function del($id=0){
  91. if(!$id){
  92. $this->error('参数错误');
  93. }
  94. $res = Db::name('bracelet_device')->where('id',$id)->update([
  95. 'del'=>1,
  96. 'del_time'=>date('Y-m-d H:i:s')
  97. ]);
  98. if($res){
  99. $this->success('删除成功');
  100. }else{
  101. $this->error('删除失败');
  102. }
  103. }
  104. /**
  105. * 设置亲情通话
  106. *
  107. * @author wst
  108. * @date 2021/6/1 17:22
  109. */
  110. public function number($id=0){
  111. if($params = request()->post()){
  112. $seqId = $params['seqId'];
  113. $id = $params['id'];
  114. unset($params['id'],$params['seqId']);
  115. $res = $this->api->deviceSosNumbers($id,$seqId,$params);
  116. if($res['success']){
  117. $this->success('操作成功');
  118. }
  119. $this->error($res['error_desc']);
  120. }else{
  121. $meta_title = '亲情号码';
  122. $detail = $this->api->getDevice($id);
  123. if(!$detail['success']) $this->error($detail['error_desc']);
  124. $info = $detail['obj']['sos_numbers'];
  125. $this->assign('info',$info);
  126. $this->assign('id',$id);
  127. $this->assign('meta_title',$meta_title);
  128. return $this->fetch();
  129. }
  130. }
  131. /**
  132. * 编辑单条亲情号码
  133. *
  134. * @author wst
  135. * @date 2021/6/1 17:44
  136. */
  137. public function editNumber(){
  138. $params = request()->get();
  139. $this->assign('info',$params);
  140. return $this->fetch();
  141. }
  142. /**
  143. * 清空单条亲情号码
  144. *
  145. * @author wst
  146. * @date 2021/6/1 17:44
  147. */
  148. public function clearNumber(){
  149. $params = request()->get();
  150. $res = $this->api->deviceSosNumbers($params['id'],$params['seqId'],['clear'=>1]);
  151. if($res['success']){
  152. $this->success('操作成功');
  153. }
  154. $this->error($res['error_desc']);
  155. }
  156. }