activity.go 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. package services
  2. import (
  3. "context"
  4. "fmt"
  5. "hongze/hongze_task/models"
  6. "hongze/hongze_task/models/yb"
  7. "hongze/hongze_task/services/alarm_msg"
  8. "hongze/hongze_task/utils"
  9. "time"
  10. )
  11. // YbTelRemind 研报电话会提醒
  12. func YbTelRemind(cont context.Context) (err error) {
  13. defer func() {
  14. if err != nil {
  15. //fmt.Println(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "发送消息至同花顺失败 ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  16. //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "发送电话会提醒失败 ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  17. go alarm_msg.SendAlarmMsg("发送电话会提醒失败 ErrMsg:"+err.Error(), 3)
  18. }
  19. }()
  20. condition := ""
  21. pars := make([]interface{}, 0)
  22. startTime := time.Now().Add(time.Second * 60 * 15).Format(utils.FormatDateTime) //15分钟后就要开始的会议
  23. condition += ` and publish_status = 1 and is_send_wx_msg = 0 and is_delete = 0 and start_time <= ? and end_time >= now() `
  24. pars = append(pars, startTime)
  25. condition += ` and first_activity_type_id in (1,3) `
  26. _, list, err := yb.GetList(condition, pars, 0, 1000)
  27. for _, activityInfo := range list {
  28. activityInfo.IsSendWxMsg = 1
  29. activityInfo.Update([]string{"IsSendWxMsg"})
  30. go sendWxMsg(activityInfo, "会议提醒")
  31. }
  32. return
  33. }
  34. // YbSalonRemind 研报沙龙提醒
  35. func YbSalonRemind(cont context.Context) (err error) {
  36. defer func() {
  37. if err != nil {
  38. //fmt.Println(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "发送消息至同花顺失败 ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  39. //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "发送电话会提醒失败 ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  40. go alarm_msg.SendAlarmMsg("发送研报沙龙提醒失败 ErrMsg:"+err.Error(), 3)
  41. }
  42. }()
  43. condition := ""
  44. pars := make([]interface{}, 0)
  45. startTime := time.Now().Add(time.Second * 60 * 60).Format(utils.FormatDateTime) //1小时后就要开始的沙龙
  46. condition += ` and publish_status = 1 and is_send_salon_wx_msg = 0 and is_delete = 0 and start_time <= ? and end_time >= now() `
  47. pars = append(pars, startTime)
  48. condition += ` and first_activity_type_id =3 `
  49. _, list, err := yb.GetList(condition, pars, 0, 1000)
  50. for _, activityInfo := range list {
  51. activityInfo.IsSendSalonWxMsg = 1
  52. activityInfo.Update([]string{"IsSendSalonWxMsg"})
  53. go sendWxMsg(activityInfo, "沙龙提醒")
  54. }
  55. return
  56. }
  57. func sendWxMsg(activityInfo *yb.Activity, remindType string) (err error) {
  58. defer func() {
  59. if err != nil {
  60. fmt.Println(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "发送电话会提醒失败 ErrMsg:"+err.Error())
  61. utils.FileLog.Info(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "发送电话会提醒失败 ErrMsg:"+err.Error())
  62. //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "发送电话会提醒失败 ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  63. }
  64. }()
  65. keyword4 := "- -"
  66. //您有一场【橡胶双周报】将在15分钟后开始
  67. timeStr := ``
  68. userIdList := make([]string, 0) //提醒用户列表
  69. if remindType == "会议提醒" {
  70. timeStr = `15分钟`
  71. list, tmpErr := yb.GetAllActivityRemindListByActivityId(activityInfo.ActivityId)
  72. if tmpErr != nil {
  73. err = tmpErr
  74. return
  75. }
  76. for _, v := range list {
  77. userIdList = append(userIdList, fmt.Sprint(v.UserId))
  78. }
  79. } else {
  80. timeStr = `1小时`
  81. list, tmpErr := yb.GetAllActivityRegisterListByActivityId(activityInfo.ActivityId)
  82. if tmpErr != nil {
  83. err = tmpErr
  84. return
  85. }
  86. for _, v := range list {
  87. userIdList = append(userIdList, fmt.Sprint(v.UserId))
  88. }
  89. keyword4 = activityInfo.Address
  90. }
  91. if len(userIdList) <= 0 {
  92. return
  93. }
  94. first := `您有一场【` + activityInfo.ActivityTypeName + `】将在` + timeStr + `后开始`
  95. keyword1 := activityInfo.ActivityTypeName + "-" + activityInfo.ActivityName
  96. keyword2 := "将在" + timeStr + "后开始"
  97. //keyword3 := `2021-10-18 16:30-17:00 星期一`
  98. keyword3 := formatActivityTimeStr(activityInfo.StartTime, activityInfo.EndTime)
  99. remark := `点击查看活动详情`
  100. //获取所有用户的openid列表
  101. openidList, err := models.GetUserOpenidListByUserIds(userIdList)
  102. if err != nil {
  103. return
  104. }
  105. //小程序跳转地址
  106. wxAppPath := `pages-activity/detail?id=` + fmt.Sprint(activityInfo.ActivityId)
  107. err = SendWxMsgWithActivityAppointmentRemind(first, keyword1, keyword2, keyword3, keyword4, remark, wxAppPath, openidList)
  108. return
  109. }
  110. // formatActivityTimeStr 格式化活动的开始结束时间
  111. func formatActivityTimeStr(startTime, endTime time.Time) string {
  112. startStr := startTime.Format("2006-01-02 15:04")
  113. endStr := endTime.Format("15:04")
  114. weekStr := ``
  115. weekInt := startTime.Weekday()
  116. switch weekInt {
  117. case 0:
  118. weekStr = `星期日`
  119. case 1:
  120. weekStr = `星期一`
  121. case 2:
  122. weekStr = `星期二`
  123. case 3:
  124. weekStr = `星期三`
  125. case 4:
  126. weekStr = `星期四`
  127. case 5:
  128. weekStr = `星期五`
  129. case 6:
  130. weekStr = `星期六`
  131. }
  132. return startStr + `-` + endStr + ` ` + weekStr
  133. }