Station.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. namespace catchAdmin\device\model;
  3. use catcher\base\CatchModel as Model;
  4. use catchAdmin\permissions\model\DataRangScopeTrait;
  5. use catchAdmin\device\model\get\StationGet;
  6. use think\facade\Db;
  7. class Station extends Model
  8. {
  9. use DataRangScopeTrait;
  10. use StationGet;
  11. // 表名
  12. public $name = 'stations';
  13. // 数据库字段映射
  14. public $field = array(
  15. 'id',
  16. 'mac',
  17. 'shortcode',
  18. 'name',
  19. 'model',
  20. 'serial_number',
  21. 'department_id',
  22. 'version',
  23. 'open_status',
  24. 'sim_no',
  25. 'longitude',
  26. 'latitude',
  27. 'online_time',
  28. 'address',
  29. 'remark',
  30. 'open_time',
  31. 'open_user_id',
  32. 'creator_id',
  33. 'created_at',
  34. 'updated_at',
  35. 'deleted_at'
  36. );
  37. /**
  38. * 获取基站列表
  39. */
  40. public function getList()
  41. {
  42. $res = $this->dataRange()
  43. ->catchSearch()
  44. ->append(['is_online'])
  45. ->order($this->aliasField('online_time'), 'desc')
  46. ->paginate();
  47. return $res;
  48. }
  49. public function getAllList(){
  50. $res = $this
  51. ->catchSearch()
  52. // ->field('mac,name,latitude,longitude,online_time')
  53. ->append(['is_online_text','is_online'])
  54. ->select()
  55. ->each(function($item, $key) {
  56. $wgsLoc = \algorithm\Geometry::gcj02ToWgs84((float)$item['latitude'],(float)$item['longitude']);
  57. // $lngLat = \algorithm\Geometry::convertGcj02ToBd09($wgsLoc['lat'],$wgsLoc['lng']);
  58. $item['longitude']=$wgsLoc['lng'];
  59. $item['latitude']=$wgsLoc['lat'];
  60. })->toArray();
  61. return $res;
  62. }
  63. /**
  64. * 根据名称搜索
  65. */
  66. public function searchNameAttr($query, $value, $data)
  67. {
  68. return $query->where('name', 'like', '%'.$value.'%');
  69. }
  70. /**
  71. * 根据编号搜索
  72. */
  73. public function searchShortCodeAttr($query, $value, $data)
  74. {
  75. return $query->where('shortcode|mac', 'like', '%'.$value.'%');
  76. }
  77. /**
  78. * 根据状态搜索
  79. */
  80. public function searchOnlineStateAttr($query, $value, $data)
  81. {
  82. $time=date('Y-m-d H:i:s',time()-300);
  83. if($value=='1'){
  84. return $query->where('online_time', '>=', $time);
  85. }elseif($value=='2'){
  86. return $query->where(function ($query) use( $time) {
  87. $query->whereOr('online_time','<', $time)->whereOr('online_time','=', null);
  88. });
  89. }
  90. }
  91. }