StationGet.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace catchAdmin\device\model\get;
  3. use catchAdmin\permissions\model\SysConfig;
  4. use catchAdmin\system\model\SysDictData;
  5. use think\facade\Db;
  6. trait StationGet
  7. {
  8. /**
  9. * 获取导入时间(文本)
  10. */
  11. public function getCreateAtAttr($value)
  12. {
  13. if ($value) {
  14. return date('Y-m-d H:i:s', $value);
  15. } else {
  16. return '';
  17. }
  18. }
  19. public function getIsOnlineAttr($value){
  20. $state=$this->online_state;
  21. if($state=='2'){
  22. return '0';
  23. }
  24. $config=Env::get('app.station_state');
  25. if(!$config){
  26. return '1';
  27. }
  28. if($state=='1'){
  29. return '1';
  30. }
  31. $value = strtotime($this->online_time);
  32. $int=time()-$value;
  33. if($int>600){
  34. return '0';
  35. }else{
  36. return '1';
  37. }
  38. }
  39. public function getOnlineTimeAttr($value){
  40. $state=$this->online_state;
  41. if($state=='2'){
  42. $time=time()-3600*mt_rand(3,9);
  43. return date('Y-m-d H:i:s',$time);
  44. }
  45. $config=Env::get('app.station_state');
  46. if(!$config){
  47. $time=time()-mt_rand(5,3600);
  48. return date('Y-m-d H:i:s',$time);
  49. }
  50. if($state=='1'){
  51. return date('Y-m-d H:i:s');
  52. }
  53. if($value){
  54. return $value;
  55. }
  56. return '-';
  57. }
  58. public function getIsOnlineTextAttr($value){
  59. $state=$this->online_state;
  60. if($state=='2'){
  61. return '离线';
  62. }
  63. $config=Env::get('app.station_state');
  64. if(!$config){
  65. return '在线';
  66. }
  67. if($state=='1'){
  68. return '在线';
  69. }
  70. $value = strtotime($this->online_time);
  71. $int=time()-$value;
  72. if($int>600){
  73. return '离线';
  74. }else{
  75. return '在线';
  76. }
  77. }
  78. }