feat:完善项目信息

This commit is contained in:
henry
2022-01-13 16:50:38 +08:00
parent 0494bbf5d0
commit 4637a5fb4b
10 changed files with 326 additions and 37 deletions

View File

@ -25,6 +25,18 @@ func (*Sys) Banner(c *gin.Context) {
api.APIResponse(err, data)(c)
}
func (*Sys) BannerLocal(c *gin.Context) {
form := &struct {
api.TenantIDStringForm
}{}
if err := api.Bind(form)(c); err != nil {
api.APIFailure(err.(error))(c)
return
}
data, err := sys.NewBanner()(api.GetSession()(c).(*session.Admin)).Local(form.Convert())
api.APIResponse(err, data)(c)
}
func (*Sys) BannerForm(c *gin.Context) {
form := &struct {
api.IDStringForm
@ -136,3 +148,59 @@ func (*Sys) NavigationDelete(c *gin.Context) {
err := sys.NewNavigation()(api.GetSession()(c).(*session.Admin)).Delete(form.Convert())
api.APIResponse(err)(c)
}
func (*Sys) Agreement(c *gin.Context) {
form := &struct {
api.TenantIDStringForm
Title string `json:"title" form:"title"`
api.PageForm
}{}
if err := api.Bind(form)(c); err != nil {
api.APIFailure(err.(error))(c)
return
}
data, err := sys.NewAgreement()(api.GetSession()(c).(*session.Admin)).Instance(form.Convert(), form.Title,
form.Page, form.PageSize)
api.APIResponse(err, data)(c)
}
func (*Sys) AgreementDetail(c *gin.Context) {
form := new(api.IDStringForm)
if err := api.Bind(form)(c); err != nil {
api.APIFailure(err.(error))(c)
return
}
data, err := sys.NewAgreement()(api.GetSession()(c).(*session.Admin)).Detail(form.Convert())
api.APIResponse(err, data)(c)
}
func (*Sys) AgreementForm(c *gin.Context) {
form := &struct {
api.IDStringForm
api.TenantIDStringForm
Title string `json:"title" form:"title" binding:"required"`
Content string `json:"content" form:"content" binding:"required"`
Status int `json:"status" form:"status" binding:"required"`
}{}
if err := api.Bind(form)(c); err != nil {
api.APIFailure(err.(error))(c)
return
}
err := sys.NewAgreement()(api.GetSession()(c).(*session.Admin)).Form(&sys.AgreementParams{
ID: form.IDStringForm.Convert(), TenantID: form.TenantIDStringForm.Convert(),
Title: form.Title, Content: form.Content, Status: form.Status,
})
api.APIResponse(err)(c)
}
func (*Sys) AgreementDelete(c *gin.Context) {
form := new(api.IDStringForm)
if err := api.Bind(form)(c); err != nil {
api.APIFailure(err.(error))(c)
return
}
err := sys.NewAgreement()(api.GetSession()(c).(*session.Admin)).Delete(form.Convert())
api.APIResponse(err)(c)
}

View File

@ -0,0 +1,151 @@
package sys
import (
"SciencesServer/app/api/admin/model"
"SciencesServer/app/basic/controller"
model2 "SciencesServer/app/common/model"
"SciencesServer/app/session"
"errors"
)
type Agreement struct {
*session.Admin
}
type AgreementHandle func(session *session.Admin) *Agreement
type (
// AgreementInfo 协议信息
AgreementInfo struct {
ID string `json:"id"`
TenantID string `json:"tenant_id"`
Area string `json:"area"`
*model2.SysAgreement
}
// AgreementDetailInfo 协议详细信息
AgreementDetailInfo struct {
ID string `json:"id"`
TenantID string `json:"tenant_id"`
*model2.SysAgreement
}
// AgreementParams 协议参数信息
AgreementParams struct {
ID, TenantID uint64
Title, Content string
Status int
}
)
// Instance 首页信息
func (c *Agreement) Instance(tenantID uint64, title string, page, pageSize int) (*controller.ReturnPages, error) {
mSysAgreement := model.NewSysAgreement()
where := make([]*model2.ModelWhere, 0)
if c.TenantID > 0 {
where = append(where, model2.NewWhere("s.tenant_id", c.TenantID))
}
if tenantID > 0 {
where = append(where, model2.NewWhere("s.tenant_id", tenantID))
}
if title != "" {
where = append(where, model2.NewWhereLike("s.title", title))
}
var count int64
out, err := mSysAgreement.Agreement(page, pageSize, &count, where...)
if err != nil {
return nil, err
}
list := make([]*AgreementInfo, 0)
for _, v := range out {
list = append(list, &AgreementInfo{
ID: v.GetEncodeID(),
TenantID: v.GetEncodeTenantID(),
Area: v.FormatBasic(),
SysAgreement: v.SysAgreement,
})
}
return &controller.ReturnPages{Data: list, Count: count}, nil
}
// Detail 详细信息
func (c *Agreement) Detail(id uint64) (*AgreementDetailInfo, error) {
mSysAgreement := model.NewSysAgreement()
mSysAgreement.ID = id
isExist, err := model2.FirstField(mSysAgreement.SysAgreement, []string{"id", "tenant_id"})
if err != nil {
return nil, err
} else if !isExist {
return nil, errors.New("操作错误,协议信息不存在或已被删除")
}
return &AgreementDetailInfo{
ID: mSysAgreement.GetEncodeID(),
TenantID: mSysAgreement.GetEncodeTenantID(),
SysAgreement: mSysAgreement.SysAgreement,
}, nil
}
func (c *Agreement) Form(params *AgreementParams) error {
mSysAgreement := model.NewSysAgreement()
if params.ID > 0 {
mSysAgreement.ID = params.ID
isExist, err := model2.FirstField(mSysAgreement.SysAgreement, []string{"id", "tenant_id", "created_at"})
if err != nil {
return err
} else if !isExist {
return errors.New("操作错误,协议信息不存在或已被删除")
}
if c.TenantID > 0 && c.TenantID != mSysAgreement.TenantID {
return errors.New("操作错误,无权限操作")
}
}
mSysAgreement.Title = params.Title
mSysAgreement.Content = params.Content
mSysAgreement.Status = model2.SysAgreementStatus(params.Status)
if mSysAgreement.ID > 0 {
if c.TenantID <= 0 {
mSysAgreement.TenantID = params.TenantID
}
return model2.Updates(mSysAgreement.SysAgreement, mSysAgreement.SysAgreement)
}
mSysAgreement.TenantID = params.TenantID
if c.TenantID > 0 {
mSysAgreement.TenantID = c.TenantID
}
return model2.Create(mSysAgreement.SysAgreement)
}
// Delete 删除操作
func (c *Agreement) Delete(id uint64) error {
mSysAgreement := model.NewSysAgreement()
mSysAgreement.ID = id
isExist, err := model2.FirstField(mSysAgreement.SysAgreement, []string{"id", "tenant_id"})
if err != nil {
return err
} else if !isExist {
return errors.New("操作错误,协议信息不存在或已被删除")
}
if c.TenantID > 0 && mSysAgreement.TenantID != c.TenantID {
return errors.New("操作错误,无权限操作")
}
return model2.Delete(mSysAgreement.SysAgreement)
}
func NewAgreement() AgreementHandle {
return func(session *session.Admin) *Agreement {
return &Agreement{session}
}
}

View File

@ -23,7 +23,7 @@ type (
ID string `json:"id"`
*model2.SysBanner
Area string `json:"area"`
Images []string `json:"images"`
Images string `json:"images"`
}
// BannerLocalInfo 轮播图位置信息
BannerLocalInfo struct {
@ -38,8 +38,7 @@ type (
// BannerParams 轮播图参数信息
BannerParams struct {
ID, TenantID uint64
Title, Local, Size, Remark string
Images []string
Title, Local, Size, Images, Remark string
IsMultiple int
}
)
@ -156,7 +155,7 @@ func (c *Banner) Form(params *BannerParams) error {
}
mSysBanner.Title = params.Title
mSysBanner.Local = params.Local
mSysBanner.Images.SetImagesAttribute(params.Images)
mSysBanner.Images.Images = params.Images
mSysBanner.Size = params.Size
mSysBanner.IsMultiple = params.IsMultiple
mSysBanner.Remark = params.Remark
@ -185,16 +184,12 @@ func (c *Banner) Local(tenantID uint64) ([]*BannerLocalInfo, error) {
if tenantID > 0 {
where = append(where, model2.NewWhere("tenant_id", tenantID))
} else {
where = append(where, model2.NewWhere("tenant_id", c.TenantID))
}
if err := model2.Pluck(mSysBanner.SysBanner, "local", &out, where...); err != nil {
return nil, err
}
c.filter(out, ">")
return nil, nil
return c.tree(c.filter(out, ">"), defaultFirstLevelKey), nil
}
// Delete 删除操作

View File

@ -0,0 +1,45 @@
package model
import (
"SciencesServer/app/common/model"
"SciencesServer/serve/orm"
"fmt"
)
type SysAgreement struct {
*model.SysAgreement
}
// SysAgreementInfo 轮播图信息
type SysAgreementInfo struct {
*model.SysAgreement
model.Area
}
// Agreement 协议信息
func (m *SysAgreement) Agreement(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*SysAgreementInfo, error) {
db := orm.GetDB().Table(m.TableName()+" AS s").
Select("s.id", "s.tenant_id", "s.title", "s.status", "s.created_at", "s.updated_at",
"t.province", "t.city").
Joins(fmt.Sprintf("LEFT JOIN %s AS t ON s.tenant_id = t.id", model.NewSysTenant().TableName())).
Where("s.is_deleted = ?", model.DeleteStatusForNot)
if len(where) > 0 {
for _, wo := range where {
db = db.Where(wo.Condition, wo.Value)
}
}
out := make([]*SysAgreementInfo, 0)
if err := db.Count(count).Error; err != nil {
return nil, err
}
if err := db.Order("s.id " + model.OrderModeToDesc).Offset((page - 1) * pageSize).Limit(pageSize).Scan(&out).Error; err != nil {
return nil, err
}
return out, nil
}
func NewSysAgreement() *SysAgreement {
return &SysAgreement{model.NewSysAgreement()}
}

View File

@ -30,7 +30,7 @@ type (
}
// WithdrawalTransferInfo 提现转账信息
WithdrawalTransferInfo struct {
Images []string `json:"images"`
Images string `json:"images"`
Remark string `json:"remark"`
}
)

View File

@ -49,14 +49,16 @@ func (this *ImageForm) FilterImageURL() string {
}
type ImagesForm struct {
Images []string `json:"images" form:"images"`
Images string `json:"images" form:"images"`
}
func (this *ImagesForm) FilterImageURL() []string {
for _, v := range this.Images {
v = strings.Replace(v, config.SettingInfo.Domain, "", -1)
func (this *ImagesForm) FilterImageURL() string {
out := make([]string, 0)
for _, v := range strings.Split(this.Images, ",") {
out = append(out, strings.Replace(v, config.SettingInfo.Domain, "", -1))
}
return this.Images
return strings.Join(out, ",")
}
type FileForm struct {

View File

@ -121,8 +121,7 @@ func (this *Instance) Handle() {
return out
}},
&synchronized{iModel: model.NewSysNavigation()},
&synchronized{iModel: model.NewSysAbout()},
&synchronized{iModel: model.NewSysBanner()},
&synchronized{iModel: model.NewSysBanner()}, &synchronized{iModel: model.NewSysAgreement()},
// 日志管理
&synchronized{iModel: model.NewSysLog()}, &synchronized{iModel: model.NewSysUserLoginLog()},
// 用户管理

View File

@ -4,7 +4,6 @@ import (
config2 "SciencesServer/app/basic/config"
"SciencesServer/config"
"SciencesServer/utils"
"encoding/json"
"strings"
"time"
)
@ -46,19 +45,13 @@ type Images struct {
}
// AnalysisSlice Slice解析
func (m *Images) AnalysisSlice(domain string) []string {
images := make([]string, 0)
utils.FromJSON(m.Images, &images)
func (m *Images) AnalysisSlice(domain string) string {
images := strings.Split(m.Images, ",")
for k, v := range images {
images[k] = domain + v
}
return images
}
func (m *Images) SetImagesAttribute(value []string) {
_bytes, _ := json.Marshal(value)
m.Images = string(_bytes)
return strings.Join(images, ",")
}
type Local struct {

View File

@ -0,0 +1,30 @@
package model
// SysAgreement 协议数据模型
type SysAgreement struct {
Model
ModelTenant
Title string `gorm:"column:title;type:varchar(50);default:'';comment:协议名称" json:"title"`
Content string `gorm:"column:content;type:varchar(255);default:'';comment:协议内容" json:"content"`
Status SysAgreementStatus `gorm:"column:status;type:tinyint(1);default:0;comment:状态" json:"status"`
ModelDeleted
ModelAt
}
// SysAgreementStatus 协议数据状态
type SysAgreementStatus int
const (
// SysAgreementStatusForShow 显示
SysAgreementStatusForShow SysAgreementStatus = iota + 1
// SysAgreementStatusForHidden 隐藏
SysAgreementStatusForHidden
)
func (m *SysAgreement) TableName() string {
return "sys_agreement"
}
func NewSysAgreement() *SysAgreement {
return &SysAgreement{}
}

View File

@ -177,17 +177,23 @@ func registerAdminAPI(app *gin.Engine) {
_api := new(api1.Sys)
// 导航信息
sys.POST("/banner", _api.Banner)
sys.POST("/banner/add", _api.NavigationForm)
sys.POST("/banner/edit", _api.NavigationForm)
sys.POST("/banner/delete", _api.NavigationDelete)
sys.POST("/banner/local", _api.BannerLocal)
sys.POST("/banner/add", _api.BannerForm)
sys.POST("/banner/edit", _api.BannerForm)
sys.POST("/banner/delete", _api.BannerDelete)
sys.GET("/industry", _api.Industry)
sys.POST("/industry/add", _api.NavigationForm)
sys.POST("/industry/edit", _api.NavigationForm)
sys.POST("/industry/delete", _api.NavigationDelete)
sys.POST("/industry/add", _api.IndustryForm)
sys.POST("/industry/edit", _api.IndustryForm)
sys.POST("/industry/delete", _api.IndustryDelete)
sys.POST("/navigation", _api.Navigation)
sys.POST("/navigation/add", _api.NavigationForm)
sys.POST("/navigation/edit", _api.NavigationForm)
sys.POST("/navigation/delete", _api.NavigationDelete)
sys.POST("/agreement", _api.Agreement)
sys.POST("/agreement/detail", _api.AgreementDetail)
sys.POST("/agreement/add", _api.AgreementForm)
sys.POST("/agreement/edit", _api.AgreementForm)
sys.POST("/agreement/delete", _api.AgreementDelete)
}
// User 用户管理
user := v1.Group("/user")