wechat_send_category_template_msg.go 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  1. package services
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "fmt"
  6. "hongze/hongze_clpt/models"
  7. "hongze/hongze_clpt/utils"
  8. "io/ioutil"
  9. "net/http"
  10. "strconv"
  11. "strings"
  12. "time"
  13. "unicode"
  14. )
  15. type SendWxCategoryTemplate struct {
  16. WxAppId string `description:"公众号appId"`
  17. Keywords []string `description:"模板消息keyword字段"`
  18. TemplateId string `description:"模板id"`
  19. RedirectUrl string `description:"跳转地址"`
  20. RedirectTarget int `description:"小程序跳转目标:1:弘则研报小程序,2:随手办公小程序,3:查研观向,4:买方研选"`
  21. Resource string `description:"资源唯一标识"`
  22. SendType int `description:"发送的消息类型:1:报告,2:指标更新提醒,3:审批通知,4:销售领取客户通知,5:活动取消通知,6活动更改时间通知,7:关注的作者发布报告通知,8:发送日报(周报、双周报、月报)模板消息,9:活动预约/报名时间通知"`
  23. OpenIdArr []string `description:"消息接收者openid"`
  24. }
  25. // 推送类目模板消息
  26. func SendCategoryTemplateMsg(sendInfo *SendWxCategoryTemplate) (err error) {
  27. //没有获取到openID不推送
  28. if len(sendInfo.OpenIdArr) == 0 {
  29. return
  30. }
  31. postData, err := json.Marshal(sendInfo)
  32. if err != nil {
  33. utils.SendAlarmMsg("SendCategoryTemplateMsg json.Marshal Err:"+err.Error(), 1)
  34. return err
  35. }
  36. body := ioutil.NopCloser(strings.NewReader(string(postData)))
  37. client := &http.Client{}
  38. req, err := http.NewRequest("POST", utils.SendWxCategoryTemplateMsgUrl, body)
  39. if err != nil {
  40. utils.SendAlarmMsg("SendCategoryTemplateMsg http.NewRequest Err:"+err.Error(), 1)
  41. return err
  42. }
  43. contentType := "application/json;charset=utf-8"
  44. req.Header.Set("Content-Type", contentType)
  45. req.Header.Set("Authorization", utils.SendTemplateMsgAuthorization)
  46. resp, err := client.Do(req)
  47. if err != nil {
  48. fmt.Println("http client.Do Err:" + err.Error())
  49. return err
  50. }
  51. defer resp.Body.Close()
  52. b, err := ioutil.ReadAll(resp.Body)
  53. if err != nil {
  54. return err
  55. }
  56. result := new(models.BaseResponse)
  57. err = json.Unmarshal(b, &result)
  58. if err != nil {
  59. return err
  60. }
  61. if result.Ret != 200 {
  62. err = errors.New(string(b))
  63. return err
  64. }
  65. return
  66. }
  67. // 研选专栏审核完成时,给提交人发送类目模板消息
  68. func SendWxCategoryMsgSpecialAuthor(specialId, status int) (err error) {
  69. defer func() {
  70. if err != nil {
  71. go utils.SendAlarmMsg(fmt.Sprint("研选专栏审核完成时,给提交人发送模板消息", specialId, ", specialId", err.Error()), 2)
  72. }
  73. }()
  74. var keyword1 string
  75. var keyword2 string
  76. var keyword3 string
  77. var keyword4 string
  78. var redirectUrl string
  79. specialItem, e := models.GetYanxuanSpecialItemById(specialId)
  80. if e != nil {
  81. err = errors.New("GetYanxuanSpecialFollowUserById, Err: " + e.Error())
  82. return
  83. }
  84. user, e := models.GetWxUserItemByUserId(specialItem.UserId)
  85. if e != nil {
  86. err = errors.New("GetWxUserItemByUserId, Err: " + e.Error())
  87. return err
  88. }
  89. openIdList, err := models.GetMfyxUserRecordListByMobile(12, user.Mobile)
  90. if err != nil && err.Error() != utils.ErrNoRow() {
  91. return err
  92. }
  93. keyword1 = utils.TruncateActivityNameString(specialItem.Title)
  94. keyword2 = specialItem.NickName
  95. if status == 1 {
  96. keyword3 = "文章已通过审核,点击查看详情"
  97. redirectUrl = utils.WX_MSG_PATH_YX_SPECIAL_DETAIL + strconv.Itoa(specialId)
  98. } else {
  99. keyword3 = "文章未通过审核,点击查看驳回原因"
  100. redirectUrl = utils.WX_MSG_PATH_YX_SPECIAL_CENTER
  101. }
  102. keyword4 = time.Now().Format(utils.FormatDateTimeMinute2)
  103. openIdArr := make([]string, 0)
  104. for _, v := range openIdList {
  105. openIdArr = append(openIdArr, v.OpenId)
  106. }
  107. keywords := []string{keyword1, keyword2, keyword3, keyword4}
  108. sendInfo := new(SendWxCategoryTemplate)
  109. sendInfo.Keywords = keywords
  110. sendInfo.TemplateId = utils.WxMsgCategoryTemplateIdCompanyApprovalMessageRai
  111. sendInfo.RedirectTarget = 4
  112. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ARTICLE_ADD
  113. sendInfo.OpenIdArr = openIdArr
  114. sendInfo.RedirectUrl = redirectUrl
  115. err = SendCategoryTemplateMsg(sendInfo)
  116. if err != nil {
  117. return
  118. }
  119. return
  120. }
  121. // 研选专栏有新内容审核通过时,给关注此专栏的客户发送模板消息
  122. func SendWxCategoryMsgSpecialFollow(specialId int) (err error) {
  123. defer func() {
  124. if err != nil {
  125. go utils.SendAlarmMsg(fmt.Sprint("研选专栏有新内容审核通过时,给关注此专栏的客户发送类目模板消息失败", specialId, ", specialId", err.Error()), 2)
  126. }
  127. }()
  128. var keyword1 string
  129. var keyword2 string
  130. var keyword3 string
  131. var keyword4 string
  132. followers, e := models.GetYanxuanSpecialFollowUserById(specialId)
  133. if e != nil {
  134. err = errors.New("GetYanxuanSpecialFollowUserById, Err: " + e.Error())
  135. return
  136. }
  137. if len(followers) == 0 {
  138. return
  139. }
  140. specialItem, e := models.GetYanxuanSpecialItemById(specialId)
  141. if e != nil {
  142. err = errors.New("GetYanxuanSpecialFollowUserById, Err: " + e.Error())
  143. return
  144. }
  145. var allInUserId string
  146. for _, v := range followers {
  147. allInUserId += strconv.Itoa(v) + ","
  148. }
  149. allInUserId = strings.TrimRight(allInUserId, ",")
  150. userList, err := models.GetWxUserListByUserIds(allInUserId)
  151. if err != nil && err.Error() != utils.ErrNoRow() {
  152. return err
  153. }
  154. mobile := ``
  155. for _, v := range userList {
  156. mobile += v.Mobile + ","
  157. }
  158. mobile = strings.TrimRight(mobile, ",")
  159. openIdList, e := models.GetMfyxWxOpenIdByMobileList(mobile)
  160. if e != nil {
  161. err = errors.New("GetSellerByAdminId, Err: " + e.Error())
  162. return
  163. }
  164. if len(openIdList) == 0 {
  165. return
  166. }
  167. keyword1 = specialItem.SpecialName
  168. keyword2 = "发布了新报告"
  169. keyword3 = specialItem.Title
  170. keyword4 = time.Now().Format(utils.FormatDateTimeMinute2)
  171. openIdArr := make([]string, 0)
  172. for _, v := range openIdList {
  173. openIdArr = append(openIdArr, v.OpenId)
  174. }
  175. redirectUrl := ""
  176. redirectUrl = utils.WX_MSG_PATH_YX_SPECIAL_DETAIL + strconv.Itoa(specialId)
  177. keywords := []string{keyword1, keyword2, keyword3, keyword4}
  178. sendInfo := new(SendWxCategoryTemplate)
  179. sendInfo.Keywords = keywords
  180. sendInfo.TemplateId = utils.WxMsgCategoryTemplateIdActivityPublishApply
  181. sendInfo.RedirectTarget = 4
  182. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ARTICLE_ADD
  183. sendInfo.OpenIdArr = openIdArr
  184. sendInfo.RedirectUrl = redirectUrl
  185. err = SendCategoryTemplateMsg(sendInfo)
  186. if err != nil {
  187. return
  188. }
  189. return
  190. }
  191. // SendReviewCategoryTemplateMsgAdmin 提交审核时给王芳,汪洋发消息
  192. func SendReviewCategoryTemplateMsgAdmin(specialId int) (err error) {
  193. defer func() {
  194. if err != nil {
  195. go utils.SendAlarmMsg(fmt.Sprint("处理试用申请给王芳,汪洋发消息失败, specialId:", specialId, "ErrMsg", err.Error()), 2)
  196. }
  197. }()
  198. var configCode string
  199. //研选专栏修改之后给这些手机号推送审核模版消息
  200. configCode = utils.TPL_MSG_YAN_XUAN_SPECIAL_APPROVAL
  201. cnf, e := models.GetConfigByCode(configCode)
  202. if e != nil {
  203. err = errors.New("GetConfigByCode, Err: " + e.Error() + configCode)
  204. return
  205. }
  206. //王芳、葛琳和沈涛
  207. openIdList, e := models.GetMfyxWxOpenIdByMobileList(cnf.ConfigValue)
  208. if e != nil {
  209. err = errors.New("GetMfyxWxOpenIdByMobileList, Err: " + e.Error())
  210. return err
  211. }
  212. if len(openIdList) == 0 {
  213. return
  214. }
  215. specialItem, e := models.GetYanxuanSpecialItemById(specialId)
  216. if e != nil {
  217. err = errors.New("GetYanxuanSpecialFollowUserById, Err: " + e.Error())
  218. return
  219. }
  220. user, e := models.GetWxUserItemByUserId(specialItem.UserId)
  221. if e != nil {
  222. err = errors.New("GetWxUserItemByUserId, Err: " + e.Error())
  223. return err
  224. }
  225. var keyword1 string
  226. var keyword2 string
  227. var keyword3 string
  228. var keyword4 string
  229. var keyword5 string
  230. keyword1 = checkNickNameString(specialItem.NickName)
  231. keyword2 = specialItem.RealName + "-" + user.CompanyName
  232. keyword2 = utils.TruncateActivityNameString(keyword2)
  233. keyword3 = checkSpecialNameString(specialItem.SpecialName)
  234. keyword4 = time.Now().Format(utils.FormatDateTimeMinute2)
  235. keyword5 = "研选专栏提交了内容待审核"
  236. openIdArr := make([]string, 0)
  237. for _, v := range openIdList {
  238. openIdArr = append(openIdArr, v.OpenId)
  239. }
  240. redirectUrl := ""
  241. redirectUrl = utils.WX_MSG_PATH_YX_SPECIAL_ENABLE_DETAIL + strconv.Itoa(specialId)
  242. keywords := []string{keyword1, keyword2, keyword3, keyword4, keyword5}
  243. sendInfo := new(SendWxCategoryTemplate)
  244. sendInfo.Keywords = keywords
  245. sendInfo.TemplateId = utils.WxCategoryMsgTemplateIdApplyXzs
  246. sendInfo.RedirectTarget = 4
  247. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ARTICLE_ADD
  248. sendInfo.OpenIdArr = openIdArr
  249. sendInfo.RedirectUrl = redirectUrl
  250. err = SendCategoryTemplateMsg(sendInfo)
  251. if err != nil {
  252. return
  253. }
  254. return
  255. }
  256. func checkNickNameString(s string) string {
  257. var trimmedString string
  258. hanCount := 0
  259. for _, r := range s {
  260. if unicode.Is(unicode.Han, r) {
  261. trimmedString += string(r)
  262. hanCount++
  263. if hanCount == 5 {
  264. break
  265. }
  266. } else {
  267. return "作者昵称"
  268. }
  269. }
  270. if trimmedString == "" {
  271. trimmedString = "作者昵称"
  272. }
  273. return trimmedString
  274. }
  275. func checkSpecialNameString(s string) string {
  276. var trimmedString string
  277. hanCount := 0
  278. for _, r := range s {
  279. if unicode.Is(unicode.Han, r) {
  280. trimmedString += string(r)
  281. hanCount++
  282. if hanCount == 5 {
  283. break
  284. }
  285. } else {
  286. return "专栏名称"
  287. }
  288. }
  289. if trimmedString == "" {
  290. trimmedString = "专栏名称"
  291. }
  292. return trimmedString
  293. }
  294. // 发送活动提问消息提醒(研选公众号类目模版消息)
  295. func SendWxCategoryMsgWithAsk(user *models.WxUserItem, activityInfo *models.ActivityDetail, askMsg string, askId int) (err error) {
  296. if activityInfo.ChartPermissionId != utils.CHART_PERMISSION_ID_YANXUAN {
  297. return
  298. }
  299. defer func() {
  300. if err != nil {
  301. fmt.Println(err)
  302. go utils.SendAlarmMsg(fmt.Sprint("发送活动提问消息提醒类目模版消息失败,用户名", user.RealName, "提问ID:", askId), 2)
  303. }
  304. }()
  305. companyId := user.CompanyId
  306. var sellerName string
  307. //潜在客户、未开权益,已开FICC的客户推给王芳,开通权益的客户推给对应销售
  308. mobile := utils.WxMsgTemplateIdAskMsgMobilePublic
  309. if companyId > 1 {
  310. raiCount, e := models.GetCompanyProductCount(companyId, utils.COMPANY_PRODUCT_RAI_ID)
  311. if e != nil {
  312. err = errors.New("GetCompanyProductCount, Err: " + e.Error())
  313. return
  314. }
  315. if raiCount > 0 {
  316. sealldetail, e := models.GetRaiSellerByCompanyId(companyId)
  317. if e != nil {
  318. err = errors.New("GetRaiSellerByCompanyId, Err: " + e.Error())
  319. return
  320. }
  321. sellerName = sealldetail.RealName
  322. mobile += "," + sealldetail.Mobile
  323. }
  324. }
  325. var mobiles []string
  326. mobiles = append(mobiles, utils.RAI_MOBILE_GAO_YI_WEN, utils.RAI_MOBILE_DONG_HENG, utils.RAI_MOBILE_WU_ANG_DI, utils.RAI_MOBILE_GE_LIN) //葛琳、高亦文、董衡、吴昂迪手机号
  327. mobile += "," + strings.Join(mobiles, ",")
  328. openIdList, e := models.GetMfyxWxOpenIdByMobileList(mobile)
  329. if e != nil {
  330. err = errors.New("GetMfyxWxOpenIdByMobileList, Err: " + e.Error())
  331. return err
  332. }
  333. if len(openIdList) == 0 {
  334. return
  335. }
  336. var keyword1 string
  337. var keyword2 string
  338. var keyword3 string
  339. var keyword4 string
  340. var keyword5 string
  341. keyword1 = user.RealName
  342. keyword2 = utils.TruncateActivityNameString(user.CompanyName)
  343. keyword3 = sellerName
  344. keyword4 = time.Now().Format(utils.FormatDateTimeMinute2)
  345. keyword5 = utils.TruncateActivityNameString("活动提问:" + askMsg)
  346. keywords := []string{keyword1, keyword2, keyword3, keyword4, keyword5}
  347. openIdArr := make([]string, 0)
  348. for _, v := range openIdList {
  349. openIdArr = append(openIdArr, v.OpenId)
  350. }
  351. redirectUrl := utils.WX_MSG_PATH_TEMPLATE_MSG + "SourceId=" + strconv.Itoa(askId) + "&SourceType=2"
  352. //redirectUrl = ""
  353. sendInfo := new(SendWxCategoryTemplate)
  354. sendInfo.Keywords = keywords
  355. sendInfo.TemplateId = utils.WxCategoryMsgTemplateIdApplyXzs
  356. sendInfo.RedirectTarget = 4
  357. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ARTICLE_ADD
  358. sendInfo.OpenIdArr = openIdArr
  359. sendInfo.RedirectUrl = redirectUrl
  360. err = SendCategoryTemplateMsg(sendInfo)
  361. return
  362. }
  363. // 用户报名模板消息推送(研选公众号类目模版消息)
  364. func SendNeiRongZuActivitieSignCategoryTemplateMsg(user *models.WxUserItem, activityDetail *models.ActivityDetail) (err error) {
  365. if activityDetail.ChartPermissionId != utils.CHART_PERMISSION_ID_YANXUAN {
  366. return
  367. }
  368. defer func() {
  369. if err != nil {
  370. go utils.SendAlarmMsg(fmt.Sprint("发送用户操作活动消息提醒,文章ID:", activityDetail.ActivityId), 2)
  371. fmt.Println(err)
  372. }
  373. }()
  374. sellerItemQy, e := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  375. if e != nil && e.Error() != utils.ErrNoRow() {
  376. return
  377. }
  378. var mobile string
  379. var sellerRealName string
  380. var mobiles []string
  381. mobiles = append(mobiles, utils.RAI_MOBILE_GAO_YI_WEN, utils.RAI_MOBILE_DONG_HENG, utils.RAI_MOBILE_WU_ANG_DI, utils.MobileShenTao, utils.MobileZhangChuanXin) //高亦文、董衡、吴昂迪手机号
  382. if sellerItemQy != nil {
  383. mobiles = append(mobiles, sellerItemQy.Mobile)
  384. sellerRealName = sellerItemQy.RealName
  385. } else {
  386. sellerRealName = "__"
  387. }
  388. mobile = strings.Join(mobiles, ",")
  389. openIdList, e := models.GetMfyxWxOpenIdByMobileList(mobile)
  390. if e != nil {
  391. err = errors.New("GetMfyxWxOpenIdByMobileList, Err: " + e.Error())
  392. return err
  393. }
  394. if len(openIdList) == 0 {
  395. err = nil
  396. return
  397. }
  398. openIdArr := make([]string, 0)
  399. for _, v := range openIdList {
  400. openIdArr = append(openIdArr, v.OpenId)
  401. }
  402. var keywords []string
  403. keywords = append(keywords, user.RealName, user.CompanyName, sellerRealName, time.Now().Format(utils.FormatDateTimeMinute2), utils.TruncateActivityNameString("报名:"+activityDetail.ActivityName))
  404. redirectUrl := utils.WX_MSG_PATH_YX_ACTIVITY_DETAIL + strconv.Itoa(activityDetail.ActivityId) //活动详情地址
  405. sendInfo := new(SendWxCategoryTemplate)
  406. sendInfo.Keywords = keywords
  407. sendInfo.TemplateId = utils.WxCategoryMsgTemplateIdApplyXzs
  408. sendInfo.RedirectTarget = 4
  409. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_APPLY
  410. sendInfo.OpenIdArr = openIdArr
  411. sendInfo.RedirectUrl = redirectUrl
  412. err = SendCategoryTemplateMsg(sendInfo)
  413. return
  414. }
  415. // 用户取消报名模板消息推送(研选公众号类目模版消息)
  416. func SendActivitieCancelSignCategoryTemplateMsg(user *models.WxUserItem, activityDetail *models.ActivityDetail) (err error) {
  417. if activityDetail.ChartPermissionId != utils.CHART_PERMISSION_ID_YANXUAN {
  418. return
  419. }
  420. defer func() {
  421. if err != nil {
  422. fmt.Println(err)
  423. go utils.SendAlarmMsg(fmt.Sprint("发送用户操作活动消息提醒,活动ID:", activityDetail.ActivityId), 2)
  424. }
  425. }()
  426. sellerItemQy, e := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  427. if e != nil && e.Error() != utils.ErrNoRow() {
  428. return
  429. }
  430. var mobile string
  431. var sellerRealName string
  432. var mobiles []string
  433. mobiles = append(mobiles, utils.RAI_MOBILE_GAO_YI_WEN, utils.RAI_MOBILE_DONG_HENG, utils.RAI_MOBILE_WU_ANG_DI, utils.MobileShenTao, utils.MobileZhangChuanXin) //高亦文、董衡、吴昂迪手机号
  434. if sellerItemQy != nil {
  435. mobiles = append(mobiles, sellerItemQy.Mobile)
  436. sellerRealName = sellerItemQy.RealName
  437. } else {
  438. sellerRealName = "__"
  439. }
  440. mobile = strings.Join(mobiles, ",")
  441. openIdList, e := models.GetMfyxWxOpenIdByMobileList(mobile)
  442. if e != nil {
  443. err = errors.New("GetMfyxWxOpenIdByMobileList, Err: " + e.Error())
  444. return err
  445. }
  446. if len(openIdList) == 0 {
  447. err = nil
  448. return
  449. }
  450. openIdArr := make([]string, 0)
  451. for _, v := range openIdList {
  452. openIdArr = append(openIdArr, v.OpenId)
  453. }
  454. var keywords []string
  455. keywords = append(keywords, user.RealName, user.CompanyName, sellerRealName, time.Now().Format(utils.FormatDateTimeMinute2), utils.TruncateActivityNameString("取消报名:"+activityDetail.ActivityName))
  456. redirectUrl := utils.WX_MSG_PATH_YX_ACTIVITY_DETAIL + strconv.Itoa(activityDetail.ActivityId) //活动详情地址
  457. sendInfo := new(SendWxCategoryTemplate)
  458. sendInfo.Keywords = keywords
  459. sendInfo.TemplateId = utils.WxCategoryMsgTemplateIdApplyXzs
  460. sendInfo.RedirectTarget = 4
  461. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_APPLY
  462. sendInfo.OpenIdArr = openIdArr
  463. sendInfo.RedirectUrl = redirectUrl
  464. err = SendCategoryTemplateMsg(sendInfo)
  465. return
  466. }
  467. // 研选类目模板消息
  468. func SendPermissionApplyTemplateMsgAdminByYxCategory(req models.ApplyTryReq, companyId int, usermobile, applyMethod, redirectUrl string) (err error) {
  469. defer func() {
  470. if err != nil {
  471. go utils.SendAlarmMsg("研选类目模板消息消息失败, SendPermissionApplyTemplateMsgAdminByYxCategoryErrMsg: "+err.Error(), 3)
  472. }
  473. }()
  474. //潜在客户、未开权益,已开FICC的客户推给王芳,开通权益的客户推给对应销售
  475. mobileOpenid := utils.WxMsgTemplateIdAskMsgMobilePublic
  476. if companyId > 1 {
  477. raiCount, e := models.GetCompanyProductCount(companyId, utils.COMPANY_PRODUCT_RAI_ID)
  478. if e != nil {
  479. err = errors.New("GetCompanyProductCount, Err: " + e.Error())
  480. return
  481. }
  482. if raiCount > 0 {
  483. sealldetail, e := models.GetRaiSellerByCompanyId(companyId)
  484. if e != nil {
  485. err = errors.New("GetRaiSellerByCompanyId, Err: " + e.Error())
  486. return
  487. }
  488. //如果有共享销售给共享销售也推模版消息
  489. if sealldetail.ShareSellerId > 0 {
  490. adminShare, e := models.GetSellerByAdminId(sealldetail.ShareSellerId)
  491. if e != nil {
  492. err = errors.New("GetSellerByAdminId, Err: " + e.Error())
  493. return
  494. }
  495. listSellerMobile, e := models.GetCygxSellerMobileMap()
  496. if e != nil {
  497. err = errors.New("GetCygxSellerMobileMap, Err: " + e.Error())
  498. return
  499. }
  500. //mapMobile := make(map[string]string)
  501. for _, vm := range listSellerMobile {
  502. if adminShare.Mobile == vm.ServerMobile {
  503. adminShare.Mobile = vm.Mobile
  504. }
  505. }
  506. mobileOpenid = sealldetail.Mobile + "," + adminShare.Mobile
  507. } else {
  508. mobileOpenid = sealldetail.Mobile
  509. }
  510. }
  511. }
  512. openIdList, e := models.GetMfyxWxOpenIdByMobileList(mobileOpenid)
  513. if e != nil {
  514. err = errors.New("GetMfyxWxOpenIdByMobileList, Err: " + e.Error())
  515. return err
  516. }
  517. if len(openIdList) == 0 {
  518. return
  519. }
  520. var keyword1 string
  521. var keyword2 string
  522. var keyword3 string
  523. var keyword4 string
  524. var keyword5 string
  525. keyword1 = req.RealName
  526. keyword2 = utils.TruncateActivityNameString(req.CompanyName)
  527. keyword3 = "权限申请"
  528. keyword4 = time.Now().Format(utils.FormatDateTimeMinute2)
  529. keyword5 = applyMethod
  530. openIdArr := make([]string, 0)
  531. for _, v := range openIdList {
  532. openIdArr = append(openIdArr, v.OpenId)
  533. }
  534. detail, e := models.GetCygxApplyRecordByMobile(usermobile)
  535. if e != nil {
  536. err = errors.New("GetCygxApplyRecordByMobile" + e.Error())
  537. return
  538. }
  539. //redirectUrl := ""
  540. //如果是潜在客户就推送可查看详情的模版消息
  541. if detail.ApplyMethod == 2 {
  542. redirectUrl = utils.WX_MSG_PATH_APPLY_DETAIL + strconv.Itoa(detail.ApplyRecordId)
  543. }
  544. keywords := []string{keyword1, keyword2, keyword3, keyword4, keyword5}
  545. sendInfo := new(SendWxCategoryTemplate)
  546. sendInfo.Keywords = keywords
  547. sendInfo.TemplateId = utils.WxCategoryMsgTemplateIdApplyXzs
  548. sendInfo.RedirectTarget = 4
  549. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ARTICLE_ADD
  550. sendInfo.OpenIdArr = openIdArr
  551. sendInfo.RedirectUrl = redirectUrl
  552. err = SendCategoryTemplateMsg(sendInfo)
  553. return
  554. }
  555. // 发送用户留言提醒(研选公众号类目模版消息)
  556. func SendCommentWxTemplateMsgByYxCategory(req models.AddCygxArticleCommentReq, user *models.WxUserItem, articleInfo *models.ArticleDetail, msgId int) (err error) {
  557. if articleInfo.ArticleTypeId == 0 {
  558. return // 非研选的文章不做推送
  559. }
  560. defer func() {
  561. if err != nil {
  562. go utils.SendAlarmMsg(fmt.Sprint("发送用户用户留言提醒失败,文章ID:", req.ArticleId, "err", err.Error()), 2)
  563. }
  564. }()
  565. companyItem, e := models.GetSellerDetailAllByCompanyId(user.CompanyId)
  566. if e != nil {
  567. return
  568. }
  569. if companyItem == nil {
  570. err = errors.New("获取客户所属销售信息失败")
  571. return
  572. }
  573. var keyword1 string
  574. var keyword2 string
  575. var keyword3 string
  576. var keyword4 string
  577. var keyword5 string
  578. var redirectUrl string
  579. var mobile string
  580. var keywords []string
  581. keyword1 = user.RealName
  582. keyword2 = utils.TruncateActivityNameString(companyItem.CompanyName)
  583. keyword3 = companyItem.SellerName
  584. keyword4 = time.Now().Format(utils.FormatDateTimeMinute2)
  585. keyword5 = "报告留言:" + req.Content
  586. keyword5 = utils.TruncateActivityNameString(keyword5)
  587. keywords = append(keywords, keyword1, keyword2, keyword3, keyword4, keyword5)
  588. var mobiles []string
  589. mobiles = append(mobiles, utils.RAI_MOBILE_GAO_YI_WEN, utils.RAI_MOBILE_DONG_HENG, utils.RAI_MOBILE_WU_ANG_DI, utils.RAI_MOBILE_GE_LIN) //葛琳、高亦文、董衡、吴昂迪手机号
  590. mobile = companyItem.Mobile + "," + utils.WxMsgTemplateIdAskMsgMobilePublic + "," + strings.Join(mobiles, ",")
  591. //mobile =
  592. openIdList, e := models.GetMfyxWxOpenIdByMobileList(mobile)
  593. if e != nil {
  594. err = errors.New("GetMfyxWxOpenIdByMobileList, Err: " + e.Error())
  595. return
  596. }
  597. if len(openIdList) == 0 {
  598. return
  599. }
  600. openIdArr := make([]string, 0)
  601. for _, v := range openIdList {
  602. openIdArr = append(openIdArr, v.OpenId)
  603. }
  604. redirectUrl = utils.WX_MSG_PATH_TEMPLATE_MSG + "SourceId=" + strconv.Itoa(msgId) + "&SourceType=1"
  605. sendInfo := new(SendWxCategoryTemplate)
  606. sendInfo.Keywords = keywords
  607. sendInfo.TemplateId = utils.WxCategoryMsgTemplateIdApplyXzs
  608. sendInfo.RedirectTarget = 4
  609. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_APPLY
  610. sendInfo.OpenIdArr = openIdArr
  611. sendInfo.RedirectUrl = redirectUrl
  612. err = SendCategoryTemplateMsg(sendInfo)
  613. return
  614. }
  615. // 发送用户操作活动消息提醒
  616. func SendWxCategoryMsgWithActivityUserRemind(keyWord1, keyWord2, keyWord3, keyWord4, redirectUrl string, openIdList []*models.OpenIdList, activityId int) (err error) {
  617. if len(openIdList) == 0 {
  618. return
  619. }
  620. defer func() {
  621. if err != nil {
  622. go utils.SendAlarmMsg(fmt.Sprint("发送用户操作活动消息提醒,SendWxCategoryMsgWithActivityUserRemind 文章ID:", activityId), 2)
  623. }
  624. }()
  625. keyWord1 = utils.TruncateActivityNameString(keyWord1)
  626. openIdArr := make([]string, 0)
  627. for _, v := range openIdList {
  628. openIdArr = append(openIdArr, v.OpenId)
  629. }
  630. var keywords []string
  631. keywords = append(keywords, keyWord1, keyWord2, keyWord3, keyWord4)
  632. sendInfo := new(SendWxCategoryTemplate)
  633. sendInfo.Keywords = keywords
  634. sendInfo.TemplateId = utils.WxMsgCategoryTemplateIdActivityPublishApply
  635. sendInfo.RedirectTarget = 4
  636. sendInfo.RedirectUrl = redirectUrl
  637. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_APPLY
  638. sendInfo.OpenIdArr = openIdArr
  639. err = SendCategoryTemplateMsg(sendInfo)
  640. return
  641. }