48 lines
1.3 KiB
Go
48 lines
1.3 KiB
Go
package model
|
|
|
|
import (
|
|
"SciencesServer/app/common/model"
|
|
"SciencesServer/serve/orm"
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
type ActivityInstance struct {
|
|
*model.ActivityInstance
|
|
}
|
|
|
|
// ActivityInstanceJoinInfo 活动报名信息
|
|
type ActivityInstanceJoinInfo struct {
|
|
ID uint64 `json:"id"`
|
|
*model.ActivityInstanceBasic
|
|
CreatedAt time.Time `json:"created_at"`
|
|
}
|
|
|
|
// Joins 活动参加信息
|
|
func (m *ActivityInstance) Joins(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*ActivityInstanceJoinInfo, error) {
|
|
db := orm.GetDB().Table(model.NewActivityJoin().TableName()+" AS j").
|
|
Select("j.id", "a.title", "a.begin_at", "a.finish_at", "a.join_deadline", "j.created_at").
|
|
Joins(fmt.Sprintf("LEFT JOIN %s AS a ON j.activity_id = a.id", m.TableName())).
|
|
Where("j.is_deleted = ?", model.DeleteStatusForNot).
|
|
Where("j.status = ?", model.ActivityJoinStatusForSuccess)
|
|
|
|
if len(where) > 0 {
|
|
` for _, v := range where {
|
|
db = db.Where(v.Condition, v.Value)
|
|
}
|
|
}
|
|
out := make([]*ActivityInstanceJoinInfo, 0)
|
|
|
|
if err := db.Count(count).Error; err != nil {
|
|
return nil, err
|
|
}
|
|
if err := db.Order("j.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()}
|
|
}
|