|
@@ -31,13 +31,6 @@ use think\exception\ValidateException;
|
|
|
class SystemConfigServices extends BaseServices implements ServeConfigInterface
|
|
|
{
|
|
|
|
|
|
-
|
|
|
- /**
|
|
|
- * 表单数据切割符号
|
|
|
- * @var string
|
|
|
- */
|
|
|
- protected $cuttingStr = '=>';
|
|
|
-
|
|
|
/**
|
|
|
* SystemConfigServices constructor.
|
|
|
* @param SystemConfig $model
|
|
@@ -108,10 +101,7 @@ class SystemConfigServices extends BaseServices implements ServeConfigInterface
|
|
|
$count = $this->getCount($where);
|
|
|
foreach ($list as &$item) {
|
|
|
$item['value'] = $item['value'] ? json_decode($item['value'], true) ?: '' : '';
|
|
|
- if ($item['type'] == 'radio' || $item['type'] == 'checkbox') {
|
|
|
- $item['value'] = $this->getRadioOrCheckboxValueInfo($item['menu_name'], $item['value']);
|
|
|
- }
|
|
|
- if ($item['type'] == 'upload' && !empty($item['value'])) {
|
|
|
+ if ($item['type'] == 'Upload' && !empty($item['value'])) {
|
|
|
$item['value'] = set_file_url($item['value']);
|
|
|
$tidy_srr = [];
|
|
|
foreach ($item['value'] as $key => $value) {
|
|
@@ -124,40 +114,6 @@ class SystemConfigServices extends BaseServices implements ServeConfigInterface
|
|
|
return compact('count', 'list');
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 获取单选按钮或者多选按钮的显示值
|
|
|
- * @param string $menu_name
|
|
|
- * @param $value
|
|
|
- * @return string
|
|
|
- * @throws DataNotFoundException
|
|
|
- * @throws DbException
|
|
|
- * @throws ModelNotFoundException
|
|
|
- */
|
|
|
- public function getRadioOrCheckboxValueInfo(string $menu_name, $value): string
|
|
|
- {
|
|
|
- $option = [];
|
|
|
- $config_one = $this->getOne(['menu_name' => $menu_name]);
|
|
|
- if (!$config_one) {
|
|
|
- return '';
|
|
|
- }
|
|
|
- $parameter = explode("\n", $config_one['parameter']);
|
|
|
- foreach ($parameter as $k => $v) {
|
|
|
- if (isset($v) && strlen($v) > 0) {
|
|
|
- $data = explode($this->cuttingStr, $v);
|
|
|
- $option[$data[0]] = $data[1];
|
|
|
- }
|
|
|
- }
|
|
|
- $str = '';
|
|
|
- if (is_array($value)) {
|
|
|
- foreach ($value as $v) {
|
|
|
- $str .= $option[$v] . ',';
|
|
|
- }
|
|
|
- } else {
|
|
|
- $str .= !empty($value) ? $option[$value] ?? '' : $option[0] ?? '';
|
|
|
- }
|
|
|
- return $str;
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 获取系统配置信息
|
|
|
* @param int $tabId
|
|
@@ -166,11 +122,16 @@ class SystemConfigServices extends BaseServices implements ServeConfigInterface
|
|
|
public function getReadList(int $tabId)
|
|
|
{
|
|
|
$info = $this->getConfigTabAllList($tabId);
|
|
|
- foreach ($info as $k => $v) {
|
|
|
- if (!is_null(json_decode($v['value'])))
|
|
|
- $info[$k]['value'] = json_decode($v['value'], true);
|
|
|
- if ($v['type'] == 'upload' && !empty($v['value'])) {
|
|
|
- if ($v['upload_type'] == 1 || $v['upload_type'] == 3) $info[$k]['value'] = explode(',', $v['value']);
|
|
|
+ foreach ($info as &$v) {
|
|
|
+ $v['value'] = $v['value'] ? json_decode($v['value'], true) ?: '' : '';
|
|
|
+ if ($v['type'] == 'Upload' && !empty($v['value'])) {
|
|
|
+ $v['value'] = set_file_url($v['value']);
|
|
|
+ $tidy_srr = [];
|
|
|
+ foreach ($v['value'] as $key => $value) {
|
|
|
+ $tidy_srr[$key]['filepath'] = $value;
|
|
|
+ $tidy_srr[$key]['filename'] = basename($value);
|
|
|
+ }
|
|
|
+ $v['value'] = $tidy_srr;
|
|
|
}
|
|
|
}
|
|
|
return $info;
|
|
@@ -197,83 +158,7 @@ class SystemConfigServices extends BaseServices implements ServeConfigInterface
|
|
|
*/
|
|
|
public function getUploadTypeList(string $configName)
|
|
|
{
|
|
|
- return $this->search(['menu_name' => $configName])->column('upload_type', 'type');
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * radio 和 checkbox规则的判断
|
|
|
- * @param $data
|
|
|
- * @return bool
|
|
|
- */
|
|
|
- public function valiDateRadioAndCheckbox($data)
|
|
|
- {
|
|
|
- $option = [];
|
|
|
- $option_new = [];
|
|
|
- $data['parameter'] = str_replace("\r\n", "\n", $data['parameter']);//防止不兼容
|
|
|
- $parameter = explode("\n", $data['parameter']);
|
|
|
- if (count($parameter) < 2) {
|
|
|
- throw new AdminException('请输入正确格式的配置参数');
|
|
|
- }
|
|
|
- foreach ($parameter as $k => $v) {
|
|
|
- if (isset($v) && !empty($v)) {
|
|
|
- $option[$k] = explode('=>', $v);
|
|
|
- }
|
|
|
- }
|
|
|
- if (count($option) < 2) {
|
|
|
- throw new AdminException('请输入正确格式的配置参数');
|
|
|
- }
|
|
|
- $bool = 1;
|
|
|
- foreach ($option as $k => $v) {
|
|
|
- $option_new[$k] = $option[$k][0];
|
|
|
- foreach ($v as $kk => $vv) {
|
|
|
- $vv_num = strlen($vv);
|
|
|
- if (!$vv_num) {
|
|
|
- $bool = 0;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if (!$bool) {
|
|
|
- throw new AdminException('请输入正确格式的配置参数');
|
|
|
- }
|
|
|
- $num1 = count($option_new);//提取该数组的数目
|
|
|
- $arr2 = array_unique($option_new);//合并相同的元素
|
|
|
- $num2 = count($arr2);//提取合并后数组个数
|
|
|
- if ($num1 > $num2) {
|
|
|
- throw new AdminException('请输入正确格式的配置参数');
|
|
|
- }
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 验证参数
|
|
|
- * @param $data
|
|
|
- * @return bool
|
|
|
- */
|
|
|
- public function valiDateValue($data)
|
|
|
- {
|
|
|
- if (!$data || !isset($data['required']) || !$data['required']) {
|
|
|
- return true;
|
|
|
- }
|
|
|
- $valids = explode(',', $data['required']);
|
|
|
- foreach ($valids as $valid) {
|
|
|
- $valid = explode(':', $valid);
|
|
|
- if (isset($valid[0]) && isset($valid[1])) {
|
|
|
- $k = strtolower(trim($valid[0]));
|
|
|
- $v = strtolower(trim($valid[1]));
|
|
|
- switch ($k) {
|
|
|
- case 'required':
|
|
|
- if ($v == 'true' && $data['value'] === '') {
|
|
|
- throw new ValidateException(($data['info'] ?? '') . '请输入默认值');
|
|
|
- }
|
|
|
- break;
|
|
|
- case 'url':
|
|
|
- if ($v == 'true' && !check_link($data['value'])) {
|
|
|
- throw new ValidateException(($data['info'] ?? '') . '请输入正确url');
|
|
|
- }
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ return $this->search(['menu_name' => $configName])->column('configuration', 'type');
|
|
|
}
|
|
|
|
|
|
|
|
@@ -333,19 +218,6 @@ class SystemConfigServices extends BaseServices implements ServeConfigInterface
|
|
|
}
|
|
|
|
|
|
|
|
|
- public function getOptions(string $parameter)
|
|
|
- {
|
|
|
- $parameter = explode("\n", $parameter);
|
|
|
- $options = [];
|
|
|
- foreach ($parameter as $v) {
|
|
|
- if (strstr($v, $this->cuttingStr) !== false) {
|
|
|
- $pdata = explode($this->cuttingStr, $v);
|
|
|
- $options[] = ['label' => $pdata[1], 'value' => (int)$pdata[0]];
|
|
|
- }
|
|
|
- }
|
|
|
- return $options;
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 获取配置
|
|
|
* @param string $key
|