12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- <?php
- namespace catchAdmin\fences\model;
- use think\facade\Db;
- trait FencesGet
- {
- /**
- * 获取围栏类型(文本)
- */
- public function getTypeNameAttr($value)
- {
- $type_arr = [
- 'circle' => '圆形围栏',
- 'polygon' => '多边形围栏',
- ];
- return $type_arr[$this->getData('fence_shape')] ? : '未知';
- }
-
- public function getInFenceTimeAreaAttr($value)
- {
- return json_decode($value, true);
- }
- public function getLevelAttr($value)
- {
- $depart_id=$this->getData('departments');
- if(!$depart_id || is_array($depart_id)){
- return 1;
- }else{
- $level=Db::table('departments')->where('id', $depart_id)->value('level');
- if($level==""){
- return 1;
- }
- $level_arr=explode('-',$level);
- return count($level_arr)+1;
- }
- }
- public function getInFenceTimeAreaTextAttr($value)
- {
- $time_areas = json_decode($this->getData('in_fence_time_area'), true);
- if (!$time_areas) {
- return '';
- }
- $text = '';
- foreach ($time_areas as $area) {
- $text .= "{$area[0]}-{$area[1]}"." / ";
- }
- return trim($text, ' / ');
- }
- public function getOutFenceTimeAreaAttr($value)
- {
- return json_decode($value, true);
- }
- public function getOutFenceTimeAreaTextAttr($value)
- {
- $time_areas = json_decode($this->getData('out_fence_time_area'), true);
- if (!$time_areas) {
- return '';
- }
- $text = '';
- foreach ($time_areas as $area) {
- $text .= "{$area[0]}-{$area[1]}"." / ";
- }
- return trim($text, ' / ');
- }
-
- public function getDepartmentsAttr($value)
- {
- return json_decode($value, true);
- }
- public function getFenceInfoAttr($value)
- {
- return json_decode($value, true);
- }
-
- public function getPushUsersAttr($value)
- {
- return json_decode($value, true);
- }
- public function getDepartmentNameAttr($value)
- {
- $id=$this->departments;
- return Db::table('departments')->where('id', $id)->value('department_name');
- }
- }
|