2021-11-25 10:15:06 +08:00
|
|
|
|
package model
|
|
|
|
|
|
2022-01-12 15:05:14 +08:00
|
|
|
|
import (
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"time"
|
|
|
|
|
)
|
2021-11-25 10:15:06 +08:00
|
|
|
|
|
|
|
|
|
// ActivityInstance 活动数据模型
|
|
|
|
|
type ActivityInstance struct {
|
|
|
|
|
Model
|
2022-01-11 17:24:38 +08:00
|
|
|
|
ModelTenant
|
2021-11-25 10:15:06 +08:00
|
|
|
|
ActivityInstanceBasic
|
2022-01-12 15:05:14 +08:00
|
|
|
|
Contact string `gorm:"column:contact;type:varchar(20);default:'';comment:联系人" json:"contact"`
|
|
|
|
|
ContactMobile string `gorm:"column:contact_mobile;type:varchar(15);default:'';comment:联系方式" json:"contact_mobile"`
|
|
|
|
|
Image
|
|
|
|
|
Area
|
2022-01-18 09:20:18 +08:00
|
|
|
|
Description string `gorm:"column:description;type:varchar(255);comment:描述" json:"description"`
|
2022-01-12 15:05:14 +08:00
|
|
|
|
Industry string `gorm:"column:industry;type:varchar(255);comment:所属领域;行业信息" json:"-"`
|
|
|
|
|
Amount float64 `gorm:"column:amount;type:decimal(10,2);default:0;comment:活动收费金额" json:"amount"`
|
|
|
|
|
Content string `gorm:"column:content;type:text;comment:活动详情" json:"content"`
|
|
|
|
|
MaxNumber int `gorm:"column:max_number;type:int(6);default:0;comment:报名限制人数,0不做限制" json:"max_number"`
|
|
|
|
|
NotifyCrowd int `gorm:"column:notify_crowd;type:tinyint(3);default:0;comment:通知人群" json:"notify_crowd"`
|
|
|
|
|
IsHome int `gorm:"column:is_home;type:tinyint(1);default:0;comment:首页展示(0:不展示,1:展示)" json:"is_home"`
|
|
|
|
|
Sort int `gorm:"column:sort;type:tinyint(3);default:0;comment:排序,数值越小,优先排序" json:"sort"`
|
|
|
|
|
Status ActivityInstanceStatus `gorm:"column:status;type:tinyint(1);default:1;comment:活动状态(1:显示,2:隐藏)" json:"status"`
|
2021-11-25 10:15:06 +08:00
|
|
|
|
ModelDeleted
|
|
|
|
|
ModelAt
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ActivityInstanceBasic 活动基本信息
|
|
|
|
|
type ActivityInstanceBasic struct {
|
2021-12-03 14:18:06 +08:00
|
|
|
|
Title string `gorm:"column:title;type:varchar(50);default:'';comment:活动名称" json:"title"`
|
2021-11-25 10:15:06 +08:00
|
|
|
|
BeginAt time.Time `gorm:"column:begin_at;type:datetime;not null;comment:活动开始" json:"begin_at"`
|
|
|
|
|
FinishAt time.Time `gorm:"column:finish_at;type:datetime;not null;comment:活动结束时间" json:"finish_at"`
|
|
|
|
|
JoinDeadline time.Time `gorm:"column:join_deadline;type:datetime;not null;comment:报名截止时间" json:"join_deadline"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type ActivityInstanceStatus int
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
// ActivityInstanceStatusForShow 状态显示
|
|
|
|
|
ActivityInstanceStatusForShow ActivityInstanceStatus = iota + 1
|
|
|
|
|
// ActivityInstanceStatusForHidden 状态隐藏
|
|
|
|
|
ActivityInstanceStatusForHidden
|
|
|
|
|
)
|
|
|
|
|
|
2022-01-11 17:24:38 +08:00
|
|
|
|
func (m *ActivityInstance) TableName() string {
|
|
|
|
|
return "activity_instance"
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-25 10:15:06 +08:00
|
|
|
|
func (m *ActivityInstanceBasic) IsOngoing() bool {
|
|
|
|
|
now := time.Now()
|
|
|
|
|
return m.BeginAt.Before(now) && m.FinishAt.After(now)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *ActivityInstanceBasic) IsCanJoin() bool {
|
|
|
|
|
return m.JoinDeadline.After(time.Now())
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-12 15:05:14 +08:00
|
|
|
|
func (m *ActivityInstance) SetIndustryAttribute(value []string) {
|
|
|
|
|
_bytes, _ := json.Marshal(value)
|
|
|
|
|
m.Industry = string(_bytes)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *ActivityInstance) GetIndustryAttribute() []string {
|
|
|
|
|
out := make([]string, 0)
|
|
|
|
|
_ = json.Unmarshal([]byte(m.Industry), &out)
|
|
|
|
|
return out
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-25 10:15:06 +08:00
|
|
|
|
func NewActivityInstance() *ActivityInstance {
|
|
|
|
|
return &ActivityInstance{}
|
|
|
|
|
}
|