activity_wx_msg.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  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. "html"
  12. "strconv"
  13. "strings"
  14. "time"
  15. )
  16. // 修改活动人数限制之后,对于因为人数已满而失败的用户,推送模板消息
  17. func SendWxMsgWithCygxActivityUpdateLimitPeople(activityId int) (err error) {
  18. var msg string
  19. defer func() {
  20. if err != nil {
  21. fmt.Println(err)
  22. go alarm_msg.SendAlarmMsg("修改活动人数限制之后,对于因为人数已满而失败的用户,推送模板消息,发送模版消息失败,Err:"+err.Error()+";msg:"+msg, 3)
  23. utils.FileLogCygx.Info(fmt.Sprintf("发送模版消息失败,Err:%s,%s", err.Error(), msg))
  24. }
  25. }()
  26. activityInfo, e := cygx.GetAddActivityInfoById(activityId)
  27. if e != nil {
  28. err = errors.New("活动不存在, Err: " + e.Error())
  29. return
  30. }
  31. if activityInfo == nil {
  32. return
  33. }
  34. //已经推送过的不做二次推送
  35. //listSendOpendId, err := models.GeUserTemplateRecordListBysendType(utils.TEMPLATE_MSG_CYGX_ACTIVITY_LIMIT_PEOPLE, strconv.Itoa(activityId))
  36. //已经推送过的不做二次推送
  37. //listSendOpendId, err := cygx.GeCygxActivityUserTemplateRecordListByActivityId(activityId, utils.TEMPLATE_MSG_CYGX_ACTIVITY_LIMIT_PEOPLE)
  38. //if err != nil && err.Error() != utils.ErrNoRow() {
  39. // return err
  40. //}
  41. //if err != nil && err.Error() != utils.ErrNoRow() {
  42. // return err
  43. //}
  44. //mapSendOpenid := make(map[string]int)
  45. //for _, v := range listSendOpendId {
  46. // mapSendOpenid[v.OpenId] = v.UserId
  47. //}
  48. var condition string
  49. var pars []interface{}
  50. condition = ` AND do_fail_type = 1 AND activity_id = ? `
  51. pars = append(pars, activityId)
  52. listSignup, e := cygx.GetActivitySignupList(condition, pars)
  53. if e != nil {
  54. err = errors.New("GetResourceDataList, Err: " + e.Error())
  55. return
  56. }
  57. var mobileArr []string
  58. for _, v := range listSignup {
  59. if v.Mobile != "" {
  60. mobileArr = append(mobileArr, v.Mobile)
  61. }
  62. }
  63. mobileLen := len(mobileArr)
  64. if mobileLen == 0 {
  65. return
  66. }
  67. //condition = ""
  68. //pars = make([]interface{}, 0)
  69. //condition += ` AND u.mobile IN (` + utils.GetOrmInReplace(mobileLen) + `)`
  70. //pars = append(pars, mobileArr)
  71. openIdList, e := cygx.GetUserRecordListByMobileArr(mobileArr)
  72. if e != nil {
  73. err = errors.New("GetWxOpenIdBList, Err: " + e.Error())
  74. return
  75. }
  76. if len(openIdList) == 0 {
  77. return
  78. }
  79. //openIdArr := make([]string, len(openIdList))
  80. //for i, v := range openIdList {
  81. // if mapSendOpenid[v.OpenId] > 0 {
  82. // continue
  83. // }
  84. // openIdArr[i] = v.OpenId
  85. //}
  86. var openiditems []*cygx.CygxActivityUserTemplateRecord
  87. var openIdArr []string
  88. for _, v := range openIdList {
  89. openIdArr = append(openIdArr, v.OpenId)
  90. openiditem := new(cygx.CygxActivityUserTemplateRecord)
  91. openiditem.ActivityId = activityId
  92. openiditem.UserId = v.UserId
  93. openiditem.OpenId = v.OpenId
  94. openiditem.SendType = utils.TEMPLATE_MSG_CYGX_ACTIVITY_LIMIT_PEOPLE
  95. openiditem.CreateTime = time.Now()
  96. openiditems = append(openiditems, openiditem)
  97. }
  98. if activityInfo.ChartPermissionId != utils.CHART_PERMISSION_ID_YANXUAN {
  99. //需求池 1043:深圳进门财经科技股份有限公司下所有的账号,所有活动的新增修改都做推送,所有的报告的新增修改都不做推送。
  100. jmcjOpenId := GetUserOpenidByComapnyIdRai(utils.JMCJ_COMPANY_ID)
  101. for _, v := range jmcjOpenId {
  102. if !utils.InArrayByStr(openIdArr, v) {
  103. openIdArr = append(openIdArr, v)
  104. }
  105. }
  106. }
  107. first := "您好,本场活动已增加活动名额至" + activityInfo.LimitPeopleNum + "人,欢迎报名"
  108. keyword1 := activityInfo.ActivityName
  109. keyword2 := "已增加活动名额至" + activityInfo.LimitPeopleNum + "人,欢迎报名"
  110. keyword3 := ""
  111. keyword4 := ""
  112. remark := "点击查看活动详情"
  113. redirectUrl := utils.WX_MSG_PATH_ACTIVITY_DETAIL + strconv.Itoa(activityId)
  114. sendInfo := new(services.SendWxTemplate)
  115. sendInfo.First = first
  116. sendInfo.Keyword1 = keyword1
  117. sendInfo.Keyword2 = keyword2
  118. sendInfo.Keyword3 = keyword3
  119. sendInfo.Keyword4 = keyword4
  120. sendInfo.Remark = remark
  121. sendInfo.TemplateId = utils.WxMsgTemplateIdActivityChangeApplyXzs
  122. sendInfo.RedirectUrl = redirectUrl
  123. sendInfo.RedirectTarget = 3
  124. sendInfo.Resource = strconv.Itoa(activityId)
  125. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ACTIVITY_LIMIT_PEOPLE
  126. sendInfo.OpenIdArr = openIdArr
  127. e = services.SendTemplateMsg(sendInfo)
  128. if e != nil {
  129. err = errors.New("SendTemplateMsg, Err: " + e.Error())
  130. return
  131. }
  132. //活动发布推送的Openid记录
  133. if len(openiditems) > 0 {
  134. e = cygx.AddCygxActivityUserTemplateRecordMulti(openiditems)
  135. if e != nil {
  136. err = errors.New("AddCygxActivityUserTemplateRecordMulti, Err: " + e.Error())
  137. return
  138. }
  139. }
  140. return
  141. }
  142. // 销售或后台管理员给用户添加报名之后,进行模版消息推送
  143. func SendWxMsgWithCygxActivitySignUpBySell(items []*cygx.CygxSignupUser) (err error) {
  144. var msg string
  145. defer func() {
  146. if err != nil {
  147. fmt.Println(err)
  148. go alarm_msg.SendAlarmMsg("修改活动人数限制之后,对于因为人数已满而失败的用户,推送模板消息,发送模版消息失败,Err:"+err.Error()+";msg:"+msg, 3)
  149. utils.FileLogCygx.Info(fmt.Sprintf("发送模版消息失败,Err:%s,%s", err.Error(), msg))
  150. }
  151. }()
  152. if len(items) == 0 {
  153. return
  154. }
  155. //var condition string
  156. //var pars []interface{}
  157. for _, v := range items {
  158. activityId := v.ActivityId
  159. uid := v.UserId
  160. activityInfo, e := cygx.GetAddActivityInfoById(activityId)
  161. if e != nil {
  162. err = errors.New("活动不存在, Err: " + e.Error())
  163. return
  164. }
  165. if activityInfo == nil {
  166. return
  167. }
  168. wxUser, e := models.GetWxUserByUserId(uid)
  169. if e != nil {
  170. err = errors.New("查询用户信息失败, Err: " + e.Error())
  171. return
  172. }
  173. var mobileArr []string
  174. mobileArr = append(mobileArr, wxUser.Mobile)
  175. mobileLen := len(mobileArr)
  176. if mobileLen == 0 {
  177. return
  178. }
  179. //condition = ""
  180. //pars = make([]interface{}, 0)
  181. //condition += ` AND u.mobile IN (` + utils.GetOrmInReplace(mobileLen) + `)`
  182. //pars = append(pars, mobileArr)
  183. openIdList, e := cygx.GetUserRecordListByMobileArr(mobileArr)
  184. if e != nil {
  185. err = errors.New("GetWxOpenIdBList, Err: " + e.Error())
  186. return
  187. }
  188. if len(openIdList) == 0 {
  189. return
  190. }
  191. openIdArr := make([]string, len(openIdList))
  192. for i, v := range openIdList {
  193. fmt.Println(v.OpenId)
  194. openIdArr[i] = v.OpenId
  195. }
  196. first := "对口销售已为您报名本场活动"
  197. keyword1 := "销售已为您报名:" + activityInfo.ActivityName
  198. keyword2 := activityInfo.ActivityTimeText
  199. keyword3 := ""
  200. keyword4 := ""
  201. remark := "点击查看活动详情"
  202. redirectUrl := utils.WX_MSG_PATH_ACTIVITY_DETAIL + strconv.Itoa(activityId)
  203. sendInfo := new(services.SendWxTemplate)
  204. sendInfo.First = first
  205. sendInfo.Keyword1 = keyword1
  206. sendInfo.Keyword2 = keyword2
  207. sendInfo.Keyword3 = keyword3
  208. sendInfo.Keyword4 = keyword4
  209. sendInfo.Remark = remark
  210. sendInfo.TemplateId = utils.WxMsgTemplateIdActivityApplyXzs
  211. sendInfo.RedirectUrl = redirectUrl
  212. sendInfo.RedirectTarget = 3
  213. sendInfo.Resource = strconv.Itoa(activityId)
  214. sendInfo.SendType = utils.TEMPLATE_MSG_ACTIVITY_APPOINTMENT
  215. sendInfo.OpenIdArr = openIdArr
  216. e = services.SendTemplateMsg(sendInfo)
  217. if e != nil {
  218. err = errors.New("SendTemplateMsg, Err: " + e.Error())
  219. return
  220. }
  221. }
  222. return
  223. }
  224. // 已结束的活动上传音频或视频后给已关注这个活动关联的产业的正式、试用 客户发送模板信息
  225. func SendWxMsgWithUpdateActivityVideoAndVoice(activityId int, fileName string) (err error) {
  226. defer func() {
  227. if err != nil {
  228. fmt.Println(err)
  229. go alarm_msg.SendAlarmMsg(fmt.Sprint("已结束的活动上传音频或视频后给已关注这个活动关联的产业的正式、试用 客户发送模板信息失败,Err:"+err.Error()+";activityId:", activityId), 3)
  230. //utils.FileLogCygx.Info(fmt.Sprintf("发送模版消息失败,Err:%s,%s", err.Error(), msg))
  231. }
  232. }()
  233. activityInfo, e := cygx.GetAddActivityInfoById(activityId)
  234. if e != nil {
  235. err = errors.New("活动不存在, Err: " + e.Error())
  236. return
  237. }
  238. if activityInfo == nil {
  239. return
  240. }
  241. industrialList, e := cygx.GetIndustrialActivityGroupListByactivityIds(strconv.Itoa(activityId))
  242. if e != nil && e.Error() != utils.ErrNoRow() {
  243. err = errors.New("GetIndustrialActivityGroupListByactivityIds: " + e.Error())
  244. return
  245. }
  246. //if len(industrialList) == 0 {
  247. // return
  248. //}
  249. var industrialManagementIds []int
  250. for _, v := range industrialList {
  251. industrialManagementIds = append(industrialManagementIds, v.IndustrialManagementId)
  252. }
  253. lenindustrialManagementIds := len(industrialManagementIds)
  254. if lenindustrialManagementIds == 0 {
  255. return
  256. }
  257. var condition string
  258. var pars []interface{}
  259. //获取试用正式权益客户
  260. condition = " AND product_id = 2 AND `status` IN('正式','试用') "
  261. listCompany, e := company.GetCompanyProductList(condition, pars)
  262. if e != nil && e.Error() != utils.ErrNoRow() {
  263. err = errors.New("GetCompanyProductList, Err: " + e.Error())
  264. return
  265. }
  266. var companyIds []int
  267. for _, v := range listCompany {
  268. companyIds = append(companyIds, v.CompanyId)
  269. }
  270. lencompanyIds := len(companyIds)
  271. if lencompanyIds == 0 {
  272. return
  273. }
  274. //根据产业关注ID,与有权限的公司ID获取对应的用户列表
  275. condition = " AND industrial_management_id IN (" + utils.GetOrmInReplace(lenindustrialManagementIds) + ") AND company_id IN (" + utils.GetOrmInReplace(lencompanyIds) + ") "
  276. pars = append(pars, industrialManagementIds, companyIds)
  277. userFllowList, e := cygx.GetCygxIndustryFllowList(condition, pars, 0, 0)
  278. if e != nil && e.Error() != utils.ErrNoRow() {
  279. err = errors.New("GetCygxIndustryFllowList, Err: " + e.Error())
  280. return
  281. }
  282. //获取这些用户的手机号
  283. var mobileArr []string
  284. for _, v := range userFllowList {
  285. mobileArr = append(mobileArr, v.Mobile)
  286. }
  287. mobileLen := len(mobileArr)
  288. if mobileLen == 0 {
  289. return
  290. }
  291. openIdList, e := cygx.GetUserRecordListByMobileArr(mobileArr)
  292. if e != nil {
  293. err = errors.New("GetWxOpenIdBList, Err: " + e.Error())
  294. return
  295. }
  296. if len(openIdList) == 0 {
  297. return
  298. }
  299. openIdArr := make([]string, len(openIdList))
  300. for _, v := range openIdList {
  301. openIdArr = append(openIdArr, v.OpenId)
  302. }
  303. keyword1 := fileName
  304. keyword2 := "路演回放已发布,欢迎查看"
  305. keyword3 := ""
  306. keyword4 := ""
  307. redirectUrl := utils.WX_MSG_PATH_ACTIVITY_DETAIL + strconv.Itoa(activityId)
  308. sendInfo := new(services.SendWxTemplate)
  309. sendInfo.Keyword1 = keyword1
  310. sendInfo.Keyword2 = keyword2
  311. sendInfo.Keyword3 = keyword3
  312. sendInfo.Keyword4 = keyword4
  313. sendInfo.TemplateId = utils.WxMsgTemplateIdActivityChangeApplyXzs
  314. sendInfo.RedirectUrl = redirectUrl
  315. sendInfo.RedirectTarget = 3
  316. sendInfo.Resource = strconv.Itoa(activityId)
  317. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ACTIVITY_LIMIT_PEOPLE
  318. sendInfo.OpenIdArr = openIdArr
  319. e = services.SendTemplateMsg(sendInfo)
  320. if e != nil {
  321. err = errors.New("SendTemplateMsg, Err: " + e.Error())
  322. return
  323. }
  324. return
  325. }
  326. // 活动更改时间消息通知
  327. func SendWxMsgWithCygxActivityUpdateTime(activityId int, oldStr, newStr, strType string) (err error) {
  328. var msg string
  329. defer func() {
  330. if err != nil {
  331. go alarm_msg.SendAlarmMsg("发送模版消息失败,Err:"+err.Error()+";msg:"+msg, 3)
  332. utils.FileLogCygx.Info(fmt.Sprintf("发送模版消息失败,Err:%s,%s", err.Error(), msg))
  333. }
  334. if msg != "" {
  335. utils.FileLogCygx.Info("发送模版消息失败,msg:%s", msg)
  336. }
  337. }()
  338. activityInfo, err := cygx.GetAddActivityInfoById(activityId)
  339. if err != nil {
  340. msg = "GetReportInfo Err:" + err.Error()
  341. return
  342. }
  343. if activityInfo == nil {
  344. utils.FileLogCygx.Info("活动信息不存在")
  345. return
  346. }
  347. var openIdList []*cygx.OpenIdList
  348. openIdList, err = cygx.GetActivityOpenIdList(activityId)
  349. if err != nil {
  350. msg = "get openIdList err:" + err.Error()
  351. return
  352. }
  353. mapOpenid := make(map[int]string)
  354. for _, v := range openIdList {
  355. mapOpenid[v.UserId] = v.OpenId
  356. }
  357. //添加预约纪要的openid
  358. openIdListAppointment, err := cygx.GetActivityAppointmentOpenIdList(activityId)
  359. if err != nil {
  360. msg = "GetActivityAppointmentOpenIdList err:" + err.Error()
  361. return
  362. }
  363. if len(openIdListAppointment) > 0 {
  364. for _, v := range openIdListAppointment {
  365. if _, ok := mapOpenid[v.UserId]; !ok {
  366. item := new(cygx.OpenIdList)
  367. item.UserId = v.UserId
  368. item.OpenId = v.OpenId
  369. openIdList = append(openIdList, item)
  370. }
  371. mapOpenid[v.UserId] = v.OpenId
  372. }
  373. }
  374. //添加带问的openid
  375. openIdListActivityHelpAsk, err := cygx.GetActivityHelpAskOpenIdList(activityId)
  376. if err != nil {
  377. msg = "openIdListActivityHelpAsk err:" + err.Error()
  378. return
  379. }
  380. if len(openIdListActivityHelpAsk) > 0 {
  381. for _, v := range openIdListActivityHelpAsk {
  382. if _, ok := mapOpenid[v.UserId]; !ok {
  383. item := new(cygx.OpenIdList)
  384. item.UserId = v.UserId
  385. item.OpenId = v.OpenId
  386. openIdList = append(openIdList, item)
  387. }
  388. mapOpenid[v.UserId] = v.OpenId
  389. }
  390. }
  391. if len(openIdList) == 0 {
  392. return err
  393. }
  394. //sendMap := make(map[string]interface{})
  395. //sendData := make(map[string]interface{})
  396. var first string
  397. var keyword1, keyword2, keyword3, keyword4, redirectUrl string
  398. activityInfo.ActivityTypeName = strings.Replace(activityInfo.ActivityTypeName, "(C类)", "", -1)
  399. if strType == "timeType" {
  400. //first = "您有一场【" + activityInfo.ActivityTypeName + "】发生了时间变更"
  401. keyword2 = "时间变更为:【 " + newStr + "】"
  402. } else if strType == "expertType" {
  403. //first = "您有一场【" + activityInfo.ActivityTypeName + "】发生了专家变更"
  404. keyword2 = "专家变更为:【" + newStr + "】"
  405. } else if strType == "addressType" {
  406. //first = "您有一场【" + activityInfo.ActivityTypeName + "】发生了地址变更"
  407. keyword2 = "地点变更为:【" + newStr + "】"
  408. } else if strType == "participationCode" {
  409. //first = "您有一场【" + activityInfo.ActivityTypeName + "】公布了拨入密码"
  410. keyword2 = "拨入密码为: " + newStr
  411. } else if strType == "Theme" {
  412. //first = "您有一场【" + activityInfo.ActivityTypeName + "】更新了活动主题"
  413. newStr = strings.Replace(newStr, "</p><p>", "\n", -1)
  414. newStr = html.EscapeString(newStr)
  415. newStrHtml, _ := cygx.GetReportContentTextSub(newStr)
  416. newStr = newStrHtml
  417. keyword2 = "主题变更为: " + newStr
  418. }
  419. keyword1 = activityInfo.ActivityName
  420. var openIdArr []string
  421. for _, v := range openIdList {
  422. openIdArr = append(openIdArr, v.OpenId)
  423. }
  424. if activityInfo.ChartPermissionId != utils.CHART_PERMISSION_ID_YANXUAN {
  425. //需求池 1043:深圳进门财经科技股份有限公司下所有的账号,所有活动的新增修改都做推送,所有的报告的新增修改都不做推送。
  426. jmcjOpenId := GetUserOpenidByComapnyIdRai(utils.JMCJ_COMPANY_ID)
  427. for _, v := range jmcjOpenId {
  428. if !utils.InArrayByStr(openIdArr, v) {
  429. openIdArr = append(openIdArr, v)
  430. }
  431. }
  432. }
  433. redirectUrl = utils.WX_MSG_PATH_ACTIVITY_DETAIL + strconv.Itoa(activityId) + "&IsSendWx=1"
  434. sendInfo := new(services.SendWxTemplate)
  435. sendInfo.First = first
  436. sendInfo.Keyword1 = keyword1
  437. sendInfo.Keyword2 = keyword2
  438. sendInfo.Keyword3 = keyword3
  439. sendInfo.Keyword4 = keyword4
  440. //sendInfo.Remark = remark
  441. sendInfo.TemplateId = utils.WxMsgTemplateIdActivityChangeApplyXzs
  442. sendInfo.RedirectUrl = redirectUrl
  443. sendInfo.RedirectTarget = 3
  444. sendInfo.Resource = strconv.Itoa(activityId)
  445. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ACTIVITY_UPDATE
  446. sendInfo.OpenIdArr = openIdArr
  447. e := services.SendTemplateMsg(sendInfo)
  448. if e != nil {
  449. err = errors.New("推送模板消息失败" + e.Error())
  450. return
  451. }
  452. return
  453. }
  454. // 活动取消消息通知
  455. func SendWxMsgWithCygxActivity(activityId int) (err error) {
  456. var msg string
  457. defer func() {
  458. if err != nil {
  459. go alarm_msg.SendAlarmMsg("发送模版消息失败,Err:"+err.Error()+";msg:"+msg, 3)
  460. utils.FileLogCygx.Info(fmt.Sprintf("发送模版消息失败,Err:%s,%s", err.Error(), msg))
  461. }
  462. if msg != "" {
  463. utils.FileLogCygx.Info("发送模版消息失败,msg:%s", msg)
  464. }
  465. }()
  466. activityInfo, err := cygx.GetAddActivityInfoById(activityId)
  467. if err != nil {
  468. msg = "GetReportInfo Err:" + err.Error()
  469. return
  470. }
  471. var openIdList []*cygx.OpenIdList
  472. openIdList, err = cygx.GetActivityOpenIdList(activityId)
  473. if err != nil {
  474. msg = "get GetActivityOpenIdList err:" + err.Error()
  475. return
  476. }
  477. mapOpenid := make(map[int]string)
  478. for _, v := range openIdList {
  479. mapOpenid[v.UserId] = v.OpenId
  480. }
  481. //添加预约纪要的openid
  482. openIdListAppointment, err := cygx.GetActivityAppointmentOpenIdList(activityId)
  483. if err != nil {
  484. msg = "GetActivityAppointmentOpenIdList err:" + err.Error()
  485. return
  486. }
  487. if len(openIdListAppointment) > 0 {
  488. for _, v := range openIdListAppointment {
  489. if _, ok := mapOpenid[v.UserId]; !ok {
  490. item := new(cygx.OpenIdList)
  491. item.UserId = v.UserId
  492. item.OpenId = v.OpenId
  493. openIdList = append(openIdList, item)
  494. }
  495. mapOpenid[v.UserId] = v.OpenId
  496. }
  497. }
  498. //添加带问的openid
  499. openIdListActivityHelpAsk, err := cygx.GetActivityHelpAskOpenIdList(activityId)
  500. if err != nil {
  501. msg = "openIdListActivityHelpAsk err:" + err.Error()
  502. return
  503. }
  504. if len(openIdListActivityHelpAsk) > 0 {
  505. for _, v := range openIdListActivityHelpAsk {
  506. if _, ok := mapOpenid[v.UserId]; !ok {
  507. item := new(cygx.OpenIdList)
  508. item.UserId = v.UserId
  509. item.OpenId = v.OpenId
  510. openIdList = append(openIdList, item)
  511. }
  512. mapOpenid[v.UserId] = v.OpenId
  513. }
  514. }
  515. activityInfo.ActivityTypeName = strings.Replace(activityInfo.ActivityTypeName, "(C类)", "", -1)
  516. if len(openIdList) == 0 {
  517. return err
  518. }
  519. var keyword1, keyword2, keyword3, keyword4, redirectUrl string
  520. keyword1 = activityInfo.ActivityName
  521. keyword2 = "活动已取消"
  522. var openIdArr []string
  523. for _, v := range openIdList {
  524. openIdArr = append(openIdArr, v.OpenId)
  525. }
  526. if activityInfo.ChartPermissionId != utils.CHART_PERMISSION_ID_YANXUAN {
  527. //需求池 1043:深圳进门财经科技股份有限公司下所有的账号,所有活动的新增修改都做推送,所有的报告的新增修改都不做推送。
  528. jmcjOpenId := GetUserOpenidByComapnyIdRai(utils.JMCJ_COMPANY_ID)
  529. for _, v := range jmcjOpenId {
  530. if !utils.InArrayByStr(openIdArr, v) {
  531. openIdArr = append(openIdArr, v)
  532. }
  533. }
  534. }
  535. redirectUrl = utils.WX_MSG_PATH_ACTIVITY_DETAIL + strconv.Itoa(activityId) + "&IsSendWx=1"
  536. sendInfo := new(services.SendWxTemplate)
  537. //sendInfo.First = first
  538. sendInfo.Keyword1 = keyword1
  539. sendInfo.Keyword2 = keyword2
  540. sendInfo.Keyword3 = keyword3
  541. sendInfo.Keyword4 = keyword4
  542. //sendInfo.Remark = remark
  543. sendInfo.TemplateId = utils.WxMsgTemplateIdActivityChangeApplyXzs
  544. sendInfo.RedirectUrl = redirectUrl
  545. sendInfo.RedirectTarget = 3
  546. sendInfo.Resource = strconv.Itoa(activityId)
  547. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ACTIVITY_CACLE
  548. sendInfo.OpenIdArr = openIdArr
  549. err = services.SendTemplateMsg(sendInfo)
  550. return
  551. }