Files
OMS/app/desktop/model/pagecols/setting.php
2026-01-04 19:08:31 +08:00

94 lines
2.5 KiB
PHP

<?php
/**
* Copyright 2012-2026 ShopeX (https://www.shopex.cn)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
class desktop_mdl_pagecols_setting extends dbeav_model
{
/**
* 获取字段配置
* @param string $tbl_name 表名
* @param string $col_key 字段键
* @return array|null
*/
public function getFieldConfig($tbl_name, $col_key)
{
$filter = array(
'tbl_name' => $tbl_name,
'col_key' => $col_key,
);
return $this->dump($filter);
}
/**
* 获取表的所有字段配置
* @param string $tbl_name 表名
* @return array
*/
public function getTableConfigs($tbl_name)
{
$filter = array('tbl_name' => $tbl_name);
return $this->getList('*', $filter);
}
/**
* 检查字段是否必填
* @param string $tbl_name 表名
* @param string $col_key 字段键
* @return bool
*/
public function isFieldRequired($tbl_name, $col_key)
{
$config = $this->getFieldConfig($tbl_name, $col_key);
return $config && $config['is_required'] == '1';
}
/**
* 获取字段默认值
* @param string $tbl_name 表名
* @param string $col_key 字段键
* @return string|null
*/
public function getFieldDefaultValue($tbl_name, $col_key)
{
$config = $this->getFieldConfig($tbl_name, $col_key);
return $config ? $config['default_value'] : null;
}
/**
* 保存字段配置
* @param array $data 配置数据
* @return bool
*/
public function saveFieldConfig($data)
{
$filter = array(
'tbl_name' => $data['tbl_name'],
'col_key' => $data['col_key'],
);
$existing = $this->dump($filter);
if ($existing) {
// 更新现有配置
$data['id'] = $existing['id'];
return $this->save($data);
} else {
// 创建新配置
return $this->insert($data);
}
}
}