feat:完善项目信息
This commit is contained in:
145
app/api/admin/controller/activity/apply.go
Normal file
145
app/api/admin/controller/activity/apply.go
Normal file
@ -0,0 +1,145 @@
|
||||
package activity
|
||||
|
||||
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 Apply struct {
|
||||
*session.Admin
|
||||
}
|
||||
|
||||
type ApplyHandle func(session *session.Admin) *Apply
|
||||
|
||||
type (
|
||||
// ApplyInfo 申请信息
|
||||
ApplyInfo struct {
|
||||
ID string `json:"id"`
|
||||
TenantID string `json:"tenant_id"`
|
||||
*model.ActivityApplyInfo
|
||||
Area string `json:"area"`
|
||||
}
|
||||
// ApplyDetailInfo 申请详细信息
|
||||
ApplyDetailInfo struct {
|
||||
ID string `json:"id"`
|
||||
TenantID string `json:"tenant_id"`
|
||||
*model.ActivityApplyInfo
|
||||
}
|
||||
)
|
||||
|
||||
// Instance 申请信息
|
||||
func (c *Apply) Instance(tenantID uint64, title, contact string, page, pageSize int) (*controller.ReturnPages, error) {
|
||||
mActivityApply := model.NewActivityApply()
|
||||
|
||||
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))
|
||||
}
|
||||
if contact != "" {
|
||||
where = append(where, model2.NewWhereLike("a.contact", title))
|
||||
}
|
||||
var count int64
|
||||
|
||||
out, err := mActivityApply.Apply(page, pageSize, &count, where...)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := make([]*ApplyInfo, 0)
|
||||
|
||||
for _, v := range out {
|
||||
list = append(list, &ApplyInfo{
|
||||
ID: v.GetEncodeID(),
|
||||
TenantID: v.GetEncodeTenantID(),
|
||||
ActivityApplyInfo: v,
|
||||
Area: v.FormatBasic(),
|
||||
})
|
||||
}
|
||||
return &controller.ReturnPages{Data: list, Count: count}, nil
|
||||
}
|
||||
|
||||
// Detail 详细信息
|
||||
func (c *Apply) Detail(id uint64) (*ApplyDetailInfo, error) {
|
||||
mActivityApply := model.NewActivityApply()
|
||||
out, err := mActivityApply.Detail(id)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &ApplyDetailInfo{
|
||||
ID: out.GetEncodeID(),
|
||||
TenantID: out.GetEncodeTenantID(),
|
||||
ActivityApplyInfo: out,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Handle 处理操作
|
||||
func (c *Apply) Handle(id uint64, remark string) error {
|
||||
mActivityApply := model.NewActivityApply()
|
||||
mActivityApply.ID = id
|
||||
|
||||
isExist, err := model2.FirstField(mActivityApply.ActivityApply, []string{"id", "tenant_id", "status"})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,活动申请信息不存在或已被删除")
|
||||
}
|
||||
if c.TenantID > 0 && mActivityApply.TenantID != c.TenantID {
|
||||
return errors.New("操作错误,无权限操作")
|
||||
}
|
||||
if mActivityApply.Status != model2.ActivityApplyStatusForProcessing {
|
||||
return errors.New("操作错误,活动申请信息状态发生变化,不可处理")
|
||||
}
|
||||
return orm.GetDB().Transaction(func(tx *gorm.DB) error {
|
||||
mActivityApply.Status = model2.ActivityApplyStatusForProcessed
|
||||
|
||||
if err = model2.Updates(mActivityApply.ActivityApply, map[string]interface{}{
|
||||
"status": model2.ActivityApplyStatusForProcessed, "updated_at": time.Now(),
|
||||
}, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
mActivityApplyLog := model.NewActivityApplyLog()
|
||||
mActivityApplyLog.ApplyID = mActivityApply.ID
|
||||
mActivityApplyLog.Remark = remark
|
||||
return model2.Create(mActivityApplyLog.ActivityApplyLog, tx)
|
||||
})
|
||||
}
|
||||
|
||||
// Delete 删除操作
|
||||
func (c *Apply) Delete(id uint64) error {
|
||||
mActivityApply := model.NewActivityApply()
|
||||
mActivityApply.ID = id
|
||||
|
||||
isExist, err := model2.FirstField(mActivityApply.ActivityApply, []string{"id", "tenant_id", "status"})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,活动申请信息不存在或已被删除")
|
||||
}
|
||||
if c.TenantID > 0 && mActivityApply.TenantID != c.TenantID {
|
||||
return errors.New("操作错误,无权限操作")
|
||||
}
|
||||
return model2.Delete(mActivityApply.ActivityApply)
|
||||
}
|
||||
|
||||
func NewApply() ApplyHandle {
|
||||
return func(session *session.Admin) *Apply {
|
||||
return &Apply{session}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user