yunzerwebsiteallinone/go/models/platform_setting.go
2026-06-22 11:24:08 +08:00

30 lines
1.0 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package models
// GetPlatformSettingValue 从 yz_system_tenant_setting_items 表中读取平台级别tid=0的配置值。
// key 不存在或读取失败时返回空字符串。
func GetPlatformSettingValue(key string) string {
type row struct {
SettingValue string
}
var r row
// tid=0 表示平台全局配置,与租户无关
err := Orm.Raw(
"SELECT IFNULL(setting_value, '') AS setting_value FROM yz_system_tenant_setting_items WHERE tid = 0 AND setting_key = ? AND delete_time IS NULL LIMIT 1",
key,
).QueryRow(&r)
if err != nil {
return ""
}
return r.SettingValue
}
// SetPlatformSettingValue 写入或更新平台级别tid=0的配置值。
func SetPlatformSettingValue(key, value string) error {
_, err := Orm.Raw(`
INSERT INTO yz_system_tenant_setting_items (tid, setting_key, setting_value, create_time, update_time)
VALUES (0, ?, ?, NOW(), NOW())
ON DUPLICATE KEY UPDATE setting_value = VALUES(setting_value), update_time = NOW(), delete_time = NULL
`, key, value).Exec()
return err
}