feat:完善网站信息,增加创新服务数据模型
This commit is contained in:
26
app/api/website/api/about.go
Normal file
26
app/api/website/api/about.go
Normal file
@ -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)
|
||||
}
|
66
app/api/website/controller/about.go
Normal file
66
app/api/website/controller/about.go
Normal file
@ -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{}
|
||||
}
|
||||
}
|
11
app/api/website/model/sys_about.go
Normal file
11
app/api/website/model/sys_about.go
Normal file
@ -0,0 +1,11 @@
|
||||
package model
|
||||
|
||||
import "SciencesServer/app/common/model"
|
||||
|
||||
type SysAbout struct {
|
||||
*model.SysAbout
|
||||
}
|
||||
|
||||
func NewSysAbout() *SysAbout {
|
||||
return &SysAbout{model.NewSysAbout()}
|
||||
}
|
@ -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()},
|
||||
// 用户管理
|
||||
|
@ -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
|
||||
|
20
app/common/model/sys_about.go
Normal file
20
app/common/model/sys_about.go
Normal file
@ -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{}
|
||||
}
|
@ -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
|
||||
|
Reference in New Issue
Block a user