78 lines
1.9 KiB
Go
78 lines
1.9 KiB
Go
package activity
|
|
|
|
import (
|
|
"SciencesServer/app/api/enterprise/model"
|
|
"SciencesServer/app/basic/controller"
|
|
model2 "SciencesServer/app/common/model"
|
|
"SciencesServer/app/session"
|
|
"time"
|
|
)
|
|
|
|
type Instance struct {
|
|
*session.Enterprise
|
|
}
|
|
|
|
type InstanceHandle func(session *session.Enterprise) *Instance
|
|
|
|
type InstanceForJoin struct {
|
|
*model.ActivityInstanceJoinInfo
|
|
ID string `json:"id"`
|
|
}
|
|
|
|
// Joins 活动参加信息
|
|
func (c *Instance) Joins(title string, status, page, pageSize int) (*controller.ReturnPages, error) {
|
|
mActivityInstance := model.NewActivityInstance()
|
|
|
|
where := []*model2.ModelWhere{
|
|
model2.NewWhere("j.identity", c.SelectIdentity),
|
|
model2.NewWhere("j.uid", c.UID),
|
|
}
|
|
|
|
if title != "" {
|
|
where = append(where, model2.NewWhereLike("a.title", title))
|
|
}
|
|
if status > 0 {
|
|
now := time.Now()
|
|
|
|
if status == 1 { // 未开始
|
|
where = append(where, model2.NewWhereCondition("a.begin_at", ">", now))
|
|
} else if status == 2 { // 进行中
|
|
where = append(where, model2.NewWhereCondition("a.begin_at", "<=", now),
|
|
model2.NewWhereCondition("a.finish_at", ">=", now))
|
|
} else { // 已结束
|
|
where = append(where, model2.NewWhereCondition("a.finish_at", "<", now))
|
|
}
|
|
}
|
|
var count int64
|
|
|
|
out, err := mActivityInstance.Joins(page, pageSize, &count, where...)
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
list := make([]*InstanceForJoin, 0)
|
|
|
|
for _, v := range out {
|
|
mActivityInstance.SetID(v.ID)
|
|
|
|
list = append(list, &InstanceForJoin{
|
|
ID: mActivityInstance.GetEncodeID(),
|
|
ActivityInstanceJoinInfo: v,
|
|
})
|
|
}
|
|
return &controller.ReturnPages{Data: out, Count: count}, err
|
|
}
|
|
|
|
// JoinDelete 活动参加信息删除
|
|
func (c *Instance) JoinDelete(id uint64) error {
|
|
mActivityJoin := model.NewActivityJoin()
|
|
mActivityJoin.ID = id
|
|
return model2.Delete(mActivityJoin.ActivityJoin)
|
|
}
|
|
|
|
func NewInstance() InstanceHandle {
|
|
return func(session *session.Enterprise) *Instance {
|
|
return &Instance{Enterprise: session}
|
|
}
|
|
}
|