activity_meeting_reminder.go 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. package models
  2. import (
  3. "fmt"
  4. "github.com/rdlucklib/rdluck_tools/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 := orm.NewOrm()
  32. o.Begin()
  33. defer func() {
  34. fmt.Println(err)
  35. if err == nil {
  36. o.Commit()
  37. } else {
  38. o.Rollback()
  39. }
  40. }()
  41. var count int
  42. var countMySchedule int
  43. sql := `SELECT COUNT(1) AS count FROM cygx_my_schedule WHERE user_id=? AND activity_id=? `
  44. err = o.Raw(sql, item.UserId, item.ActivityId).QueryRow(&countMySchedule)
  45. if err != nil {
  46. return
  47. }
  48. if countMySchedule == 0 {
  49. itemMy := new(CygxMySchedule)
  50. itemMy.UserId = item.UserId
  51. itemMy.ActivityId = item.ActivityId
  52. itemMy.CreateTime = time.Now()
  53. itemMy.Mobile = item.Mobile
  54. itemMy.Email = item.Email
  55. itemMy.CompanyId = item.CompanyId
  56. itemMy.CompanyName = item.CompanyName
  57. lastId, err = o.Insert(itemMy)
  58. if err != nil {
  59. return
  60. }
  61. }
  62. sql = `SELECT COUNT(1) AS count FROM cygx_activity_meeting_reminder WHERE user_id=? AND activity_id=? `
  63. err = o.Raw(sql, item.UserId, item.ActivityId).QueryRow(&count)
  64. if err != nil {
  65. return
  66. }
  67. if count > 0 {
  68. sql := `UPDATE cygx_activity_meeting_reminder SET is_cancel = 0 WHERE user_id=? AND activity_id=? `
  69. _, err = o.Raw(sql, item.UserId, item.ActivityId).Exec()
  70. } else {
  71. lastId, err = o.Insert(item)
  72. }
  73. itemLog := new(CygxActivityMeetingReminderLog)
  74. itemLog.UserId = item.UserId
  75. itemLog.ActivityId = item.ActivityId
  76. itemLog.CreateTime = time.Now()
  77. itemLog.Mobile = item.Mobile
  78. itemLog.Email = item.Email
  79. itemLog.CompanyId = item.CompanyId
  80. itemLog.CompanyName = item.CompanyName
  81. itemLog.Type = 1
  82. lastId, err = o.Insert(itemLog)
  83. return
  84. }
  85. //获取用户报名数量
  86. func GetActivityMeetingReminderCount(uid, activityId int) (count int, err error) {
  87. sqlCount := `SELECT COUNT(1) AS count FROM cygx_activity_meeting_reminder WHERE is_cancel=0 AND user_id=? AND activity_id=? `
  88. o := orm.NewOrm()
  89. err = o.Raw(sqlCount, uid, activityId).QueryRow(&count)
  90. return
  91. }
  92. //取消会议提醒
  93. func CancelActivityMeetingReminder(item *CygxActivityMeetingReminder) (lastId int64, err error) {
  94. o := orm.NewOrm()
  95. o.Begin()
  96. defer func() {
  97. fmt.Println(err)
  98. if err == nil {
  99. o.Commit()
  100. } else {
  101. o.Rollback()
  102. }
  103. }()
  104. //判断是否删除我的日程
  105. var count int
  106. sql := `SELECT COUNT(1) AS count FROM cygx_activity_signup WHERE is_cancel = 0 AND user_id=? AND activity_id=? `
  107. err = o.Raw(sql, item.UserId, item.ActivityId).QueryRow(&count)
  108. if err != nil {
  109. return
  110. }
  111. if count == 0 {
  112. sql = `DELETE FROM cygx_my_schedule WHERE user_id=? AND activity_id=? `
  113. _, err = o.Raw(sql, item.UserId, item.ActivityId).Exec()
  114. if err != nil {
  115. return
  116. }
  117. }
  118. sql = `DELETE FROM cygx_activity_meeting_reminder WHERE user_id=? AND activity_id=? `
  119. _, err = o.Raw(sql, item.UserId, item.ActivityId).Exec()
  120. if err != nil {
  121. return
  122. }
  123. itemLog := new(CygxActivityMeetingReminderLog)
  124. itemLog.UserId = item.UserId
  125. itemLog.ActivityId = item.ActivityId
  126. itemLog.CreateTime = time.Now()
  127. itemLog.Mobile = item.Mobile
  128. itemLog.Email = item.Email
  129. itemLog.CompanyId = item.CompanyId
  130. itemLog.CompanyName = item.CompanyName
  131. itemLog.Type = 2
  132. lastId, err = o.Insert(itemLog)
  133. return
  134. }
  135. //获取某一用户的日程数量
  136. func GetUserActivityMeetingReminderCount(uid int) (count int, err error) {
  137. sqlCount := `SELECT COUNT(1) AS count FROM cygx_activity_meeting_reminder_log WHERE user_id=? `
  138. o := orm.NewOrm()
  139. err = o.Raw(sqlCount, uid).QueryRow(&count)
  140. return
  141. }