package models import ( "fmt" "rdluck_tools/orm" "time" ) type CygxActivityMeetingReminder struct { Id int `orm:"column(id);pk"` ActivityId int `description:"活动ID"` UserId int `description:"用户ID"` CreateTime time.Time `description:"创建时间"` Mobile string `description:"手机号"` Email string `description:"邮箱"` CompanyId int `description:"公司id"` CompanyName string `description:"公司名称"` } //记录日志 type CygxActivityMeetingReminderLog struct { Id int `orm:"column(id);pk"` ActivityId int `description:"活动ID"` UserId int `description:"用户ID"` CreateTime time.Time `description:"创建时间"` Mobile string `description:"手机号"` Email string `description:"邮箱"` CompanyId int `description:"公司id"` CompanyName string `description:"公司名称"` Type int `description:"操作方式,1报名,2取消报名"` } //添加会议提醒信息 func AddActivityMeetingReminder(item *CygxActivityMeetingReminder) (lastId int64, err error) { o := orm.NewOrm() o.Begin() defer func() { fmt.Println(err) if err == nil { o.Commit() } else { o.Rollback() } }() var count int sql := `SELECT COUNT(1) AS count FROM cygx_activity_meeting_reminder WHERE user_id=? AND activity_id=? ` err = o.Raw(sql, item.UserId, item.ActivityId).QueryRow(&count) if err != nil { return } if count > 0 { sql := `UPDATE cygx_activity_meeting_reminder SET is_cancel = 0 WHERE user_id=? AND activity_id=? ` _, err = o.Raw(sql, item.UserId, item.ActivityId).Exec() } else { lastId, err = o.Insert(item) } itemLog := new(CygxActivityMeetingReminderLog) itemLog.UserId = item.UserId itemLog.ActivityId = item.ActivityId itemLog.CreateTime = time.Now() itemLog.Mobile = item.Mobile itemLog.Email = item.Email itemLog.CompanyId = item.CompanyId itemLog.CompanyName = item.CompanyName itemLog.Type = 1 lastId, err = o.Insert(itemLog) return } //获取用户报名数量 func GetActivityMeetingReminderCount(uid, activityId int) (count int, err error) { sqlCount := `SELECT COUNT(1) AS count FROM cygx_activity_meeting_reminder WHERE is_cancel=0 AND user_id=? AND activity_id=? ` o := orm.NewOrm() err = o.Raw(sqlCount, uid, activityId).QueryRow(&count) return } //取消报名 func CancelActivityMeetingReminder(item *CygxActivityMeetingReminder) (lastId int64, err error) { o := orm.NewOrm() o.Begin() defer func() { fmt.Println(err) if err == nil { o.Commit() } else { o.Rollback() } }() sql := `UPDATE cygx_activity_meeting_reminder SET is_cancel = 1 WHERE user_id=? AND activity_id=? ` _, err = o.Raw(sql, item.UserId, item.ActivityId).Exec() if err != nil { return } itemLog := new(CygxActivityMeetingReminderLog) itemLog.UserId = item.UserId itemLog.ActivityId = item.ActivityId itemLog.CreateTime = time.Now() itemLog.Mobile = item.Mobile itemLog.Email = item.Email itemLog.CompanyId = item.CompanyId itemLog.CompanyName = item.CompanyName itemLog.Type = 2 lastId, err = o.Insert(itemLog) return }