cygx_questionnaire.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. package cygx
  2. import (
  3. "errors"
  4. "fmt"
  5. "hongze/hz_crm_api/models"
  6. "hongze/hz_crm_api/models/company"
  7. "hongze/hz_crm_api/models/cygx"
  8. "hongze/hz_crm_api/services"
  9. "hongze/hz_crm_api/services/alarm_msg"
  10. "hongze/hz_crm_api/utils"
  11. "strconv"
  12. )
  13. //func init() {
  14. // SendWxMsgCygxQuestionnaire(2)
  15. //}
  16. // 投票发布时,给所有开通买方研选正式试用的客户
  17. func SendWxMsgCygxQuestionnaire(questionnaireId int) (err error) {
  18. defer func() {
  19. if err != nil {
  20. fmt.Println(err)
  21. go alarm_msg.SendAlarmMsg(fmt.Sprint("投票发布时,给所有开通买方研选正式试用的客户,questionnaireId:", questionnaireId, err.Error()), 2)
  22. }
  23. }()
  24. //获取问卷详情
  25. detail, e := cygx.GetCygxQuestionnaireDetail(questionnaireId)
  26. if e != nil {
  27. err = errors.New("GetCygxQuestionnaireDetail, Err: " + e.Error())
  28. return
  29. }
  30. var keyword1 string
  31. var keyword2 string
  32. var keyword3 string
  33. var keyword4 string
  34. var companyIds []int
  35. var condition string
  36. var pars []interface{}
  37. condition = " AND chart_permission_id = 31 AND `status` IN ('正式','试用') "
  38. //获取所有开通买方研选正式试用的客户列表
  39. listCompany, e := company.GetCompanyReportPermissionList(condition, pars, 0, 0)
  40. if e != nil && e.Error() != utils.ErrNoRow() {
  41. err = errors.New("GetCygxQuestionnaireDetail, Err: " + e.Error())
  42. return
  43. }
  44. for _, v := range listCompany {
  45. companyIds = append(companyIds, v.CompanyId)
  46. }
  47. //获取相关的用户
  48. userList, e := models.GetWxUserByCompanyIds(companyIds)
  49. if e != nil && e.Error() != utils.ErrNoRow() {
  50. err = errors.New("GetWxUserByCompanyIds, Err: " + e.Error())
  51. return
  52. }
  53. mobile := make([]string, 0)
  54. for _, v := range userList {
  55. mobile = append(mobile, v.Mobile)
  56. }
  57. //获取用户对应的Openid
  58. openIdList, e := cygx.GetUserRecordListByMobileArr(mobile)
  59. if e != nil {
  60. err = errors.New("GetSellerByAdminId, Err: " + e.Error())
  61. return
  62. }
  63. if len(openIdList) == 0 {
  64. return
  65. }
  66. keyword1 = "买方研选【" + detail.ActivityTypeName + "】主题投票"
  67. keyword2 = "请选择您感兴趣的主题"
  68. openIdArr := make([]string, 0)
  69. for _, v := range openIdList {
  70. openIdArr = append(openIdArr, v.OpenId)
  71. }
  72. redirectUrl := ""
  73. if utils.RunMode == "release" {
  74. redirectUrl = utils.WX_MSG_PATH_QUESTIONNAIRE_DETAIL + strconv.Itoa(questionnaireId)
  75. }
  76. sendInfo := new(services.SendWxTemplate)
  77. sendInfo.Keyword1 = keyword1
  78. sendInfo.Keyword2 = keyword2
  79. sendInfo.Keyword3 = keyword3
  80. sendInfo.Keyword4 = keyword4
  81. sendInfo.TemplateId = utils.WxMsgTemplateIdActivityChangeApplyXzs
  82. sendInfo.RedirectUrl = redirectUrl
  83. sendInfo.RedirectTarget = 3
  84. sendInfo.Resource = strconv.Itoa(questionnaireId)
  85. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ARTICLE_ADD
  86. sendInfo.OpenIdArr = openIdArr
  87. e = services.SendTemplateMsg(sendInfo)
  88. if e != nil {
  89. err = errors.New("SendTemplateMsg, Err: " + e.Error())
  90. return
  91. }
  92. return
  93. }