feat:完善项目信息
This commit is contained in:
@ -8,6 +8,18 @@ import (
|
||||
|
||||
type Config struct{}
|
||||
|
||||
func (*Config) Index(c *gin.Context) {
|
||||
form := &struct {
|
||||
Kind int `json:"kind" form:"kind" binding:"required"`
|
||||
}{}
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := controller.NewConfig()(nil).Instance(form.Kind)
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (*Config) Area(c *gin.Context) {
|
||||
form := &struct {
|
||||
Code string `json:"code" form:"code"`
|
||||
|
||||
@ -1,7 +1,9 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/admin/model"
|
||||
"SciencesServer/app/basic/config"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/session"
|
||||
config2 "SciencesServer/config"
|
||||
)
|
||||
@ -10,8 +12,25 @@ type Config struct{ *session.Admin }
|
||||
|
||||
type ConfigHandle func(session *session.Admin) *Config
|
||||
|
||||
func (c *Config) Basic() {
|
||||
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 区域信息
|
||||
|
||||
@ -2,7 +2,8 @@ package controller
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/website/model"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/basic/config"
|
||||
config2 "SciencesServer/config"
|
||||
)
|
||||
|
||||
type Platform struct{}
|
||||
@ -10,36 +11,44 @@ type Platform struct{}
|
||||
type PlatformHandle func() *Platform
|
||||
|
||||
type PlatformInfo struct {
|
||||
Title string `json:"title"`
|
||||
Link string `json:"link"`
|
||||
Name string `json:"name"`
|
||||
Code string `json:"code"`
|
||||
Domain string `json:"domain"`
|
||||
Children []*PlatformInfo `json:"children"`
|
||||
}
|
||||
|
||||
// tree 树状
|
||||
func (c *Platform) tree(src []*model2.SysPlatform, parentID uint64) []*PlatformInfo {
|
||||
out := make([]*PlatformInfo, 0)
|
||||
|
||||
for _, v := range src {
|
||||
if v.ParentID == parentID {
|
||||
out = append(out, &PlatformInfo{
|
||||
Title: v.Title,
|
||||
Link: v.Link,
|
||||
Children: c.tree(src, v.ID),
|
||||
})
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// Instance 平台信息
|
||||
func (c *Platform) Instance() ([]*PlatformInfo, error) {
|
||||
mSysPlatform := model.NewSysPlatform()
|
||||
out, err := mSysPlatform.Platform()
|
||||
func (c *Platform) Instance() (map[string]*PlatformInfo, error) {
|
||||
mSysPlatform := model.NewSysTenant()
|
||||
out, err := mSysPlatform.Tenant()
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return c.tree(out, 0), nil
|
||||
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 {
|
||||
|
||||
@ -1,27 +0,0 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"SciencesServer/app/common/model"
|
||||
"SciencesServer/serve/orm"
|
||||
)
|
||||
|
||||
type SysPlatform struct {
|
||||
*model.SysPlatform
|
||||
}
|
||||
|
||||
// Platform 平台信息
|
||||
func (m *SysPlatform) Platform() ([]*model.SysPlatform, error) {
|
||||
out := make([]*model.SysPlatform, 0)
|
||||
|
||||
err := orm.GetDB().Table(m.TableName()).
|
||||
Select("id", "parent_id", "`key`", "`code`", "title", "link").
|
||||
Where("is_deleted = ?", model.DeleteStatusForNot).
|
||||
Order("sort " + model.OrderModeToDesc).
|
||||
Scan(&out).Error
|
||||
|
||||
return out, err
|
||||
}
|
||||
|
||||
func NewSysPlatform() *SysPlatform {
|
||||
return &SysPlatform{model.NewSysPlatform()}
|
||||
}
|
||||
27
app/api/website/model/sys_tenant.go
Normal file
27
app/api/website/model/sys_tenant.go
Normal file
@ -0,0 +1,27 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"SciencesServer/app/common/model"
|
||||
"SciencesServer/serve/orm"
|
||||
)
|
||||
|
||||
type SysTenant struct {
|
||||
*model.SysTenant
|
||||
}
|
||||
|
||||
// Tenant 租户平台信息
|
||||
func (m *SysTenant) Tenant() ([]*model.SysTenant, error) {
|
||||
out := make([]*model.SysTenant, 0)
|
||||
|
||||
err := orm.GetDB().Table(m.TableName()).
|
||||
Select("id", "`key`", "name", "domain", "province", "city").
|
||||
Where("is_deleted = ?", model.DeleteStatusForNot).
|
||||
Order("province " + model.OrderModeToAsc).Order("city " + model.OrderModeToAsc).
|
||||
Scan(&out).Error
|
||||
|
||||
return out, err
|
||||
}
|
||||
|
||||
func NewSysTenant() *SysTenant {
|
||||
return &SysTenant{model.NewSysTenant()}
|
||||
}
|
||||
Reference in New Issue
Block a user