feat:完善项目信息
This commit is contained in:
@ -143,19 +143,21 @@ func (*Service) SolutionCaseDetail(c *gin.Context) {
|
||||
func (*Service) SolutionCaseForm(c *gin.Context) {
|
||||
form := &struct {
|
||||
api.IDStringForm
|
||||
KindID string `json:"kind_id" form:"kind_id" binding:"required"`
|
||||
Title string `json:"title" form:"title" binding:"required"`
|
||||
Content string `json:"content" form:"content" binding:"required"`
|
||||
Tags []string `json:"tags" form:"tags"`
|
||||
Sort int `json:"sort" form:"sort"`
|
||||
api.TenantIDStringForm
|
||||
KindID string `json:"kind_id" form:"kind_id" binding:"required"`
|
||||
Title string `json:"title" form:"title" binding:"required"`
|
||||
api.ImageForm
|
||||
Description string `json:"description" form:"description" binding:"description"`
|
||||
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 := service.NewSolutionCase()(api.GetSession()(c).(*session.Admin)).Form(&service.SolutionCaseParams{
|
||||
ID: form.Convert(), KindID: (&api.IDStringForm{ID: form.KindID}).Convert(),
|
||||
Title: form.Title, Content: form.Content, Sort: form.Sort,
|
||||
ID: form.IDStringForm.Convert(), TenantID: form.TenantIDStringForm.Convert(), KindID: (&api.IDStringForm{ID: form.KindID}).Convert(),
|
||||
Image: form.FilterImageURL(), Title: form.Title, Description: form.Description, Content: form.Content, Sort: form.Sort,
|
||||
})
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
@ -194,6 +196,7 @@ func (*Service) SolutionCaseKindSelect(c *gin.Context) {
|
||||
func (*Service) SolutionCaseKindForm(c *gin.Context) {
|
||||
form := &struct {
|
||||
api.IDStringForm
|
||||
api.TenantIDStringForm
|
||||
Mode int `json:"mode" form:"mode" binding:"required"`
|
||||
Title string `json:"title" form:"title" binding:"required"`
|
||||
api.ImageForm
|
||||
@ -204,7 +207,8 @@ func (*Service) SolutionCaseKindForm(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
err := service.NewSolutionCase()(api.GetSession()(c).(*session.Admin)).KindForm(&service.SolutionCaseKindParams{
|
||||
ID: form.Convert(), Mode: form.Mode, Image: form.FilterImageURL(), Title: form.Title, Sort: form.Sort,
|
||||
ID: form.IDStringForm.Convert(), TenantID: form.TenantIDStringForm.Convert(), Mode: form.Mode,
|
||||
Image: form.FilterImageURL(), Title: form.Title, Sort: form.Sort,
|
||||
})
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
@ -219,3 +223,33 @@ func (*Service) SolutionCaseKindDelete(c *gin.Context) {
|
||||
err := service.NewSolutionCase()(api.GetSession()(c).(*session.Admin)).KindDelete(form.Convert())
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (*Service) Message(c *gin.Context) {
|
||||
form := &struct {
|
||||
api.TenantIDStringForm
|
||||
Name string `json:"name" form:"name"`
|
||||
Status int `json:"status" form:"status"`
|
||||
Content string `json:"content" form:"content"`
|
||||
api.PageForm
|
||||
}{}
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := service.NewMessage()(api.GetSession()(c).(*session.Admin)).Instance(form.TenantIDStringForm.Convert(),
|
||||
form.Name, form.Status, form.Content, form.Page, form.PageSize)
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (*Service) MessageHandle(c *gin.Context) {
|
||||
form := &struct {
|
||||
api.IDStringForm
|
||||
Content string `json:"content" form:"content"`
|
||||
}{}
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := service.NewMessage()(api.GetSession()(c).(*session.Admin)).Handle(form.Convert(), form.Content)
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
105
app/api/admin/controller/service/message.go
Normal file
105
app/api/admin/controller/service/message.go
Normal file
@ -0,0 +1,105 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/admin/model"
|
||||
"SciencesServer/app/basic/controller"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/session"
|
||||
"SciencesServer/serve/orm"
|
||||
"errors"
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Message struct {
|
||||
*session.Admin
|
||||
}
|
||||
|
||||
type MessageHandle func(session *session.Admin) *Message
|
||||
|
||||
type MessageInfo struct {
|
||||
ID string `json:"id"`
|
||||
*model.ServiceMessageInfo
|
||||
Area string `json:"area"`
|
||||
}
|
||||
|
||||
// Instance 列表信息
|
||||
func (c *Message) Instance(tenantID uint64, name string, status int, content string, page, pageSize int) (*controller.ReturnPages, error) {
|
||||
mServiceMessage := model.NewServiceMessage()
|
||||
|
||||
where := make([]*model2.ModelWhere, 0)
|
||||
|
||||
if c.TenantID > 0 {
|
||||
where = append(where, model2.NewWhere("m.tenant_id", c.TenantID))
|
||||
}
|
||||
if tenantID > 0 {
|
||||
where = append(where, model2.NewWhere("m.tenant_id", tenantID))
|
||||
}
|
||||
if name != "" {
|
||||
where = append(where, model2.NewWhereLike("m.name", name))
|
||||
}
|
||||
if status > 0 {
|
||||
where = append(where, model2.NewWhere("m.status", status))
|
||||
}
|
||||
if content != "" {
|
||||
where = append(where, model2.NewWhereLike("m.content", content))
|
||||
}
|
||||
var count int64
|
||||
|
||||
out, err := mServiceMessage.Message(page, pageSize, &count, where...)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
list := make([]*MessageInfo, 0)
|
||||
|
||||
for _, v := range out {
|
||||
list = append(list, &MessageInfo{
|
||||
ID: v.GetEncodeID(),
|
||||
ServiceMessageInfo: v,
|
||||
Area: v.FormatBasic(),
|
||||
})
|
||||
}
|
||||
return &controller.ReturnPages{Data: list, Count: count}, err
|
||||
}
|
||||
|
||||
// Handle 处理操作
|
||||
func (c *Message) Handle(id uint64, content string) error {
|
||||
mServiceMessage := model.NewServiceMessage()
|
||||
mServiceMessage.ID = id
|
||||
|
||||
isExist, err := model2.FirstField(mServiceMessage.ServiceMessage, []string{"id", "tenant_id", "status"})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,留言信息不存在或已被删除")
|
||||
} else if c.TenantID > 0 && mServiceMessage.TenantID != c.TenantID {
|
||||
return errors.New("操作错误,无权限操作")
|
||||
}
|
||||
if mServiceMessage.Status != model2.ServiceMessageStatusForProcessing {
|
||||
return errors.New("操作错误,当前留言信息已处理")
|
||||
}
|
||||
return orm.GetDB().Transaction(func(tx *gorm.DB) error {
|
||||
if err = model2.Updates(mServiceMessage.ServiceMessage, map[string]interface{}{
|
||||
"status": model2.ServiceMessageStatusForProcessed, "updated_at": time.Now(),
|
||||
}, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
mServiceMessageLog := model.NewServiceMessageLog()
|
||||
mServiceMessageLog.UID = c.UID
|
||||
mServiceMessageLog.MessageID = id
|
||||
mServiceMessageLog.Content = content
|
||||
|
||||
if err = model2.Create(mServiceMessage.ServiceMessage); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func NewMessage() MessageHandle {
|
||||
return func(session *session.Admin) *Message {
|
||||
return &Message{session}
|
||||
}
|
||||
}
|
@ -5,6 +5,7 @@ import (
|
||||
"SciencesServer/app/basic/controller"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/session"
|
||||
config2 "SciencesServer/config"
|
||||
"errors"
|
||||
)
|
||||
|
||||
@ -25,11 +26,12 @@ type (
|
||||
SolutionCaseDetailInfo struct {
|
||||
ID string `json:"id"`
|
||||
*model2.ServiceSolutionCase
|
||||
KindID string `json:"kind_id"`
|
||||
TenantID string `json:"tenant_id"`
|
||||
KindID string `json:"kind_id"`
|
||||
}
|
||||
// SolutionCaseParams 案例参数信息
|
||||
SolutionCaseParams struct {
|
||||
ID, KindID uint64
|
||||
ID, TenantID, KindID uint64
|
||||
Title, Image, Description, Content string
|
||||
Sort int
|
||||
}
|
||||
@ -37,7 +39,8 @@ type (
|
||||
SolutionCaseKindInfo struct {
|
||||
ID string `json:"id"`
|
||||
*model2.ServiceSolutionCaseKind
|
||||
Area string `json:"area"`
|
||||
TenantID string `json:"tenant_id"`
|
||||
Area string `json:"area"`
|
||||
}
|
||||
// SolutionCaseKindSelectInfo 案例分类筛选信息
|
||||
SolutionCaseKindSelectInfo struct {
|
||||
@ -47,7 +50,7 @@ type (
|
||||
}
|
||||
// SolutionCaseKindParams 案例分类参数信息
|
||||
SolutionCaseKindParams struct {
|
||||
ID uint64
|
||||
ID, TenantID uint64
|
||||
Mode int
|
||||
Title, Image string
|
||||
Sort int
|
||||
@ -82,7 +85,7 @@ func (c *SolutionCase) Instance(tenantID uint64, title string, kindID uint64, pa
|
||||
list := make([]*SolutionCaseInfo, 0)
|
||||
|
||||
for _, v := range out {
|
||||
v.Image.Image = v.Image.Analysis("")
|
||||
v.Image.Image = v.Image.Analysis(config2.SettingInfo.Domain)
|
||||
|
||||
list = append(list, &SolutionCaseInfo{
|
||||
ID: v.GetEncodeID(),
|
||||
@ -105,11 +108,12 @@ func (c *SolutionCase) Detail(id uint64) (*SolutionCaseDetailInfo, error) {
|
||||
} else if !isExist {
|
||||
return nil, errors.New("操作错误,案例信息不存在或已被删除")
|
||||
}
|
||||
mServiceSolutionCase.Image.Image = mServiceSolutionCase.Image.Analysis("")
|
||||
mServiceSolutionCase.Image.Image = mServiceSolutionCase.Image.Analysis(config2.SettingInfo.Domain)
|
||||
|
||||
return &SolutionCaseDetailInfo{
|
||||
ID: mServiceSolutionCase.GetEncodeID(),
|
||||
ServiceSolutionCase: mServiceSolutionCase.ServiceSolutionCase,
|
||||
TenantID: mServiceSolutionCase.GetEncodeTenantID(),
|
||||
KindID: (&model2.Model{ID: mServiceSolutionCase.KindID}).GetEncodeID(),
|
||||
}, nil
|
||||
}
|
||||
@ -140,10 +144,16 @@ func (c *SolutionCase) Form(params *SolutionCaseParams) error {
|
||||
mServiceSolutionCase.Sort = params.Sort
|
||||
|
||||
if mServiceSolutionCase.ID > 0 {
|
||||
if c.TenantID <= 0 {
|
||||
mServiceSolutionCase.TenantID = params.TenantID
|
||||
}
|
||||
return model2.Updates(mServiceSolutionCase.ServiceSolutionCase, mServiceSolutionCase.ServiceSolutionCase)
|
||||
}
|
||||
mServiceSolutionCase.TenantID = c.TenantID
|
||||
mServiceSolutionCase.TenantID = params.TenantID
|
||||
|
||||
if c.TenantID > 0 {
|
||||
mServiceSolutionCase.TenantID = c.TenantID
|
||||
}
|
||||
return model2.Create(mServiceSolutionCase.ServiceSolutionCase)
|
||||
}
|
||||
|
||||
@ -193,9 +203,12 @@ func (c *SolutionCase) Kind(tenantID uint64, mode int, title string, page, pageS
|
||||
list := make([]*SolutionCaseKindInfo, 0)
|
||||
|
||||
for _, v := range out {
|
||||
v.Image.Image = v.Image.Analysis(config2.SettingInfo.Domain)
|
||||
|
||||
list = append(list, &SolutionCaseKindInfo{
|
||||
ID: v.GetEncodeID(),
|
||||
ServiceSolutionCaseKind: v.ServiceSolutionCaseKind,
|
||||
TenantID: v.GetEncodeTenantID(),
|
||||
Area: v.FormatBasic(),
|
||||
})
|
||||
}
|
||||
@ -259,10 +272,16 @@ func (c *SolutionCase) KindForm(params *SolutionCaseKindParams) error {
|
||||
mServiceSolutionCaseKind.Sort = params.Sort
|
||||
|
||||
if mServiceSolutionCaseKind.ID > 0 {
|
||||
if c.TenantID <= 0 {
|
||||
mServiceSolutionCaseKind.TenantID = params.TenantID
|
||||
}
|
||||
return model2.Updates(mServiceSolutionCaseKind.ServiceSolutionCaseKind, mServiceSolutionCaseKind.ServiceSolutionCaseKind)
|
||||
}
|
||||
mServiceSolutionCaseKind.TenantID = c.TenantID
|
||||
mServiceSolutionCaseKind.TenantID = params.TenantID
|
||||
|
||||
if c.TenantID > 0 {
|
||||
mServiceSolutionCaseKind.TenantID = c.TenantID
|
||||
}
|
||||
return model2.Create(mServiceSolutionCaseKind.ServiceSolutionCaseKind)
|
||||
}
|
||||
|
||||
|
48
app/api/admin/model/service_message.go
Normal file
48
app/api/admin/model/service_message.go
Normal file
@ -0,0 +1,48 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"SciencesServer/app/common/model"
|
||||
"SciencesServer/serve/orm"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
type ServiceMessage struct {
|
||||
*model.ServiceMessage
|
||||
}
|
||||
|
||||
type ServiceMessageInfo struct {
|
||||
*model.ServiceMessage
|
||||
model.Area
|
||||
HandleContent string `json:"handle_content"`
|
||||
HandleCreatedAt time.Time `json:"handle_created_at"`
|
||||
}
|
||||
|
||||
func (m *ServiceMessage) Message(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*ServiceMessageInfo, error) {
|
||||
db := orm.GetDB().Table(m.TableName()+" AS m").
|
||||
Select("m.*", "l.content AS handle_content", "l.created_at AS handle_created_at",
|
||||
"t.province", "t.city").
|
||||
Joins(fmt.Sprintf("LEFT JOIN (SELECT MAX(id) AS id, message_id, MAX(created_at) AS created_at, MAX(content) AS content "+
|
||||
"FROM %s WHERE is_deleted = %d GROUP BY message_id) AS l ON m.id = l.message_id",
|
||||
model.NewServiceMessageLog().TableName(), model.DeleteStatusForNot)).
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS t ON m.tenant_id = t.id", model.NewSysTenant().TableName()))
|
||||
|
||||
if len(where) > 0 {
|
||||
for _, v := range where {
|
||||
db = db.Where(v.Condition, v.Value)
|
||||
}
|
||||
}
|
||||
out := make([]*ServiceMessageInfo, 0)
|
||||
|
||||
if err := db.Count(count).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := db.Order("m.id " + model.OrderModeToDesc).Offset((page - 1) * pageSize).Limit(pageSize).Scan(&out).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func NewServiceMessage() *ServiceMessage {
|
||||
return &ServiceMessage{model.NewServiceMessage()}
|
||||
}
|
11
app/api/admin/model/service_message_log.go
Normal file
11
app/api/admin/model/service_message_log.go
Normal file
@ -0,0 +1,11 @@
|
||||
package model
|
||||
|
||||
import "SciencesServer/app/common/model"
|
||||
|
||||
type ServiceMessageLog struct {
|
||||
*model.ServiceMessageLog
|
||||
}
|
||||
|
||||
func NewServiceMessageLog() *ServiceMessageLog {
|
||||
return &ServiceMessageLog{model.NewServiceMessageLog()}
|
||||
}
|
@ -14,6 +14,7 @@ type ServiceSolutionCase struct {
|
||||
// ServiceSolutionCaseInfo 服务案例信息
|
||||
type ServiceSolutionCaseInfo struct {
|
||||
model.Model
|
||||
model.ModelTenant
|
||||
Title string `json:"title"`
|
||||
model.Image
|
||||
Description string `json:"description"`
|
||||
@ -26,7 +27,7 @@ type ServiceSolutionCaseInfo struct {
|
||||
// SolutionCase 案例信息
|
||||
func (m *ServiceSolutionCase) SolutionCase(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*ServiceSolutionCaseInfo, error) {
|
||||
db := orm.GetDB().Table(m.TableName()+" AS s").
|
||||
Select("s.id", "s.title", "s.image", "s.description", "s.visits", "k.title AS kind_title", "s.created_at",
|
||||
Select("s.id", "s.tenant_id", "s.title", "s.image", "s.description", "s.visits", "k.title AS kind_title", "s.created_at",
|
||||
"t.province", "t.city").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS t ON s.tenant_id = t.id", model.NewSysTenant().TableName())).
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS k ON s.kind_id = k.id", model.NewServiceSolutionCaseKind().TableName())).
|
||||
|
Reference in New Issue
Block a user