49 lines
1.1 KiB
Go
49 lines
1.1 KiB
Go
package controller
|
|
|
|
import (
|
|
"SciencesServer/app/api/admin/model"
|
|
"SciencesServer/app/basic/config"
|
|
model2 "SciencesServer/app/common/model"
|
|
"SciencesServer/app/session"
|
|
config2 "SciencesServer/config"
|
|
)
|
|
|
|
type Config struct{ *session.Admin }
|
|
|
|
type ConfigHandle func(session *session.Admin) *Config
|
|
|
|
type (
|
|
ConfigInfo struct {
|
|
Kind int `json:"kind"`
|
|
Name string `json:"name"`
|
|
Key string `json:"key"`
|
|
Value string `json:"value"`
|
|
}
|
|
)
|
|
|
|
func (c *Config) Instance(kind int) ([]*ConfigInfo, error) {
|
|
mSysConfig := model.NewSysConfig()
|
|
|
|
out := make([]*ConfigInfo, 0)
|
|
|
|
if err := model2.ScanFields(mSysConfig.SysConfig, &out, []string{"kind", "name", "`key`", "`value`"},
|
|
&model2.ModelWhereOrder{Where: model2.NewWhere("kind", kind)}); err != nil {
|
|
return nil, err
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
// Area 区域信息
|
|
func (c *Config) Area(key string) map[string]string {
|
|
if key == "" {
|
|
key = config2.DefaultChinaAreaCode
|
|
}
|
|
return config.MemoryForAreaInfo[key]
|
|
}
|
|
|
|
func NewConfig() ConfigHandle {
|
|
return func(session *session.Admin) *Config {
|
|
return &Config{Admin: session}
|
|
}
|
|
}
|