public function actionAdd() { if (XUtils::method() == 'POST') { HDraw::deleteQRCode(); // echo var_dump($_POST); if (isset($_POST['type'])) { $type = $_POST['type']; if ($type == 'static') { $test = AsAsset::model()->findByPk($_POST['RFID']); // echo var_dump($test); if (is_null($test)) { $asset = new AsAsset(); // 资产数据库表 $asset->RFID = $_POST['RFID']; // 提交页面的RFID的值 $asset->assetName = $_POST['assetName']; // $asset->state=$_POST['state']; $asset->specification = $_POST['specification']; $asset->Price = $_POST['Price']; $asset->storageId = $_POST['storageId']; $asset->inTime = $_POST['inTime']; $asset->outPrm = $_POST['outPrm']; if ($asset->outPrm == 'n') { $asset->state = "in"; } else { $asset->state = $_POST['state']; } $asset->brwPhone = ""; $test = AsAsset::model()->findByPk($RFID); // echo var_dump($asset); if ($asset->save() > 0) { // 数据库表类的函数save(),存储是否成功,来自yii框架 echo "<script language=\"JavaScript\">alert(\"添加成功\");</script>"; } else { echo "<script language=\"JavaScript\">alert(\"添加失败\");</script>"; } } else { echo "<script language=\"JavaScript\">alert(\"该标签已存在\");</script>"; } } else { if ($type == 'consume') { $test = AsConsume::model()->findByPk($_POST['assetId']); if (is_null($test)) { $consume = new AsConsume(); // 资产数据库表 $consume->assetId = $_POST['assetId']; $consume->assetName = $_POST['assetName']; $consume->specification = $_POST['specification']; $consume->Price = $_POST['Price']; $consume->state = $_POST['state']; $consume->storageId = $_POST['storageId']; $consume->inTime = $_POST['inTime']; $consume->outPrm = "y"; $consume->brwPhone = ""; $content = "assetId:" . $consume->assetId . ";assetName:" . $consume->assetName . ";specification:" . $consume->specification . ";Price:" . $consume->Price . ";storageId:" . $consume->storageId . ";outPrm:" . $consume->outPrm . ";brwPhone:" . $consume->brwPhone . ";state:" . $consume->state . ";inTime:" . $consume->inTime . ";"; $display = $consume->assetId . '/' . $consume->assetName . '/' . $consume->specification; // echo var_dump($consume); if ($consume->save() > 0) { // 数据库表类的函数save(),存储是否成功,来自yii框架 echo "<script language=\"JavaScript\">alert(\"添加成功\");</script>"; $finalQRCode = $this->QRcode($consume->assetId, $content, $display); } else { echo "<script language=\"JavaScript\">alert(\"添加失败\");</script>"; } } else { echo "<script language=\"JavaScript\">alert(\"该编号已经存在\");</script>"; } } } } } if ($type == "") { $type = "static"; } // var_dump($consume['']); $this->render('add', array('type' => $type, 'finalQRCode' => $finalQRCode, 'consume' => $consume)); }
public function actionIndex() { if (XUtils::method() == 'POST') { if (isset($_POST['analyseType'])) { // echo var_dump( $_POST ['analyseType']); // echo var_dump($_SESSION["name"]."......."); HDraw::deletePic(); //删除历史图片 $analyseType = $_POST['analyseType']; if ($analyseType == "1") { $sql = "SELECT name,SUM(power) as c1 from energy_power WHERE time>='" . $_POST['inTime'] . "' AND time<='" . $_POST['outTime'] . "' GROUP BY name ORDER BY c1 DESC LIMIT 0,10"; $data = Yii::app()->db->createCommand($sql)->queryAll(); $data = json_decode(CJSON::encode($data), TRUE); $data_x = array(); $data_y = array(); foreach ($data as $key => $value) { $data_x[] = $value['name']; $data_y[] = $value['c1']; } // echo var_dump($data); $x_title = x_name; // $y_title = "n 数度"; $graph_title = "能耗排序图前十 (单位:度)"; // echo var_dump($data_x); // echo var_dump($data_y); // echo var_dump(empty($data_x)); if (empty($data_x)) { // 数据库表类的函数save(),存储是否成功,来自yii框架 echo "<script language=\"JavaScript\">alert(\"该段时间没有记录!\");</script>"; } else { $max_y = max($data_y); $name = HDraw::HistogramShow($data_x, $data_y, $x_title, $y_title, $graph_title, $max_y); } } elseif ($analyseType == "2") { $sql = "SELECT name,SUM(power) as c1 from energy_power WHERE time>='" . $_POST['inTime'] . "' AND time<='" . $_POST['outTime'] . "' GROUP BY name ORDER BY c1 ASC LIMIT 0,10"; $data = Yii::app()->db->createCommand($sql)->queryAll(); $data = json_decode(CJSON::encode($data), TRUE); $data_x = array(); $data_y = array(); foreach ($data as $key => $value) { $data_x[] = $value['name']; $data_y[] = $value['c1']; } // echo var_dump($data); $x_title = "房间号"; // $y_title = " 数度"; $graph_title = "能耗排序图后十 (单位:度)"; // echo var_dump($data_x); // echo var_dump($data_y); // echo var_dump(empty($data_x)); if (empty($data_x)) { // 数据库表类的函数save(),存储是否成功,来自yii框架 echo "<script language=\"JavaScript\">alert(\"该段时间没有记录!\");</script>"; } else { $max_y = max($data_y); $name = HDraw::HistogramShow($data_x, $data_y, $x_title, $y_title, $graph_title, $max_y); } } elseif ($analyseType == "3") { $sql = "SELECT roomId,SUM(power) as c1 FROM energy_power,energy_room WHERE energy_power.id in(SELECT energy_room.assetID FROM energy_room) GROUP BY energy_room.roomId DESC"; // $sql = "SELECT roomId,SUM(energy_power.power)" $name1 = Yii::app()->db->createCommand($sql)->queryAll(); $name1 = json_decode(CJSON::encode($name1), TRUE); // echo var_dump($name1); // $max_y = max($data_y); foreach ($name1 as $key => $value) { $data_x[] = "房间" . $value['roomId'] . ""; $data_y[] = $value['c1'] / 10; } $x_title = "房间号"; // $y_title = " 能耗占比"; $graph_title = "房间能耗排序图前十(单位:度)"; if (empty($name1)) { echo "<script language=\"JavaScript\">alert(\"该段时间没有记录!\");</script>"; } else { $max_y = max($data_y); $name = HDraw::horizontalBarShow($data_x, $data_y, $x_title, $y_title, $graph_title, $max_y); } } elseif ($analyseType == "4") { $sql = "SELECT name,SUM(power) as c1 from energy_power WHERE time>='" . $_POST['inTime'] . "' AND time<='" . $_POST['outTime'] . "' GROUP BY name ORDER BY c1"; $data = Yii::app()->db->createCommand($sql)->queryAll(); $data = json_decode(CJSON::encode($data), TRUE); $piedata = array(); $piename = array(); $location = 9; $ages = array(); foreach ($data as $value) { $ages[] = $value['c1']; } array_multisort($ages, SORT_DESC, $data); // echo var_dump($data); foreach ($data as $key => $value) { if ($key < $location) { $piename[] = $value['name']; $piedata[] = $value['c1']; } else { $piedata[$location] += $value['c1']; $piename[$location] = "其他"; } } // echo var_dump($piedata); $title = "资产能耗占比 "; if (empty($piedata)) { // 数据库表类的函数save(),存储是否成功,来自yii框架 echo "<script language=\"JavaScript\">alert(\"该段时间没有记录!\");</script>"; } else { $name = HDraw::pieShow($piedata, $piename, $title); } } elseif ($analyseType == "5") { // echo var_dump($_POST['inTime']); if (!empty($_POST['month'])) { $month = $_POST['month']; } $now = (int) $month; $thismonth = date('Y'); $thismonth .= "-" . $month; // $now1 = DATE_FORMAT('2015-08-09', '%Y%M'); // echo var_dump($thismonth); $sql = "SELECT power,time from energy_power WHERE date_format(time,'%Y-%m') ='" . $thismonth . "' and name='" . $_POST['assetName'] . "' ORDER BY time"; // echo var_dump($_POST ['assetName']); $sql1 = "SELECT power,time from energy_power WHERE date_format(time,'%Y-%m') ='" . $thismonth . "' and name='" . $_POST['assetName2'] . "' ORDER BY time"; $name1 = Yii::app()->db->createCommand($sql)->queryAll(); $name1 = json_decode(CJSON::encode($name1), TRUE); $name2 = Yii::app()->db->createCommand($sql1)->queryAll(); $name2 = json_decode(CJSON::encode($name2), TRUE); // echo var_dump(empty ( $name2)); $judge = 1; if (empty($name1) && empty($name2)) { $judge = 0; echo "<script language=\"JavaScript\">alert(\"名称或时间输入有误,请重新输入!\");</script>"; } else { foreach ($name1 as $key => $value) { $data_x[] = $value['time']; $data_y[] = $value['power']; } foreach ($name2 as $key => $value) { $data2_y[] = $value['power']; } // echo var_dump($months); $x_title = "日期"; $y_title = "度数"; $graph_title = " " . $_POST['assetName'] . " " . $_POST['assetName2'] . " " . $now . "月耗电量变化图(单位:度)"; // $data_x=array("1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"); $name = HDraw::liner2Show($data_x, $data_y, $data2_y, $x_title, $y_title, $graph_title); } } elseif ($analyseType == "6") { $flog = 6; //设置开关,动态刷新资产能耗走势图 // $thisTime = date("Y-m-d H:i:s",strtotime("- 45 minutes 2 seconds")); // echo var_dump($thisTime); // $now1 = DATE_FORMAT('2015-08-09', '%Y%M'); // echo var_dump($thismonth); $sql = " SELECT electric,time from energy_day WHERE name='" . $_POST['assetName'] . "' ORDER BY time DESC LIMIT 0,50"; // echo var_dump($_POST ['assetName']); // $sql1="SELECT power,time from energy_power WHERE date_format(time,'%Y-%m') ='".$thismonth."' and name='".$_POST ['assetName2']."' ORDER BY time"; $name1 = Yii::app()->db->createCommand($sql)->queryAll(); $name1 = json_decode(CJSON::encode($name1), TRUE); // echo var_dump($name1); // $name2 = Yii::app ()->db->createCommand($sql1)->queryAll(); // $name2 = json_decode ( CJSON::encode ( $name2 ), TRUE ); // echo var_dump(empty ( $name2)); // echo var_dump($name1); // var_dump($name1); $judge = 1; if (empty($name1)) { $judge = 0; echo "<script language=\"JavaScript\">alert(\"名称输入有误,请重新输入!\");</script>"; } else { foreach ($name1 as $key => $value) { $data_x[] = ""; $data_y[] = $value['electric']; $t = $value['time']; } $data_y = array_reverse($data_y); $data_x[count($name1) - 1] = $t; // echo var_dump($data_x[count($name1)-1]); $x_title = "日期"; $y_title = "度数"; $graph_title = " " . $_POST['assetName'] . $now . " 实时电流值(单位:mA)"; // $data_x=array("1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"); $name = HDraw::liner3Show($data_x, $data_y, $x_title, $y_title, $graph_title); } } } } $this->render('index', array('data' => $data, 'flog' => $flog, 'pages' => $pages, 'analyseType' => $analyseType, 'month' => $month, 'inTime' => $_POST['inTime'], 'outTime' => $_POST['outTime'], 'assetName' => $_POST['assetName'], 'assetName2' => $_POST['assetName2'], 'judge' => $judge, 'name' => $name)); }
public function actionIndex() { if (XUtils::method() == 'POST') { if (isset($_POST['analyseType'])) { // echo var_dump( $_POST ['analyseType']); // echo var_dump($_SESSION["name"]."......."); HDraw::deletePic(); //删除历史图片 $analyseType = $_POST['analyseType']; if ($analyseType == "1") { $sql = "SELECT assetName,COUNT(*) as c1 from as_analyse WHERE borrowTime>='" . $_POST['inTime'] . "' AND borrowTime<='" . $_POST['outTime'] . "' GROUP BY assetName ORDER BY COUNT(*) DESC LIMIT 0,10"; $data = Yii::app()->db->createCommand($sql)->queryAll(); $data = json_decode(CJSON::encode($data), TRUE); $data_x = array(); $data_y = array(); foreach ($data as $key => $value) { $data_x[] = $value['assetName']; $data_y[] = $value['c1']; } // echo var_dump($data); $x_title = x_name; // $y_title = " 数次出借"; $graph_title = "借出次数排序图前十(单位:次)"; // echo var_dump($data_x); // echo var_dump($data_y); // echo var_dump(empty($data_x)); if (empty($data_x)) { // 数据库表类的函数save(),存储是否成功,来自yii框架 echo "<script language=\"JavaScript\">alert(\"该段时间没有记录!\");</script>"; } else { $max_y = max($data_y); $name = HDraw::HistogramShow($data_x, $data_y, $x_title, $y_title, $graph_title, $max_y); } } elseif ($analyseType == "2") { $sql = "SELECT assetName,COUNT(*) as c1 from as_analyse WHERE borrowTime>='" . $_POST['inTime'] . "' AND borrowTime<='" . $_POST['outTime'] . "' GROUP BY assetName ORDER BY COUNT(*) ASC LIMIT 10"; $data = Yii::app()->db->createCommand($sql)->queryAll(); $data = json_decode(CJSON::encode($data), TRUE); $data_x = array(); $data_y = array(); foreach ($data as $key => $value) { $data_x[] = $value['assetName']; $data_y[] = $value['c1']; } // echo var_dump($data); $x_title = x_name; // $y_title = " 数次出借"; $graph_title = "借出次数排序图后十(单位:次)"; // echo var_dump($data_x); // echo var_dump($data_y); // echo var_dump(empty($data_x)); if (empty($data_x)) { // 数据库表类的函数save(),存储是否成功,来自yii框架 echo "<script language=\"JavaScript\">alert(\"该段时间没有记录!\");</script>"; } else { $max_y = max($data_y); $name = HDraw::HistogramShow($data_x, $data_y, $x_title, $y_title, $graph_title, $max_y); } } elseif ($analyseType == "3") { $sql = "SELECT assetName,COUNT(*) as c1 from as_asset WHERE assetName in(SELECT assetName from as_analyse) GROUP BY assetName"; $sql_ast = "SELECT assetName,borrowTime,returnTime from as_analyse WHERE borrowTime>='" . $_POST['inTime'] . "' AND borrowTime<='" . $_POST['outTime'] . "'"; $data1 = Yii::app()->db->createCommand($sql_ast)->queryAll(); $data1 = json_decode(CJSON::encode($data1), TRUE); // echo var_dump($data1); $data_x = array(); $data_y = array(); $data_name = array(); $data_num = array(); $date_each = array(); $date_sum = array(); if (empty($data1)) { // 数据库表类的函数save(),存储是否成功,来自yii框架 echo "<script language=\"JavaScript\">alert(\"该段时间没有记录!\");</script>"; } else { foreach ($data1 as $key => $value) { $data_name[] = $value['assetName']; if ($value['returnTime'] < $_POST['outTime']) { $date_each[] = (strtotime($value['returnTime']) - strtotime($value['borrowTime'])) / time + 1; } else { $date_each[] = (strtotime($_POST['outTime']) - strtotime($value['borrowTime'])) / time + 1; } } // echo var_dump($data_name); // echo var_dump($date_each); $date = strtotime($_POST['outTime']) - strtotime($_POST['inTime']); $date = $date / time; // echo var_dump($date); $flog = 0; $data2 = Yii::app()->db->createCommand($sql)->queryAll(); $data2 = json_decode(CJSON::encode($data2), TRUE); // echo var_dump($data2); foreach ($data2 as $key => $value) { if (in_array($value['assetName'], $data_name)) { $data_x[] = $value['assetName']; $data_num[] = $value['c1']; foreach ($data1 as $key1 => $value1) { // echo var_dump($date_each[$key]); if ($value1['assetName'] == $data_x[$flog]) { // echo var_dump($key1); // echo var_dump($flog); $date_sum[$flog] += $date_each[$key1]; // echo var_dump($date_sum[$flog]); } } $data_y[$flog] = $date_sum[$flog] / ($data_num[$flog] * $date); // echo var_dump($data_y[$key]); $flog++; } } array_multisort($data_y, SORT_DESC, $data_x); // echo var_dump($data_y); $max_y = max($data_y); $x_title = x_name; // $y_title = " 率用占"; $graph_title = "资产占用率排序图"; $name = HDraw::HistogramShow($data_x, $data_y, $x_title, $y_title, $graph_title, $max_y); } } elseif ($analyseType == "4") { $sql = "SELECT assetName,COUNT(*) as c1 from as_analyse WHERE borrowTime>='" . $_POST['inTime'] . "' AND returnTime<='" . $_POST['outTime'] . "' GROUP BY assetName ORDER BY COUNT(*) LIMIT 0,10"; $data = Yii::app()->db->createCommand($sql)->queryAll(); $data = json_decode(CJSON::encode($data), TRUE); $piedata = array(); $piename = array(); // var_dump($data); $location = 9; $ages = array(); foreach ($data as $value) { $ages[] = $value['c1']; } array_multisort($ages, SORT_DESC, $data); // echo var_dump($data); foreach ($data as $key => $value) { if ($key < $location) { $piename[] = $value['assetName']; $piedata[] = $value['c1']; } else { $piedata[$location] += $value['c1']; $piename[$location] = "其他"; } } // foreach ($data as $key => $value) { // $piename[]=$value['assetName']; // $piedata[]=$value['c1']; // } // echo var_dump($piedata); $title = "借出次数统计结果 "; if (empty($piedata)) { // 数据库表类的函数save(),存储是否成功,来自yii框架 echo "<script language=\"JavaScript\">alert(\"该段时间没有记录!\");</script>"; } else { $name = HDraw::pieShow($piedata, $piename, $title); } } elseif ($analyseType == "5") { $sql = "SELECT assetName,borrowTime,COUNT(*) as c1 from as_analyse WHERE assetName='" . $_POST['assetName'] . "' GROUP BY DATE_FORMAT(borrowTime, '%Y%M')"; // echo var_dump($_POST ['assetName']); $sql1 = "SELECT assetName FROM as_asset WHERE assetName='" . $_POST['assetName'] . "'"; $name1 = Yii::app()->db->createCommand($sql)->queryAll(); $name1 = json_decode(CJSON::encode($name1), TRUE); $name2 = Yii::app()->db->createCommand($sql1)->queryAll(); $name2 = json_decode(CJSON::encode($name2), TRUE); $judge = 1; if (empty($name1)) { if (!empty($name2)) { echo "<script language=\"JavaScript\">alert(\"该资产年内没有接出!\");</script>"; } else { $judge = 0; echo "<script language=\"JavaScript\">alert(\"资产名称输入有误,重新的输入!\");</script>"; } // $judge = 0; // echo "<script language=\"JavaScript\">alert(\"资产名称输入有误,重新的输入!\");</script>"; } else { $data_y = array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); $months = array(); foreach ($name1 as $key => $value) { $months[] = date("m", strtotime($value['borrowTime'])); $data_y[(int) $months[$key] - 1] = $value['c1']; } // echo var_dump($months); $x_title = "月份"; $y_title = "次数"; $graph_title = " " . $_POST['assetName'] . "年内每月借出次数变化图(单位:次)"; $data_x = array("1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"); $name = HDraw::linerShow($data_x, $data_y, $x_title, $y_title, $graph_title); } } elseif ($analyseType == "7") { if (empty($_POST['inTime']) || empty($_POST['outTime'])) { echo "<script language=\"JavaScript\">alert(\"请输入时间!\");</script>"; } elseif ($_POST['inTime'] > $_POST['outTime']) { echo "<script language=\"JavaScript\">alert(\"开始时间大于截止日期,请重新输入!\");</script>"; } else { // $criteria = new CDbCriteria (); // $count = AsAsset::model ()->count ( $criteria ); // $pages = new CPagination ( $count ); // $pages->pageSize = PAGESIZE; // $pages->applyLimit ( $criteria ); $flog = 7; $sql = "SELECT assetName,RFID,storageId,specification,inTime FROM as_asset WHERE assetName not in(SELECT assetName FROM as_analyse WHERE borrowTime>='" . $_POST['inTime'] . "' AND returnTime<='" . $_POST['outTime'] . "') LIMIT 0,15"; $data7 = Yii::app()->db->createCommand($sql)->queryAll(); $data = json_decode(CJSON::encode($data7), TRUE); } } elseif ($analyseType == "8") { $sql1 = "SELECT assetName,scrapeTime,specification,COUNT(*) as c2 FROM as_asset WHERE assetName='" . $_POST['assetName'] . "' and scrapeTime<=CURDATE() and scrapeTime >=DATE_SUB(CURDATE(),INTERVAL dayofyear(now())-1 DAY) GROUP BY specification"; $test = Yii::app()->db->createCommand($sql1)->queryAll(); $test = json_decode(CJSON::encode($test), TRUE); // echo var_dump($test); $data_x = array(); $data_y = array(); foreach ($test as $key => $value) { $data_x[] = $value['specification']; $data_y[] = $value['c2']; } $x_title = ""; // $y_title = " 量数"; $graph_title = $_POST['assetName'] . "资产报废数据统计(单位:个)"; // echo var_dump($data_x); // echo var_dump($data_y); // echo var_dump(empty($data_x)); if (empty($data_x)) { // 数据库表类的函数save(),存储是否成功,来自yii框架 echo "<script language=\"JavaScript\">alert(\"没有记录!\");</script>"; } else { $max_y = max($data_y); $name = HDraw::HistogramShow($data_x, $data_y, $x_title, $y_title, $graph_title, $max_y); } } } } $this->render('index', array('data' => $data, 'flog' => $flog, 'pages' => $pages, 'analyseType' => $analyseType, 'inTime' => $_POST['inTime'], 'outTime' => $_POST['outTime'], 'assetName' => $_POST['assetName'], 'judge' => $judge, 'name' => $name)); }