feat:完善项目信息
This commit is contained in:
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}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user