59 lines
1.3 KiB
Go
59 lines
1.3 KiB
Go
package controller
|
|
|
|
import (
|
|
"SciencesServer/app/api/website/model"
|
|
"SciencesServer/app/basic/config"
|
|
config2 "SciencesServer/config"
|
|
)
|
|
|
|
type Platform struct{}
|
|
|
|
type PlatformHandle func() *Platform
|
|
|
|
type PlatformInfo struct {
|
|
Name string `json:"name"`
|
|
Code string `json:"code"`
|
|
Domain string `json:"domain"`
|
|
Children []*PlatformInfo `json:"children"`
|
|
}
|
|
|
|
// Instance 平台信息
|
|
func (c *Platform) Instance() (map[string]*PlatformInfo, error) {
|
|
mSysPlatform := model.NewSysTenant()
|
|
out, err := mSysPlatform.Tenant()
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
ret := make(map[string]*PlatformInfo, 0)
|
|
|
|
for _, v := range out {
|
|
if _, has := ret[v.Province]; !has {
|
|
ret[v.Province] = &PlatformInfo{
|
|
Name: config.MemoryForAreaInfo[config2.DefaultChinaAreaCode][v.Province],
|
|
Code: v.Province,
|
|
Domain: "",
|
|
Children: []*PlatformInfo{&PlatformInfo{
|
|
Name: config.MemoryForAreaInfo[v.Province][v.City],
|
|
Code: v.City,
|
|
Domain: v.Domain,
|
|
Children: nil,
|
|
}},
|
|
}
|
|
continue
|
|
}
|
|
ret[v.Province].Children = append(ret[v.Province].Children, &PlatformInfo{
|
|
Name: config.MemoryForAreaInfo[v.Province][v.City],
|
|
Domain: v.Domain,
|
|
Children: nil,
|
|
})
|
|
}
|
|
return ret, nil
|
|
}
|
|
|
|
func NewPlatform() PlatformHandle {
|
|
return func() *Platform {
|
|
return &Platform{}
|
|
}
|
|
}
|