activity_meeting_reminder.go 5.1 KB

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