StationGet.php 1.9 KB

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