minutes_summary.go 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. package services
  2. import (
  3. "errors"
  4. "fmt"
  5. "hongze/hongze_clpt/models"
  6. "hongze/hongze_clpt/utils"
  7. "strconv"
  8. "strings"
  9. "time"
  10. )
  11. // 上周纪要汇总用户阅读,给销售发消息提醒
  12. func MinutesSummaryHistoryUserRmind(user *models.WxUserItem, articleId int) (err error) {
  13. //30秒内阅读同一篇报告不做重复推送
  14. key := "CYGX_" + utils.CYGX_OBJ_MINUTESSUMMARY + "_READ" + strconv.Itoa(articleId) + "_" + strconv.Itoa(user.UserId)
  15. if utils.Rc.IsExist(key) {
  16. return
  17. }
  18. utils.Rc.Put(key, 1, 30*time.Second)
  19. defer func() {
  20. if err != nil {
  21. go utils.SendAlarmMsg(fmt.Sprint("上周纪要汇总用户阅读,给销售发消息提醒,模板消息推送 ,MinutesSummaryHistoryUserRmind"+err.Error(), "userId:", user.UserId, "articleId:", articleId), 2)
  22. }
  23. }()
  24. countUser, err := models.GetUserRemind(user.UserId)
  25. if err != nil {
  26. return err
  27. }
  28. if countUser == 0 {
  29. return err
  30. }
  31. var first string
  32. var keyword1 string
  33. var keyword2 string
  34. var keyword3 string
  35. var keyword4 string
  36. var remark string
  37. //获取销售手机号
  38. sellerItemQy, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  39. if err != nil && err.Error() != utils.ErrNoRow() {
  40. return err
  41. }
  42. if sellerItemQy != nil {
  43. sllerAndShareMobileArr, e := GetCompanySellerAndShareMobileByRai(user.CompanyId) //获取所属销售以及对应销售的手机号
  44. if e != nil {
  45. err = errors.New("GetCompanySellerAndShareMobileByRai, Err: " + e.Error())
  46. return
  47. }
  48. sllerAndShareMobiles := strings.Join(sllerAndShareMobileArr, ",")
  49. openIdList, e := models.GetWxOpenIdByMobileList(sllerAndShareMobiles)
  50. if e != nil {
  51. err = errors.New("GetSellerByAdminId, Err: " + e.Error())
  52. return
  53. }
  54. if len(openIdList) == 0 {
  55. return
  56. }
  57. detail, e := models.GetCygxMinutesSummaryInfoById(articleId)
  58. if e != nil {
  59. err = errors.New("GetCygxProductInteriorDetail, Err: " + e.Error())
  60. return
  61. }
  62. if detail == nil {
  63. return
  64. }
  65. keyword1 = detail.Title
  66. keyword2 = fmt.Sprint("互动:阅读报告,", user.RealName, "--", user.CompanyName)
  67. openIdArr := make([]string, 0)
  68. for _, v := range openIdList {
  69. openIdArr = append(openIdArr, v.OpenId)
  70. }
  71. redirectUrl := utils.WX_MSG_PATH_LAST_WEEK_DETAIL + strconv.Itoa(articleId)
  72. sendInfo := new(SendWxTemplate)
  73. sendInfo.First = first
  74. sendInfo.Keyword1 = keyword1
  75. sendInfo.Keyword2 = keyword2
  76. sendInfo.Keyword3 = keyword3
  77. sendInfo.Keyword4 = keyword4
  78. sendInfo.Remark = remark
  79. sendInfo.TemplateId = utils.WxMsgTemplateIdArticleUserRemind
  80. sendInfo.RedirectUrl = redirectUrl
  81. sendInfo.RedirectTarget = 3
  82. sendInfo.Resource = strconv.Itoa(articleId)
  83. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ARTICLE_ADD
  84. sendInfo.OpenIdArr = openIdArr
  85. e = PublicSendTemplateMsg(sendInfo)
  86. if e != nil {
  87. err = errors.New("PublicSendTemplateMsg, Err: " + e.Error())
  88. return
  89. }
  90. }
  91. return
  92. }