package yb

import (
	"github.com/beego/beego/v2/client/orm"
	"time"
)

// ActivityRemind 活动会议提醒表
type ActivityRemind struct {
	ActivityRemindId int    `orm:"column(activity_remind_id);pk" description:"活动提醒ID"`
	ActivityId       int    `description:"活动ID"`
	UserId           int    `description:"微信用户表ID"`
	CompanyId        int    `description:"客户id"`
	RealName         string `description:"用户实际名称"`
	Mobile           string `description:"用户手机号"`
	//RegisterState int8      `description:"报名状态 0-取消报名 1-已报名"`
	CreateTime time.Time `description:"创建时间"`
}

// TableName 表名变更
func (activityRemind *ActivityRemind) TableName() string {
	return "yb_activity_remind"
}

// GetAllActivityRemindListByActivityId 根据活动id获取所有的提醒用户
func GetAllActivityRemindListByActivityId(activityId int) (list []*ActivityRemind, err error) {
	o := orm.NewOrm()
	sql := "select * from yb_activity_remind where activity_id = ? "
	sql += ` order by activity_remind_id asc ` //按照预约时间正序
	_, err = o.Raw(sql, activityId).QueryRows(&list)
	return
}

// Update 更新活动报名
func (activityRemind *ActivityRemind) Update(cols []string) (err error) {
	o := orm.NewOrm()
	_, err = o.Update(activityRemind, cols...)
	return
}

// DelActivityReminds 根据活动ID清除所有提醒
func DelActivityReminds(activityId int) (err error) {
	o := orm.NewOrm()
	sql := "DELETE FROM yb_activity_remind WHERE activity_id = ?"
	_, err = o.Raw(sql, activityId).Exec()
	return
}
