sky999
天山茗客 Lv7
UID 181291
Digest
2
Points 6
Posts 3284
金币 2269 块
Permissions 10
Register 2020-11-28
Status offline
|
if ($type == "plc_yield") {
pretreatment();
for ($i = 0; $i < $index; $i++) {
$response["array"][$i]["number"] = $number_array[$i];
if ($value_array[$i] != "?") {
$sql = "SELECT value, datetime FROM plc_last WHERE number = '" . $number_array[$i] . "'";
$result = @mysql_query($sql);
$row = mysql_fetch_array($result);
$last_value = (int)$row["value"];
$last_datetime = $row["datetime"];
$sql = "UPDATE plc_last SET value = '" . $value_array[$i] . "', datetime = '" . $datetime . "' WHERE number = '" . $number_array[$i] . "'";
$result = @mysql_query($sql);
if ($last_value && $last_datetime) {
if ((int)$value_array[$i] >= $last_value) {
$value_difference = (int)$value_array[$i] - $last_value;
} else {
$value_difference = (int)$value_array[$i];
}
$datetime_difference = strtotime($datetime) - strtotime($last_datetime);
$array_1 = explode(":", $datetime);
$array_2 = explode(":", $last_datetime);
if ($datetime_difference <= 300 || $array_1[0] == $array_2[0]) {
$array = explode(":", $datetime);
$start_datetime = $array[0] . ":00:00";
$sql = "SELECT id, value FROM plc_yield_hour WHERE number = '" . $number_array[$i] . ".1' AND datetime >= '" . $start_datetime . "'";
$result = @mysql_query($sql);
if ($row = mysql_fetch_array($result)) {
$id = $row["id"];
$value = $row["value"];
$value = $value + $value_difference;
$sql = "UPDATE plc_yield_hour SET value = " . $value . ", datetime = '" . $datetime . "' WHERE id = " . $id;
$result = @mysql_query($sql);
} else {
$sql = "INSERT INTO plc_yield_hour (number, value, datetime) VALUES ('" . $number_array[$i] . ".1', " . $value_difference . ", '" . $datetime . "')";
$result = @mysql_query($sql);
}
$array = explode(" ", $datetime);
$start_datetime = $array[0] . " 00:00:00";
$sql = "SELECT id, value FROM plc_yield_day WHERE number = '" . $number_array[$i] . ".2' AND datetime >= '" . $start_datetime . "'";
$result = @mysql_query($sql);
if ($row = mysql_fetch_array($result)) {
$id = $row["id"];
$value = $row["value"];
$value = $value + $value_difference;
$sql = "UPDATE plc_yield_day SET value = " . $value . ", datetime = '" . $datetime . "' WHERE id = " . $id;
$result = @mysql_query($sql);
} else {
$sql = "INSERT INTO plc_yield_day (number, value, datetime) VALUES ('" . $number_array[$i] . ".2', " . $value_difference . ", '" . $datetime . "')";
$result = @mysql_query($sql);
}
$array = explode("-", $datetime);
$start_datetime = $array[0] . "-" . $array[1] . "-1 00:00:00";
$sql = "SELECT id, value FROM plc_yield_month WHERE number = '" . $number_array[$i] . ".3' AND datetime >= '" . $start_datetime . "'";
$result = @mysql_query($sql);
if ($row = mysql_fetch_array($result)) {
$id = $row["id"];
$value = $row["value"];
$value = $value + $value_difference;
$sql = "UPDATE plc_yield_month SET value = " . $value . ", datetime = '" . $datetime . "' WHERE id = " . $id;
$result = @mysql_query($sql);
} else {
$sql = "INSERT INTO plc_yield_month (number, value, datetime) VALUES ('" . $number_array[$i] . ".3', " . $value_difference . ", '" . $datetime . "')";
$result = @mysql_query($sql);
}
$array = explode(" ", $datetime);
$start_datetime = $array[0] . " 00:00:00";
$sql = "SELECT id, change_datetime, on_duration, run_duration FROM plc_activation_rate_day WHERE number = '" . $number_array[$i] . ".4' AND start_datetime >= '" . $start_datetime . "'";
$result = @mysql_query($sql);
if ($row = mysql_fetch_array($result)) {
$id = $row["id"];
$change_datetime = $row["change_datetime"];
$on_duration = $row["on_duration"];
$run_duration = $row["run_duration"];
if ($datetime_difference <= 300) {
if ($value_difference != 0) {
$change_datetime_difference = strtotime($datetime) - strtotime($change_datetime);
if ($change_datetime_difference <= 300) {
$run_duration = $run_duration + $change_datetime_difference;
}
$change_datetime = $datetime;
}
$on_duration = $on_duration + $datetime_difference;
$value = $run_duration / $on_duration;
$sql = "UPDATE plc_activation_rate_day SET value = " . $value . ", change_datetime = '" . $change_datetime . "', on_duration = " . $on_duration . ", run_duration = " . $run_duration . " WHERE id = " . $id;
$result = @mysql_query($sql);
} else {
if ($value_difference != 0) {
$change_datetime = $datetime;
}
$sql = "UPDATE plc_activation_rate_day SET change_datetime = '" . $change_datetime . "' WHERE id = " . $id;
$result = @mysql_query($sql);
}
} else {
$sql = "INSERT INTO plc_activation_rate_day (number, value, start_datetime, change_datetime, on_duration, run_duration) VALUES ('" . $number_array[$i] . ".4', 0, '" . $datetime . "', '" . $datetime . "', 0, 0)";
$result = @mysql_query($sql);
}
}
}
$response["array"][$i]["value"] = 0;
} else {
$response["array"][$i]["value"] = 1;
}
}
}
| ![](images/common/sigline.gif) 做好事情,赚取应得。
和睦共处,合作共赢。
|
|