activity_meeting_reminder.go 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. package models
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "time"
  6. )
  7. type CygxActivityMeetingReminder struct {
  8. Id int `orm:"column(id);pk"`
  9. ActivityId int `description:"活动ID"`
  10. UserId int `description:"用户ID"`
  11. CreateTime time.Time `description:"创建时间"`
  12. Mobile string `description:"手机号"`
  13. Email string `description:"邮箱"`
  14. CompanyId int `description:"公司id"`
  15. CompanyName string `description:"公司名称"`
  16. }
  17. //记录日志
  18. type CygxActivityMeetingReminderLog struct {
  19. Id int `orm:"column(id);pk"`
  20. ActivityId int `description:"活动ID"`
  21. UserId int `description:"用户ID"`
  22. CreateTime time.Time `description:"创建时间"`
  23. Mobile string `description:"手机号"`
  24. Email string `description:"邮箱"`
  25. CompanyId int `description:"公司id"`
  26. CompanyName string `description:"公司名称"`
  27. Type int `description:"操作方式,1报名,2取消报名"`
  28. }
  29. //添加会议提醒信息
  30. func AddActivityMeetingReminder(item *CygxActivityMeetingReminder) (lastId int64, err error) {
  31. o, err := orm.NewOrm().Begin()
  32. if err != nil {
  33. return
  34. }
  35. defer func() {
  36. fmt.Println(err)
  37. if err == nil {
  38. o.Commit()
  39. } else {
  40. o.Rollback()
  41. }
  42. }()
  43. var count int
  44. var countMySchedule int
  45. sql := `SELECT COUNT(1) AS count FROM cygx_my_schedule WHERE user_id=? AND activity_id=? `
  46. err = o.Raw(sql, item.UserId, item.ActivityId).QueryRow(&countMySchedule)
  47. if err != nil {
  48. return
  49. }
  50. if countMySchedule == 0 {
  51. itemMy := new(CygxMySchedule)
  52. itemMy.UserId = item.UserId
  53. itemMy.ActivityId = item.ActivityId
  54. itemMy.CreateTime = time.Now()
  55. itemMy.Mobile = item.Mobile
  56. itemMy.Email = item.Email
  57. itemMy.CompanyId = item.CompanyId
  58. itemMy.CompanyName = item.CompanyName
  59. lastId, err = o.Insert(itemMy)
  60. if err != nil {
  61. return
  62. }
  63. }
  64. sql = `SELECT COUNT(1) AS count FROM cygx_activity_meeting_reminder WHERE user_id=? AND activity_id=? `
  65. err = o.Raw(sql, item.UserId, item.ActivityId).QueryRow(&count)
  66. if err != nil {
  67. return
  68. }
  69. if count > 0 {
  70. sql := `UPDATE cygx_activity_meeting_reminder SET is_cancel = 0 WHERE user_id=? AND activity_id=? `
  71. _, err = o.Raw(sql, item.UserId, item.ActivityId).Exec()
  72. } else {
  73. lastId, err = o.Insert(item)
  74. }
  75. itemLog := new(CygxActivityMeetingReminderLog)
  76. itemLog.UserId = item.UserId
  77. itemLog.ActivityId = item.ActivityId
  78. itemLog.CreateTime = time.Now()
  79. itemLog.Mobile = item.Mobile
  80. itemLog.Email = item.Email
  81. itemLog.CompanyId = item.CompanyId
  82. itemLog.CompanyName = item.CompanyName
  83. itemLog.Type = 1
  84. lastId, err = o.Insert(itemLog)
  85. return
  86. }
  87. //获取用户报名数量
  88. func GetActivityMeetingReminderCount(uid, activityId int) (count int, err error) {
  89. sqlCount := `SELECT COUNT(1) AS count FROM cygx_activity_meeting_reminder WHERE is_cancel=0 AND user_id=? AND activity_id=? `
  90. o := orm.NewOrm()
  91. err = o.Raw(sqlCount, uid, activityId).QueryRow(&count)
  92. return
  93. }
  94. //取消会议提醒
  95. func CancelActivityMeetingReminder(item *CygxActivityMeetingReminder) (lastId int64, err error) {
  96. o, err := orm.NewOrm().Begin()
  97. if err != nil {
  98. return
  99. }
  100. defer func() {
  101. fmt.Println(err)
  102. if err == nil {
  103. o.Commit()
  104. } else {
  105. o.Rollback()
  106. }
  107. }()
  108. //判断是否删除我的日程
  109. var countSignup int
  110. var countAppointment int
  111. sql := `SELECT COUNT(1) AS count FROM cygx_activity_signup WHERE is_cancel = 0 AND user_id=? AND activity_id=? `
  112. err = o.Raw(sql, item.UserId, item.ActivityId).QueryRow(&countSignup)
  113. sql = `SELECT COUNT(1) AS count FROM cygx_activity_appointment WHERE user_id=? AND activity_id=? `
  114. err = o.Raw(sql, item.UserId, item.ActivityId).QueryRow(&countAppointment)
  115. if err != nil {
  116. return
  117. }
  118. if countSignup == 0 && countAppointment == 0 {
  119. sql = `DELETE FROM cygx_my_schedule WHERE user_id=? AND activity_id=? `
  120. _, err = o.Raw(sql, item.UserId, item.ActivityId).Exec()
  121. if err != nil {
  122. return
  123. }
  124. }
  125. sql = `DELETE FROM cygx_activity_meeting_reminder WHERE user_id=? AND activity_id=? `
  126. _, err = o.Raw(sql, item.UserId, item.ActivityId).Exec()
  127. if err != nil {
  128. return
  129. }
  130. itemLog := new(CygxActivityMeetingReminderLog)
  131. itemLog.UserId = item.UserId
  132. itemLog.ActivityId = item.ActivityId
  133. itemLog.CreateTime = time.Now()
  134. itemLog.Mobile = item.Mobile
  135. itemLog.Email = item.Email
  136. itemLog.CompanyId = item.CompanyId
  137. itemLog.CompanyName = item.CompanyName
  138. itemLog.Type = 2
  139. lastId, err = o.Insert(itemLog)
  140. return
  141. }
  142. //获取某一用户的日程数量
  143. func GetUserActivityMeetingReminderCount(uid int) (count int, err error) {
  144. sqlCount := `SELECT COUNT(1) AS count FROM cygx_activity_meeting_reminder_log WHERE user_id=? `
  145. o := orm.NewOrm()
  146. err = o.Raw(sqlCount, uid).QueryRow(&count)
  147. return
  148. }
  149. //GetCygxReminderListByUser 获取设置会议提醒的人
  150. func GetCygxReminderListByUser(condition string, pars []interface{}) (item []*CygxActivityMeetingReminder, err error) {
  151. o := orm.NewOrm()
  152. sql := `SELECT *
  153. FROM
  154. cygx_activity_meeting_reminder
  155. WHERE 1 = 1 ` + condition
  156. _, err = o.Raw(sql, pars).QueryRows(&item)
  157. return
  158. }