feat:完善项目信息
This commit is contained in:
77
app/api/website/controller/sys/agreement.go
Normal file
77
app/api/website/controller/sys/agreement.go
Normal file
@ -0,0 +1,77 @@
|
||||
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 (
|
||||
// AgreementInfo 协议信息
|
||||
AgreementInfo struct {
|
||||
ID string `json:"id"`
|
||||
Title string `json:"title"`
|
||||
}
|
||||
// AgreementDetailInfo 协议详细信息
|
||||
AgreementDetailInfo struct {
|
||||
ID string `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Content string `json:"content"`
|
||||
}
|
||||
)
|
||||
|
||||
// Instance 首页信息
|
||||
func (c *Agreement) Instance() ([]*AgreementInfo, error) {
|
||||
mSysAgreement := model.NewSysAgreement()
|
||||
out := make([]*model2.SysAgreement, 0)
|
||||
|
||||
if err := model2.ScanFields(mSysAgreement.SysAgreement, &out, []string{"id", "title"}, &model2.ModelWhereOrder{
|
||||
Where: model2.NewWhere("tenant_id", c.tenantID),
|
||||
}, &model2.ModelWhereOrder{
|
||||
Where: model2.NewWhere("status", model2.SysAgreementStatusForShow),
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
list := make([]*AgreementInfo, 0)
|
||||
|
||||
for _, v := range out {
|
||||
list = append(list, &AgreementInfo{
|
||||
ID: v.GetEncodeID(),
|
||||
Title: v.Title,
|
||||
})
|
||||
}
|
||||
return list, nil
|
||||
}
|
||||
|
||||
// Detail 详细信息
|
||||
func (c *Agreement) Detail(id uint64) (*AgreementDetailInfo, error) {
|
||||
mSysAgreement := model.NewSysAgreement()
|
||||
mSysAgreement.ID = id
|
||||
|
||||
if isExist, err := model2.FirstField(mSysAgreement.SysAgreement, []string{"id", "title", "content"}); err != nil {
|
||||
return nil, err
|
||||
} else if !isExist {
|
||||
return nil, errors.New("操作错误,协议信息不存在")
|
||||
}
|
||||
return &AgreementDetailInfo{
|
||||
ID: mSysAgreement.GetEncodeID(), Title: mSysAgreement.Title, Content: mSysAgreement.Content,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func NewAgreement() AgreementHandle {
|
||||
return func(session *session.Enterprise, tenantID uint64) *Agreement {
|
||||
return &Agreement{
|
||||
Enterprise: session,
|
||||
tenantID: tenantID,
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user