diff --git a/app/api/website/api/about.go b/app/api/website/api/about.go new file mode 100644 index 0000000..8d0470b --- /dev/null +++ b/app/api/website/api/about.go @@ -0,0 +1,26 @@ +package api + +import ( + "SciencesServer/app/api/website/controller" + "SciencesServer/app/basic/api" + "github.com/gin-gonic/gin" +) + +type About struct{} + +func (*About) Instance(c *gin.Context) { + form := &struct { + NavigationID string `json:"navigation_id" form:"navigation_id"` + }{} + if err := api.Bind(form)(c); err != nil { + api.APIFailure(err.(error))(c) + return + } + data, err := controller.NewAbout()().Instance((&api.IDStringForm{ID: form.NavigationID}).Convert()) + api.APIResponse(err, data)(c) +} + +func (*About) Navigation(c *gin.Context) { + data, err := controller.NewAbout()().Navigation() + api.APIResponse(err, data)(c) +} diff --git a/app/api/website/controller/about.go b/app/api/website/controller/about.go new file mode 100644 index 0000000..2ef60e5 --- /dev/null +++ b/app/api/website/controller/about.go @@ -0,0 +1,66 @@ +package controller + +import ( + "SciencesServer/app/api/website/model" + model2 "SciencesServer/app/common/model" +) + +type About struct{} + +type AboutHandle func() *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{ + 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() *About { + return &About{} + } +} diff --git a/app/api/website/model/sys_about.go b/app/api/website/model/sys_about.go new file mode 100644 index 0000000..6be7f7e --- /dev/null +++ b/app/api/website/model/sys_about.go @@ -0,0 +1,11 @@ +package model + +import "SciencesServer/app/common/model" + +type SysAbout struct { + *model.SysAbout +} + +func NewSysAbout() *SysAbout { + return &SysAbout{model.NewSysAbout()} +} diff --git a/app/common/init.go b/app/common/init.go index e2e4ee7..d14e453 100644 --- a/app/common/init.go +++ b/app/common/init.go @@ -114,6 +114,7 @@ func initModel() { return out }}, &synchronized{iModel: model.NewSysPlatform()}, &synchronized{iModel: model.NewSysNavigation()}, + &synchronized{iModel: model.NewSysAbout()}, // 日志管理 &synchronized{iModel: model.NewSysLog()}, &synchronized{iModel: model.NewSysUserLoginLog()}, // 用户管理 diff --git a/app/common/model/activity_instance.go b/app/common/model/activity_instance.go index 3ec9711..3307ce1 100644 --- a/app/common/model/activity_instance.go +++ b/app/common/model/activity_instance.go @@ -10,7 +10,7 @@ type ActivityInstance struct { Image ActivityInstanceBasic Amount float64 `gorm:"column:amount;type:decimal(10,2);default:0;comment:活动收费金额" json:"amount"` - Content string `gorm:"column:title;type:text;comment:活动详情" json:"content"` + Content string `gorm:"column:content;type:text;comment:活动详情" json:"content"` MaxNumber int `gorm:"column:max_number;type:int(6);default:0;comment:报名限制人数,0不做限制" json:"max_number"` Status ActivityInstanceStatus `gorm:"column:status;type:tinyint(1);default:1;comment:活动状态(1:显示,2:隐藏)" json:"status"` ModelDeleted diff --git a/app/common/model/sys_about.go b/app/common/model/sys_about.go new file mode 100644 index 0000000..6c4cdea --- /dev/null +++ b/app/common/model/sys_about.go @@ -0,0 +1,20 @@ +package model + +// SysAbout 系统关于我们数据模型 +type SysAbout struct { + Model + ParentID uint64 `gorm:"column:parent_id;type:int;default:0;comment:父级ID" json:"parent_id"` + Title string `gorm:"column:title;type:varchar(20);default:'';comment:标题信息" json:"title"` + Content string `gorm:"column:content;type:text;comment:详细信息" json:"content"` + Sort int `gorm:"column:sort;type:tinyint(3);default:0;comment:从大到小排序" json:"-"` + ModelDeleted + ModelAt +} + +func (m *SysAbout) TableName() string { + return "sys_about" +} + +func NewSysAbout() *SysAbout { + return &SysAbout{} +} diff --git a/router/address.go b/router/address.go index 7ce81a6..2ddfbf8 100644 --- a/router/address.go +++ b/router/address.go @@ -48,7 +48,7 @@ func registerAPI(app *gin.Engine) { _api := new(api2.Message) messageV1.POST("/launch", _api.Launch) } - // ServiceV1 服务信息管理 + // Service 服务信息管理 serviceV1 := v1.Group("/service") { _api := new(api2.Service) @@ -59,6 +59,13 @@ func registerAPI(app *gin.Engine) { serviceV1.GET("/innovate/kind", _api.InnovateKind) serviceV1.POST("/innovate/detail", _api.InnovateDetail) } + // About 关于我们管理 + aboutV1 := v1.Group("/about") + { + _api := new(api2.About) + aboutV1.POST("", _api.Instance) + aboutV1.GET("/navigation", _api.Navigation) + } } // registerAdminAPI 注册API