activity_meeting_reminder.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. package models
  2. import (
  3. "fmt"
  4. "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. sql := `SELECT COUNT(1) AS count FROM cygx_activity_meeting_reminder WHERE user_id=? AND activity_id=? `
  43. err = o.Raw(sql, item.UserId, item.ActivityId).QueryRow(&count)
  44. if err != nil {
  45. return
  46. }
  47. if count > 0 {
  48. sql := `UPDATE cygx_activity_meeting_reminder SET is_cancel = 0 WHERE user_id=? AND activity_id=? `
  49. _, err = o.Raw(sql, item.UserId, item.ActivityId).Exec()
  50. } else {
  51. lastId, err = o.Insert(item)
  52. }
  53. itemLog := new(CygxActivityMeetingReminderLog)
  54. itemLog.UserId = item.UserId
  55. itemLog.ActivityId = item.ActivityId
  56. itemLog.CreateTime = time.Now()
  57. itemLog.Mobile = item.Mobile
  58. itemLog.Email = item.Email
  59. itemLog.CompanyId = item.CompanyId
  60. itemLog.CompanyName = item.CompanyName
  61. itemLog.Type = 1
  62. lastId, err = o.Insert(itemLog)
  63. return
  64. }
  65. //获取用户报名数量
  66. func GetActivityMeetingReminderCount(uid, activityId int) (count int, err error) {
  67. sqlCount := `SELECT COUNT(1) AS count FROM cygx_activity_meeting_reminder WHERE is_cancel=0 AND user_id=? AND activity_id=? `
  68. o := orm.NewOrm()
  69. err = o.Raw(sqlCount, uid, activityId).QueryRow(&count)
  70. return
  71. }
  72. //取消报名
  73. func CancelActivityMeetingReminder(item *CygxActivityMeetingReminder) (lastId int64, err error) {
  74. o := orm.NewOrm()
  75. o.Begin()
  76. defer func() {
  77. fmt.Println(err)
  78. if err == nil {
  79. o.Commit()
  80. } else {
  81. o.Rollback()
  82. }
  83. }()
  84. sql := `UPDATE cygx_activity_meeting_reminder SET is_cancel = 1 WHERE user_id=? AND activity_id=? `
  85. _, err = o.Raw(sql, item.UserId, item.ActivityId).Exec()
  86. if err != nil {
  87. return
  88. }
  89. itemLog := new(CygxActivityMeetingReminderLog)
  90. itemLog.UserId = item.UserId
  91. itemLog.ActivityId = item.ActivityId
  92. itemLog.CreateTime = time.Now()
  93. itemLog.Mobile = item.Mobile
  94. itemLog.Email = item.Email
  95. itemLog.CompanyId = item.CompanyId
  96. itemLog.CompanyName = item.CompanyName
  97. itemLog.Type = 2
  98. lastId, err = o.Insert(itemLog)
  99. return
  100. }