70 lines
1.7 KiB
Go
70 lines
1.7 KiB
Go
package sys
|
|
|
|
import (
|
|
"SciencesServer/app/api/website/model"
|
|
model2 "SciencesServer/app/common/model"
|
|
)
|
|
|
|
type About struct {
|
|
tenantID uint64
|
|
}
|
|
|
|
type AboutHandle func(tenantID uint64) *About
|
|
|
|
type (
|
|
// AboutInfo 基本信息
|
|
AboutInfo struct {
|
|
ID string `json:"id"`
|
|
Title string `json:"title"`
|
|
Content string `json:"content"`
|
|
}
|
|
// AboutNavigationInfo 导航栏信息
|
|
AboutNavigationInfo struct {
|
|
ID string `json:"id"`
|
|
Title string `json:"title"`
|
|
}
|
|
)
|
|
|
|
// Instance 关于信息
|
|
func (c *About) Instance(parentID uint64) (*AboutInfo, error) {
|
|
mSysAbout := model.NewSysAbout()
|
|
|
|
if isExist, err := model2.FirstField(mSysAbout.SysAbout, []string{"id", "title", "content"},
|
|
model2.NewWhere("parent_id", parentID)); err != nil {
|
|
return nil, err
|
|
} else if !isExist {
|
|
return nil, nil
|
|
}
|
|
return &AboutInfo{ID: mSysAbout.GetEncodeID(), Title: mSysAbout.Title, Content: mSysAbout.Content}, nil
|
|
}
|
|
|
|
// Navigation 导航栏
|
|
func (c *About) Navigation() ([]*AboutNavigationInfo, error) {
|
|
mSysAbout := model.NewSysAbout()
|
|
out := make([]*model2.SysAbout, 0)
|
|
|
|
if err := model2.ScanFields(mSysAbout.SysAbout, &out, []string{"id", "title"}, &model2.ModelWhereOrder{
|
|
Where: model2.NewWhere("parent_id", 0),
|
|
Order: model2.NewOrder("sort", model2.OrderModeToDesc),
|
|
}, &model2.ModelWhereOrder{
|
|
Where: model2.NewWhere("tenant_id", c.tenantID),
|
|
Order: model2.NewOrder("id", model2.OrderModeToDesc),
|
|
}); err != nil {
|
|
return nil, err
|
|
}
|
|
list := make([]*AboutNavigationInfo, 0)
|
|
|
|
for _, v := range out {
|
|
list = append(list, &AboutNavigationInfo{
|
|
ID: v.GetEncodeID(), Title: v.Title,
|
|
})
|
|
}
|
|
return list, nil
|
|
}
|
|
|
|
func NewAbout() AboutHandle {
|
|
return func(tenantID uint64) *About {
|
|
return &About{tenantID: tenantID}
|
|
}
|
|
}
|