package controller import ( "SciencesServer/app/api/admin/model" model2 "SciencesServer/app/common/model" "SciencesServer/app/session" "errors" ) type Config struct{ *session.Enterprise } type ConfigHandle func(session *session.Enterprise) *Config type ( // ConfigInfo 配置信息 ConfigInfo struct { Name string `json:"name"` Value string `json:"value"` } ) func (c *Config) Instance(kind int, key string) (*ConfigInfo, error) { mSysConfig := model.NewSysConfig() where := []*model2.ModelWhere{model2.NewWhere("`key`", key)} if kind > 0 { where = append(where, model2.NewWhere("kind", kind)) } isExist, err := model2.FirstField(mSysConfig.SysConfig, []string{"id", "name", "`value`"}, where...) if err != nil { return nil, err } else if !isExist { return nil, errors.New("操作错误,数据不存在或已被删除") } return &ConfigInfo{Name: mSysConfig.Name, Value: mSysConfig.Value}, nil } func NewConfig() ConfigHandle { return func(session *session.Enterprise) *Config { return &Config{Enterprise: session} } }