FencesGet.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. namespace catchAdmin\fences\model;
  3. use think\facade\Db;
  4. trait FencesGet
  5. {
  6. /**
  7. * 获取围栏类型(文本)
  8. */
  9. public function getTypeNameAttr($value)
  10. {
  11. $type_arr = [
  12. 'circle' => '圆形围栏',
  13. 'polygon' => '多边形围栏',
  14. ];
  15. return $type_arr[$this->getData('fence_shape')] ? : '未知';
  16. }
  17. public function getInFenceTimeAreaAttr($value)
  18. {
  19. return json_decode($value, true);
  20. }
  21. public function getLevelAttr($value)
  22. {
  23. $depart_id=$this->getData('departments');
  24. if(!$depart_id || is_array($depart_id)){
  25. return 1;
  26. }else{
  27. $level=Db::table('departments')->where('id', $depart_id)->value('level');
  28. if($level==""){
  29. return 1;
  30. }
  31. $level_arr=explode('-',$level);
  32. return count($level_arr)+1;
  33. }
  34. }
  35. public function getInFenceTimeAreaTextAttr($value)
  36. {
  37. $time_areas = json_decode($this->getData('in_fence_time_area'), true);
  38. if (!$time_areas) {
  39. return '';
  40. }
  41. $text = '';
  42. foreach ($time_areas as $area) {
  43. $text .= "{$area[0]}-{$area[1]}"." / ";
  44. }
  45. return trim($text, ' / ');
  46. }
  47. public function getOutFenceTimeAreaAttr($value)
  48. {
  49. return json_decode($value, true);
  50. }
  51. public function getOutFenceTimeAreaTextAttr($value)
  52. {
  53. $time_areas = json_decode($this->getData('out_fence_time_area'), true);
  54. if (!$time_areas) {
  55. return '';
  56. }
  57. $text = '';
  58. foreach ($time_areas as $area) {
  59. $text .= "{$area[0]}-{$area[1]}"." / ";
  60. }
  61. return trim($text, ' / ');
  62. }
  63. public function getDepartmentsAttr($value)
  64. {
  65. return json_decode($value, true);
  66. }
  67. public function getFenceInfoAttr($value)
  68. {
  69. return json_decode($value, true);
  70. }
  71. public function getPushUsersAttr($value)
  72. {
  73. return json_decode($value, true);
  74. }
  75. public function getDepartmentNameAttr($value)
  76. {
  77. $id=$this->departments;
  78. return Db::table('departments')->where('id', $id)->value('department_name');
  79. }
  80. }