123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- <?php
- namespace catchAdmin\device\model\get;
- use catchAdmin\permissions\model\SysConfig;
- use catchAdmin\system\model\SysDictData;
- use think\facade\Db;
- trait DeviceGet
- {
- /**
- * 获取导入时间(文本)
- */
- public function getCreateAtAttr($value)
- {
- if ($value) {
- return date('Y-m-d H:i:s', $value);
- } else {
- return '';
- }
- }
- /**
- * 获取设备型号(文本)
- */
- public function getModelTextAttr($value)
- {
- $value = $this->model;
- return (new SysDictData())->getValueByCode('DeviceModel', $value) ?: '';
- }
- /**
- * 获取绑定物体(文本)
- */
- public function getBindNumberAttr($value)
- {
- $bid = $this->bind_id;
- return Db::table('vehicles')->where('id', $bid)->value('license_plate') ?: '';
- }
- /**
- * 获取导入用户(文本)
- */
- public function getCreatorUserAttr($value)
- {
- $uid = $this->creator_id;
- return Db::table('users')->where('id', $uid)->value('username') ?: '';
- }
- /**
- * 获取使用状态(文本)
- */
- public function getDeviceStateAttr($value)
- {
- if($this->bind_id){
- return 1;
- }else{
- return 0;
- }
- }
- /**
- * 获取部门名称(文本)
- */
- public function getDepartNameAttr()
- {
- $id = $this->getData('department_id');
- return Db::table('departments')->where('id', $id)->value('department_name');
- }
- /**
- * 获取定位模式(文本)
- */
- public function getLocModeTextAttr()
- {
- $code = $this->getData('loc_mode');
- if(!$code){
- return '未知';
- }
- return (new SysDictData())->getValueByCode('DeviceLocationMode', $code) ?: '';
- }
- /**
- * 获取告警原因(文本)
- */
- public function getAlarmReasonListAttr()
- {
- $alarm_list=[];
- $list=Db::table('alarm_records')->where('device_number', $this->imei)->where('state','start')->select();
- foreach($list as $val){
- $text=(new SysDictData())->getValueByCode('AlarmType', $val['alarm_reason']);
- $continue_time=time()-$val['start_time'];
- $hour=$continue_time/3600;
- $minute=($continue_time % 3600)/60;
- $second=($continue_time % 3600)%60;
- $continue_str=(int)$hour.'小时'.(int)$minute.'分'.$second.'秒';
- $item=array('value'=>$val['alarm_reason'],'text'=> $text,'start_time'=>date('Y-m-d H:i:s',$val['start_time']),'continue_time'=>$continue_str);
- $alarm_list[]=$item;
- }
- return $alarm_list;
- }
- /**
- * 获取告警状态文本
- */
- public function getAlarmStateTextAttr($value)
- {
- $alarm_state = $this->getData('alarm_state');
- return $alarm_state ? '告警' : '正常';
- }
- /**
- * 获取在线状态文本
- */
- public function getNetStateAttr($value)
- {
- $online_time = $this->getData('online_time');
- $offline_intval = (new SysConfig())->getConfigValueBy('device_offline_interval','basic_config');
- if($online_time){
- $diff = time()-strtotime($online_time);
- if($diff - $offline_intval >= 0){
- $value = 1;
- }else{
- $value = 0;
- }
- }else{
- $value = 2;
- }
- return $value;
- }
- /**
- * 电量
- */
- public function getBatteryLevelAttr($value)
- {
- $online_time = $this->getData('online_time');
-
- if($online_time==''){
- return '--';
- }elseif($value==0){
- return '<5';
- }
- return $value;
- }
- /**
- * 获取在线状态图标
- */
- public function getStatusIconAttr($value)
- {
- $online_time = $this->getData('online_time');
- $offline_intval = (new SysConfig())->getConfigValueBy('device_offline_interval','basic_config');
- if($online_time){
- $diff = time()-strtotime($online_time);
- if($diff - $offline_intval >= 0){
- $value = 'offline';
- }else{
- $value = 'run';
- }
- }else{
- $value = 'unuse';
- }
- return $value;
- }
- /**
- * 获取在线状态图标
- */
- public function getStatusTextAttr($value)
- {
- $online_time = $this->getData('online_time');
- $offline_intval = (new SysConfig())->getConfigValueBy('device_offline_interval','basic_config');
- if($online_time){
- $diff = time()-strtotime($online_time);
- if($diff - $offline_intval >= 0){
- $value = '离线';
- }else{
- $value = '在线';
- }
- }else{
- $value = '未使用';
- }
- return $value;
- }
- /**
- * 获取在线时间
- */
- public function getLastOnlineTimeAttr()
- {
- $online_time = $this->getData('online_time');
- $wifi_online_time = $this->getData('wifi_online_time');
- if($online_time<$wifi_online_time){
- return $wifi_online_time;
- }else{
- return $online_time;
- }
-
- }
-
- }
|