123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689 |
- <?php
- class DpsbDeviceAction extends CommonAction {
- const tableName = 'dpsb_device';
- const pkName = 'ID';
-
-
- function sys_addedit_old( ){
- $form = new \Jiaruan\LigerIframeForm();
- $form->before_add = function(&$data){
- //检测地址码是否重复
- /*$device_addr = trim($data['DeviceAddr']);
- $device_info = M('dpsb_device')->where(array('DeviceAddr'=>$device_addr))->find();
- if($device_info){
- json_fail('该地址码已存在,请重新输入!');
- }*/
- };
- $form->before_save = function(&$data){
- $id = I('get.id');
- $device_addr = trim($data['DeviceAddr']);
- $device_imei = trim($data['DeviceImei']);
- $cond = array('ID'=>$id);
- $userinfo = M('dpsb_device')->where($cond)->field('DeviceAddr,DeviceImei')->find();
-
- $device_info = M('dpsb_device')->where(array('DeviceAddr'=>$device_addr))->find();
- if($device_addr != $userinfo['DeviceAddr'] && $device_info){
- json_fail('该地址码已存在,请重新输入!');
- }
- };
- $form->form_filter = function(&$form){
- //显示设备类型
- $type_list = \Zndp\Device\Option::getDeviceTypeOption();
- $form['fields']['DeviceTypeId']['editor'] = array('options'=>$type_list);
- //显示设备组下拉数据
- $type = new \Zndp\Device\Option;
- $channeltype = $type->getGroupOption();
- $form['fields']['DeviceGroupId']['editor'] = array('options'=>$channeltype);
- };
-
-
- $form->display($this);
- }
-
-
- function sys_list( ){
- $list = new \Jms\Gui\ClGrid();
- $list->sql_sort = 'DeviceAddr desc';
- $list->sql_filter = function($search,&$cond){
- $farmid = I('get.id');
- if($farmid){ // 点击导航树进入
- //获取当前部门下所有基地
- $farm_ids = \Zndp\User\Util::get_depart_farm($farmid);
- //取出基地下所有设备组
- $where = array('FarmId'=>array('IN',$farm_ids));
- $group_ids = M('dpsb_group')->field('ID')->where($where)->select();
- $group_ids = array_column($group_ids,'ID');
- $cond['DeviceGroupId'] = array('in',$group_ids);
- }else{
- if($this->userinfo['OrganizationId']){ //默认选中
- //获取当前部门下所有基地
- $farm_ids = \Zndp\User\Util::get_depart_farm($this->userinfo['OrganizationId']);
- $where = array('FarmId'=>array('IN',$farm_ids));
- //取出基地下所有设备组
- $group_ids = M('dpsb_group')->field('ID')->where($where)->select();
- $group_ids = array_column($group_ids,'ID');
- $cond['DeviceGroupId'] = array('in',$group_ids);
- }else{ //平台管理员
- $cond['DeviceGroupId'] = array('neq',0);
- }
- }
- };
- $list->row_filter = function(&$row) use ($list){
- $row['DeviceAddr'] = $list->renderXEditableInput('地址码',$row,'DeviceAddr',array('rule'=>array('required'=>true)));
- $row['DeviceGroupId'] = $list->renderXEditableInput('设备组ID',$row,'DeviceGroupId',array('rule'=>array('required'=>true)));
- $row['WorkUnitName'] = $list->renderXEditableInput('设备名称',$row,'WorkUnitName',array('rule'=>array('required'=>true)));
- $row['IccId'] = str_replace(' ','<br/>',$row['IccId']);
- $where = array('ID'=>$row['DeviceTypeId']);
- $row['DeviceTypeId_text'] = M('dpsb_type')->where($where)->getField('TypeName');
- };
- $list->display($this);
- }
-
-
- public function sys_del( ){
- if (IS_AJAX) {
- $device_id = I('get.id');
- if ( empty($device_id)) {
- json_fail('设备id不能为空');
- }
- // 如果已经绑定大棚,需要先解绑
- $where = array( 'DeviceId' => $device_id, 'FarmlandId' => array('neq',-1) );
- $count = M('dpsb_chgroup')->where($where)->count();
- if( $count > 0 ){
- json_fail('有'.$count.'个田地与设备绑定中,无法删除');
- }
- if(M('dpsb_device')->where(array( 'ID' => $device_id ))->delete() === false){
- json_fail('设备表删除失败','');
- }
- if(M('dpsb_chgroup')->where(array( 'DeviceId' => $device_id ))->delete() === false){
- json_fail('通道组组表删除失败','');
- }
- if(M('dpsb_channel')->where(array( 'DeviceId' => $device_id ))->delete() === false){
- json_fail('通道表删除失败','');
- }
- if(M('dpsb_policy')->where(array( 'DeviceId' => $device_id ))->delete() === false){
- json_fail('决策表删除失败','');
- }
- if(M('dpsj_device')->where(array( 'DeviceId' => $device_id ))->delete() === false){
- json_fail('设备数据删除失败','');
- }
- if(M('dpsj_channel')->where(array( 'DeviceId' => $device_id ))->delete() === false){
- json_fail('通道数据删除失败','');
- }
- json_success('删除成功','');
- }
-
- }
-
-
- function sys_binding( ){
- $form = new \Jiaruan\LigerIframeForm();
- $form->before_save = function(&$data){
- $id = I('get.id');
- $group_id = trim($data['DeviceGroupId']);
- $cond = array('ID'=>$group_id);
- $groupinfo = M('dpsb_group')->where($cond)->find();
- if(!$groupinfo){
- json_fail('设备组ID不存在');
- }
- };
-
- $form->display($this);
- }
-
-
- function sys_add_list( ){
- $list = new \Jms\Gui\ClGrid();
- $list->sql_sort = 'AddTime desc';
- $list->right_filter = function($right,$type){
- $page = $_SERVER['PATH_INFO'];
- return \Jms\Ucenter\Right::defaultFilter($page,$right,$type);
- };
- $list->sql_filter = function($search,&$cond){
- //$cond['DeviceAddr'] = '';
- $cond['DeviceGroupId'] = 0;
- //$cond['WorkUnitName'] = '';
-
- //搜索
- if($search['DeviceImei']){
- $cond['DeviceImei'] = $search['DeviceImei'];
- }
- if($search['IccId']){
- $cond['IccId'] = $search['IccId'];
- }
- };
- $list->row_filter = function(&$row) use ($list){
- $type_info = M('dpsb_type')->field('TypeName,DeviceModel')->where($where)->find();
- $row['DeviceTypeId_text'] = $type_info['TypeName'] .' - '.$type_info['DeviceModel'];
- };
- //搜索栏回调
- $list->searchbar_filter = function(&$searchbar) {
-
- };
- $list->display($this);
- }
-
-
- public function sys_debug( ){
- if (IS_AJAX) {
- $id = I('get.id');
- if(empty($id)){
- json_fail('id不存在');
- }
- $addr = M('dpsb_device')->where(array('ID'=>$id))->getField('DeviceAddr');
- $host = '127.0.0.1';
- $port = 10240;
- $socket = new Jms\Network\TcpClient($host,$port);
- $cmd = array(
- "method" => "apiUploadDebug",
- "Addr"=>$addr,
- );
- $res = $socket->send(json_encode($cmd));
- if($res['success']){
- json_success('下发成功');
- }else{
- json_fail($res['message']);
- }
- }
- }
-
-
- public function sys_upload( ){
- if (IS_AJAX) {
- $id = I('get.id');
- if(empty($id)){
- json_fail('id不存在');
- }
- $addr = M('dpsb_device')->where(array('ID'=>$id))->getField('DeviceAddr');
- $host = '127.0.0.1';
- $port = 10240;
- $socket = new Jms\Network\TcpClient($host,$port);
- $cmd = array(
- "method" => "apiUpgrade",
- "Addr"=>$addr,
- );
- $res = $socket->send(json_encode($cmd));
- if($res['success']){
- json_success('下发成功');
- }else{
- json_fail($res['message']);
- }
- }
- }
-
-
- public function sys_reboot( ){
- if (IS_AJAX) {
- $id = I('get.id');
- if(empty($id)){
- json_fail('id不存在');
- }
- $addr = M('dpsb_device')->where(array('ID'=>$id))->getField('DeviceAddr');
- $host = '127.0.0.1';
- $port = 10240;
- $socket = new Jms\Network\TcpClient($host,$port);
- $cmd = array(
- "method" => "apiReboot",
- "Addr"=>$addr,
- );
- $res = $socket->send(json_encode($cmd));
- if($res['success']){
- json_success('下发成功');
- }else{
- json_fail($res['message']);
- }
- }
- }
-
-
- public function sys_sreboot( ){
- if (IS_AJAX) {
- $id = I('get.id');
- if(empty($id)){
- json_fail('id不存在');
- }
- $addr = M('dpsb_device')->where(array('ID'=>$id))->getField('DeviceAddr');
- $host = '127.0.0.1';
- $port = 10240;
- $socket = new Jms\Network\TcpClient($host,$port);
- $cmd = array(
- "method" => "apiSysReboot",
- "Addr"=>$addr,
- );
- $res = $socket->send(json_encode($cmd));
- if($res['success']){
- json_success('下发成功');
- }else{
- json_fail($res['message']);
- }
- }
- }
-
-
- function sys_addedit_crops( ){
- $form = new \Jiaruan\LigerIframeForm();
- $form->before_save = function(&$data){
-
- };
-
- $form->display($this);
- }
-
-
- function sys_msg_set( ){
- $form = new \Jms\Gui\ClForm();
- $form->before_display = function(&$data){
- $data['ExceptContent'] = $data['ExceptContent']?:'温度异常了';
- };
- $form->before_save = function(&$data){
- // 温度不能是空字符串
- if($data['HighTemp'] === '' || $data['LowTemp'] === ''){
- json_fail('温度不能为空');
- }
- // 温度必须是数字或数字字符串
- if( !is_numeric($data['HighTemp']) || !is_numeric($data['LowTemp']) ){
- json_fail('温度必须是数字');
- }
- };
-
- $form->display($this);
- }
-
-
- public function get_alarm_set( ){
- $device_addr = I('get.device_addr');
- if(!$device_addr){
- json_fail('Missing DeviceAddr param!');
- }
- $where = array('DeviceAddr'=>$device_addr);
- $field = "Mobiles,ExceptContent,SmsInterval,HighTemp,IsUseHT,LowTemp,IsUseLT,SoundLightAlarmInterval,SoundLightDuration,SeveralExceptions";
- $result = M('dpsb_device')->where($where)->field($field)->find();
- if(!$result){ //设备不存在
- json_fail('DeviceAddr not exists!');
- }
- //返回json格式数据
- $json_data = json_encode($result,JSON_UNESCAPED_UNICODE);
- echo $json_data;
-
- }
-
-
- function set_screen_msg( ){
- /*
- 对外地址(提供给农科院) http://zndp.rltest.cn/index.php?s=dpsb_device/set_screen_msg&token=zndp
- 查看地址(这个地址也可以修改) http://zndp.rltest.cn/index.php?s=dpsb_device/set_screen_msg&token=zndp&addr=617261
- */
- if (!$_GET['token'] || $_GET['token'] != 'zndp') {
- echo '非法访问';
- die;
- }
-
- //根据设备地址获取id信息,不能根据id修改信息
- $_GET['id'] = 0;
- if (IS_POST || $_GET['addr']) {
- if ($_GET['addr']) {
- $addr = $_GET['addr'];
- } else {
- $input = json_decode(file_get_contents("php://input"), true);
- $addr = $input['DeviceAddr'];
- }
- if (!$addr) {
- json_fail('设备地址有误');
- }
- $where = array('DeviceAddr' => $addr);
- $rows = M(self::tableName)->field('id')->where($where)->select();
- if (!$rows || count($rows) != 1) {
- json_fail('设备地址错误');
- }
- $_GET['id'] = $rows[0]['id'];
- }
-
-
- $form = new \Jiaruan\LigerIframeForm();
- $form->before_save = function(&$data){
-
- };
-
- $form->display($this);
- echo '
- <style>
- ::-webkit-input-placeholder { /* WebKit, Blink, Edge */ color:#ccc; }
- :-moz-placeholder { /* Mozilla Firefox 4 to 18 */ color:#ccc; }
- ::-moz-placeholder { /* Mozilla Firefox 19+ */ color:#ccc; }
- :-ms-input-placeholder { /* Internet Explorer 10-11 */ color:#ccc; }
- </style>';
- }
-
-
- function oper_list( ){
- $list = new \Jms\Gui\ClGrid();
- $list->sql_sort = 'AddTime desc';
- $list->sql_filter = function($search,&$cond){
- $userid = \Jms\Ucenter\Cookie::getLoginUserId();
- $where = array('ID'=>$userid);
- $depart_id = M('uc_user')->where($where)->getField('OrganizationId');
- if(!$depart_id){
- json_fail('登录用户信息有误,请联系管理员!');
- }
- //获取登录角色部门下所有基地
- $depart_ids = \Zndp\User\Util::get_depart_farm($depart_id);
- //获取基地下的设备组
- $where = array('FarmId'=>array('IN',$depart_id));
- $group_ids = M('dpsb_group')->field('ID')->where($where)->select();
- $group_ids = array_column($group_ids,'ID');
- //根据设备组id查出设备
- $cond['DeviceGroupId'] = array('in',$group_ids);
- //搜索
- if($search['WorkUnitName']){
- $cond['WorkUnitName'] = array('like','%'.$search['WorkUnitName'].'%');
- }
- if($search['DeviceImei']){
- $cond['DeviceImei'] = array('like','%'.$search['DeviceImei'] .'%');
- }
- };
-
- $list->display($this);
- }
-
-
- function set_screen_msg2( ){
- $form = new \Jms\Gui\ClForm();
- $shed = array(1=>'FirstCrop','SecondCrop','ThirdCrop','FourthCrop');
- $form->before_display = function(&$data) use($shed){
- // 展示点阵屏信息
- for($i=1; $i<=count($shed); $i++){
- $shed_data = json_decode($data[$shed[$i]], true);
- $data['num'.$i] = $shed_data['num'.$i];
- $data['variety'.$i] = $shed_data['variety'.$i];
- $data['farmer'.$i] = $shed_data['farmer'.$i];
- $data['output'.$i] = $shed_data['output'.$i];
- $data['unit'.$i] = $shed_data['unit'.$i];
- }
- };
- $form->before_save = function(&$data) use($shed){
- // 保存点阵屏信息
- for($i=1; $i<=count($shed); $i++){
- $shed_data = array(
- 'num'.$i => $data['num'.$i],
- 'variety'.$i =>$data['variety'.$i],
- 'farmer'.$i =>$data['farmer'.$i],
- 'output'.$i =>$data['output'.$i],
- 'unit'.$i =>$data['unit'.$i]
- );
- $data[$shed[$i]] = json_encode($shed_data, JSON_UNESCAPED_UNICODE);
- }
- };
- $form->display($this);
- }
-
-
- function sys_list_search( ){
-
- }
-
-
- function set_screen_msg3( ){
- $form = new \Jms\Gui\ClForm();
- $shed = array(1=>'FirstCrop','SecondCrop','ThirdCrop','FourthCrop');
- $form->before_display = function(&$data) use($shed){
- // 展示点阵屏信息
- for($i=1; $i<=count($shed); $i++){
- $shed_data = json_decode($data[$shed[$i]], true);
- $data['num'.$i] = $shed_data['num'.$i];
- $data['variety'.$i] = $shed_data['variety'.$i];
- $data['farmer'.$i] = $shed_data['farmer'.$i];
- $data['output'.$i] = $shed_data['output'.$i];
- $data['unit'.$i] = $shed_data['unit'.$i];
- }
- };
- $form->before_save = function(&$data) use($shed){
- // 保存点阵屏信息
- for($i=1; $i<=count($shed); $i++){
- $shed_data = array(
- 'num'.$i => $data['num'.$i],
- 'variety'.$i =>$data['variety'.$i],
- 'farmer'.$i =>$data['farmer'.$i],
- 'output'.$i =>$data['output'.$i],
- 'unit'.$i =>$data['unit'.$i]
- );
- $data[$shed[$i]] = json_encode($shed_data, JSON_UNESCAPED_UNICODE);
- }
- };
- $form->display($this);
- }
-
-
- function sys_nav_tree( ){
- //获取导航树数据
- $fields = 'ID as id,ParentID as pId,DepartName as name,Level as level';
- $zndp_util = new \Zndp\User\Util();
- $depart_id = $this->userinfo['OrganizationId'];
- $depart_list = $zndp_util->get_depart_option($depart_id,$fields,'name',false);
- if(empty($depart_list)){
- //没有数据,显示该
- $depart_list[0] = array('id'=>'','pid'=>'','name'=>'没有组织','direct_url'=>'');
- }else{
- for($i=0; $i<count($depart_list); $i++){// 放入链接
- if($depart_list[$i]['level'] <= \Zndp\User\DepartEnum::WORK_STATION){
- $depart_list[$i]['open']= true;
- }
- $depart_list[$i]['direct_url'] = '?s=dpsb_device/sys_list';
- }
- }
- //平台,超级管理员,插入所有用户列表
- $admin_arr = array(\Zndp\User\RoleEnum::GENERAL_ADMINISTRATOR,\Zndp\User\RoleEnum::SUPER_ADMINISTRATOR);
- if( in_array($this->userinfo['RoleId'], $admin_arr) ){
- $all_list = array('id'=>'0','pId'=>'-1','name'=>'所有设备','direct_url'=>'?s=dpsb_device/sys_list','open'=>true);
- array_unshift($depart_list,$all_list);
- }
- //未分配的设备
- $undistr_devic = array('id'=>'-2','pId'=>'-1','name'=>'未分配设备','direct_url'=>'?s=dpsb_device/sys_add_list');
- array_unshift($depart_list,$undistr_devic);
- //设备组
- $device_group = array('id'=>'-3','pId'=>'-1','name'=>'设备组列表','direct_url'=>'?s=dpsb_group/sys_list');
- array_unshift($depart_list,$device_group);
- $this->assign('title','用户管理');
- $this->assign('tree_data',$depart_list);
- $this->display();
- }
-
-
- function sys_list2( ){
- $list = new \Jms\Gui\ClGrid();
- $list->sql_sort = 'DeviceAddr desc';
- $list->before_xeditable_modify = function($name,$data) use ($list){
- if( $name == 'WorkUnitName' ){ //修改设备名称
- $dpsb_device = M('dpsb_device');
- // 同一设备组内唯一
- $where = array( $data['pkfield'] => $data['pk'] );
- $group_id = $dpsb_device->where($where)->getField('DeviceGroupId');
- $where = array(
- $data['pkfield'] => array('neq',$data['pk']),
- 'DeviceGroupId' => $group_id,
- 'WorkUnitName' => $data['value'],
- );
- $count = $dpsb_device->where($where)->count();
- if( $count > 0 ){
- json_fail('设备名称已存在');
- }
- }
- };
- $list->right_filter = function($right,$type){
- $page = $_SERVER['PATH_INFO'];
- return \Jms\Ucenter\Right::defaultFilter($page,$right,$type);
- };
- $list->sql_filter = function($search,&$cond){
- $farmid = I('get.id');
- if($farmid){ // 点击导航树进入
- //获取当前部门下所有基地
- $farm_ids = \Zndp\User\Util::get_depart_farm($farmid);
- //取出基地下所有设备组
- $where = array('FarmId'=>array('IN',$farm_ids));
- $group_ids = M('dpsb_group')->field('ID')->where($where)->select();
- $group_ids = array_column($group_ids,'ID');
- $cond['DeviceGroupId'] = array('in',$group_ids);
- }else{
- if($this->userinfo['OrganizationId']){ //默认选中
- //获取当前部门下所有基地
- $farm_ids = \Zndp\User\Util::get_depart_farm($this->userinfo['OrganizationId']);
- $where = array('FarmId'=>array('IN',$farm_ids));
- //取出基地下所有设备组
- $group_ids = M('dpsb_group')->field('ID')->where($where)->select();
- $group_ids = array_column($group_ids,'ID');
- $cond['DeviceGroupId'] = array('in',$group_ids);
- }else{ //平台管理员
- $cond['DeviceGroupId'] = array('neq',0);
- }
- }
- //搜索
- $keyword = $search['keyword'];
- if($keyword){
- $field = $search['select_list'];
- $cond[$field] = array('LIKE','%'.$keyword.'%');
- }
- };
- $list->row_filter = function(&$row) use ($list){
- // 获取设备组名称
- $where = array('ID'=>$row['DeviceGroupId']);
- $row['DeviceGroupId_text'] = M('dpsb_group')->where($where)->getField('OrgName');
- $row['WorkUnitName_text'] = $list->renderXEditableInput('设备名称',$row,'WorkUnitName',array('rule'=>array('required'=>true)));
- // 获取设备类型名称
- $where = array('ID'=>$row['DeviceTypeId']);
- $type_info = M('dpsb_type')->field('TypeName,DeviceModel')->where($where)->find();
- $row['DeviceTypeId_text'] = $type_info['TypeName'] .' - '.$type_info['DeviceModel'];
- $row['IccId'] = str_replace(' ','<br/>',$row['IccId']);
- // 是否在线
- if( time() - strtotime($row['OnlineTime']) < 180 ){//超过3分钟算离线
- $row['OnlineTime_text'] = "<font color='green'>在线</font>";
- }else{
- $row['OnlineTime_text'] = "<font color='red'>离线</font>";
- }
- // 是否安装
- $where = array('DeviceId'=>$row['ID'],'FarmlandId'=>array('gt',-1));
- $count = M('dpsb_chgroup')->where($where)->count();
- if($count > 0){
- $row['InstallState'] = "<font color='green'>已安装</font>";
- }else{
- $row['InstallState'] = "<font color='red'>未安装</font>";
- }
- //设备已关联田地
- $where = array('DeviceId'=>$row['ID'],'FarmlandId'=>array('NEQ',-1));
- $chgroup_list = M('dpsb_chgroup')->field('ChGroup,FarmlandId')->where($where)->select();
- $assoc_string = '';//关联田地显示字符串
- $dpyh_farmland = M('dpyh_farmland');
- foreach($chgroup_list as $chgroup){
- $where = array('ID'=>$chgroup['FarmlandId']);
- $farmland_name = $dpyh_farmland->where($where)->getField('FarmlandName');
- $assoc_string .= '通道组'.$chgroup['ChGroup'].' - '.$farmland_name.'<br/>';
- }
- $row['AssocFarmland'] = $assoc_string;
- };
- $list->display($this);
- }
-
-
- function sys_new_search( ){
-
- }
-
-
- function sys_list3( ){
- $list = new \Jms\Gui\ClGrid();
- $list->sql_sort = 'DeviceAddr desc';
- $list->right_filter = function($right,$type){
- $page = $_SERVER['PATH_INFO'];
- return \Jms\Ucenter\Right::defaultFilter($page,$right,$type);
- };
- $list->before_xeditable_modify = function($name,$data) use ($list){
- if( $name == 'WorkUnitName' ){ //修改设备名称
- $dpsb_device = M('dpsb_device');
- // 同一设备组内唯一
- $where = array( $data['pkfield'] => $data['pk'] );
- $group_id = $dpsb_device->where($where)->getField('DeviceGroupId');
- $where = array(
- $data['pkfield'] => array('neq',$data['pk']),
- 'DeviceGroupId' => $group_id,
- 'WorkUnitName' => $data['value'],
- );
- $count = $dpsb_device->where($where)->count();
- if( $count > 0 ){
- json_fail('设备名称已存在');
- }
- }
- };
- $list->sql_filter = function($search,&$cond){
- $group_id = I('get.id');
- $cond['DeviceGroupId'] = $group_id;
-
- //搜索
- $keyword = $search['keyword'];
- if($keyword){
- $field = $search['select_list'];
- $cond[$field] = array('LIKE','%'.$keyword.'%');
- }
- };
- $list->row_filter = function(&$row) use ($list){
- $row['WorkUnitName_text'] = $list->renderXEditableInput('设备名称',$row,'WorkUnitName',array('rule'=>array('required'=>true)));
- // 获取设备类型名称
- $where = array('ID'=>$row['DeviceTypeId']);
- $type_info = M('dpsb_type')->field('TypeName,DeviceModel')->where($where)->find();
- $row['DeviceTypeId_text'] = $type_info['TypeName'] .' - '.$type_info['DeviceModel'];
- $row['IccId'] = str_replace(' ','<br/>',$row['IccId']);
- if( time() - strtotime($row['OnlineTime']) < 180 ){//超过3分钟算离线
- $row['OnlineTime_text'] = "<font color='green'>在线</font>";
- }else{
- $row['OnlineTime_text'] = "<font color='red'>离线</font>";
- }
- $where = array('DeviceId'=>$row['ID'],'FarmlandId'=>array('gt',-1));
- $count = M('dpsb_chgroup')->where($where)->count();
- if($count > 0){
- $row['InstallState'] = "<font color='green'>已安装</font>";
- }else{
- $row['InstallState'] = "<font color='red'>未安装</font>";
- }
- //设备已关联田地
- $where = array('DeviceId'=>$row['ID'],'FarmlandId'=>array('NEQ',-1));
- $chgroup_list = M('dpsb_chgroup')->field('ChGroup,FarmlandId')->where($where)->select();
- $assoc_string = '';//关联田地显示字符串
- $dpyh_farmland = M('dpyh_farmland');
- foreach($chgroup_list as $chgroup){
- $where = array('ID'=>$chgroup['FarmlandId']);
- $farmland_name = $dpyh_farmland->where($where)->getField('FarmlandName');
- $assoc_string .= '通道组'.$chgroup['ChGroup'].' - '.$farmland_name.'<br/>';
- }
- $row['AssocFarmland'] = $assoc_string;
- };
- $list->display($this);
- }
-
-
- function sys_addedit( ){
- $form = new \Jms\Gui\ClForm();
- $form->before_save = function(&$data){
- $device_id = I('get.id');
- $where = array(
- 'ID' => array('neq',$device_id),
- 'DeviceGroupId' => $data['DeviceGroupId'],
- 'WorkUnitName' => $data['WorkUnitName']
- );
- $count = M('dpsb_device')->where($where)->count();
- if( $count > 0 ){
- json_fail('设备名称已存在');
- }
- };
- $form->form_filter = function(&$form){
- //显示设备组下拉数据
- $type = new \Zndp\Device\Option;
- $channeltype = $type->getGroupOption();
- $form['fields']['DeviceGroupId']['editor'] = array('options'=>$channeltype);
- };
- $form->display($this);
- }
-
- }
|