article_apply_appointment_expert.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. package services
  2. import (
  3. "errors"
  4. "fmt"
  5. "hongze/hongze_mfyx/models"
  6. "hongze/hongze_mfyx/utils"
  7. "strconv"
  8. "strings"
  9. "time"
  10. )
  11. // 约访专家的请求
  12. func AddArticleApplyAppointmentExpert(user *models.WxUserItem, articleId int) (err error) {
  13. defer func() {
  14. if err != nil {
  15. go utils.SendAlarmMsg("约访专家的请求失败"+err.Error(), 2)
  16. }
  17. }()
  18. item := new(models.CygxArticleApplyAppointmentExpert)
  19. item.UserId = user.UserId
  20. item.ArticleId = articleId
  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.RegisterPlatform = utils.REGISTER_PLATFORM
  28. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  29. if err != nil && err.Error() != utils.ErrNoRow() {
  30. return
  31. }
  32. item.RealName = user.RealName
  33. if sellerItem != nil {
  34. item.SellerName = sellerItem.RealName
  35. }
  36. _, e := models.AddCygxArticleApplyAppointmentExpert(item)
  37. if e != nil {
  38. err = errors.New("AddCygxArticleApplyAppointmentExpert, Err: " + e.Error())
  39. return
  40. }
  41. return
  42. }
  43. // 用户约访专家的请求,向对应销售发送模版消息
  44. func SendArticleApplyAppointmentExpertTemplateMsg(user *models.WxUserItem, articleId int) (err error) {
  45. var msg string
  46. msg = fmt.Sprint(user, articleId)
  47. defer func() {
  48. if err != nil {
  49. go utils.SendAlarmMsg("活动带问提醒发送模版消息失败"+msg, 2)
  50. }
  51. }()
  52. //文章详情
  53. detailArticle, e := models.GetArticleDetailById(articleId)
  54. if e != nil {
  55. err = errors.New("GetArticleDetailById, Err: " + e.Error())
  56. return
  57. }
  58. var mobiles []string
  59. //获取权益销售
  60. sellerItem, e := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  61. if e != nil {
  62. err = errors.New("GetAdminByRoleName, Err: " + e.Error())
  63. return
  64. }
  65. //内容组全员手机号
  66. configCode := utils.TPL_MSG_NEI_RONG_ZU
  67. cnf, e := models.GetConfigByCode(configCode)
  68. if e != nil {
  69. err = errors.New("GetConfigByCode, Err: " + e.Error() + configCode)
  70. return
  71. }
  72. //汪洋手机号
  73. cnfWangYang, e := models.GetConfigByCode(utils.TPL_MSG_WANG_YANG)
  74. if e != nil {
  75. err = errors.New("GetConfigByCode, Err: " + e.Error() + configCode)
  76. return
  77. }
  78. mobiles = append(mobiles, sellerItem.Mobile)
  79. mobiles = append(mobiles, cnfWangYang.ConfigValue)
  80. listMobile := strings.Split(cnf.ConfigValue, ",")
  81. for _, v := range listMobile {
  82. mobiles = append(mobiles, v)
  83. }
  84. openIdList, e := models.GetWxOpenIdByMobileSliceList(mobiles)
  85. if e != nil {
  86. err = errors.New("GetWxOpenIdByMobileSliceList, Err: " + e.Error() + configCode)
  87. return
  88. }
  89. if len(openIdList) == 0 {
  90. return
  91. }
  92. if len(openIdList) == 0 {
  93. return
  94. }
  95. openIdArr := make([]string, 0)
  96. for _, v := range openIdList {
  97. openIdArr = append(openIdArr, v.OpenId)
  98. }
  99. var keyword1 string
  100. var keyword2 string
  101. var keyword3 string
  102. var keyword4 string
  103. keyword1 = fmt.Sprint(user.RealName, "--", user.CompanyName, "(", sellerItem.RealName, ")")
  104. if user.Mobile == "" {
  105. user.Mobile = user.Email
  106. }
  107. keyword2 = user.Mobile
  108. keyword3 = time.Now().Format(utils.FormatDateTime)
  109. keyword4 = fmt.Sprint("约访专家(", detailArticle.Title, ")")
  110. var redirectUrl string
  111. redirectUrl = utils.WX_MSG_PATH_ARTICLE_DETAIL + strconv.Itoa(articleId)
  112. sendInfo := new(SendWxTemplate)
  113. sendInfo.Keyword1 = keyword1
  114. sendInfo.Keyword2 = keyword2
  115. sendInfo.Keyword3 = keyword3
  116. sendInfo.Keyword4 = keyword4
  117. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ACTIVITY_ADD
  118. sendInfo.TemplateId = utils.WxMsgTemplateIdApplyXzs
  119. sendInfo.RedirectUrl = redirectUrl
  120. sendInfo.RedirectTarget = 3
  121. sendInfo.Resource = strconv.Itoa(articleId)
  122. sendInfo.OpenIdArr = openIdArr
  123. err = PublicSendTemplateMsg(sendInfo)
  124. return
  125. }