Browse Source

修改阈值可配置

master
wanghongjun 3 years ago
parent
commit
123c10024c
  1. 62
      source/application/admin/controller/setting/Config.php
  2. 21
      source/application/admin/view/setting/config/index.php
  3. 21
      source/application/common/logic/PassFlow.php

62
source/application/admin/controller/setting/Config.php

@ -5,6 +5,7 @@ namespace app\admin\controller\setting;
use app\admin\controller\Controller; use app\admin\controller\Controller;
use app\common\dm\Dm; use app\common\dm\Dm;
use app\common\model\Pass; use app\common\model\Pass;
use think\Session;
/** /**
* 配置 * 配置
@ -24,26 +25,65 @@ class Config extends Controller
if ($this->request->isAjax()) { if ($this->request->isAjax()) {
$request = $this->request->request(); $request = $_POST;
if ( Session::get('__token__') != $request['token']) $this->renderError('token验证失败');
$threshold = $request['threshold']; $threshold = $request['threshold'];
if (empty($threshold)) $this->renderError('请填写阈值'); if (!is_array($threshold)) $this->renderError('参数类型错误');
if (is_numeric($threshold) && $threshold > 0) $this->renderError('阈值必须是数字');
# 修改阈值 $errorArr = [];
$dm->update('bt_config',['value' => $threshold],'"key"='."'threshold'"); $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("<br>",$errorArr));
}
return $this->renderSuccess('操作成功'); return $this->renderSuccess('操作成功');
} }
$configList = []; $configRes = $dm->select("bt_config");
foreach ($configRes as &$configRow) {
$configRes = $dm->find("bt_config",' "key" = ' . "'threshold'"); $configRow['groupName'] = '';
$threshold = $configRes['value']; $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', [ return $this->fetch('index', [
'configList' => $configList, 'configList' => $configRes,
'threshold' => $threshold, 'token' => $this->request->token()
]); ]);
} }
} }

21
source/application/admin/view/setting/config/index.php

@ -1,12 +1,19 @@
<style> <style>
.tpl-form-input { .tpl-form-input {
width: 60px!important; width: 200px!important;
display: inline-block!important; display: inline-block!important;
text-align: center; text-align: center;
} }
.am-checkbox-inline span{ .am-checkbox-inline span{
margin-right: 10px; margin-right: 10px;
} }
.notice-title{
background-color: #fff7cc;
margin-bottom: 20px;
border: 1px solid #feb;
border-radius: 4px;
font-size: 14px;
}
</style> </style>
<div class="row"> <div class="row">
<div class="am-u-sm-12 am-u-md-12 am-u-lg-12"> <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
@ -17,16 +24,24 @@
<div class="widget-head am-cf"> <div class="widget-head am-cf">
<div class="widget-title am-fl">预警阈值</div> <div class="widget-title am-fl">预警阈值</div>
</div> </div>
<div class="notice-title">
&nbsp;&nbsp;计算方式1:阈值<=50% = 舒适、阈值>50% 阈值<=100% = 拥挤、阈值>100% = 爆满
<br>
&nbsp;&nbsp;计算方式2:100-200, 小于100 = 舒适、大于100小于200 = 拥挤、大于200 = 爆满
</div>
<?php foreach ($configList as $item) { ?>
<div class="am-form-group"> <div class="am-form-group">
<label class="am-u-sm-3 am-form-label form-require"> 阈值 </label> <label class="am-u-sm-3 am-form-label form-require"><?= $item['groupName'] ?> 阈值 </label>
<div class="am-u-sm-9"> <div class="am-u-sm-9">
<label class="am-checkbox-inline"> <label class="am-checkbox-inline">
<input type="text" class="tpl-form-input" name="threshold" value="<?= $threshold ?>" required> <input type="text" class="tpl-form-input" name="threshold[<?= $item['id'] ?>]" value="<?= $item['value'] ?>" required>
</label> </label>
</div> </div>
</div> </div>
<?php } ?>
<div class="am-form-group"> <div class="am-form-group">
<div class="am-u-sm-9 am-u-sm-push-3 am-margin-top-lg"> <div class="am-u-sm-9 am-u-sm-push-3 am-margin-top-lg">
<input type="hidden" name="token" value="<?= $token ?>">
<button type="submit" class="j-submit am-btn am-btn-secondary">提交 <button type="submit" class="j-submit am-btn am-btn-secondary">提交
</button> </button>
</div> </div>

21
source/application/common/logic/PassFlow.php

@ -361,7 +361,7 @@ class PassFlow
if (!isset($data[$value['groupId']]['holdValue'])) $data[$value['groupId']]['holdValue'] = 0; if (!isset($data[$value['groupId']]['holdValue'])) $data[$value['groupId']]['holdValue'] = 0;
$data[$value['groupId']]['holdValue'] += $value['holdValue']; $data[$value['groupId']]['holdValue'] += $value['holdValue'];
} }
$groupThreshold = self::$groupThreshold; $groupThreshold = self::getConfig($dm);
$returnData = []; $returnData = [];
foreach ($data as $groupId => $val) { 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;
}
} }

Loading…
Cancel
Save