123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- <?php
- namespace app\common\model;
- use think\Db;
- class TemperatureDevice extends Base
- {
- protected $abnormal = [
- '正常',
- '设备离线',
- '传感器异常',
- '传感器未连接',
- ];
- public function getList($page,$size,$orgId,$userId,$groupId=0){
- $map[] = ['org_id', '=', $orgId];
- $map[] = ['del', '=', 0];
- if($groupId >0){
- $ids = Db::name('group_device')
- ->where('org_id',$orgId)
- ->where('group_id',$groupId)
- ->column('device_id');
- if(empty($ids)){
- $map[] = ['id', '=', -1];
- }else{
- $map[] = ['id', 'in', $ids];
- }
- }
- if($userId!=1){
- $ids = Db::name('temperature_auth')
- ->where('user_id',$userId)
- ->where('org_id',$orgId)
- ->column('temperature_id');
- if(!empty($ids)){
- $map[] = ['id', 'in',$ids];
- }else{
- $map[] = ['id', '=',-1];
- }
- }
- $lists = Db::name('temperature_device')
- ->where($map)->page($page, $size)
- ->select();
- foreach ($lists as $k => &$v) {
- $v['tj'] = '';
- $v['abnormal_name'] = $this->abnormal[$v['abnormal']];
- $gd = Db::name('group_device')
- ->where('device_id',$v['id'])
- ->column('group_id');
- if(empty($gd)){
- $t = '';
- }else{
- $x = Db::name('group')
- ->where('id','in',$gd)
- ->column('title');
- $t = implode(',',$x);
- $v['dev_name'] = $v['dev_name'].'('.$t.')';
- }
- }
- return $lists?$lists:[];
- }
- public function getGroup($orgId,$userId,$page,$size){
- $map[] = ['org_id', '=', $orgId];
- $map[] = ['del', '=', 0];
- if ($userId!=1){
- $ids = Db::name('temperature_auth')
- ->where('user_id',$userId)
- ->where('org_id',$orgId)
- ->column('temperature_id');
- if(!empty($ids)){
- $map[] = ['id', 'in',$ids];
- }else{
- $map[] = ['id', '=',-1];
- }
- }
- $lists = Db::name('temperature_device')
- ->where($map)
- ->column('id');
- if(empty($lists)){
- return[];
- }else{
- $groupId = Db::name('group_device')
- ->where('org_id',$orgId)
- ->where('device_id','in',$lists)
- ->column('group_id');
- if(empty($groupId)) return [];
- $iid = array_unique($groupId);
- $gList = Db::name('group')
- ->where('id','in',$iid)
- ->field('id,title')
- ->page($page, $size)
- ->select();
- return $gList;
- }
- }
- public function getAllList($orgId){
- $map[] = ['org_id', '=', $orgId];
- $map[] = ['del', '=', 0];
- $ids = Db::name('group_device')
- ->where('org_id',$orgId)
- ->where('group_id','>',0)
- ->column('device_id');
- if(!empty($ids)){
- $map[] = ['id', 'not in', $ids];
- }
- $lists = Db::name('temperature_device')
- ->field('id,dev_name as title')
- ->where($map)
- ->select();
- return $lists?$lists:[];
- }
- public function getIdSList($orgId,$id){
- $map[] = ['org_id', '=', $orgId];
- $map[] = ['del', '=', 0];
- $ids = Db::name('group_device')
- ->where('org_id',$orgId)
- ->where('group_id','=',$id)
- ->column('device_id');
- if(!empty($ids)){
- $map[] = ['id', 'in', $ids];
- }
- $lists = Db::name('temperature_device')
- ->field('id,dev_name as title')
- ->where($map)
- ->select();
- $lists = $lists?$lists:[];
- $ids1 = Db::name('group_device')
- ->where('org_id',$orgId)
- ->where('group_id','>',0)
- ->column('device_id');
- $map1[] = ['org_id', '=', $orgId];
- $map1[] = ['del', '=', 0];
- if(!empty($ids1)){
- $map1[] = ['id', 'not in', $ids1];
- }
- $lists1 = Db::name('temperature_device')
- ->field('id,dev_name as title')
- ->where($map1)
- ->select();
- $lists1 = $lists1?$lists1:[];
- $lists = array_merge($lists,$lists1);
- return $lists;
- }
- public function updates(){
- $data = request()->post();
- $data['org_id'] = cur_org_id();
- $data['snaddr'] = trim($data['snaddr']);
- return $this->updateInfo($data,'TemperatureDevice','');
- }
- }
|