activity_meeting_reminder.go 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. package cygx
  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. Source 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. type AddMeetingReminderReq struct {
  31. List []*AddUserList
  32. ActivityIds string `description:"活动ID,多个用,隔开"`
  33. }
  34. type AddUserList struct {
  35. UserId int `description:"用户ID"`
  36. IsAppointment int `description:"是否预约纪要,1:是,0:否"`
  37. SignupType int `description:"报名方式,1预约外呼,2自主拨入,3我要报名"`
  38. }
  39. // 获取用户报名数量
  40. func GetActivityMeetingReminderCount(uid, activityId int) (count int, err error) {
  41. sqlCount := `SELECT COUNT(1) AS count FROM cygx_activity_meeting_reminder WHERE is_cancel=0 AND user_id=? AND activity_id=? `
  42. o := orm.NewOrm()
  43. err = o.Raw(sqlCount, uid, activityId).QueryRow(&count)
  44. return
  45. }
  46. // 取消会议提醒
  47. func CancelActivityMeetingReminder(item *CygxActivityMeetingReminder) (lastId int64, err error) {
  48. o, err := orm.NewOrm().Begin()
  49. if err != nil {
  50. return
  51. }
  52. defer func() {
  53. fmt.Println(err)
  54. if err == nil {
  55. o.Commit()
  56. } else {
  57. o.Rollback()
  58. }
  59. }()
  60. //判断是否删除我的日程
  61. var countSignup int
  62. var countAppointment int
  63. sql := `SELECT COUNT(1) AS count FROM cygx_activity_signup WHERE is_cancel = 0 AND user_id=? AND activity_id=? `
  64. err = o.Raw(sql, item.UserId, item.ActivityId).QueryRow(&countSignup)
  65. sql = `SELECT COUNT(1) AS count FROM cygx_activity_appointment WHERE user_id=? AND activity_id=? `
  66. err = o.Raw(sql, item.UserId, item.ActivityId).QueryRow(&countAppointment)
  67. if err != nil {
  68. return
  69. }
  70. if countSignup == 0 && countAppointment == 0 {
  71. sql = `DELETE FROM cygx_my_schedule WHERE user_id=? AND activity_id=? `
  72. _, err = o.Raw(sql, item.UserId, item.ActivityId).Exec()
  73. if err != nil {
  74. return
  75. }
  76. }
  77. sql = `DELETE FROM cygx_activity_meeting_reminder WHERE user_id=? AND activity_id=? `
  78. _, err = o.Raw(sql, item.UserId, item.ActivityId).Exec()
  79. return
  80. }
  81. // 会议提醒的人数列表
  82. func GetCygxActivityMeetingReminderList(activityId int, sqlStr string) (item []*CygxAppointmentList, err error) {
  83. o := orm.NewOrm()
  84. sql := `SELECT s.id,s.activity_id,s.user_id,s.create_time,s.mobile,s.company_id ,u.real_name,c.company_name,a.activity_time,
  85. (SELECT p.seller_name from company_product as p WHERE p.company_id = u.company_id AND p.product_id = 2 ) AS seller_name,
  86. GROUP_CONCAT( DISTINCT p.seller_name SEPARATOR '/' ) AS pseller_name
  87. FROM
  88. cygx_activity_meeting_reminder AS s
  89. INNER JOIN wx_user AS u ON u.user_id = s.user_id
  90. LEFT JOIN cygx_activity AS a ON a.activity_id = s.activity_id
  91. LEFT JOIN company_product AS p ON p.company_id = u.company_id
  92. LEFT JOIN company AS c ON c.company_id = u.company_id
  93. WHERE a.activity_id = ? ` + sqlStr + ` GROUP BY s.user_id ORDER BY s.create_time DESC `
  94. _, err = o.Raw(sql, activityId).QueryRows(&item)
  95. return
  96. }
  97. // 会议提醒的人数数量
  98. func GetCygxActivityMeetingReminderCount(activityId int, sqlStr string) (count int, err error) {
  99. o := orm.NewOrm()
  100. sql := `SELECT COUNT(*) FROM
  101. cygx_activity_meeting_reminder AS s
  102. INNER JOIN wx_user AS u ON u.user_id = s.user_id
  103. LEFT JOIN cygx_activity AS a ON a.activity_id = s.activity_id
  104. LEFT JOIN company_product AS p ON p.company_id = u.company_id
  105. WHERE
  106. s.activity_id = ? ` + sqlStr + `
  107. GROUP BY s.user_id)`
  108. sql = `SELECT COUNT(*) as count FROM (` + sql + ` a`
  109. err = o.Raw(sql, activityId).QueryRow(&count)
  110. return
  111. }
  112. // 通过ID获取会议提醒详情
  113. func GetCygxActivityMeetingReminderInfoById(id int) (item *CygxActivityMeetingReminder, err error) {
  114. o := orm.NewOrm()
  115. sql := `SELECT * FROM cygx_activity_meeting_reminder WHERE id=?`
  116. err = o.Raw(sql, id).QueryRow(&item)
  117. return
  118. }
  119. // 添加会议提醒
  120. func AddActivityMeetingReminderUser(items []*CygxActivityAppointment, itemsReminder []*CygxActivityMeetingReminder) (err error) {
  121. o := orm.NewOrm()
  122. to, err := o.Begin()
  123. if err != nil {
  124. return
  125. }
  126. defer func() {
  127. if err != nil {
  128. _ = to.Rollback()
  129. } else {
  130. _ = to.Commit()
  131. }
  132. }()
  133. //添加预约纪要部分
  134. if len(items) > 0 {
  135. for _, item := range items {
  136. var count int
  137. sql := `SELECT COUNT(1) AS count FROM cygx_activity_appointment WHERE user_id=? AND activity_id=? `
  138. err = to.Raw(sql, item.UserId, item.ActivityId).QueryRow(&count)
  139. if err != nil {
  140. return
  141. }
  142. if count == 0 {
  143. _, err = to.Insert(item)
  144. if err != nil {
  145. return
  146. }
  147. }
  148. }
  149. }
  150. //添加会议提醒
  151. for _, item := range itemsReminder {
  152. var count int
  153. sql := `SELECT COUNT(1) AS count FROM cygx_my_schedule WHERE user_id=? AND activity_id=? `
  154. err = to.Raw(sql, item.UserId, item.ActivityId).QueryRow(&count)
  155. if err != nil {
  156. return
  157. }
  158. if count == 0 {
  159. itemMy := new(CygxMySchedule)
  160. itemMy.UserId = item.UserId
  161. itemMy.ActivityId = item.ActivityId
  162. itemMy.CreateTime = time.Now()
  163. itemMy.Mobile = item.Mobile
  164. itemMy.Email = item.Email
  165. itemMy.CompanyId = item.CompanyId
  166. itemMy.CompanyName = item.CompanyName
  167. _, err = to.Insert(itemMy)
  168. if err != nil {
  169. return
  170. }
  171. }
  172. sql = `SELECT COUNT(1) AS count FROM cygx_activity_appointment WHERE user_id=? AND activity_id=? `
  173. err = to.Raw(sql, item.UserId, item.ActivityId).QueryRow(&count)
  174. if err != nil {
  175. return
  176. }
  177. if count == 0 {
  178. _, err = to.Insert(item)
  179. if err != nil {
  180. return
  181. }
  182. }
  183. }
  184. return
  185. }