feat:完善项目信息
This commit is contained in:
@ -204,3 +204,60 @@ func (*Sys) AgreementDelete(c *gin.Context) {
|
||||
err := sys.NewAgreement()(api.GetSession()(c).(*session.Admin)).Delete(form.Convert())
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (*Sys) About(c *gin.Context) {
|
||||
form := &struct {
|
||||
api.TenantIDStringForm
|
||||
}{}
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := sys.NewAbout()(api.GetSession()(c).(*session.Admin)).Instance(form.Convert())
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (*Sys) AboutDetail(c *gin.Context) {
|
||||
form := new(api.IDStringForm)
|
||||
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := sys.NewAbout()(api.GetSession()(c).(*session.Admin)).Instance(form.Convert())
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (*Sys) AboutForm(c *gin.Context) {
|
||||
form := &struct {
|
||||
api.IDStringForm
|
||||
api.TenantIDStringForm
|
||||
ParentID string `json:"parent_id" form:"parent_id"`
|
||||
Title string `json:"title" form:"title" binding:"required"`
|
||||
Content string `json:"content" form:"content" binding:"required"`
|
||||
Sort int `json:"sort" form:"sort"`
|
||||
}{}
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := sys.NewAbout()(api.GetSession()(c).(*session.Admin)).Form(&sys.AboutParams{
|
||||
ID: form.IDStringForm.Convert(),
|
||||
TenantID: form.TenantIDStringForm.Convert(),
|
||||
ParentID: (&api.IDStringForm{ID: form.ParentID}).Convert(),
|
||||
Title: form.Title, Content: form.Content, Sort: form.Sort,
|
||||
})
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (*Sys) AboutDelete(c *gin.Context) {
|
||||
form := &struct {
|
||||
api.TenantIDStringForm
|
||||
}{}
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := sys.NewAbout()(api.GetSession()(c).(*session.Admin)).Instance(form.Convert())
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
152
app/api/admin/controller/sys/about.go
Normal file
152
app/api/admin/controller/sys/about.go
Normal file
@ -0,0 +1,152 @@
|
||||
package sys
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/admin/model"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/session"
|
||||
"errors"
|
||||
)
|
||||
|
||||
type About struct {
|
||||
*session.Admin
|
||||
}
|
||||
|
||||
type AboutHandle func(session *session.Admin) *About
|
||||
|
||||
type (
|
||||
// AboutInfo 关于信息
|
||||
AboutInfo struct {
|
||||
ID string `json:"id"`
|
||||
ParentID string `json:"parent_id"`
|
||||
Area string `json:"area"`
|
||||
Children []*AboutInfo `json:"children"`
|
||||
}
|
||||
// AboutDetailInfo 详细信息
|
||||
AboutDetailInfo struct {
|
||||
ID string `json:"id"`
|
||||
TenantID string `json:"tenant_id"`
|
||||
ParentID string `json:"parent_id"`
|
||||
*model2.SysAbout
|
||||
}
|
||||
// AboutParams 关于参数信息
|
||||
AboutParams struct {
|
||||
ID, TenantID, ParentID uint64
|
||||
Title, Content string
|
||||
Sort int
|
||||
}
|
||||
)
|
||||
|
||||
func (c *About) tree(src []*model.SysAboutInfo, parentID uint64) []*AboutInfo {
|
||||
out := make([]*AboutInfo, 0)
|
||||
|
||||
for _, v := range src {
|
||||
if v.ParentID == parentID {
|
||||
out = append(out, &AboutInfo{
|
||||
ID: v.GetEncodeID(),
|
||||
ParentID: (&model2.Model{ID: v.ParentID}).GetEncodeID(),
|
||||
Area: v.FormatBasic(),
|
||||
Children: c.tree(src, v.ID),
|
||||
})
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// Instance 首页信息
|
||||
func (c *About) Instance(tenantID uint64) ([]*AboutInfo, error) {
|
||||
mSysAbout := model.NewSysAbout()
|
||||
|
||||
where := make([]*model2.ModelWhere, 0)
|
||||
|
||||
if c.TenantID > 0 {
|
||||
where = append(where, model2.NewWhere("a.tenant_id", c.TenantID))
|
||||
}
|
||||
|
||||
if tenantID > 0 {
|
||||
where = append(where, model2.NewWhere("a.tenant_id", tenantID))
|
||||
}
|
||||
out, err := mSysAbout.About(where...)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return c.tree(out, 0), nil
|
||||
}
|
||||
|
||||
func (c *About) Detail(id uint64) (*AboutDetailInfo, error) {
|
||||
mSysAbout := model.NewSysAbout()
|
||||
mSysAbout.ID = id
|
||||
|
||||
isExist, err := model2.First(mSysAbout.SysAbout)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if !isExist {
|
||||
return nil, errors.New("操作错误,关于信息不存在或已被删除")
|
||||
}
|
||||
return &AboutDetailInfo{
|
||||
ID: mSysAbout.GetEncodeID(),
|
||||
TenantID: mSysAbout.GetEncodeTenantID(),
|
||||
ParentID: (&model2.Model{ID: mSysAbout.ParentID}).GetEncodeID(),
|
||||
SysAbout: mSysAbout.SysAbout,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (c *About) Form(params *AboutParams) error {
|
||||
mSysAbout := model.NewSysAbout()
|
||||
|
||||
if params.ID > 0 {
|
||||
mSysAbout.ID = params.ID
|
||||
|
||||
isExist, err := model2.FirstField(mSysAbout.SysAbout, []string{"id", "tenant_id", "created_at"})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,关于信息不存在或已被删除")
|
||||
}
|
||||
if c.TenantID > 0 && c.TenantID != mSysAbout.TenantID {
|
||||
return errors.New("操作错误,无权限操作")
|
||||
}
|
||||
}
|
||||
mSysAbout.Title = params.Title
|
||||
mSysAbout.ParentID = params.ParentID
|
||||
mSysAbout.Content = params.Content
|
||||
mSysAbout.Sort = params.Sort
|
||||
|
||||
if mSysAbout.ID > 0 {
|
||||
if c.TenantID <= 0 {
|
||||
mSysAbout.TenantID = params.TenantID
|
||||
}
|
||||
return model2.Updates(mSysAbout.SysAbout, mSysAbout.SysAbout)
|
||||
}
|
||||
mSysAbout.TenantID = params.TenantID
|
||||
|
||||
if c.TenantID > 0 {
|
||||
mSysAbout.TenantID = c.TenantID
|
||||
}
|
||||
return model2.Create(mSysAbout.SysAbout)
|
||||
}
|
||||
|
||||
func (c *About) Delete(id uint64) error {
|
||||
mSysAbout := model.NewSysAbout()
|
||||
mSysAbout.ID = id
|
||||
|
||||
isExist, err := model2.FirstField(mSysAbout.SysAbout, []string{"id", "tenant_id"})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,关于信息不存在或已被删除")
|
||||
}
|
||||
if c.TenantID > 0 && mSysAbout.TenantID != c.TenantID {
|
||||
return errors.New("操作错误,无权限操作")
|
||||
}
|
||||
return model2.Delete(mSysAbout.SysAbout)
|
||||
}
|
||||
|
||||
func NewAbout() AboutHandle {
|
||||
return func(session *session.Admin) *About {
|
||||
return &About{session}
|
||||
}
|
||||
}
|
@ -77,7 +77,7 @@ func (c *Agreement) Detail(id uint64) (*AgreementDetailInfo, error) {
|
||||
mSysAgreement := model.NewSysAgreement()
|
||||
mSysAgreement.ID = id
|
||||
|
||||
isExist, err := model2.FirstField(mSysAgreement.SysAgreement, []string{"id", "tenant_id"})
|
||||
isExist, err := model2.First(mSysAgreement.SysAgreement)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -20,7 +20,8 @@ type BannerHandle func(session *session.Admin) *Banner
|
||||
type (
|
||||
// BannerInfo 轮播图信息
|
||||
BannerInfo struct {
|
||||
ID string `json:"id"`
|
||||
ID string `json:"id"`
|
||||
TenantID string `json:"tenant_id"`
|
||||
*model2.SysBanner
|
||||
Area string `json:"area"`
|
||||
Images string `json:"images"`
|
||||
@ -126,7 +127,7 @@ func (c *Banner) Instance(tenantID uint64, title, local string, page, pageSize i
|
||||
|
||||
for _, v := range out {
|
||||
list = append(list, &BannerInfo{
|
||||
ID: v.GetEncodeID(),
|
||||
ID: v.GetEncodeID(), TenantID: v.GetEncodeTenantID(),
|
||||
SysBanner: v.SysBanner,
|
||||
Area: v.FormatBasic(),
|
||||
Images: v.Images.AnalysisSlice(config.SettingInfo.Domain),
|
||||
|
39
app/api/admin/model/sys_about.go
Normal file
39
app/api/admin/model/sys_about.go
Normal file
@ -0,0 +1,39 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"SciencesServer/app/common/model"
|
||||
"SciencesServer/serve/orm"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type SysAbout struct {
|
||||
*model.SysAbout
|
||||
}
|
||||
|
||||
type SysAboutInfo struct {
|
||||
*model.SysAbout
|
||||
model.Area
|
||||
}
|
||||
|
||||
func (m *SysAbout) About(where ...*model.ModelWhere) ([]*SysAboutInfo, error) {
|
||||
db := orm.GetDB().Table(m.TableName()+" AS a").
|
||||
Select("a.id", "a.parent_id", "a.title", "t.province", "t.city").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS t ON a.tenant_id = t.id", model.NewSysTenant().TableName())).
|
||||
Where("a.is_deleted = ?", model.DeleteStatusForNot)
|
||||
|
||||
if len(where) > 0 {
|
||||
for _, v := range where {
|
||||
db = db.Where(v.Condition, v.Value)
|
||||
}
|
||||
}
|
||||
out := make([]*SysAboutInfo, 0)
|
||||
|
||||
if err := db.Order("a.sort " + model.OrderModeToAsc).Order("a.id " + model.OrderModeToDesc).Scan(&out).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func NewSysAbout() *SysAbout {
|
||||
return &SysAbout{model.NewSysAbout()}
|
||||
}
|
Reference in New Issue
Block a user