collection.go 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. package services
  2. import (
  3. "errors"
  4. "fmt"
  5. "hongze/hongze_cygx/models"
  6. "hongze/hongze_cygx/utils"
  7. "strconv"
  8. "strings"
  9. "time"
  10. )
  11. //精选看板
  12. // 用户提交研选调研需求,给王芳、对口销售、内容组全员发模板消息
  13. func SendCygxApplyCollectionTemplateMsg(user *models.WxUserItem, content string, articleId int) (err error) {
  14. var msg string
  15. msg = fmt.Sprint(user, articleId)
  16. defer func() {
  17. if err != nil {
  18. go utils.SendAlarmMsg("SendCygxBannerYxSurveyTemplateMsg Err"+msg, 2)
  19. }
  20. }()
  21. var mobiles []string
  22. //获取权益销售
  23. sellerItem, e := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  24. if e != nil {
  25. err = errors.New("GetAdminByRoleName, Err: " + e.Error())
  26. return
  27. }
  28. //内容组全员手机号
  29. configCode := utils.TPL_MSG_NEI_RONG_ZU
  30. cnf, e := models.GetConfigByCode(configCode)
  31. if e != nil {
  32. err = errors.New("GetConfigByCode, Err: " + e.Error() + configCode)
  33. return
  34. }
  35. //王芳手机号
  36. cnfWangFang, e := models.GetConfigByCode(utils.TPL_MSG)
  37. if e != nil {
  38. err = errors.New("GetConfigByCode, Err: " + e.Error() + configCode)
  39. return
  40. }
  41. mobiles = append(mobiles, sellerItem.Mobile)
  42. mobiles = append(mobiles, cnfWangFang.ConfigValue)
  43. listMobile := strings.Split(cnf.ConfigValue, ",")
  44. for _, v := range listMobile {
  45. mobiles = append(mobiles, v)
  46. }
  47. openIdList, e := models.GetWxOpenIdByMobileSliceList(mobiles)
  48. if e != nil {
  49. err = errors.New("GetWxOpenIdByMobileSliceList, Err: " + e.Error() + configCode)
  50. return
  51. }
  52. if len(openIdList) == 0 {
  53. return
  54. }
  55. openIdArr := make([]string, 0)
  56. for _, v := range openIdList {
  57. openIdArr = append(openIdArr, v.OpenId)
  58. }
  59. var keyword1 string
  60. var keyword2 string
  61. var keyword3 string
  62. var keyword4 string
  63. keyword1 = fmt.Sprint(user.RealName, "--", user.CompanyName, "(", sellerItem.RealName, ")")
  64. if user.Mobile == "" {
  65. user.Mobile = user.Email
  66. }
  67. keyword2 = user.Mobile
  68. keyword3 = time.Now().Format(utils.FormatDateTime)
  69. keyword4 = fmt.Sprint("精选看板:", content)
  70. var redirectUrl string
  71. if utils.RunMode == "release" {
  72. redirectUrl = utils.WX_MSG_PATH_APPLY_COLLECTION_DETAIL + strconv.Itoa(articleId)
  73. }
  74. sendInfo := new(SendWxTemplate)
  75. sendInfo.Keyword1 = keyword1
  76. sendInfo.Keyword2 = keyword2
  77. sendInfo.Keyword3 = keyword3
  78. sendInfo.Keyword4 = keyword4
  79. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ACTIVITY_ADD
  80. sendInfo.TemplateId = utils.WxMsgTemplateIdApplyXzs
  81. sendInfo.RedirectUrl = redirectUrl
  82. sendInfo.RedirectTarget = 3
  83. sendInfo.Resource = strconv.Itoa(articleId)
  84. sendInfo.OpenIdArr = openIdArr
  85. err = PublicSendTemplateMsg(sendInfo)
  86. return
  87. }