feat:完善网站信息,增加创新服务数据模型
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/website/controller"
|
||||
"SciencesServer/app/api/website/controller/service"
|
||||
"SciencesServer/app/basic/api"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
@ -9,7 +9,7 @@ import (
|
||||
type Service struct{}
|
||||
|
||||
func (*Service) SolutionCase(c *gin.Context) {
|
||||
data, err := controller.NewService()(nil, "").SolutionCase()
|
||||
data, err := service.NewSolutionCase()(nil, "").Instance()
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
@ -22,7 +22,7 @@ func (*Service) SolutionCaseList(c *gin.Context) {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := controller.NewService()(nil, "").SolutionCaseList(form.Convert(), form.Page, form.PageSize)
|
||||
data, err := service.NewSolutionCase()(nil, "").List(form.Convert(), form.Page, form.PageSize)
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
@ -33,6 +33,36 @@ func (*Service) SolutionCaseDetail(c *gin.Context) {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := controller.NewService()(nil, "").SolutionCaseDetail(form.Convert())
|
||||
data, err := service.NewSolutionCase()(nil, "").Detail(form.Convert())
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (*Service) Innovate(c *gin.Context) {
|
||||
form := &struct {
|
||||
Kind int `json:"kind" form:"kind"`
|
||||
Title string `json:"title" form:"title"`
|
||||
api.PageForm
|
||||
}{}
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := service.NewInnovate()(nil, "").Instance(form.Kind, form.Title, form.Page, form.PageSize)
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (*Service) InnovateKind(c *gin.Context) {
|
||||
data, err := service.NewInnovate()(nil, "").Kind()
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (*Service) InnovateDetail(c *gin.Context) {
|
||||
form := new(api.IDStringForm)
|
||||
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := service.NewInnovate()(nil, "").Detail(form.Convert())
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
116
app/api/website/controller/service/innovate.go
Normal file
116
app/api/website/controller/service/innovate.go
Normal file
@ -0,0 +1,116 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/website/model"
|
||||
"SciencesServer/app/basic/controller"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/session"
|
||||
"errors"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Innovate 创新服务
|
||||
type Innovate struct {
|
||||
*session.Enterprise
|
||||
local string
|
||||
}
|
||||
|
||||
type InnovateHandle func(session *session.Enterprise, local string) *Innovate
|
||||
|
||||
type (
|
||||
// InnovateInfo 创新服务信息
|
||||
InnovateInfo struct {
|
||||
ID string `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Tags []string `json:"tags"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
// InnovateKindInfo 创新服务分类信息
|
||||
InnovateKindInfo struct {
|
||||
ID string `json:"id"`
|
||||
Title string `json:"title"`
|
||||
}
|
||||
// InnovateDetailInfo 详细信息
|
||||
InnovateDetailInfo struct {
|
||||
ID string `json:"id"`
|
||||
*model2.ServiceInnovate
|
||||
}
|
||||
)
|
||||
|
||||
// Instance 首页信息
|
||||
func (c *Innovate) Instance(kind int, title string, page, pageSize int) (*controller.ReturnPages, error) {
|
||||
mServiceInnovate := model.NewServiceInnovate()
|
||||
|
||||
out := make([]*model2.ServiceInnovate, 0)
|
||||
|
||||
var count int64
|
||||
|
||||
where := []*model2.ModelWhereOrder{&model2.ModelWhereOrder{Order: model2.NewOrder("id", model2.OrderModeToDesc)}}
|
||||
|
||||
if kind > 0 {
|
||||
where = append(where, &model2.ModelWhereOrder{Where: model2.NewWhere("kind", kind)})
|
||||
}
|
||||
if title != "" {
|
||||
where = append(where, &model2.ModelWhereOrder{Where: model2.NewWhereLike("title", title)})
|
||||
}
|
||||
|
||||
if err := model2.PagesFields(mServiceInnovate.ServiceInnovate, &out, []string{"id", "title", "tag", "created_at"}, page, pageSize,
|
||||
&count, where...); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
list := make([]*InnovateInfo, 0)
|
||||
|
||||
for _, v := range out {
|
||||
list = append(list, &InnovateInfo{
|
||||
ID: v.GetEncodeID(), Title: v.Title, Tags: v.GetTagAttribute(), CreatedAt: v.CreatedAt,
|
||||
})
|
||||
}
|
||||
return &controller.ReturnPages{Data: list, Count: count}, nil
|
||||
}
|
||||
|
||||
// Kind 类别信息
|
||||
func (c *Innovate) Kind() ([]*InnovateKindInfo, error) {
|
||||
mServiceInnovateKind := model.NewServiceInnovateKind()
|
||||
out := make([]*model2.ServiceInnovateKind, 0)
|
||||
|
||||
if err := model2.ScanFields(mServiceInnovateKind.ServiceInnovateKind, &out, []string{"id", "title"}, &model2.ModelWhereOrder{
|
||||
Order: model2.NewOrder("sort", model2.OrderModeToDesc),
|
||||
}, &model2.ModelWhereOrder{
|
||||
Order: model2.NewOrder("id", model2.OrderModeToDesc),
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
list := make([]*InnovateKindInfo, 0)
|
||||
|
||||
for _, v := range out {
|
||||
list = append(list, &InnovateKindInfo{
|
||||
ID: v.GetEncodeID(), Title: v.Title,
|
||||
})
|
||||
}
|
||||
return list, nil
|
||||
}
|
||||
|
||||
// Detail 详细信息
|
||||
func (c *Innovate) Detail(id uint64) (*InnovateDetailInfo, error) {
|
||||
mServiceInnovate := model.NewServiceInnovate()
|
||||
mServiceInnovate.ID = id
|
||||
|
||||
if isExit, err := model2.First(mServiceInnovate.ServiceInnovate); err != nil {
|
||||
return nil, err
|
||||
} else if !isExit {
|
||||
return nil, errors.New("操作错误,服务信息数据不存在或已被删除")
|
||||
}
|
||||
return &InnovateDetailInfo{
|
||||
ID: mServiceInnovate.GetEncodeID(),
|
||||
ServiceInnovate: mServiceInnovate.ServiceInnovate,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func NewInnovate() InnovateHandle {
|
||||
return func(session *session.Enterprise, local string) *Innovate {
|
||||
return &Innovate{
|
||||
Enterprise: session,
|
||||
local: local,
|
||||
}
|
||||
}
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
package controller
|
||||
package service
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/manage/controller"
|
||||
"SciencesServer/app/api/website/model"
|
||||
"SciencesServer/app/basic/controller"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/session"
|
||||
"SciencesServer/config"
|
||||
@ -11,53 +11,53 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type Service struct {
|
||||
type SolutionCase struct {
|
||||
*session.Enterprise
|
||||
local string
|
||||
}
|
||||
|
||||
type ServiceHandle func(session *session.Enterprise, local string) *Service
|
||||
type SolutionCaseHandle func(session *session.Enterprise, local string) *SolutionCase
|
||||
|
||||
type (
|
||||
// ServiceSolutionCase 服务解决方案案例信息
|
||||
ServiceSolutionCase struct {
|
||||
// SolutionCaseInfo 基本信息
|
||||
SolutionCaseInfo struct {
|
||||
ID string `json:"id"`
|
||||
MarkID uint64 `json:"-"`
|
||||
Kind model2.ServiceSolutionCaseKind `json:"kind"`
|
||||
Title string `json:"title"`
|
||||
Image string `json:"image"`
|
||||
Children []*ServiceSolutionCaseInfo `json:"children"`
|
||||
Children []*SolutionCaseBasic `json:"children"`
|
||||
}
|
||||
// ServiceSolutionCaseInfo 基本信息
|
||||
ServiceSolutionCaseInfo struct {
|
||||
// SolutionCaseBasic 基本信息
|
||||
SolutionCaseBasic struct {
|
||||
ID string `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Image string `json:"image"`
|
||||
Description string `json:"description"`
|
||||
}
|
||||
// ServiceSolutionCaseDetail 详细信息
|
||||
ServiceSolutionCaseDetail struct {
|
||||
ServiceSolutionCaseInfo
|
||||
// SolutionCaseDetail 详细信息
|
||||
SolutionCaseDetail struct {
|
||||
SolutionCaseBasic
|
||||
Visits int `json:"visits"`
|
||||
Content string `json:"content"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
)
|
||||
|
||||
// SolutionCase 服务解决方案案例
|
||||
func (c *Service) SolutionCase() ([]*ServiceSolutionCase, error) {
|
||||
// Instance 服务解决方案案例
|
||||
func (c *SolutionCase) Instance() ([]*SolutionCaseInfo, error) {
|
||||
mServiceSolutionCase := model.NewServiceSolutionCase()
|
||||
out, err := mServiceSolutionCase.SolutionCase(2)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ret := make([]*ServiceSolutionCase, 0)
|
||||
ret := make([]*SolutionCaseInfo, 0)
|
||||
|
||||
for _, v := range out {
|
||||
isExist := false
|
||||
|
||||
detail := &ServiceSolutionCaseInfo{
|
||||
detail := &SolutionCaseBasic{
|
||||
ID: (&model2.Model{ID: v.DetailID}).GetEncodeID(), Title: v.DetailTitle,
|
||||
Image: (&model2.Image{Image: v.DetailImage}).Analysis(config.SettingInfo.Domain),
|
||||
Description: v.DetailDescription,
|
||||
@ -70,21 +70,18 @@ func (c *Service) SolutionCase() ([]*ServiceSolutionCase, error) {
|
||||
}
|
||||
}
|
||||
if !isExist {
|
||||
ret = append(ret, &ServiceSolutionCase{
|
||||
ID: v.GetEncodeID(),
|
||||
MarkID: v.ID,
|
||||
Kind: v.Kind,
|
||||
Title: v.Title,
|
||||
ret = append(ret, &SolutionCaseInfo{
|
||||
ID: v.GetEncodeID(), MarkID: v.ID, Kind: v.Kind, Title: v.Title,
|
||||
Image: v.Image.Analysis(config.SettingInfo.Domain),
|
||||
Children: []*ServiceSolutionCaseInfo{detail},
|
||||
Children: []*SolutionCaseBasic{detail},
|
||||
})
|
||||
}
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
// SolutionCaseList 列表信息
|
||||
func (c *Service) SolutionCaseList(id uint64, page, pageSize int) (*controller.ReturnPages, error) {
|
||||
// List 列表信息
|
||||
func (c *SolutionCase) List(id uint64, page, pageSize int) (*controller.ReturnPages, error) {
|
||||
mServiceSolutionCaseDetail := model.NewServiceSolutionCaseDetail()
|
||||
|
||||
out := make([]*model2.ServiceSolutionCaseDetail, 0)
|
||||
@ -102,12 +99,11 @@ func (c *Service) SolutionCaseList(id uint64, page, pageSize int) (*controller.R
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
list := make([]*ServiceSolutionCaseInfo, 0)
|
||||
list := make([]*SolutionCaseBasic, 0)
|
||||
|
||||
for _, v := range out {
|
||||
list = append(list, &ServiceSolutionCaseInfo{
|
||||
ID: v.GetEncodeID(),
|
||||
Title: v.Title,
|
||||
list = append(list, &SolutionCaseBasic{
|
||||
ID: v.GetEncodeID(), Title: v.Title,
|
||||
Image: v.Image.Analysis(config.SettingInfo.Domain),
|
||||
Description: v.Description,
|
||||
})
|
||||
@ -115,8 +111,8 @@ func (c *Service) SolutionCaseList(id uint64, page, pageSize int) (*controller.R
|
||||
return &controller.ReturnPages{Data: list, Count: count}, nil
|
||||
}
|
||||
|
||||
// SolutionCaseDetail 详细信息
|
||||
func (c *Service) SolutionCaseDetail(id uint64) (*ServiceSolutionCaseDetail, error) {
|
||||
// Detail 详细信息
|
||||
func (c *SolutionCase) Detail(id uint64) (*SolutionCaseDetail, error) {
|
||||
mServiceSolutionCaseDetail := model.NewServiceSolutionCaseDetail()
|
||||
mServiceSolutionCaseDetail.ID = id
|
||||
|
||||
@ -124,13 +120,13 @@ func (c *Service) SolutionCaseDetail(id uint64) (*ServiceSolutionCaseDetail, err
|
||||
"image", "description", "content", "visits", "created_at"}); err != nil {
|
||||
return nil, err
|
||||
} else if !isExist {
|
||||
return nil, errors.New("操作错误,服务解决案例信息不存在或已被删除")
|
||||
return nil, errors.New("操作错误,案例信息不存在或已被删除")
|
||||
}
|
||||
_ = model2.Updates(mServiceSolutionCaseDetail.ServiceSolutionCaseDetail, map[string]interface{}{
|
||||
"visits": gorm.Expr("visits + ?", 1), "updated_at": time.Now(),
|
||||
})
|
||||
return &ServiceSolutionCaseDetail{
|
||||
ServiceSolutionCaseInfo: ServiceSolutionCaseInfo{
|
||||
return &SolutionCaseDetail{
|
||||
SolutionCaseBasic: SolutionCaseBasic{
|
||||
ID: mServiceSolutionCaseDetail.GetEncodeID(),
|
||||
Title: mServiceSolutionCaseDetail.Title,
|
||||
Image: mServiceSolutionCaseDetail.Image.Analysis(config.SettingInfo.Domain),
|
||||
@ -142,9 +138,9 @@ func (c *Service) SolutionCaseDetail(id uint64) (*ServiceSolutionCaseDetail, err
|
||||
}, nil
|
||||
}
|
||||
|
||||
func NewService() ServiceHandle {
|
||||
return func(session *session.Enterprise, local string) *Service {
|
||||
return &Service{
|
||||
func NewSolutionCase() SolutionCaseHandle {
|
||||
return func(session *session.Enterprise, local string) *SolutionCase {
|
||||
return &SolutionCase{
|
||||
Enterprise: session,
|
||||
local: local,
|
||||
}
|
11
app/api/website/model/service_innovate.go
Normal file
11
app/api/website/model/service_innovate.go
Normal file
@ -0,0 +1,11 @@
|
||||
package model
|
||||
|
||||
import "SciencesServer/app/common/model"
|
||||
|
||||
type ServiceInnovate struct {
|
||||
*model.ServiceInnovate
|
||||
}
|
||||
|
||||
func NewServiceInnovate() *ServiceInnovate {
|
||||
return &ServiceInnovate{model.NewServiceInnovate()}
|
||||
}
|
11
app/api/website/model/service_innovate_kind.go
Normal file
11
app/api/website/model/service_innovate_kind.go
Normal file
@ -0,0 +1,11 @@
|
||||
package model
|
||||
|
||||
import "SciencesServer/app/common/model"
|
||||
|
||||
type ServiceInnovateKind struct {
|
||||
*model.ServiceInnovateKind
|
||||
}
|
||||
|
||||
func NewServiceInnovateKind() *ServiceInnovateKind {
|
||||
return &ServiceInnovateKind{model.NewServiceInnovateKind()}
|
||||
}
|
@ -9,7 +9,7 @@ type ActivityApply struct {
|
||||
Mode ActivityInstanceMode `gorm:"column:mode;type:tinyint(1);default:1;comment:活动模式" json:"mode"`
|
||||
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 ActivityApplyStatus `gorm:"column:status;type:tinyint(1);default:0;comment:审核状态" json:"status"`
|
||||
ModelDeleted
|
||||
|
@ -55,6 +55,9 @@ func registerAPI(app *gin.Engine) {
|
||||
serviceV1.GET("/solution_case", _api.SolutionCase)
|
||||
serviceV1.POST("/solution_case/list", _api.SolutionCaseList)
|
||||
serviceV1.POST("/solution_case/detail", _api.SolutionCaseDetail)
|
||||
serviceV1.POST("/innovate", _api.Innovate)
|
||||
serviceV1.POST("/innovate/kind", _api.InnovateKind)
|
||||
serviceV1.POST("/innovate/detail", _api.InnovateDetail)
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user