feat:完善项目
This commit is contained in:
69
app/api/website/controller/sys/about.go
Normal file
69
app/api/website/controller/sys/about.go
Normal file
@ -0,0 +1,69 @@
|
||||
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}
|
||||
}
|
||||
}
|
@ -3,17 +3,15 @@ package sys
|
||||
import (
|
||||
"SciencesServer/app/api/website/model"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/session"
|
||||
"errors"
|
||||
)
|
||||
|
||||
// Agreement 协议信息
|
||||
type Agreement struct {
|
||||
*session.Enterprise
|
||||
tenantID uint64
|
||||
}
|
||||
|
||||
type AgreementHandle func(session *session.Enterprise, tenantID uint64) *Agreement
|
||||
type AgreementHandle func(tenantID uint64) *Agreement
|
||||
|
||||
type (
|
||||
// AgreementInfo 协议信息
|
||||
@ -68,10 +66,9 @@ func (c *Agreement) Detail(id uint64) (*AgreementDetailInfo, error) {
|
||||
}
|
||||
|
||||
func NewAgreement() AgreementHandle {
|
||||
return func(session *session.Enterprise, tenantID uint64) *Agreement {
|
||||
return func(tenantID uint64) *Agreement {
|
||||
return &Agreement{
|
||||
Enterprise: session,
|
||||
tenantID: tenantID,
|
||||
tenantID: tenantID,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
53
app/api/website/controller/sys/navigation.go
Normal file
53
app/api/website/controller/sys/navigation.go
Normal file
@ -0,0 +1,53 @@
|
||||
package sys
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/website/model"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
)
|
||||
|
||||
type Navigation struct {
|
||||
tenantID uint64
|
||||
}
|
||||
|
||||
type NavigationHandle func(tenantID uint64) *Navigation
|
||||
|
||||
type NavigationInfo struct {
|
||||
Title string `json:"title"`
|
||||
Link string `json:"link"`
|
||||
IsTarget bool `json:"is_target"`
|
||||
Children []*NavigationInfo `json:"children"`
|
||||
}
|
||||
|
||||
// tree 树状
|
||||
func (c *Navigation) tree(src []*model2.SysNavigation, parentID uint64) []*NavigationInfo {
|
||||
out := make([]*NavigationInfo, 0)
|
||||
|
||||
for _, v := range src {
|
||||
if v.ParentID == parentID {
|
||||
out = append(out, &NavigationInfo{
|
||||
Title: v.Title,
|
||||
Link: v.Link,
|
||||
IsTarget: v.IsTarget > 0,
|
||||
Children: c.tree(src, v.ID),
|
||||
})
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// Instance 导航栏信息
|
||||
func (c *Navigation) Instance() ([]*NavigationInfo, error) {
|
||||
mSysNavigation := model.NewSysNavigation()
|
||||
out, err := mSysNavigation.Navigation(model2.NewWhere("tenant_id", c.tenantID))
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return c.tree(out, 0), nil
|
||||
}
|
||||
|
||||
func NewNavigation() NavigationHandle {
|
||||
return func(tenantID uint64) *Navigation {
|
||||
return &Navigation{tenantID: tenantID}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user