refactor: 修改额外配置项联动配置验证
This commit is contained in:
@@ -3,6 +3,7 @@ declare (strict_types = 1);
|
|||||||
|
|
||||||
namespace app\admin\validate\v1;
|
namespace app\admin\validate\v1;
|
||||||
|
|
||||||
|
use app\admin\model\v1\SysConfigModel;
|
||||||
use think\Validate;
|
use think\Validate;
|
||||||
|
|
||||||
class SysConfigValidate extends Validate
|
class SysConfigValidate extends Validate
|
||||||
@@ -19,7 +20,7 @@ class SysConfigValidate extends Validate
|
|||||||
'title' => 'require|max:64',
|
'title' => 'require|max:64',
|
||||||
'name' => 'require|unique:sys_config|max:64',
|
'name' => 'require|unique:sys_config|max:64',
|
||||||
'value' => 'max:255',
|
'value' => 'max:255',
|
||||||
'extra' => 'max:255',
|
'extra' => 'max:255|checkLinkage',
|
||||||
'type' => 'max:64',
|
'type' => 'max:64',
|
||||||
'sort' => 'integer',
|
'sort' => 'integer',
|
||||||
'remark' => 'max:255'
|
'remark' => 'max:255'
|
||||||
@@ -53,4 +54,54 @@ class SysConfigValidate extends Validate
|
|||||||
{
|
{
|
||||||
return $this->remove('id', 'require|integer');
|
return $this->remove('id', 'require|integer');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 验证额外配置项中联动数据配置
|
||||||
|
protected function checkLinkage($value, $rule, $data)
|
||||||
|
{
|
||||||
|
if (empty($value)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
$submit_linkage_names = [];
|
||||||
|
$submit_extra = explode(PHP_EOL, $value);
|
||||||
|
foreach ($submit_extra as $v) {
|
||||||
|
if (preg_match('/^([^:]+):(.*?)(?:\[(.*?)\])?$/i', trim($v), $match)) {
|
||||||
|
if (isset($match[3])) {
|
||||||
|
$submit_linkage_names = array_merge($submit_linkage_names, array_map(function ($it) {
|
||||||
|
return str_replace(['"', "'"], '', trim($it));
|
||||||
|
}, explode(',', $match[3])));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$configs_extra = SysConfigModel::whereNotNull('extra')
|
||||||
|
->where('extra', '<>', '')
|
||||||
|
->where(function($query) use($data) {
|
||||||
|
if (isset($data['id'])) {
|
||||||
|
$query->where('id', '<>', $data['id']);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
->column('extra');
|
||||||
|
$exists_linkage_names = [];
|
||||||
|
foreach ($configs_extra as $it) {
|
||||||
|
$exists_extra = explode(PHP_EOL, $it);
|
||||||
|
foreach ($exists_extra as $v) {
|
||||||
|
if (preg_match('/^([^:]+):(.*?)(?:\[(.*?)\])?$/i', trim($v), $match)) {
|
||||||
|
if (isset($match[3])) {
|
||||||
|
$exists_linkage_names = array_merge($exists_linkage_names, array_map(function ($it) {
|
||||||
|
return str_replace(['"', "'"], '', trim($it));
|
||||||
|
}, explode(',', $match[3])));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$intersect = array_intersect($submit_linkage_names, $exists_linkage_names);
|
||||||
|
if (!empty($intersect)) {
|
||||||
|
$v = implode(',', $intersect);
|
||||||
|
return "{$v}被多次设为联动配置项";
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user