StationGet.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. /**
  20. * 获取设备型号(文本)
  21. */
  22. public function getModelTextAttr($value)
  23. {
  24. $value = $this->model;
  25. return (new SysDictData())->getValueByCode('StationModel', $value) ?: '';
  26. }
  27. /**
  28. * 获取开局用户(文本)
  29. */
  30. public function getOpenUserNameAttr($value)
  31. {
  32. $uid = $this->open_user_id;
  33. return Db::table('users')->where('id', $uid)->value('username') ?: '';
  34. }
  35. /**
  36. * 获取导入用户(文本)
  37. */
  38. public function getCreatorNameAttr($value)
  39. {
  40. $uid = $this->creator_id;
  41. return Db::table('users')->where('id', $uid)->value('username') ?: '';
  42. }
  43. /**
  44. * 获取部门名称(文本)
  45. */
  46. public function getDepartNameAttr()
  47. {
  48. $id = $this->getData('department_id');
  49. return Db::table('departments')->where('id', $id)->value('department_name');
  50. }
  51. /**
  52. * 获取在线状态文本
  53. */
  54. public function getNetStateAttr($value)
  55. {
  56. $online_time = $this->getData('online_time');
  57. $offline_intval = (new SysConfig())->getConfigValueBy('station_offline_interval','basic_config');
  58. if($online_time){
  59. $diff = time()-strtotime($online_time);
  60. if($diff - $offline_intval >= 0){
  61. $value = 1;
  62. }else{
  63. $value = 0;
  64. }
  65. }else{
  66. $value = 2;
  67. }
  68. return $value;
  69. }
  70. }