1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- <?php
- namespace catchAdmin\device\model\get;
- use catchAdmin\permissions\model\SysConfig;
- use catchAdmin\system\model\SysDictData;
- use think\facade\Db;
- trait StationGet
- {
- /**
- * 获取导入时间(文本)
- */
- 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('StationModel', $value) ?: '';
- }
- /**
- * 获取开局用户(文本)
- */
- public function getOpenUserNameAttr($value)
- {
- $uid = $this->open_user_id;
- return Db::table('users')->where('id', $uid)->value('username') ?: '';
- }
- /**
- * 获取导入用户(文本)
- */
- public function getCreatorNameAttr($value)
- {
- $uid = $this->creator_id;
- return Db::table('users')->where('id', $uid)->value('username') ?: '';
- }
- /**
- * 获取部门名称(文本)
- */
- public function getDepartNameAttr()
- {
- $id = $this->getData('department_id');
- return Db::table('departments')->where('id', $id)->value('department_name');
- }
- /**
- * 获取在线状态文本
- */
- public function getNetStateAttr($value)
- {
- $online_time = $this->getData('online_time');
- $offline_intval = (new SysConfig())->getConfigValueBy('station_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;
- }
- }
|