From 123c10024c56146663e227a87e99891763ddd6bd Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq,com> Date: Mon, 21 Aug 2023 17:09:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=98=88=E5=80=BC=E5=8F=AF?= =?UTF-8?q?=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/controller/setting/Config.php | 62 +++++++++++++++---- .../admin/view/setting/config/index.php | 21 ++++++- source/application/common/logic/PassFlow.php | 21 ++++++- 3 files changed, 89 insertions(+), 15 deletions(-) diff --git a/source/application/admin/controller/setting/Config.php b/source/application/admin/controller/setting/Config.php index f620414..044ceab 100644 --- a/source/application/admin/controller/setting/Config.php +++ b/source/application/admin/controller/setting/Config.php @@ -5,6 +5,7 @@ namespace app\admin\controller\setting; use app\admin\controller\Controller; use app\common\dm\Dm; use app\common\model\Pass; +use think\Session; /** * 配置 @@ -24,26 +25,65 @@ class Config extends Controller if ($this->request->isAjax()) { - $request = $this->request->request(); + $request = $_POST; + if ( Session::get('__token__') != $request['token']) $this->renderError('token验证失败'); $threshold = $request['threshold']; - if (empty($threshold)) $this->renderError('请填写阈值'); - if (is_numeric($threshold) && $threshold > 0) $this->renderError('阈值必须是数字'); + if (!is_array($threshold)) $this->renderError('参数类型错误'); - # 修改阈值 - $dm->update('bt_config',['value' => $threshold],'"key"='."'threshold'"); + $errorArr = []; + $i = 0; + foreach ($threshold as $id => $value) { + $error = []; + $i++; + $strpos = strpos($value,'-'); + if ($strpos !== false) { + $arr = explode("-",$value); + if (!preg_match("/^\d+$/",$arr[0])) $error[] = "第{$i}行,第1个数据必须是数字"; + if (!preg_match("/^\d+$/",$arr[1])) $error[] = "第{$i}行,第2个必须是数字"; + if ($arr[1] < $arr[0]) $error[] = "第{$i}行,第2个不能小于第1个数据"; + } else { + if (!preg_match("/^\d+$/",$value)) $error[] = "第{$i}行,数据必须是数字"; + } + + # 验证数据是否发生修改 + $queryRes = $dm->find('bt_config',['id' => $id]); + if (empty($queryRes)) $error[] = "第{$i}行,数据不存在"; + if ($queryRes['value'] == $value) continue; + + if (!empty($error)) { + $errorArr = array_merge($errorArr,$error); + continue; + } + + $dm->update('bt_config',['value' => $value],['id' => $id]); + } + + if (!empty($errorArr)) { + return $this->renderError(implode("
",$errorArr)); + } return $this->renderSuccess('操作成功'); } - $configList = []; - - $configRes = $dm->find("bt_config",' "key" = ' . "'threshold'"); - $threshold = $configRes['value']; + $configRes = $dm->select("bt_config"); + foreach ($configRes as &$configRow) { + $configRow['groupName'] = ''; + $tyGroupRes = $dm->find('bt_passenger_monitor_group',['groupId' => $configRow['key']],'"groupName"'); + if ($tyGroupRes) { + $configRow['groupName'] = $tyGroupRes['groupName']; + } + if (empty($configRow['groupName'])) { + $whGroupRes = $dm->find('bt_library',['group_id' => $configRow['key']],'"group_name"'); + if ($whGroupRes) { + $configRow['groupName'] = $whGroupRes['group_name']; + } + } + } return $this->fetch('index', [ - 'configList' => $configList, - 'threshold' => $threshold, + 'configList' => $configRes, + 'token' => $this->request->token() ]); } } \ No newline at end of file diff --git a/source/application/admin/view/setting/config/index.php b/source/application/admin/view/setting/config/index.php index 3baa3ea..6a8e3d4 100644 --- a/source/application/admin/view/setting/config/index.php +++ b/source/application/admin/view/setting/config/index.php @@ -1,12 +1,19 @@
@@ -17,16 +24,24 @@
预警阈值
+
+   计算方式1:阈值<=50% = 舒适、阈值>50% 阈值<=100% = 拥挤、阈值>100% = 爆满 +
+   计算方式2:100-200, 小于100 = 舒适、大于100小于200 = 拥挤、大于200 = 爆满 +
+
- +
+
+
diff --git a/source/application/common/logic/PassFlow.php b/source/application/common/logic/PassFlow.php index e41f497..cbe6e87 100644 --- a/source/application/common/logic/PassFlow.php +++ b/source/application/common/logic/PassFlow.php @@ -361,7 +361,7 @@ class PassFlow if (!isset($data[$value['groupId']]['holdValue'])) $data[$value['groupId']]['holdValue'] = 0; $data[$value['groupId']]['holdValue'] += $value['holdValue']; } - $groupThreshold = self::$groupThreshold; + $groupThreshold = self::getConfig($dm); $returnData = []; foreach ($data as $groupId => $val) { @@ -814,4 +814,23 @@ class PassFlow } + public static function getConfig($dm) + { + $res = $dm->select('bt_config'); + $data = []; + foreach ($res as $row) { + + $dataValue = $row['value']; + if (strpos($row['value'],"-") !== false) { + $arr = explode("-",$dataValue); + $dataValue = [ + 'min' => $arr[0], + 'max' => $arr[1] + ]; + } + $data[$row['key']] = $dataValue; + + } + return $data; + } }