activity_wx_template_msg.go 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. package services
  2. import (
  3. "errors"
  4. "fmt"
  5. "hongze/hongze_mfyx/models"
  6. "hongze/hongze_mfyx/utils"
  7. "strconv"
  8. "time"
  9. )
  10. // SendResearchActivitiesTemplateMsg 线下调研活动报名给所属销售跟建会人员推送
  11. func SendResearchActivitiesTemplateMsg(user *models.WxUserItem, activityDetail *models.ActivityDetail, doStatus string) (err error) {
  12. //如果不是公司线下调研就返回
  13. if activityDetail.ActivityTypeId != 4 {
  14. return
  15. }
  16. defer func() {
  17. if err != nil {
  18. go utils.SendEmail("线下调研活动报名给所属销售跟建会人员推送失败Err"+time.Now().Format("2006-01-02 15:04:05"), ";Err:"+err.Error(), utils.EmailSendToUsers)
  19. go utils.SendAlarmMsg(fmt.Sprint("线下调研活动报名给所属销售跟建会人员推送失败Err:", err.Error(), "活动ID:", activityDetail.ActivityId, "手机号:", user.Mobile), 2)
  20. }
  21. }()
  22. var mobiles []string
  23. //获取销售信息
  24. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  25. if err != nil && err.Error() != utils.ErrNoRow() {
  26. return
  27. }
  28. if sellerItem != nil {
  29. mobiles = append(mobiles, sellerItem.Mobile)
  30. }
  31. //获取建会人员信息
  32. admin, err := models.GetSysAdminById(activityDetail.AdminId)
  33. if err != nil && err.Error() != utils.ErrNoRow() {
  34. return
  35. }
  36. if admin != nil {
  37. mobiles = append(mobiles, admin.Mobile)
  38. }
  39. var first string
  40. var keyword1 string
  41. var keyword2 string
  42. var keyword3 string
  43. var keyword4 string
  44. var remark string
  45. var redirectUrl string
  46. //first = "【" + activityDetail.ActivityName + "】有客户报名"
  47. keyword1 = user.RealName + "——" + user.CompanyName + "(" + sellerItem.RealName + ")"
  48. keyword2 = user.Mobile
  49. keyword3 = time.Now().Format(utils.FormatDateTime)
  50. keyword4 = doStatus + ":" + activityDetail.ActivityName
  51. //remark = "点击查看报告详情"
  52. openIdList, e := models.GetWxOpenIdByMobileSliceList(mobiles)
  53. if e != nil {
  54. err = errors.New("GetWxOpenIdByMobileList, Err: " + e.Error())
  55. return
  56. }
  57. openIdArr := make([]string, 0)
  58. for _, v := range openIdList {
  59. openIdArr = append(openIdArr, v.OpenId)
  60. }
  61. redirectUrl = utils.WX_MSG_PATH_ACTIVITY_DETAIL + strconv.Itoa(activityDetail.ActivityId)
  62. sendInfo := new(SendWxTemplate)
  63. sendInfo.First = first
  64. sendInfo.Keyword1 = keyword1
  65. sendInfo.Keyword2 = keyword2
  66. sendInfo.Keyword3 = keyword3
  67. sendInfo.Keyword4 = keyword4
  68. sendInfo.Remark = remark
  69. sendInfo.TemplateId = utils.WxMsgTemplateIdApplyXzs
  70. sendInfo.RedirectUrl = redirectUrl
  71. sendInfo.RedirectTarget = 3
  72. sendInfo.Resource = strconv.Itoa(activityDetail.ArticleId)
  73. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_COMMENT
  74. sendInfo.OpenIdArr = openIdArr
  75. err = PublicSendTemplateMsg(sendInfo)
  76. if err != nil {
  77. return
  78. }
  79. return
  80. }
  81. // SendActivitieSignTemplateMsg 线下调研活动扫码签到给对应销售发模班消息
  82. func SendActivitieSignTemplateMsg(user *models.WxUserItem, activityDetail *models.ActivityDetail) (err error) {
  83. defer func() {
  84. if err != nil {
  85. go utils.SendAlarmMsg(fmt.Sprint("线下调研活动扫码签到给对应销售发模班消息推送失败Err:", err.Error(), "活动ID:", activityDetail.ActivityId, "手机号:", user.Mobile), 2)
  86. }
  87. }()
  88. var mobiles []string
  89. //获取销售信息
  90. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  91. if err != nil && err.Error() != utils.ErrNoRow() {
  92. return
  93. }
  94. if sellerItem != nil {
  95. mobiles = append(mobiles, sellerItem.Mobile)
  96. }
  97. var first string
  98. var keyword1 string
  99. var keyword2 string
  100. var keyword3 string
  101. var keyword4 string
  102. var remark string
  103. var redirectUrl string
  104. first = ""
  105. keyword1 = activityDetail.ActivityName
  106. keyword2 = user.RealName + "——" + user.CompanyName
  107. keyword3 = time.Now().Format(utils.FormatDateTime)
  108. keyword4 = ""
  109. remark = ""
  110. openIdList, e := models.GetWxOpenIdByMobileSliceList(mobiles)
  111. if e != nil {
  112. err = errors.New("GetWxOpenIdByMobileList, Err: " + e.Error())
  113. return
  114. }
  115. openIdArr := make([]string, 0)
  116. for _, v := range openIdList {
  117. openIdArr = append(openIdArr, v.OpenId)
  118. }
  119. if utils.RunMode != "release" {
  120. redirectUrl = utils.WX_MSG_PATH_ACTIVITY_DETAIL + strconv.Itoa(activityDetail.ActivityId)
  121. } else {
  122. redirectUrl = utils.WX_MSG_PATH_ACTIVITY_SIGN + strconv.Itoa(activityDetail.ActivityId)
  123. }
  124. sendInfo := new(SendWxTemplate)
  125. sendInfo.First = first
  126. sendInfo.Keyword1 = keyword1
  127. sendInfo.Keyword2 = keyword2
  128. sendInfo.Keyword3 = keyword3
  129. sendInfo.Keyword4 = keyword4
  130. sendInfo.Remark = remark
  131. sendInfo.TemplateId = utils.WxMsgTemplateIdActivitySign
  132. sendInfo.RedirectUrl = redirectUrl
  133. sendInfo.RedirectTarget = 3
  134. sendInfo.Resource = strconv.Itoa(activityDetail.ActivityId)
  135. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_COMMENT
  136. sendInfo.OpenIdArr = openIdArr
  137. err = PublicSendTemplateMsg(sendInfo)
  138. if err != nil {
  139. return
  140. }
  141. return
  142. }
  143. // SendActivitieCancelSignTemplateMsg 取消活动给销售和内容组四人发模版消息
  144. func SendActivitieCancelSignTemplateMsg(user *models.WxUserItem, activityDetail *models.ActivityDetail) (err error) {
  145. defer func() {
  146. if err != nil {
  147. go utils.SendAlarmMsg(fmt.Sprint("取消活动给销售和内容组四人发模版消息Err:", err.Error(), "活动ID:", activityDetail.ActivityId, "手机号:", user.Mobile), 2)
  148. }
  149. }()
  150. //获取销售手机号
  151. sellerItemQy, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  152. if err != nil && err.Error() != utils.ErrNoRow() {
  153. return
  154. }
  155. configCode := utils.TPL_MSG_NEI_RONG_ZU
  156. cnf, e := models.GetConfigByCode(configCode)
  157. if e != nil {
  158. err = errors.New("GetConfigByCode, Err: " + e.Error() + configCode)
  159. return
  160. }
  161. openIdList, e := models.GetUserRecordListByMobile(4, cnf.ConfigValue+","+sellerItemQy.Mobile)
  162. if e != nil && e.Error() != utils.ErrNoRow() {
  163. err = errors.New("GetUserRecordListByMobile, Err: " + e.Error() + cnf.ConfigValue)
  164. return
  165. }
  166. keyword1 := user.RealName + "--" + user.CompanyName + "(" + sellerItemQy.RealName + ")"
  167. keyword2 := user.Mobile
  168. keyword3 := time.Now().Format(utils.FormatDateTime)
  169. keyword4 := "取消报名" + "【" + activityDetail.ActivityName + "】"
  170. openIdArr := make([]string, 0)
  171. for _, v := range openIdList {
  172. openIdArr = append(openIdArr, v.OpenId)
  173. }
  174. sendInfo := new(SendWxTemplate)
  175. sendInfo.Keyword1 = keyword1
  176. sendInfo.Keyword2 = keyword2
  177. sendInfo.Keyword3 = keyword3
  178. sendInfo.Keyword4 = keyword4
  179. sendInfo.TemplateId = utils.WxMsgTemplateIdApplyXzs
  180. sendInfo.RedirectTarget = 3
  181. sendInfo.Resource = user.Mobile
  182. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_APPLY
  183. sendInfo.OpenIdArr = openIdArr
  184. err = PublicSendTemplateMsg(sendInfo)
  185. return
  186. }
  187. // SendNeiRongZuActivitieSignTemplateMsg 报名活动给销售和内容组四人发模版消息
  188. func SendNeiRongZuActivitieSignTemplateMsg(user *models.WxUserItem, activityDetail *models.ActivityDetail) (err error) {
  189. defer func() {
  190. if err != nil {
  191. go utils.SendAlarmMsg(fmt.Sprint("取消活动给销售和内容组四人发模版消息Err:", err.Error(), "活动ID:", activityDetail.ActivityId, "手机号:", user.Mobile), 2)
  192. }
  193. }()
  194. //获取销售手机号
  195. sellerItemQy, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  196. if err != nil && err.Error() != utils.ErrNoRow() {
  197. return
  198. }
  199. configCode := utils.TPL_MSG_NEI_RONG_ZU
  200. cnf, e := models.GetConfigByCode(configCode)
  201. if e != nil {
  202. err = errors.New("GetConfigByCode, Err: " + e.Error() + configCode)
  203. return
  204. }
  205. openIdList, e := models.GetUserRecordListByMobile(4, cnf.ConfigValue+","+sellerItemQy.Mobile)
  206. if e != nil && e.Error() != utils.ErrNoRow() {
  207. err = errors.New("GetUserRecordListByMobile, Err: " + e.Error() + cnf.ConfigValue)
  208. return
  209. }
  210. keyword1 := user.RealName + "--" + user.CompanyName + "(" + sellerItemQy.RealName + ")"
  211. keyword2 := user.Mobile
  212. keyword3 := time.Now().Format(utils.FormatDateTime)
  213. keyword4 := "报名" + "【" + activityDetail.ActivityName + "】"
  214. openIdArr := make([]string, 0)
  215. for _, v := range openIdList {
  216. openIdArr = append(openIdArr, v.OpenId)
  217. }
  218. sendInfo := new(SendWxTemplate)
  219. sendInfo.Keyword1 = keyword1
  220. sendInfo.Keyword2 = keyword2
  221. sendInfo.Keyword3 = keyword3
  222. sendInfo.Keyword4 = keyword4
  223. sendInfo.TemplateId = utils.WxMsgTemplateIdApplyXzs
  224. sendInfo.RedirectTarget = 3
  225. sendInfo.Resource = user.Mobile
  226. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_APPLY
  227. sendInfo.OpenIdArr = openIdArr
  228. err = PublicSendTemplateMsg(sendInfo)
  229. return
  230. }