| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');include_once(FCPATH . 'application/controllers/Base_Controller.php');class Network extends Base_Controller {    public function __construct() {        parent::__construct();        $this->load->model('Project_model');        $this->load->model('Network_model');        $this->load->model('Lamp_model');        // $this->load->model('Zone_model');        $this->load->model('Alarm_model');        $this->load->model('Videomonitor_model');        $this->load->model('Weathermonitor_model');    }    // 获取网络下拉列表    public function get() {        exit(json_result('0000', $this->response['0000'], array('networks'=>array())));        $userid = $this->get_user_info('id');        $project_id = $this->input->post('project_id', true);        if (empty($project_id)) {            exit(json_result('0308',$this->response['0308'],array()));        }        $project_id = intval($project_id);        $data = !empty($project_id) ? $this->Network_model->get_list_in('projectid', array($project_id), 'id, networkname as name,lampcount as lamp,status,gatewaytype') : array();        $temp = array();        foreach ($data as $key => $value) {            if ($value['gatewaytype'] == 'direct') {                continue;            }            $temp[] = $value;        }        exit(json_result('0000', $this->response['0000'], array('networks'=>$temp)));    }        // 网络路段筛选列表    public function network_section_list() {        exit(json_result('0000', $this->response['0000'], array('networks'=>array())));        $userid = $this->get_user_info('id');        $project_id = $this->input->post('project_id', true);        if (empty($project_id)) {            exit(json_result('0308',$this->response['0308'],array()));        }        $project_id = intval($project_id);        $data = !empty($project_id) ? $this->Network_model->get_list_in('projectid', array($project_id), 'id, networkname as name,gatewaytype') : array();        $temp = array();        foreach ($data as $key => $value) {            $value['type'] = 0;            if ($value['gatewaytype'] == 'direct') {                continue;            }            $temp[] = $value;        }        if (empty($temp)) {            $sectionList = $this->Lamp_model->get_list(array('projectid'=>$project_id), 'section,count(*) as sum',NULL, NULL, 'section ASC,id DESC', 'section');            foreach ($sectionList as $s) {                if ($s['section'] == '') continue;                $temp[] = array(                    'name' => $s['section'],                    'id' => $s['section'],                    'lamp' => $s['sum'],                    'type' => 1,                );            }        }        exit(json_result('0000', $this->response['0000'], array('networks'=>$temp)));    }    // 删除网络(支持批量)    public function del() {        $role = $this->get_user_info('role');        // if ($role == COMPANY_CUSTOMER) {        //     exit(json_result('0011', $this->response['0011'], array()));        // }        $network_ids = $this->input->post('network_ids', true);        if(empty($network_ids)) {            exit(json_result('0300', $this->response['0300'], array()));        }        $ids = explode(",", $network_ids);        // 删除网络对应区域        // $this->Zone_model->delZone($ids);        // 修改项目中网络数        $dataArr = $this->Network_model->getBatch($ids);        foreach ($dataArr as $data) {            $this->Project_model->minus_network_count($data);        }        // 删除网络下路灯的该井告警信息        $this->Alarm_model->delBatchByCondition($ids, 'networkid');        // 删除网络下的路灯        $this->Lamp_model->delBatch($ids, 'networkid');        // 删除网络下的监控        // $this->Videomonitor_model->delData(array('networkid'=>$ids));        $this->Weathermonitor_model->delData(array('networkid'=>$ids));        foreach ($ids as $v) {            $networkData = $this->Network_model->getData(array('id'=>$v),'projectid,networkid,networkname,protocoltype');            $projectData = $this->Project_model->getData(array('id'=>$networkData['projectid']),'projectname');            $this->add_operation_log('delete',"删除\"{$projectData['projectname']}\"项目下的\"{$networkData['networkname']}\"网络,网络编号\"{$networkData['networkid']}\"",0);            $this->add_operation_log('delete',"Delete network.Network number:\"{$networkData['networkid']}\".Network name:\"{$networkData['networkname']}\".Project name:\"{$projectData['projectname']}\"",0,1);            $cmdstr = '{"cmd_type":"delete_network_cmd","cmd_id":'.$v.'}';            send_cmd($cmdstr,0,0,$v['protocoltype']);        }        // 删除网络        $this->Network_model->delBatch($ids);        // foreach ($ids as $v) {        //     $cmdstr = '{"cmd_type":"delete_network_cmd","cmd_id":'.$v.'}';        //     send_cmd($cmdstr,0,0);        // }        exit(json_result('0000', $this->response['0000'], array()));    }    // 获取网络详情    public function detail() {        $network_id = $this->input->post('network_id', true);        if(empty($network_id)){            exit(json_result('0300', $this->response['0300'], array()));        }        $fields = 'networkid as network_no,                   networkname as network_name,                   status,                   section,                   simcard,                   regpack,                   longitude,                   latitude,                   lampcount,                   createtime,                   gatewaytype,                   faultcount,                   protocoltype,                   ip,                   port,                   hbpack,                   hbcycle,                   devicesn as sn,                   channel';        $data = $this->Network_model->getData(array('id' => $network_id), $fields);        $data['gatewaytype'] = $data['gatewaytype'] == 'direct' ? '1' : '0';        $data['lampcount'] = $this->Lamp_model->get_total('','','*',array('networkid'=>$network_id));        if(!$data){            exit(json_result('0302', $this->response['0202'], $data));        } else {            exit(json_result('0000', $this->response['0000'], $data));        }    }    // 添加/编辑网络    public function save() {        $role = $this->get_user_info('role');        // if ($role == COMPANY_CUSTOMER) {        //     exit(json_result('0011', $this->response['0011'], array()));        // }        $where['id']         = $this->input->post('network_id',true);        $data['projectid']   = $this->input->post('project_id',true);        $data['networkid']   = $this->input->post('network_no',true);        if (empty($data['networkid'])) exit(json_result('0305',$this->response['0305'],array()));        if(!preg_match('/^[A-Za-z0-9]+$/', $data['networkid'])) exit(json_result('0309',$this->response['0309'],array()));        $data['networkname'] = $this->input->post('network_name',true);        $section     = $this->input->post('section',true);        $simcard     = $this->input->post('simcard',true);        $longitude   = doubleval($this->input->post('longitude',true));        $latitude    = doubleval($this->input->post('latitude',true));        $data['status']    = $this->input->post('status',true);        // $gatewaytype    = $this->input->post('gatewaytype',true);        $data['ip']    = $this->input->post('ip',true);        $data['regpack']    = $this->input->post('regpack',true);        $data['hbpack']    = $this->input->post('hbpack',true);        $devicesn    = $this->input->post('sn',true);        $data['lampcount']    = $this->input->post('lampcount',true);        $data['port']    = $this->input->post('port',true);        $protocoltype = $this->input->post('protocoltype',true);        $data['hbcycle'] = $this->input->post('hbcycle',true);        $data['channel'] = intval($this->input->post('channel',true));        // $data['gatewaytype'] = empty($gatewaytype) ? '' : $gatewaytype;        if(isset($longitude)) $data['longitude'] = $longitude;        if(isset($latitude)) $data['latitude'] = $latitude;        if(isset($simcard)) $data['simcard'] = $simcard;        if(isset($section)) $data['section'] = $section;        if(isset($devicesn)) $data['devicesn'] = $devicesn;        if(isset($protocoltype)) $data['protocoltype'] = $protocoltype;        // 网络设备类型        $devicetype = $this->input->post('devicetype',true);        if (!empty($devicetype)) $data['devicetype'] = $devicetype;        $data['lampcount'] = empty($data['lampcount']) ? 0 : $data['lampcount'];        if(empty($data['networkname'])) exit(json_result('0306',$this->response['0306'],array()));        if(empty($data['projectid'])) exit(json_result('0307',$this->response['0307'],array()));        if (!empty($data['protocoltype'])) {            if (!is_numeric($data['protocoltype']) || $data['protocoltype'] < 0 || $data['protocoltype'] > 3) {                exit(json_result('0304', $this->response['0304'], array()));            }        }        $data = remove_null_params($data);                if (empty($where['id'])) {            if ($this->Network_model->getDataCount(array('networkid'=>$data['networkid'], 'projectid'=>$data['projectid'])) > 0) {                exit(json_result('0301', $this->response['0301'], array()));            }                    if ($this->Network_model->getDataCount(array('networkname'=>$data['networkname'], 'projectid'=>$data['projectid'])) > 0) {                exit(json_result('0303', $this->response['0303'], array()));            }                        // $data['id']  = $this->Zone_model->insert(array(            //     'name'   => $data['networkname'],            //     'parent' => $data['projectid'] ,            //     'level'  => 4            // ));                 $timezone = $this->Project_model->get_timezone_by_projectid($data['projectid']);                   $data['createtime'] = get_time_by_timezone($timezone['value']);            $networkId = $this->Network_model->insert($data);            $data['faultcount'] = 0;            $this->Project_model->add_network_count($data);                        // $networkId = $data['id'];            $projectData = $this->Project_model->getData(array('id'=>$data['projectid']),'projectname');            $this->add_operation_log('insert',"在\"{$projectData['projectname']}\"项目下添加\"{$data['networkname']}\"网络,网络编号\"{$data['networkid']}\"",0);            $this->add_operation_log('insert',"Add network.Network number:\"{$data['networkid']}\".Network name:\"{$data['networkname']}\".Project name:\"{$projectData['projectname']}\"",0,1);        } else {            if ($this->Network_model->getDataCount(array('networkid'=>$data['networkid'], 'projectid'=>$data['projectid']), $where['id']) > 0) {                exit(json_result('0301', $this->response['0301'], array()));            }                    if ($this->Network_model->getDataCount(array('networkname'=>$data['networkname'], 'projectid'=>$data['projectid']), $where['id']) > 0) {                exit(json_result('0303', $this->response['0303'], array()));            }            // $this->Zone_model->update($where, array('name'=>$data['networkname'], 'parent'=>$data['projectid']));            $old = $this->Network_model->getData($where);            if ($old['projectid'] != $data['projectid']) {                $new['projectid'] = $data['projectid'];                $new['lampcount'] = $old['lampcount'];                $new['faultcount'] = $old['faultcount'];                $new['count'] = $old['monitorcount'];                $old['count'] = $old['monitorcount'];                $this->Project_model->add_network_count($new);                $this->Project_model->minus_network_count($old);                $this->Project_model->add_monitor_count($new);                $this->Project_model->minus_monitor_count($old);                // 修改路灯所属项目                $this->Lamp_model->update(['networkid'=>$where['id']], ['projectid'=>$data['projectid']]);            }            $this->Network_model->update($where, $data);                        $networkId = $where['id'];            $projectData = $this->Project_model->getData(array('id'=>$data['projectid']),'projectname');            $this->add_operation_log('update',"修改\"{$projectData['projectname']}\"项目下的\"{$data['networkname']}\"网络,网络编号\"{$old['networkid']}\"",0);            $this->add_operation_log('update',"Update network.Network number:\"{$old['networkid']}\".Network name:\"{$data['networkname']}\".Project name:\"{$projectData['projectname']}\"",0,1);        }        exit(json_result('0000', $this->response['0000'], array("id" => intval($networkId))));    }    }
 |