feat:完善项目信息
This commit is contained in:
1
app/api/admin/api/activity.go
Normal file
1
app/api/admin/api/activity.go
Normal file
@ -0,0 +1 @@
|
||||
package api
|
@ -147,7 +147,7 @@ func (*Service) SolutionCaseForm(c *gin.Context) {
|
||||
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"`
|
||||
Description string `json:"description" form:"description" binding:"required"`
|
||||
Content string `json:"content" form:"content" binding:"required"`
|
||||
Sort int `json:"sort" form:"sort"`
|
||||
}{}
|
||||
@ -253,3 +253,15 @@ func (*Service) MessageHandle(c *gin.Context) {
|
||||
err := service.NewMessage()(api.GetSession()(c).(*session.Admin)).Handle(form.Convert(), form.Content)
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (*Service) MessageDelete(c *gin.Context) {
|
||||
form := &struct {
|
||||
api.IDStringForm
|
||||
}{}
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := service.NewMessage()(api.GetSession()(c).(*session.Admin)).Delete(form.Convert())
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
109
app/api/admin/controller/activity/instance.go
Normal file
109
app/api/admin/controller/activity/instance.go
Normal file
@ -0,0 +1,109 @@
|
||||
package activity
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/admin/model"
|
||||
"SciencesServer/app/basic/controller"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/session"
|
||||
"errors"
|
||||
)
|
||||
|
||||
type Instance struct {
|
||||
*session.Admin
|
||||
}
|
||||
|
||||
type InstanceHandle func(session *session.Admin) *Instance
|
||||
|
||||
type (
|
||||
// InstanceInfo 活动信息
|
||||
InstanceInfo struct {
|
||||
ID string `json:"id"`
|
||||
*model.ActivityInstanceInfo
|
||||
Area string `json:"area"`
|
||||
}
|
||||
// InstanceDetailInfo 活动详细信息
|
||||
InstanceDetailInfo struct {
|
||||
ID string `json:"id"`
|
||||
TenantID string `json:"tenant_id"`
|
||||
*model2.ActivityInstance
|
||||
}
|
||||
)
|
||||
|
||||
func (c *Instance) Index(tenantID uint64, title string, page, pageSize int) (*controller.ReturnPages, error) {
|
||||
mActivityInstance := model.NewActivityInstance()
|
||||
|
||||
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))
|
||||
}
|
||||
if title != "" {
|
||||
where = append(where, model2.NewWhereLike("a.title", title))
|
||||
}
|
||||
var count int64
|
||||
|
||||
out, err := mActivityInstance.Activity(page, pageSize, &count, where...)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
list := make([]*InstanceInfo, 0)
|
||||
|
||||
for _, v := range out {
|
||||
list = append(list, &InstanceInfo{
|
||||
ID: v.GetEncodeID(),
|
||||
ActivityInstanceInfo: v,
|
||||
Area: v.FormatBasic(),
|
||||
})
|
||||
}
|
||||
return &controller.ReturnPages{Data: list, Count: count}, nil
|
||||
}
|
||||
|
||||
// Detail 详细信息
|
||||
func (c *Instance) Detail(id uint64) (*InstanceDetailInfo, error) {
|
||||
mActivityInstance := model.NewActivityInstance()
|
||||
mActivityInstance.ID = id
|
||||
|
||||
isExist, err := model2.First(mActivityInstance.ActivityInstance)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if !isExist {
|
||||
return nil, errors.New("操作错误,活动信息不存在或已被删除")
|
||||
}
|
||||
return &InstanceDetailInfo{
|
||||
ID: mActivityInstance.GetEncodeID(),
|
||||
TenantID: mActivityInstance.GetEncodeTenantID(),
|
||||
ActivityInstance: mActivityInstance.ActivityInstance,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (c *Instance) Form() {
|
||||
|
||||
}
|
||||
|
||||
func (c *Instance) Delete(id uint64) error {
|
||||
mActivityInstance := model.NewActivityInstance()
|
||||
mActivityInstance.ID = id
|
||||
|
||||
isExist, err := model2.FirstField(mActivityInstance.ActivityInstance, []string{"id", "tenant_id"})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,活动信息不存在或已被删除")
|
||||
}
|
||||
if c.TenantID > 0 && c.TenantID != mActivityInstance.TenantID {
|
||||
return errors.New("操作错误,无权限操作")
|
||||
}
|
||||
return model2.Delete(mActivityInstance.ActivityInstance)
|
||||
}
|
||||
|
||||
func NewInstance() InstanceHandle {
|
||||
return func(session *session.Admin) *Instance {
|
||||
return &Instance{session}
|
||||
}
|
||||
}
|
@ -143,7 +143,6 @@ func (c *Innovate) Form(params *InnovateParams) error {
|
||||
// Delete 删除操作
|
||||
func (c *Innovate) Delete(id uint64) error {
|
||||
mServiceInnovate := model.NewServiceInnovate()
|
||||
|
||||
mServiceInnovate.ID = id
|
||||
|
||||
isExist, err := model2.FirstField(mServiceInnovate.ServiceInnovate, []string{"id", "tenant_id"})
|
||||
@ -199,11 +198,15 @@ func (c *Innovate) KindSelect() ([]*InnovateKindSelectInfo, error) {
|
||||
out := make([]*model2.ServiceInnovateKind, 0)
|
||||
|
||||
where := []*model2.ModelWhereOrder{&model2.ModelWhereOrder{
|
||||
Where: model2.NewWhere("tenant_id", c.TenantID),
|
||||
Order: model2.NewOrder("sort", model2.OrderModeToAsc),
|
||||
}, &model2.ModelWhereOrder{
|
||||
Order: model2.NewOrder("id", model2.OrderModeToDesc),
|
||||
}}
|
||||
if c.TenantID > 0 {
|
||||
where = append(where, &model2.ModelWhereOrder{
|
||||
Where: model2.NewWhere("tenant_id", c.TenantID),
|
||||
})
|
||||
}
|
||||
if err := model2.ScanFields(mServiceInnovateKind.ServiceInnovateKind, &out, []string{"id", "title"}, where...); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -91,13 +91,33 @@ func (c *Message) Handle(id uint64, content string) error {
|
||||
mServiceMessageLog.MessageID = id
|
||||
mServiceMessageLog.Content = content
|
||||
|
||||
if err = model2.Create(mServiceMessage.ServiceMessage); err != nil {
|
||||
if err = model2.Create(mServiceMessage.ServiceMessage, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
// Delete 删除操作
|
||||
func (c *Message) Delete(id uint64) 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 model2.Delete(mServiceMessage.ServiceMessage)
|
||||
}
|
||||
|
||||
func NewMessage() MessageHandle {
|
||||
return func(session *session.Admin) *Message {
|
||||
return &Message{session}
|
||||
|
@ -220,11 +220,16 @@ func (c *SolutionCase) KindSelect() (map[model2.ServiceSolutionCaseMode]*Solutio
|
||||
mServiceSolutionCaseKind := model.NewServiceSolutionCaseKind()
|
||||
|
||||
where := []*model2.ModelWhereOrder{&model2.ModelWhereOrder{
|
||||
Where: model2.NewWhere("tenant_id", c.TenantID),
|
||||
Order: model2.NewOrder("sort", model2.OrderModeToAsc),
|
||||
}, &model2.ModelWhereOrder{
|
||||
Order: model2.NewOrder("id", model2.OrderModeToDesc),
|
||||
}}
|
||||
|
||||
if c.TenantID > 0 {
|
||||
where = append(where, &model2.ModelWhereOrder{
|
||||
Where: model2.NewWhere("tenant_id", c.TenantID),
|
||||
})
|
||||
}
|
||||
out := make([]*model2.ServiceSolutionCaseKind, 0)
|
||||
|
||||
if err := model2.ScanFields(mServiceSolutionCaseKind.ServiceSolutionCaseKind, &out, []string{"id", "mode", "title"}, where...); err != nil {
|
||||
|
47
app/api/admin/model/activity_instance.go
Normal file
47
app/api/admin/model/activity_instance.go
Normal file
@ -0,0 +1,47 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"SciencesServer/app/common/model"
|
||||
"SciencesServer/serve/orm"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type ActivityInstance struct {
|
||||
*model.ActivityInstance
|
||||
}
|
||||
|
||||
type ActivityInstanceInfo struct {
|
||||
*model.ActivityInstance
|
||||
JoinCount int `json:"join_count"`
|
||||
model.Area
|
||||
}
|
||||
|
||||
// Activity 活动信息
|
||||
func (m *ActivityInstance) Activity(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*ActivityInstanceInfo, error) {
|
||||
db := orm.GetDB().Table(m.TableName()+" AS a").
|
||||
Select("a.id", "a.tenant_id", "a.mode", "a.image", "a.title", "a.begin_at", "a.finish_at", "a.join_deadline",
|
||||
"a.amount", "a.max_number", "a.status", "a.created_at", "j.count AS join_count", "t.province", "t.city").
|
||||
Joins(fmt.Sprintf("LEFT JOIN (SELECT activity_id, COUNT(id) AS count FROM %s WHERE is_delete = %d AND status = %d GROUP BY activity_id) AS j ON a.id = j.activity_id",
|
||||
model.NewActivityJoin().TableName(), model.DeleteStatusForNot, model.ActivityJoinStatusForSuccess)).
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS t ON i.tenant_id = t.id", model.NewSysTenant().TableName())).
|
||||
Where("a.is_deleted = ?", model.DeleteStatusForNot)
|
||||
|
||||
if len(where) > 0 {
|
||||
for _, wo := range where {
|
||||
db = db.Where(wo.Condition, wo.Value)
|
||||
}
|
||||
}
|
||||
out := make([]*ActivityInstanceInfo, 0)
|
||||
|
||||
if err := db.Count(count).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := db.Order("a.id " + model.OrderModeToDesc).Offset((page - 1) * pageSize).Limit(pageSize).Scan(&out).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func NewActivityInstance() *ActivityInstance {
|
||||
return &ActivityInstance{model.NewActivityInstance()}
|
||||
}
|
11
app/api/admin/model/activity_join.go
Normal file
11
app/api/admin/model/activity_join.go
Normal file
@ -0,0 +1,11 @@
|
||||
package model
|
||||
|
||||
import "SciencesServer/app/common/model"
|
||||
|
||||
type ActivityJoin struct {
|
||||
*model.ActivityJoin
|
||||
}
|
||||
|
||||
func NewActivityJoin() *ActivityJoin {
|
||||
return &ActivityJoin{model.NewActivityJoin()}
|
||||
}
|
Reference in New Issue
Block a user