GreenDevice.php 1.2 KB

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. namespace app\green\model;
  3. use think\Db;
  4. use think\Model;
  5. class GreenDevice extends Model {
  6. public function operate(){
  7. return $this->hasOne('GreenOperate','id','operate_id');
  8. }
  9. //用户
  10. public function user(){
  11. return $this->hasOne('app\common\model\SystemUser','id','manage_uid');
  12. }
  13. //箱满
  14. public function danger(){
  15. return $this->hasOne('GreenAlarm','device_id','device_id')->where(['state' => 0]);
  16. }
  17. //告警列表
  18. public function alarm(){
  19. return $this->hasMany('GreenAlarm','device_id','device_id');
  20. }
  21. //查找最近10个回收柜
  22. public function selectNear($param){
  23. return Db::query('select id,longitude,latitude,title,address from '.config('database.prefix').'green_device where latitude > '.$param['latitude'].'-1 and latitude < '.$param['latitude'].'+1 and longitude > '.$param['longitude'].'-1 and longitude < '.$param['longitude'].'+1 order by ACOS(SIN(('.$param['latitude'].' * 3.1415) / 180 ) *SIN((latitude * 3.1415) / 180 ) +COS(('.$param['latitude'].' * 3.1415) / 180 ) * COS((latitude * 3.1415) / 180 ) *COS(('.$param['longitude'].'* 3.1415) / 180 - (longitude * 3.1415) / 180 ) ) * 6380 asc limit 10');
  24. }
  25. }