|
|
@ -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() |
|
|
]); |
|
|
]); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |