activity_wx_template_msg.go 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. package services
  2. import (
  3. "errors"
  4. "fmt"
  5. "hongze/hongze_clpt/models"
  6. "hongze/hongze_clpt/utils"
  7. "strconv"
  8. "time"
  9. )
  10. // SendResearchActivitiesTemplateMsg 线下调研活动报名给所属销售跟建会人员推送
  11. func SendResearchActivitiesTemplateMsg(user *models.WxUserItem, activityDetail *models.ActivityDetail, doStatus string) (err error) {
  12. //如果不是公司线下调研就返回
  13. if activityDetail.ActivityTypeId != 4 {
  14. return
  15. }
  16. defer func() {
  17. if err != nil {
  18. go utils.SendEmail("线下调研活动报名给所属销售跟建会人员推送失败Err"+time.Now().Format("2006-01-02 15:04:05"), ";Err:"+err.Error(), utils.EmailSendToUsers)
  19. go utils.SendAlarmMsg(fmt.Sprint("线下调研活动报名给所属销售跟建会人员推送失败Err:", err.Error(), "活动ID:", activityDetail.ActivityId, "手机号:", user.Mobile), 2)
  20. }
  21. }()
  22. var mobiles []string
  23. //获取销售信息
  24. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  25. if err != nil && err.Error() != utils.ErrNoRow() {
  26. return
  27. }
  28. if sellerItem != nil {
  29. mobiles = append(mobiles, sellerItem.Mobile)
  30. }
  31. //获取建会人员信息
  32. admin, err := models.GetSysAdminById(activityDetail.AdminId)
  33. if err != nil && err.Error() != utils.ErrNoRow() {
  34. return
  35. }
  36. if admin != nil {
  37. mobiles = append(mobiles, admin.Mobile)
  38. }
  39. var first string
  40. var keyword1 string
  41. var keyword2 string
  42. var keyword3 string
  43. var keyword4 string
  44. var remark string
  45. var redirectUrl string
  46. //first = "【" + activityDetail.ActivityName + "】有客户报名"
  47. keyword1 = user.RealName + "——" + user.CompanyName + "(" + sellerItem.RealName + ")"
  48. keyword2 = user.Mobile
  49. keyword3 = time.Now().Format(utils.FormatDateTime)
  50. keyword4 = doStatus + ":" + activityDetail.ActivityName
  51. //remark = "点击查看报告详情"
  52. openIdList, e := models.GetWxOpenIdByMobileSliceList(mobiles)
  53. if e != nil {
  54. err = errors.New("GetWxOpenIdByMobileList, Err: " + e.Error())
  55. return
  56. }
  57. openIdArr := make([]string, 0)
  58. for _, v := range openIdList {
  59. openIdArr = append(openIdArr, v.OpenId)
  60. }
  61. redirectUrl = utils.WX_MSG_PATH_ACTIVITY_DETAIL + strconv.Itoa(activityDetail.ActivityId)
  62. sendInfo := new(SendWxTemplate)
  63. sendInfo.First = first
  64. sendInfo.Keyword1 = keyword1
  65. sendInfo.Keyword2 = keyword2
  66. sendInfo.Keyword3 = keyword3
  67. sendInfo.Keyword4 = keyword4
  68. sendInfo.Remark = remark
  69. sendInfo.TemplateId = utils.WxMsgTemplateIdApplyXzs
  70. sendInfo.RedirectUrl = redirectUrl
  71. sendInfo.RedirectTarget = 3
  72. sendInfo.Resource = strconv.Itoa(activityDetail.ArticleId)
  73. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_COMMENT
  74. sendInfo.OpenIdArr = openIdArr
  75. err = PublicSendTemplateMsg(sendInfo)
  76. if err != nil {
  77. return
  78. }
  79. return
  80. }