banner_yx_survey.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 AddCygxBannerYxSurvey(user *models.WxUserItem, content string) (err error) {
  13. defer func() {
  14. if err != nil {
  15. fmt.Println(err)
  16. go utils.SendAlarmMsg("约访专家的请求失败"+err.Error(), 2)
  17. }
  18. }()
  19. item := new(models.CygxBannerYxSurvey)
  20. item.UserId = user.UserId
  21. item.CreateTime = time.Now()
  22. item.ModifyTime = time.Now()
  23. item.Mobile = user.Mobile
  24. item.Email = user.Email
  25. item.CompanyId = user.CompanyId
  26. item.CompanyName = user.CompanyName
  27. item.Content = content
  28. item.RegisterPlatform = utils.REGISTER_PLATFORM
  29. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  30. if err != nil && err.Error() != utils.ErrNoRow() {
  31. return
  32. }
  33. item.RealName = user.RealName
  34. if sellerItem != nil {
  35. item.SellerName = sellerItem.RealName
  36. }
  37. _, e := models.AddCygxBannerYxSurvey(item)
  38. if e != nil {
  39. err = errors.New("AddCygxBannerYxSurvey, Err: " + e.Error())
  40. return
  41. }
  42. return
  43. }
  44. // 用户提交研选调研需求,给汪洋、对口销售、内容组全员发模板消息
  45. func SendCygxBannerYxSurveyTemplateMsg(user *models.WxUserItem, content string, articleId int) (err error) {
  46. var msg string
  47. msg = fmt.Sprint(user, articleId)
  48. defer func() {
  49. if err != nil {
  50. go utils.SendAlarmMsg("SendCygxBannerYxSurveyTemplateMsg Err"+msg, 2)
  51. }
  52. }()
  53. var mobiles []string
  54. //获取权益销售
  55. sellerItem, e := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  56. if e != nil {
  57. err = errors.New("GetAdminByRoleName, Err: " + e.Error())
  58. return
  59. }
  60. //内容组全员手机号
  61. configCode := utils.TPL_MSG_NEI_RONG_ZU
  62. cnf, e := models.GetConfigByCode(configCode)
  63. if e != nil {
  64. err = errors.New("GetConfigByCode, Err: " + e.Error() + configCode)
  65. return
  66. }
  67. //汪洋手机号
  68. cnfWangYang, e := models.GetConfigByCode(utils.TPL_MSG_WANG_YANG)
  69. if e != nil {
  70. err = errors.New("GetConfigByCode, Err: " + e.Error() + configCode)
  71. return
  72. }
  73. mobiles = append(mobiles, sellerItem.Mobile)
  74. mobiles = append(mobiles, cnfWangYang.ConfigValue)
  75. listMobile := strings.Split(cnf.ConfigValue, ",")
  76. for _, v := range listMobile {
  77. mobiles = append(mobiles, v)
  78. }
  79. mobiles = append(mobiles, utils.MobileShenTao, utils.MobileZhangChuanXin, utils.MobileWangFang) // 添加沈涛、张传星、王芳手机号
  80. openIdList, e := models.GetWxOpenIdByMobileSliceList(mobiles)
  81. if e != nil {
  82. err = errors.New("GetWxOpenIdByMobileSliceList, Err: " + e.Error() + configCode)
  83. return
  84. }
  85. if len(openIdList) == 0 {
  86. return
  87. }
  88. openIdArr := make([]string, 0)
  89. for _, v := range openIdList {
  90. openIdArr = append(openIdArr, v.OpenId)
  91. }
  92. var keyword1 string
  93. var keyword2 string
  94. var keyword3 string
  95. var keyword4 string
  96. keyword1 = fmt.Sprint(user.RealName, "--", user.CompanyName, "(", sellerItem.RealName, ")")
  97. if user.Mobile == "" {
  98. user.Mobile = user.Email
  99. }
  100. keyword2 = user.Mobile
  101. keyword3 = time.Now().Format(utils.FormatDateTime)
  102. keyword4 = fmt.Sprint("研选调研需求:", content)
  103. var redirectUrl string
  104. if utils.RunMode == "release" {
  105. redirectUrl = utils.WX_MSG_PATH_YX_SURVEY_DETAIL + strconv.Itoa(articleId)
  106. }
  107. sendInfo := new(SendWxTemplate)
  108. sendInfo.Keyword1 = keyword1
  109. sendInfo.Keyword2 = keyword2
  110. sendInfo.Keyword3 = keyword3
  111. sendInfo.Keyword4 = keyword4
  112. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ACTIVITY_ADD
  113. sendInfo.TemplateId = utils.WxMsgTemplateIdApplyXzs
  114. sendInfo.RedirectUrl = redirectUrl
  115. sendInfo.RedirectTarget = 3
  116. sendInfo.Resource = strconv.Itoa(articleId)
  117. sendInfo.OpenIdArr = openIdArr
  118. err = PublicSendTemplateMsg(sendInfo)
  119. return
  120. }