t
This commit is contained in:
57
app/main/model/agentConfigModel.go
Normal file
57
app/main/model/agentConfigModel.go
Normal file
@@ -0,0 +1,57 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/stores/cache"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
)
|
||||
|
||||
var _ AgentConfigModel = (*customAgentConfigModel)(nil)
|
||||
|
||||
type (
|
||||
// AgentConfigModel is an interface to be customized, add more methods here,
|
||||
// and implement the added methods in customAgentConfigModel.
|
||||
AgentConfigModel interface {
|
||||
agentConfigModel
|
||||
IsCommissionSafeMode(ctx context.Context) bool
|
||||
SetCommissionSafeMode(ctx context.Context, enabled bool) error
|
||||
}
|
||||
|
||||
customAgentConfigModel struct {
|
||||
*defaultAgentConfigModel
|
||||
}
|
||||
)
|
||||
|
||||
// 配置键常量
|
||||
const (
|
||||
AgentConfigKeyCommissionSafeMode = "commission_safe_mode"
|
||||
)
|
||||
|
||||
// NewAgentConfigModel returns a model for the database table.
|
||||
func NewAgentConfigModel(conn sqlx.SqlConn, c cache.CacheConf) AgentConfigModel {
|
||||
return &customAgentConfigModel{
|
||||
defaultAgentConfigModel: newAgentConfigModel(conn, c),
|
||||
}
|
||||
}
|
||||
|
||||
// IsCommissionSafeMode 从数据库查询佣金安全防御模式是否开启
|
||||
func (m *customAgentConfigModel) IsCommissionSafeMode(ctx context.Context) bool {
|
||||
config, err := m.FindOneByConfigKey(ctx, AgentConfigKeyCommissionSafeMode)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
enabled, _ := strconv.ParseBool(config.ConfigValue)
|
||||
return enabled
|
||||
}
|
||||
|
||||
// SetCommissionSafeMode 更新佣金安全防御模式开关
|
||||
func (m *customAgentConfigModel) SetCommissionSafeMode(ctx context.Context, enabled bool) error {
|
||||
config, err := m.FindOneByConfigKey(ctx, AgentConfigKeyCommissionSafeMode)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
config.ConfigValue = strconv.FormatBool(enabled)
|
||||
return m.UpdateWithVersion(ctx, nil, config)
|
||||
}
|
||||
Reference in New Issue
Block a user