123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- package models
- import (
- "fmt"
- "github.com/beego/beego/v2/client/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:"公司名称"`
- RegisterPlatform int `description:"来源 1小程序,2:网页"`
- }
- //记录日志
- 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, err := orm.NewOrm().Begin()
- if err != nil {
- return
- }
- defer func() {
- fmt.Println(err)
- if err == nil {
- o.Commit()
- } else {
- o.Rollback()
- }
- }()
- var count int
- var countMySchedule int
- sql := `SELECT COUNT(1) AS count FROM cygx_my_schedule WHERE user_id=? AND activity_id=? `
- err = o.Raw(sql, item.UserId, item.ActivityId).QueryRow(&countMySchedule)
- if err != nil {
- return
- }
- if countMySchedule == 0 {
- itemMy := new(CygxMySchedule)
- itemMy.UserId = item.UserId
- itemMy.ActivityId = item.ActivityId
- itemMy.CreateTime = time.Now()
- itemMy.Mobile = item.Mobile
- itemMy.Email = item.Email
- itemMy.CompanyId = item.CompanyId
- itemMy.CompanyName = item.CompanyName
- lastId, err = o.Insert(itemMy)
- if err != nil {
- return
- }
- }
- 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, err := orm.NewOrm().Begin()
- if err != nil {
- return
- }
- defer func() {
- fmt.Println(err)
- if err == nil {
- o.Commit()
- } else {
- o.Rollback()
- }
- }()
- //判断是否删除我的日程
- var countSignup int
- var countAppointment int
- sql := `SELECT COUNT(1) AS count FROM cygx_activity_signup WHERE is_cancel = 0 AND user_id=? AND activity_id=? `
- err = o.Raw(sql, item.UserId, item.ActivityId).QueryRow(&countSignup)
- sql = `SELECT COUNT(1) AS count FROM cygx_activity_appointment WHERE user_id=? AND activity_id=? `
- err = o.Raw(sql, item.UserId, item.ActivityId).QueryRow(&countAppointment)
- if err != nil {
- return
- }
- if countSignup == 0 && countAppointment == 0 {
- sql = `DELETE FROM cygx_my_schedule WHERE user_id=? AND activity_id=? `
- _, err = o.Raw(sql, item.UserId, item.ActivityId).Exec()
- if err != nil {
- return
- }
- }
- sql = `DELETE FROM cygx_activity_meeting_reminder 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
- }
- //获取某一用户的日程数量
- func GetUserActivityMeetingReminderCount(uid int) (count int, err error) {
- sqlCount := `SELECT COUNT(1) AS count FROM cygx_activity_meeting_reminder_log WHERE user_id=? `
- o := orm.NewOrm()
- err = o.Raw(sqlCount, uid).QueryRow(&count)
- return
- }
- //GetCygxReminderListByUser 获取设置会议提醒的人
- func GetCygxReminderListByUser(condition string, pars []interface{}) (item []*CygxActivityMeetingReminder, err error) {
- o := orm.NewOrm()
- sql := `SELECT *
- FROM
- cygx_activity_meeting_reminder
- WHERE 1 = 1 ` + condition
- _, err = o.Raw(sql, pars).QueryRows(&item)
- return
- }
|