display(); } /* */ public function header(){ $this->display(); } /* */ public function jk_left(){ $userid = get_userid(); $farmid = MM('uc_user')->where(array('ID'=>$userid))->getField('FarmId'); $farmname = MM('dpyh_farm')->where(array('ID'=>$farmid))->getField('FarmName'); $group_list = MM('dpsb_group')->where(array('FarmId'=>$farmid))->select(); $device_list = array(); foreach($group_list as $row){ $device_list[$row['OrgName']] = MM('dpsb_device')->where(array('DeviceGroupId'=>$row['ID']))->select(); } $this->assign('farmname',$farmname); $this->assign('device_list',$device_list); $this->display(); } /* */ public function jk_right(){ $deviceid = I('get.id'); if(!$deviceid){ $userid = get_userid(); $farmid = MM('uc_user')->where(array('ID'=>$userid))->getField('FarmId'); $farmname = MM('dpyh_farm')->where(array('ID'=>$farmid))->getField('FarmName'); $group = MM('dpsb_group')->where(array('FarmId'=>$farmid))->order('ID asc')->find(); $deviceid = MM('dpsb_device')->where(array('DeviceGroupId'=>$group['ID']))->order('ID asc')->getField('ID'); } $groupid = MM('dpsb_device')->where(array('ID'=>$deviceid))->getField('DeviceGroupId'); if(!$groupid){ json_fail('设备组不存在'); } $farmid = MM('dpsb_group')->where(array('ID'=>$groupid))->getField('FarmId'); if(!$farmid){ json_fail('农场不存在'); } $farmname = MM('dpyh_farm')->where(array('ID'=>$farmid))->getField('FarmName'); if(!$farmname){ json_fail('农场名称不存在'); } $where = array( 'DeviceId'=>$deviceid, 'ChType' => array('IN',\Zndp\Device\ChannelType::SENSOR_TYPES), ); $channel_list = MM('dpsb_channel')->where($where)->order('ID asc')->select(); $type = new \Zndp\Device\ChannelType; foreach($channel_list as $key=>$row){ $channel_list[$key]['Unit1'] = $type->getTypeUnit($row['ChType']); $channel_list[$key]['channelname'] = $type->getDisplayName($row['ChType']) . ($row['ChGroup']+1); } $where = array( 'DeviceId'=>$deviceid, 'ChType' => array('IN',\Zndp\Device\ChannelType::CONTROL_SENSOR), ); $control_list = MM('dpsb_channel')->where($where)->order('ID asc')->select(); foreach($control_list as $key=>$value){ $control_list[$key]['policyid'] = MM('dpsb_policy')->where(array('DeviceId'=>$deviceid,'Channel'=>$value['ChNumber']))->getField('ID'); } $addr = MM('dpsb_device')->where(array('ID'=>$deviceid))->getField('DeviceAddr'); $imei = MM('dpsb_device')->where(array('ID'=>$deviceid))->getField('DeviceImei'); $gathertime = MM('dpsb_device')->where(array('ID'=>$deviceid))->getField('GatherTime'); $year = date('Y'); $month = date('m'); $day = date('d'); $this->assign('gathertime',$gathertime); $this->assign('channel_list',$channel_list); $this->assign('control_list',$control_list); $this->assign('farmname',$farmname); $this->assign('addr',$addr); $this->assign('imei',$imei); $this->assign('policyid',$policyid); $this->assign('deviceid',$deviceid); $this->assign('year',$year); $this->assign('month',$month); $this->assign('day',$day); $this->display(); } /* */ public function login(){ if($this->isAjax()){ $account = I('post.account'); $password = I('post.password'); if($account=='' || $password==''){ json_fail('参数错误'); } $cond = array( 'UserName' => $account, 'Password' => \Zndp\User\Util::encPwd($password), ); $user_info = MM('uc_user')->where($cond)->find(); if(!$user_info){ $this->login_advice($user_info,'登录失败!用户不存在或密码错误.'); exit; } if($user_info['IsDisabled']){ $this->login_advice($user_info,'用户已禁用,不可以登录'); exit; } //检测是否有后台登录权限 if($user_info['RoleId'] != \Zndp\User\RoleEnum::FARM_OPERATOR){ $this->login_advice($user_info,'无登陆权限!'); exit; } //登录成功切点 $this->login_advice($user_info,''); //登录成功 \Jiaruan\UcCookie::set($user_info['ID']); $data = array('redirect_url' => '?s=dpqd_index/index'); json_success('登陆成功',$data); }else{ $this->display(); } } /* 参数说明: user_info: message: */ private function login_advice($user_info, $message){ $result = $message? false:true; $password = I('post.password'); if($result) $password = "******"; $param = array( 'account' => I('post.account'), 'password' => $password, ); $options = array( 'user_info' => $user_info, 'result' => $result, 'message' => $message ); PB('uc_after_login',$param,$options); if(!$result){ json_fail($message); } } /* */ public function sj_left(){ $this->display(); } /* */ public function sj_right(){ $userid = get_userid(); if(!$userid){ json_fail('用户id不存在,请重新登录'); } $type =10; $farmid = MM('uc_user')->where(array('ID'=>$userid))->getField('FarmId'); if(!$farmid) json_fail('用户下没有农场'); $farmname = MM('dpyh_farm')->where(array('ID'=>$farmid))->getField('FarmName'); $group_list = MM('dpsb_group')->where(array('FarmId'=>$farmid))->select(); if(!$group_list) json_fail('农场下没有设备组'); $channel_list_data = array(); foreach($group_list as $row){ $device_list = MM('dpsb_device')->where(array('DeviceGroupId'=>$row['ID']))->select(); foreach($device_list as $key=>$device){ $channel_data = $this->get_channel_info($device['ID']); array_push($channel_list_data,$channel_data); } } $this->assign('channel_list_data',$channel_list_data); $this->display(); } /* 参数说明: device_id: */ private function get_channel_info($device_id){ $device_name = MM('dpsb_device')->where(array('ID'=>$device_id))->getField('WorkUnitName'); if(!$device_name) return false; $data = array( "title" => $device_name, "channels" => array(), ); $chtype = new \Zndp\Device\ChannelType; for($i=0;$i<3;$i++){ //温度数据 $where = array( 'DeviceId'=>$device_id, 'ChType' => \Zndp\Device\ChannelType::TEMPERATURE, 'ChGroup' => $i, ); $temperature_info = MM('dpsb_channel')->where($where)->find(); if(!$temperature_info){ continue; } $temperature_info['unit'] = $chtype->getTypeUnit($temperature_info['ChType']); array_push($data['channels'],$temperature_info); //湿度数据 $where = array( 'DeviceId'=>$device_id, 'ChType' => \Zndp\Device\ChannelType::HUMIDITY, 'ChGroup' => $i, ); $humidity_info = MM('dpsb_channel')->where($where)->find(); if(!$humidity_info){ continue; } $humidity_info['unit'] = $chtype->getTypeUnit($humidity_info['ChType']); array_push($data['channels'],$humidity_info); //光照数据 $where = array( 'DeviceId'=>$device_id, 'ChType' => \Zndp\Device\ChannelType::ILLINATIONUM, 'ChGroup' => $i, ); $illumination_info = MM('dpsb_channel')->where($where)->find(); if(!$illumination_info){ continue; } $illumination_info['unit'] = $chtype->getTypeUnit($illumination_info['ChType']); array_push($data['channels'],$illumination_info); } return $data; } }