$total,'total_1'=>$total_1,'total_2'=>$total_2,'total_3'=>$total_3); return self::send_resu($data); } public function deviceDataTable(){ // $projectid = v('project_id'); $module_hanyupinyin = v("id"); $terminal = v('terminal'); $project_id = $_SESSION['project_id']; if($project_id == '0'){ if(empty($module_hanyupinyin)){ if(empty($terminal)){ $sql = 'select device.id,project.name as project,terminal.name as terminal,device.name,device.sn,device.type,device.register_address,device.status,device.note,device.longitude,device.latitude from project,terminal,device where project.id=device.project_id and terminal.id=device.terminal_id'; }else{ $sql = prepare('select device.id,project.name as project,terminal.name as terminal,device.name,device.sn,device.type,device.register_address,device.status,device.note,device.longitude,device.latitude from project,terminal,device where project.id=device.project_id and terminal.id=device.terminal_id and terminal.name=?s',array($terminal)); } }else{ if(empty($terminal)){ $sql = prepare('select device.id,project.name as project,terminal.name as terminal,device.name,device.sn,device.type,device.register_address,device.status,device.note,device.longitude,device.latitude from project,terminal,device where project.id=device.project_id and terminal.id=device.terminal_id and device.project_id=?i',array($module_hanyupinyin)); }else{ $sql = prepare('select device.id,project.name as project,terminal.name as terminal,device.name,device.sn,device.type,device.register_address,device.status,device.note,device.longitude,device.latitude from project,terminal,device where project.id=device.project_id and terminal.id=device.terminal_id and device.project_id=?i and terminal.name=?s',array($module_hanyupinyin,$terminal)); } } }else{ if(empty($module_hanyupinyin)){ if(empty($terminal)){ $sql = prepare("select device.id,project.name as project,terminal.name as terminal,device.name,device.sn,device.type,device.register_address,device.status,device.note,device.longitude,device.latitude from project,terminal,device where project.id=device.project_id and terminal.id=device.terminal_id and device.project_id=?i ",array($project_id)); }else{ $sql = prepare("select device.id,project.name as project,terminal.name as terminal,device.name,device.sn,device.type,device.register_address,device.status,device.note,device.longitude,device.latitude from project,terminal,device where project.id=device.project_id and terminal.id=device.terminal_id and device.project_id=?i and terminal.name=?s",array($project_id,$terminal)); } }else{ if(empty($terminal)){ $sql = prepare("select device.id,project.name as project,terminal.name as terminal,device.name,device.sn,device.type,device.register_address,device.status,device.note,device.longitude,device.latitude from project,terminal,device where project.id=device.project_id and terminal.id=device.terminal_id and device.project_id=?i ",array($project_id)); }else{ $sql = prepare("select device.id,project.name as project,terminal.name as terminal,device.name,device.sn,device.type,device.register_address,device.status,device.note,device.longitude,device.latitude from project,terminal,device where project.id=device.project_id and terminal.id=device.terminal_id and device.project_id=?i and terminal.name=?s",array($project_id,$terminal)); } } } $data = get_data($sql); $total = count($data); return self::send_result($total,$data); } /** * 返回设备详情 */ public function device_details() { $device_id = v("id"); // 累计调控次数 $sql_count = prepare("select (main_sewage_pump_count+standby_sewage_pump_count+main_rain_pump_count+gate_up_count+gate_down_count) as control_count from data where device_id = ?i order by id desc limit 1",array($device_id)); $data['control_count'] = get_var($sql_count); $sql_warn = prepare("select count(warn.id) from warn where device_id = ?i ",array($device_id)); $data['warn_count'] = get_var($sql_warn); //基本信息 场站名称 地址 负责人 联系方式 $sql = prepare("select project.name as project_name,terminal.name as terminal_name,device.name,device.register_address,if(device.status=1,'使用中','实施中') as status,device.created_at from device left join project on project.id = device.project_id left join terminal on terminal.id = device.terminal_id where device.id=?i",array($device_id)); $data['info'] = get_line($sql); //设备情况 控制状态 控制模式 闸门状态 1主污泵状态 2备污泵状态 3雨水泵 $sql_strategy = prepare("select strategy.name from strategy,device where strategy.id=device.strategy_id and device.id=?i",array($device_id)); $data['strategy'] = get_var($sql_strategy); $sql_controlmodel = prepare("select CASE WHEN control_model = 1 THEN '手动模式' else '自动模式' END from device where id=?i limit 1",array($device_id)); $data['controlmodel'] = get_var($sql_controlmodel); $sql_device_status = prepare("select if(main_sewage_pump=1,'开启','关闭') as main_sewage_pump,if(standby_sewage_pump=1,'开启','关闭') as standby_sewage_pump,if(main_rain_pump=1,'开启','关闭') as main_rain_pump,if(gate_up=1,'闸门上升','闸门上升停止') as gate_up,if(gate_down=1,'闸门下降','闸门下降停止') as gate_down from data where device_id = ?i order by id desc limit 1",array($device_id)); $data['gate_up'] = get_line($sql_device_status)['gate_up']; $data['gate_down'] = get_line($sql_device_status)['gate_down']; $data['main_sewage_pump'] = get_line($sql_device_status)['main_sewage_pump']; $data['standby_sewage_pump'] = get_line($sql_device_status)['standby_sewage_pump']; $data['main_rain_pump'] = get_line($sql_device_status)['main_rain_pump']; if (!empty($_SESSION)) { render($data, 'web', 'device_details'); } else { header("Location:?c=index&a=index"); } } // 设备详情列表 public function deviceDetailsDataTable(){ $id = v("id"); $sql = prepare("select elec_conductivity_data,elec_resistivity_data,elec_conductivity_tds_data,rainfall_data,rainsnow,level_data,ph_data,ammonia_data,created_at from data where device_id = ?i order by created_at desc limit 200",array($id)); $data = get_data($sql); $total = count($data); return self::send_result($total,$data); } public function terminal(){ $module_hanyupinyin = 1; if(empty($module_hanyupinyin)){ $sql_terminal = prepare("select terminal.id,terminal.name from terminal,project where project.id=terminal.project_id",array($module_hanyupinyin)); $terminal = get_data($sql_terminal); }else{ $sql_terminal = prepare("select terminal.id,terminal.name from terminal,project where project.id=terminal.project_id and terminal.project_id=?i",array($module_hanyupinyin)); $terminal = get_data($sql_terminal); } return self::send_resu($terminal); } // 设备修改 public function device_edit() { $device_id = v('id'); $sql = prepare("select device.id,project.name as project_name,terminal.name as terminal_name,device.name,device.register_address as address,device.sn,device.longitude,device.latitude,device.created_at from device left join project on project.id = device.project_id left join terminal on terminal.id = device.terminal_id where device.id=?i",array($device_id)); $data= get_line($sql); render($data, 'web', 'device_edit'); } // 设备修改 public function device_update() { $id = $_POST['id']; $project_name = $_POST['project_name']; $terminal_name = $_POST['terminal_name']; $name = $_POST['name']; $address = $_POST['address']; $longitude = $_POST['longitude']; $latitude = $_POST['latitude']; $sn = $_POST['sn']; $sql = prepare("update device set name=?s,register_address=?s,longitude=?s,latitude=?s,sn=?s where id=?i",array($name,$address,$longitude,$latitude,$sn,$id)); $impact = run_sql($sql); if($impact) { $result = "success"; }else { $result = "false"; } return self::send_resu($result); } }