wx_category_template_msg.go 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106
  1. package services
  2. import (
  3. "context"
  4. "encoding/json"
  5. "errors"
  6. "fmt"
  7. "hongze/hongze_cygx/models"
  8. "hongze/hongze_cygx/utils"
  9. "io/ioutil"
  10. "net/http"
  11. "strconv"
  12. "strings"
  13. "time"
  14. "unicode"
  15. )
  16. type SendWxCategoryTemplate struct {
  17. WxAppId string `description:"公众号appId"`
  18. Keywords []string `description:"模板消息keyword字段"`
  19. TemplateId string `description:"模板id"`
  20. RedirectUrl string `description:"跳转地址"`
  21. RedirectTarget int `description:"小程序跳转目标:1:弘则研报小程序,2:随手办公小程序,3:查研观向,4:买方研选"`
  22. Resource string `description:"资源唯一标识"`
  23. SendType int `description:"发送的消息类型:1:报告,2:指标更新提醒,3:审批通知,4:销售领取客户通知,5:活动取消通知,6活动更改时间通知,7:关注的作者发布报告通知,8:发送日报(周报、双周报、月报)模板消息,9:活动预约/报名时间通知"`
  24. OpenIdArr []string `description:"消息接收者openid"`
  25. }
  26. // 推送类目模板消息
  27. func SendCategoryTemplateMsg(sendInfo *SendWxCategoryTemplate) (err error) {
  28. if len(sendInfo.OpenIdArr) == 0 {
  29. return
  30. }
  31. postData, err := json.Marshal(sendInfo)
  32. if err != nil {
  33. go 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. go 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. // 研选类目模板消息
  69. func SendPermissionApplyTemplateMsgAdminByYxCategory(req models.ApplyTryReq, companyId int, usermobile, applyMethod, redirectUrl string) (err error) {
  70. defer func() {
  71. if err != nil {
  72. go utils.SendAlarmMsg("研选类目模板消息消息失败, SendPermissionApplyTemplateMsgAdminByYxCategoryErrMsg: "+err.Error(), 3)
  73. }
  74. }()
  75. //潜在客户、未开权益,已开FICC的客户推给王芳,开通权益的客户推给对应销售
  76. mobileOpenid := utils.WxMsgTemplateIdAskMsgMobilePublic
  77. if companyId > 1 {
  78. raiCount, e := models.GetCompanyProductCount(companyId, utils.COMPANY_PRODUCT_RAI_ID)
  79. if e != nil {
  80. err = errors.New("GetCompanyProductCount, Err: " + e.Error())
  81. return
  82. }
  83. if raiCount > 0 {
  84. sealldetail, e := models.GetRaiSellerByCompanyId(companyId)
  85. if e != nil {
  86. err = errors.New("GetRaiSellerByCompanyId, Err: " + e.Error())
  87. return
  88. }
  89. //如果有共享销售给共享销售也推模版消息
  90. if sealldetail.ShareSellerId > 0 {
  91. adminShare, e := models.GetSellerByAdminId(sealldetail.ShareSellerId)
  92. if e != nil {
  93. err = errors.New("GetSellerByAdminId, Err: " + e.Error())
  94. return
  95. }
  96. listSellerMobile, e := models.GetCygxSellerMobileMap()
  97. if e != nil {
  98. err = errors.New("GetCygxSellerMobileMap, Err: " + e.Error())
  99. return
  100. }
  101. //mapMobile := make(map[string]string)
  102. for _, vm := range listSellerMobile {
  103. if adminShare.Mobile == vm.ServerMobile {
  104. adminShare.Mobile = vm.Mobile
  105. }
  106. }
  107. mobileOpenid = sealldetail.Mobile + "," + adminShare.Mobile
  108. } else {
  109. mobileOpenid = sealldetail.Mobile
  110. }
  111. }
  112. }
  113. openIdList, e := models.GetMfyxWxOpenIdByMobileList(mobileOpenid)
  114. if e != nil {
  115. err = errors.New("GetMfyxWxOpenIdByMobileList, Err: " + e.Error())
  116. return err
  117. }
  118. if len(openIdList) == 0 {
  119. return
  120. }
  121. var keyword1 string
  122. var keyword2 string
  123. var keyword3 string
  124. var keyword4 string
  125. var keyword5 string
  126. keyword1 = req.RealName
  127. keyword2 = utils.TruncateActivityNameString(req.CompanyName)
  128. keyword3 = "权限申请"
  129. keyword4 = time.Now().Format(utils.FormatDateTimeMinute2)
  130. keyword5 = applyMethod
  131. openIdArr := make([]string, 0)
  132. for _, v := range openIdList {
  133. openIdArr = append(openIdArr, v.OpenId)
  134. }
  135. detail, e := models.GetCygxApplyRecordByMobile(usermobile)
  136. if e != nil {
  137. err = errors.New("GetCygxApplyRecordByMobile" + e.Error())
  138. return
  139. }
  140. //redirectUrl := ""
  141. //如果是潜在客户就推送可查看详情的模版消息
  142. if detail.ApplyMethod == 2 {
  143. redirectUrl = utils.WX_MSG_PATH_APPLY_DETAIL + strconv.Itoa(detail.ApplyRecordId)
  144. }
  145. keywords := []string{keyword1, keyword2, keyword3, keyword4, keyword5}
  146. sendInfo := new(SendWxCategoryTemplate)
  147. sendInfo.Keywords = keywords
  148. sendInfo.TemplateId = utils.WxCategoryMsgTemplateIdApplyXzs
  149. sendInfo.RedirectTarget = 4
  150. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ARTICLE_ADD
  151. sendInfo.OpenIdArr = openIdArr
  152. sendInfo.RedirectUrl = redirectUrl
  153. err = SendCategoryTemplateMsg(sendInfo)
  154. return
  155. }
  156. // 用户模块End
  157. // 报告模块
  158. // 发送用户留言提醒(研选公众号类目模版消息)
  159. func SendCommentWxTemplateMsgByYxCategory(req models.AddCygxArticleCommentReq, user *models.WxUserItem, articleInfo *models.ArticleDetail, msgId int) (err error) {
  160. if articleInfo.ArticleTypeId == 0 {
  161. return // 非研选的文章不做推送
  162. }
  163. defer func() {
  164. if err != nil {
  165. go utils.SendAlarmMsg(fmt.Sprint("发送用户用户留言提醒失败,文章ID:", req.ArticleId, "err", err.Error()), 2)
  166. }
  167. }()
  168. companyItem, e := models.GetSellerDetailAllByCompanyId(user.CompanyId)
  169. if e != nil {
  170. return
  171. }
  172. if companyItem == nil {
  173. err = errors.New("获取客户所属销售信息失败")
  174. return
  175. }
  176. var keyword1 string
  177. var keyword2 string
  178. var keyword3 string
  179. var keyword4 string
  180. var keyword5 string
  181. var redirectUrl string
  182. var mobile string
  183. var keywords []string
  184. keyword1 = user.RealName
  185. keyword2 = utils.TruncateActivityNameString(companyItem.CompanyName)
  186. keyword3 = companyItem.SellerName
  187. keyword4 = time.Now().Format(utils.FormatDateTimeMinute2)
  188. keyword5 = "报告留言:" + req.Content
  189. keyword5 = utils.TruncateActivityNameString(keyword5)
  190. keywords = append(keywords, keyword1, keyword2, keyword3, keyword4, keyword5)
  191. var mobiles []string
  192. 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) //葛琳、高亦文、董衡、吴昂迪手机号
  193. mobile = companyItem.Mobile + "," + utils.WxMsgTemplateIdAskMsgMobilePublic + "," + strings.Join(mobiles, ",")
  194. //mobile =
  195. openIdList, e := models.GetMfyxWxOpenIdByMobileList(mobile)
  196. if e != nil {
  197. err = errors.New("GetMfyxWxOpenIdByMobileList, Err: " + e.Error())
  198. return
  199. }
  200. if len(openIdList) == 0 {
  201. return
  202. }
  203. openIdArr := make([]string, 0)
  204. for _, v := range openIdList {
  205. openIdArr = append(openIdArr, v.OpenId)
  206. }
  207. redirectUrl = utils.WX_MSG_PATH_TEMPLATE_MSG + "SourceId=" + strconv.Itoa(msgId) + "&SourceType=1"
  208. sendInfo := new(SendWxCategoryTemplate)
  209. sendInfo.Keywords = keywords
  210. sendInfo.TemplateId = utils.WxCategoryMsgTemplateIdApplyXzs
  211. sendInfo.RedirectTarget = 4
  212. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_APPLY
  213. sendInfo.OpenIdArr = openIdArr
  214. sendInfo.RedirectUrl = redirectUrl
  215. err = SendCategoryTemplateMsg(sendInfo)
  216. return
  217. }
  218. // 发送报告提问消息提醒
  219. func SendWxCategoryMsgWithActivityAsk(companyName, realName, sellerName, askTime, askMsg string, openIdList []*models.OpenIdList, msgId int) (err error) {
  220. if len(openIdList) == 0 {
  221. return
  222. }
  223. defer func() {
  224. if err != nil {
  225. go utils.SendAlarmMsg(fmt.Sprint("发送报告提问消息提醒类目模版消息失败,用户名", realName, "留言ID:", msgId), 2)
  226. }
  227. }()
  228. var keyword1 string
  229. var keyword2 string
  230. var keyword3 string
  231. var keyword4 string
  232. var keyword5 string
  233. keyword1 = realName
  234. keyword2 = companyName
  235. keyword3 = sellerName
  236. keyword4 = askTime
  237. keyword5 = utils.TruncateActivityNameString("活动提问:" + askMsg)
  238. keywords := []string{keyword1, keyword2, keyword3, keyword4, keyword5}
  239. openIdArr := make([]string, 0)
  240. for _, v := range openIdList {
  241. openIdArr = append(openIdArr, v.OpenId)
  242. }
  243. redirectUrl := utils.WX_MSG_PATH_YX_ACTIVITY_DETAIL + strconv.Itoa(msgId)
  244. sendInfo := new(SendWxCategoryTemplate)
  245. sendInfo.Keywords = keywords
  246. sendInfo.TemplateId = utils.WxCategoryMsgTemplateIdApplyXzs
  247. sendInfo.RedirectTarget = 4
  248. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ARTICLE_ADD
  249. sendInfo.OpenIdArr = openIdArr
  250. sendInfo.RedirectUrl = redirectUrl
  251. err = SendCategoryTemplateMsg(sendInfo)
  252. if err != nil {
  253. return
  254. }
  255. return
  256. }
  257. //报告模块END
  258. // 活动模块
  259. // 帮我带问的问题,会前1小时发送
  260. func SendMfyxEmailFileForAskMsgResearch(cont context.Context) (err error) {
  261. var msg string
  262. //var touser string
  263. defer func() {
  264. if err != nil {
  265. go utils.SendAlarmMsg("发送附件模版消息失败:"+err.Error(), 2)
  266. go utils.SendEmail("发送附件模版消息失败"+"【"+utils.APPNAME+"】"+time.Now().Format(utils.FormatDateTime), msg+";Err:"+err.Error(), utils.EmailSendToUsers)
  267. }
  268. if msg != "" {
  269. go utils.SendAlarmMsg(msg, 2)
  270. utils.FileLog.Info("发送模版消息失败,msg:%s", msg)
  271. }
  272. }()
  273. endDate := time.Now().Add(+time.Minute * 60).Format(utils.FormatDateTime)
  274. condition := `AND a.activity_type_id = 1 AND a.chart_permission_id = 31 `
  275. total, err := models.GetCountActivityResearchToSendFile(condition, endDate)
  276. if total == 0 {
  277. fmt.Println("发送附件完成0")
  278. return nil
  279. }
  280. if err != nil {
  281. msg = "发送附件模版消息失败 Err:" + err.Error()
  282. return
  283. }
  284. listActivity, err := models.GetActivityResearchToSendFile(condition, endDate)
  285. if err != nil {
  286. msg = "发送附件模版消息失败 Err:" + err.Error()
  287. return
  288. }
  289. for _, v := range listActivity {
  290. activityInfo, _ := models.GetAddActivityInfoById(v.ActivityId)
  291. if activityInfo == nil {
  292. msg = "活动不存在,Err:activityId:" + strconv.Itoa(v.ActivityId)
  293. return
  294. }
  295. list, errFile := models.GetActivityMsgExport(v.ActivityId)
  296. if errFile != nil {
  297. msg = "获取失败,Err:" + errFile.Error()
  298. return
  299. }
  300. for _, v2 := range list {
  301. user, e := models.GetWxUserItemByUserId(v2.UserId)
  302. if e != nil && e.Error() != utils.ErrNoRow() {
  303. err = errors.New("GetWxUserItemByUserId, Err: " + e.Error())
  304. return err
  305. }
  306. //获取销售信息
  307. sellerItem, e := models.GetSellerByCompanyIdCheckFicc(v2.CompanyId, 2)
  308. if e != nil && e.Error() != utils.ErrNoRow() {
  309. err = errors.New("GetSellerByCompanyIdCheckFicc, Err: " + e.Error())
  310. return
  311. }
  312. //给所属销售推送消息
  313. if sellerItem != nil && user != nil {
  314. openIpItem, _ := models.GetMfyxUserRecordByMobile(12, sellerItem.Mobile)
  315. openIdList := make([]*models.OpenIdList, 0)
  316. openIdList = append(openIdList, openIpItem)
  317. SendWxCategoryMsgWithActivityAsk(user.CompanyName, user.RealName, sellerItem.RealName, time.Now().Format(utils.FormatDateTimeMinute2), v2.Content, openIdList, v.ActivityId)
  318. }
  319. }
  320. errFile = models.UPdateActivityMsgToSendFile(v.ActivityId)
  321. if errFile != nil {
  322. msg = "获取失败,Err:" + errFile.Error()
  323. return
  324. }
  325. }
  326. return
  327. }
  328. // 推送会议开始消息提醒60分钟前
  329. func SendMfyxActivityBeginMsg(cont context.Context) (err error) {
  330. //func SendActivityBeginMsg() (err error) {
  331. defer func() {
  332. if err != nil {
  333. go utils.SendAlarmMsg("60分钟会议消息提醒失败"+err.Error(), 2)
  334. fmt.Println("发送失败,Err:", err.Error())
  335. }
  336. }()
  337. endDate := time.Now().Add(+time.Minute * 60).Format(utils.FormatDateTime)
  338. listActivity, err := models.GetMfyxActivitySendMsgListAll(endDate)
  339. fmt.Println(len(listActivity))
  340. if err != nil {
  341. fmt.Println("GetActivitySendMsgListAll Err:", err.Error())
  342. return
  343. }
  344. if len(listActivity) == 0 {
  345. return
  346. }
  347. //var remark = "点击查看活动详情"
  348. var signupIds string
  349. for _, v := range listActivity {
  350. signupIds += strconv.Itoa(v.Id) + ","
  351. //var reserveResults string
  352. //var first string
  353. openIdItem := new(models.OpenIdList)
  354. openIdItem.OpenId = v.OpenId
  355. openIdItem.UserId = v.UserId
  356. openIdList := make([]*models.OpenIdList, 0)
  357. openIdList = append(openIdList, openIdItem)
  358. openIdArr := make([]string, 0)
  359. for _, v := range openIdList {
  360. openIdArr = append(openIdArr, v.OpenId)
  361. }
  362. keywords := []string{utils.TruncateActivityNameString(v.ActivityName), v.ActivityTime}
  363. sendInfo := new(SendWxCategoryTemplate)
  364. sendInfo.Keywords = keywords
  365. sendInfo.TemplateId = utils.WxMsgCategoryTemplateIdArticleUserRemind
  366. sendInfo.RedirectTarget = 4
  367. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ARTICLE_ADD
  368. sendInfo.OpenIdArr = openIdArr
  369. sendInfo.RedirectUrl = utils.WX_MSG_PATH_YX_ACTIVITY_DETAIL + strconv.Itoa(v.ActivityId)
  370. err = SendCategoryTemplateMsg(sendInfo)
  371. if err != nil {
  372. return
  373. }
  374. }
  375. if len(signupIds) == 0 {
  376. return
  377. }
  378. signupIds = strings.TrimRight(signupIds, ",")
  379. err = models.UPdateSendedMsgStatus(signupIds)
  380. if err != nil {
  381. var msg string
  382. go utils.SendEmail("发送模版消息失败"+"【"+utils.APPNAME+"】"+time.Now().Format(utils.FormatDateTime), msg+";Err:"+err.Error(), utils.EmailSendToUsers)
  383. utils.FileLog.Info("发送模版消息失败,Err:%s", err.Error())
  384. }
  385. return
  386. }
  387. // 推送会议开始消息提醒15分钟前
  388. func SendMfyxActivityBeginMsgMeeting(cont context.Context) (err error) {
  389. //func SendActivityBeginMsgMeeting() (err error) {
  390. defer func() {
  391. if err != nil {
  392. go utils.SendAlarmMsg("15分钟会议消息提醒失败:"+err.Error(), 2)
  393. fmt.Println("发送失败,Err:", err.Error())
  394. }
  395. }()
  396. var condition string
  397. var pars []interface{}
  398. endDate := time.Now().Add(+time.Minute * 15).Format(utils.FormatDateTime)
  399. condition = ` AND activity_time <= ? AND activity_time >= NOW() AND publish_status = 1 `
  400. pars = append(pars, endDate)
  401. listActivity, e := models.GetCygxActivityList(condition, pars, 0, 100000)
  402. if e != nil && e.Error() != utils.ErrNoRow() {
  403. err = errors.New("GetCygxActivityList, Err: " + e.Error())
  404. return
  405. }
  406. if len(listActivity) == 0 {
  407. return
  408. }
  409. //var signupIds string
  410. //var remark = "点击查看活动详情"
  411. var activityIds []int
  412. //同一时间举办的活动不多所以这里循环查询
  413. for _, v := range listActivity {
  414. activityIds = append(activityIds, v.ActivityId)
  415. var mobiles []string
  416. pars = make([]interface{}, 0)
  417. condition = ` AND activity_id = ? AND is_send_wx_msg = 0 `
  418. pars = append(pars, v.ActivityId)
  419. //获取设置消息提醒的用户列表
  420. listxReminder, e := models.GetCygxReminderListByUser(condition, pars)
  421. if e != nil {
  422. err = errors.New("GetCygxReminderListByUser, Err: " + e.Error())
  423. return
  424. }
  425. for _, vReminder := range listxReminder {
  426. mobiles = append(mobiles, vReminder.Mobile)
  427. }
  428. pars = make([]interface{}, 0)
  429. condition = ` AND do_fail_type = 0 AND activity_id = ? AND signup_type = 1 AND is_send_wx_msg = 0 `
  430. pars = append(pars, v.ActivityId)
  431. //获取设置预约外呼的用户列表
  432. listSignup, e := models.GetActivitySignupList(condition, pars)
  433. if e != nil && e.Error() != utils.ErrNoRow() {
  434. err = errors.New("GetActivitySignupList, Err: " + e.Error())
  435. return
  436. }
  437. for _, vSignup := range listSignup {
  438. mobiles = append(mobiles, vSignup.Mobile)
  439. }
  440. //获取这些手机号对应的Openid
  441. listOpenid, e := models.GetMfyxUserRecordListByMobileArr(mobiles)
  442. if e != nil && e.Error() != utils.ErrNoRow() {
  443. err = errors.New("GetUserRecordListByMobileArr, Err: " + e.Error())
  444. return
  445. }
  446. openIdList := make([]*models.OpenIdList, 0)
  447. for _, vOpenid := range listOpenid {
  448. openIdItem := new(models.OpenIdList)
  449. openIdItem.OpenId = vOpenid.OpenId
  450. openIdItem.UserId = vOpenid.UserId
  451. openIdList = append(openIdList, openIdItem)
  452. }
  453. openIdArr := make([]string, 0)
  454. for _, v := range openIdList {
  455. openIdArr = append(openIdArr, v.OpenId)
  456. }
  457. keywords := []string{utils.TruncateActivityNameString(v.ActivityName), v.ActivityTime}
  458. sendInfo := new(SendWxCategoryTemplate)
  459. sendInfo.Keywords = keywords
  460. sendInfo.TemplateId = utils.WxMsgCategoryTemplateIdArticleUserRemind
  461. sendInfo.RedirectTarget = 4
  462. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ARTICLE_ADD
  463. sendInfo.OpenIdArr = openIdArr
  464. sendInfo.RedirectUrl = utils.WX_MSG_PATH_YX_ACTIVITY_DETAIL + strconv.Itoa(v.ActivityId)
  465. err = SendCategoryTemplateMsg(sendInfo)
  466. if err != nil {
  467. return
  468. }
  469. }
  470. err = models.UpdateSendedMsgMeetingSendWxMsg(activityIds)
  471. return
  472. }
  473. // 线下调研活动扫码签到给对应销售发类目模班消息
  474. func SendActivitieSignCategoryTemplateMsg(user *models.WxUserItem, activityDetail *models.ActivityDetail) (err error) {
  475. if activityDetail.ChartPermissionId != utils.CHART_PERMISSION_ID_YANXUAN {
  476. return
  477. }
  478. defer func() {
  479. if err != nil {
  480. go utils.SendAlarmMsg(fmt.Sprint("线下调研活动扫码签到给对应销售发模班消息推送失败 SendActivitieSignCategoryTemplateMsg Err:", err.Error(), "活动ID:", activityDetail.ActivityId, "手机号:", user.Mobile), 2)
  481. }
  482. }()
  483. var mobiles []string
  484. //获取销售信息
  485. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  486. if err != nil && err.Error() != utils.ErrNoRow() {
  487. return
  488. }
  489. if sellerItem != nil {
  490. mobiles = append(mobiles, sellerItem.Mobile, utils.MobileWuAngDi, utils.MobileDongHeng, utils.MobileShenTao, utils.MobileZhangChuanXin)
  491. }
  492. var keyword1 string
  493. var keyword2 string
  494. var keyword3 string
  495. var keyword4 string
  496. var keyword5 string
  497. var redirectUrl string
  498. keyword1 = user.RealName
  499. keyword2 = user.CompanyName
  500. keyword3 = sellerItem.RealName
  501. keyword4 = utils.TruncateActivityNameString(activityDetail.ActivityName)
  502. keyword5 = time.Now().Format(utils.FormatDateTimeMinute2)
  503. openIdList, e := models.GetMfyxWxOpenIdByMobileSliceList(mobiles)
  504. if e != nil {
  505. err = errors.New("GetWxOpenIdByMobileList, Err: " + e.Error())
  506. return
  507. }
  508. openIdArr := make([]string, 0)
  509. for _, v := range openIdList {
  510. openIdArr = append(openIdArr, v.OpenId)
  511. }
  512. redirectUrl = utils.WX_MSG_PATH_YX_SIGNUP_DETAIL + strconv.Itoa(activityDetail.ActivityId)
  513. keywords := []string{keyword1, keyword2, keyword3, keyword4, keyword5}
  514. sendInfo := new(SendWxCategoryTemplate)
  515. sendInfo.Keywords = keywords
  516. sendInfo.TemplateId = utils.WxCategoryMsgTemplateIdActivitySign
  517. sendInfo.RedirectTarget = 4
  518. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ARTICLE_ADD
  519. sendInfo.OpenIdArr = openIdArr
  520. sendInfo.RedirectUrl = redirectUrl
  521. err = SendCategoryTemplateMsg(sendInfo)
  522. if err != nil {
  523. return
  524. }
  525. return
  526. }
  527. // 发送活动提问消息提醒(研选公众号类目模版消息)
  528. func SendWxCategoryMsgWithAsk(user *models.WxUserItem, activityInfo *models.ActivityDetail, askMsg string, askId int) (err error) {
  529. if activityInfo.ChartPermissionId != utils.CHART_PERMISSION_ID_YANXUAN {
  530. return
  531. }
  532. defer func() {
  533. if err != nil {
  534. fmt.Println(err)
  535. go utils.SendAlarmMsg(fmt.Sprint("发送活动提问消息提醒类目模版消息失败,用户名", user.RealName, "提问ID:", askId), 2)
  536. }
  537. }()
  538. companyId := user.CompanyId
  539. var sellerName string
  540. //潜在客户、未开权益,已开FICC的客户推给王芳,开通权益的客户推给对应销售
  541. mobile := utils.WxMsgTemplateIdAskMsgMobilePublic
  542. if companyId > 1 {
  543. raiCount, e := models.GetCompanyProductCount(companyId, utils.COMPANY_PRODUCT_RAI_ID)
  544. if e != nil {
  545. err = errors.New("GetCompanyProductCount, Err: " + e.Error())
  546. return
  547. }
  548. if raiCount > 0 {
  549. sealldetail, e := models.GetRaiSellerByCompanyId(companyId)
  550. if e != nil {
  551. err = errors.New("GetRaiSellerByCompanyId, Err: " + e.Error())
  552. return
  553. }
  554. sellerName = sealldetail.RealName
  555. mobile += "," + sealldetail.Mobile
  556. }
  557. }
  558. var mobiles []string
  559. 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) //葛琳、高亦文、董衡、吴昂迪手机号
  560. mobile += "," + strings.Join(mobiles, ",")
  561. openIdList, e := models.GetMfyxWxOpenIdByMobileList(mobile)
  562. if e != nil {
  563. err = errors.New("GetMfyxWxOpenIdByMobileList, Err: " + e.Error())
  564. return err
  565. }
  566. if len(openIdList) == 0 {
  567. return
  568. }
  569. var keyword1 string
  570. var keyword2 string
  571. var keyword3 string
  572. var keyword4 string
  573. var keyword5 string
  574. keyword1 = user.RealName
  575. keyword2 = utils.TruncateActivityNameString(user.CompanyName)
  576. keyword3 = sellerName
  577. keyword4 = time.Now().Format(utils.FormatDateTimeMinute2)
  578. keyword5 = utils.TruncateActivityNameString("活动提问:" + askMsg)
  579. keywords := []string{keyword1, keyword2, keyword3, keyword4, keyword5}
  580. openIdArr := make([]string, 0)
  581. for _, v := range openIdList {
  582. openIdArr = append(openIdArr, v.OpenId)
  583. }
  584. redirectUrl := utils.WX_MSG_PATH_TEMPLATE_MSG + "SourceId=" + strconv.Itoa(askId) + "&SourceType=2"
  585. //redirectUrl = ""
  586. sendInfo := new(SendWxCategoryTemplate)
  587. sendInfo.Keywords = keywords
  588. sendInfo.TemplateId = utils.WxCategoryMsgTemplateIdApplyXzs
  589. sendInfo.RedirectTarget = 4
  590. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ARTICLE_ADD
  591. sendInfo.OpenIdArr = openIdArr
  592. sendInfo.RedirectUrl = redirectUrl
  593. err = SendCategoryTemplateMsg(sendInfo)
  594. return
  595. }
  596. // 用户报名模板消息推送(研选公众号类目模版消息)
  597. func SendNeiRongZuActivitieSignCategoryTemplateMsg(user *models.WxUserItem, activityDetail *models.ActivityDetail) (err error) {
  598. if activityDetail.ChartPermissionId != utils.CHART_PERMISSION_ID_YANXUAN {
  599. return
  600. }
  601. defer func() {
  602. if err != nil {
  603. go utils.SendAlarmMsg(fmt.Sprint("发送用户操作活动消息提醒,文章ID:", activityDetail.ActivityId), 2)
  604. fmt.Println(err)
  605. }
  606. }()
  607. sellerItemQy, e := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  608. if e != nil && e.Error() != utils.ErrNoRow() {
  609. return
  610. }
  611. var mobile string
  612. var sellerRealName string
  613. var mobiles []string
  614. mobiles = append(mobiles, utils.RAI_MOBILE_GAO_YI_WEN, utils.RAI_MOBILE_DONG_HENG, utils.RAI_MOBILE_WU_ANG_DI, utils.MobileShenTao, utils.MobileZhangChuanXin) //高亦文、董衡、吴昂迪手机号
  615. if sellerItemQy != nil {
  616. mobiles = append(mobiles, sellerItemQy.Mobile)
  617. sellerRealName = sellerItemQy.RealName
  618. } else {
  619. sellerRealName = "__"
  620. }
  621. mobile = strings.Join(mobiles, ",")
  622. openIdList, e := models.GetMfyxWxOpenIdByMobileList(mobile)
  623. if e != nil {
  624. err = errors.New("GetMfyxWxOpenIdByMobileList, Err: " + e.Error())
  625. return err
  626. }
  627. if len(openIdList) == 0 {
  628. err = nil
  629. return
  630. }
  631. openIdArr := make([]string, 0)
  632. for _, v := range openIdList {
  633. openIdArr = append(openIdArr, v.OpenId)
  634. }
  635. var keywords []string
  636. keywords = append(keywords, user.RealName, user.CompanyName, sellerRealName, time.Now().Format(utils.FormatDateTimeMinute2), utils.TruncateActivityNameString("报名:"+activityDetail.ActivityName))
  637. redirectUrl := utils.WX_MSG_PATH_YX_ACTIVITY_DETAIL + strconv.Itoa(activityDetail.ActivityId) //活动详情地址
  638. sendInfo := new(SendWxCategoryTemplate)
  639. sendInfo.Keywords = keywords
  640. sendInfo.TemplateId = utils.WxCategoryMsgTemplateIdApplyXzs
  641. sendInfo.RedirectTarget = 4
  642. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_APPLY
  643. sendInfo.OpenIdArr = openIdArr
  644. sendInfo.RedirectUrl = redirectUrl
  645. err = SendCategoryTemplateMsg(sendInfo)
  646. return
  647. }
  648. // 用户取消报名模板消息推送(研选公众号类目模版消息)
  649. func SendActivitieCancelSignCategoryTemplateMsg(user *models.WxUserItem, activityDetail *models.ActivityDetail) (err error) {
  650. if activityDetail.ChartPermissionId != utils.CHART_PERMISSION_ID_YANXUAN {
  651. return
  652. }
  653. defer func() {
  654. if err != nil {
  655. fmt.Println(err)
  656. go utils.SendAlarmMsg(fmt.Sprint("发送用户操作活动消息提醒,活动ID:", activityDetail.ActivityId), 2)
  657. }
  658. }()
  659. sellerItemQy, e := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  660. if e != nil && e.Error() != utils.ErrNoRow() {
  661. return
  662. }
  663. var mobile string
  664. var sellerRealName string
  665. var mobiles []string
  666. mobiles = append(mobiles, utils.RAI_MOBILE_GAO_YI_WEN, utils.RAI_MOBILE_DONG_HENG, utils.RAI_MOBILE_WU_ANG_DI, utils.MobileShenTao, utils.MobileZhangChuanXin) //高亦文、董衡、吴昂迪手机号
  667. if sellerItemQy != nil {
  668. mobiles = append(mobiles, sellerItemQy.Mobile)
  669. sellerRealName = sellerItemQy.RealName
  670. } else {
  671. sellerRealName = "__"
  672. }
  673. mobile = strings.Join(mobiles, ",")
  674. openIdList, e := models.GetMfyxWxOpenIdByMobileList(mobile)
  675. if e != nil {
  676. err = errors.New("GetMfyxWxOpenIdByMobileList, Err: " + e.Error())
  677. return err
  678. }
  679. if len(openIdList) == 0 {
  680. err = nil
  681. return
  682. }
  683. openIdArr := make([]string, 0)
  684. for _, v := range openIdList {
  685. openIdArr = append(openIdArr, v.OpenId)
  686. }
  687. var keywords []string
  688. keywords = append(keywords, user.RealName, user.CompanyName, sellerRealName, time.Now().Format(utils.FormatDateTimeMinute2), utils.TruncateActivityNameString("取消报名:"+activityDetail.ActivityName))
  689. redirectUrl := utils.WX_MSG_PATH_YX_ACTIVITY_DETAIL + strconv.Itoa(activityDetail.ActivityId) //活动详情地址
  690. sendInfo := new(SendWxCategoryTemplate)
  691. sendInfo.Keywords = keywords
  692. sendInfo.TemplateId = utils.WxCategoryMsgTemplateIdApplyXzs
  693. sendInfo.RedirectTarget = 4
  694. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_APPLY
  695. sendInfo.OpenIdArr = openIdArr
  696. sendInfo.RedirectUrl = redirectUrl
  697. err = SendCategoryTemplateMsg(sendInfo)
  698. return
  699. }
  700. // 发送用户操作活动消息提醒
  701. func SendWxCategoryMsgWithActivityUserRemind(keyWord1, keyWord2, keyWord3, keyWord4, redirectUrl string, openIdList []*models.OpenIdList, activityId int) (err error) {
  702. if len(openIdList) == 0 {
  703. return
  704. }
  705. defer func() {
  706. if err != nil {
  707. go utils.SendAlarmMsg(fmt.Sprint("发送用户操作活动消息提醒,SendWxCategoryMsgWithActivityUserRemind 文章ID:", activityId), 2)
  708. }
  709. }()
  710. keyWord1 = utils.TruncateActivityNameString(keyWord1)
  711. openIdArr := make([]string, 0)
  712. for _, v := range openIdList {
  713. openIdArr = append(openIdArr, v.OpenId)
  714. }
  715. var keywords []string
  716. keywords = append(keywords, keyWord1, keyWord2, keyWord3, keyWord4)
  717. sendInfo := new(SendWxCategoryTemplate)
  718. sendInfo.Keywords = keywords
  719. sendInfo.TemplateId = utils.WxMsgCategoryTemplateIdActivityPublishApply
  720. sendInfo.RedirectTarget = 4
  721. sendInfo.RedirectUrl = redirectUrl
  722. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_APPLY
  723. sendInfo.OpenIdArr = openIdArr
  724. err = SendCategoryTemplateMsg(sendInfo)
  725. return
  726. }
  727. // 买方研选推送会议开始消息提醒60/15分钟前
  728. func SendWxMsgWithFrequencyBycategoryMfyx(keyWord1, keyWord2 string, openIdList []*models.OpenIdList, activityId int) (err error) {
  729. if len(openIdList) == 0 {
  730. return
  731. }
  732. defer func() {
  733. if err != nil {
  734. go utils.SendAlarmMsg(fmt.Sprint("发送用户操作活动消息提醒,SendWxCategoryMsgWithActivityUserRemind 文章ID:", activityId), 2)
  735. }
  736. }()
  737. keyWord1 = utils.TruncateActivityNameString(keyWord1)
  738. openIdArr := make([]string, 0)
  739. for _, v := range openIdList {
  740. openIdArr = append(openIdArr, v.OpenId)
  741. }
  742. var keywords []string
  743. keyWord2 = utils.StrTimeToTime(keyWord2).Format(utils.FormatDateTimeMinute2) //去掉时间格式后面的秒
  744. keywords = append(keywords, keyWord1, keyWord2)
  745. redirectUrl := utils.WX_MSG_PATH_YX_ACTIVITY_DETAIL + strconv.Itoa(activityId)
  746. sendInfo := new(SendWxCategoryTemplate)
  747. sendInfo.Keywords = keywords
  748. sendInfo.TemplateId = utils.WxMsgTemplateIdActivityChangeApplyXzs
  749. sendInfo.RedirectTarget = 4
  750. sendInfo.RedirectUrl = redirectUrl
  751. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_APPLY
  752. sendInfo.OpenIdArr = openIdArr
  753. err = SendCategoryTemplateMsg(sendInfo)
  754. return
  755. }
  756. // 活动模块END
  757. // 专栏模块
  758. // 研选专栏审核完成时,给提交人发送类目模板消息
  759. func SendWxCategoryMsgSpecialAuthor(specialId, status int) (err error) {
  760. defer func() {
  761. if err != nil {
  762. go utils.SendAlarmMsg(fmt.Sprint("研选专栏审核完成时,给提交人发送模板消息 SendWxCategoryMsgSpecialAuthor ", specialId, ", specialId", err.Error()), 2)
  763. }
  764. }()
  765. var keyword1 string
  766. var keyword2 string
  767. var keyword3 string
  768. var keyword4 string
  769. var redirectUrl string
  770. specialItem, e := models.GetYanxuanSpecialItemById(specialId)
  771. if e != nil {
  772. err = errors.New("GetYanxuanSpecialFollowUserById, Err: " + e.Error())
  773. return
  774. }
  775. user, e := models.GetWxUserItemByUserId(specialItem.UserId)
  776. if e != nil {
  777. err = errors.New("GetWxUserItemByUserId, Err: " + e.Error())
  778. return err
  779. }
  780. openIdList, err := models.GetMfyxWxOpenIdByMobileList(user.Mobile)
  781. if err != nil && err.Error() != utils.ErrNoRow() {
  782. return err
  783. }
  784. if len(openIdList) == 0 {
  785. return
  786. }
  787. keyword1 = utils.TruncateActivityNameString(specialItem.Title)
  788. keyword2 = specialItem.NickName
  789. if status == 1 {
  790. keyword3 = "文章已通过审核,点击查看详情"
  791. redirectUrl = utils.WX_MSG_PATH_YX_SPECIAL_DETAIL + strconv.Itoa(specialId)
  792. } else {
  793. keyword3 = "文章未通过审核,点击查看驳回原因"
  794. redirectUrl = utils.WX_MSG_PATH_YX_SPECIAL_CENTER
  795. }
  796. keyword4 = time.Now().Format(utils.FormatDateTimeMinute2)
  797. openIdArr := make([]string, 0)
  798. for _, v := range openIdList {
  799. openIdArr = append(openIdArr, v.OpenId)
  800. }
  801. keywords := []string{keyword1, keyword2, keyword3, keyword4}
  802. sendInfo := new(SendWxCategoryTemplate)
  803. sendInfo.Keywords = keywords
  804. sendInfo.TemplateId = utils.WxMsgCategoryTemplateIdCompanyApprovalMessageRai
  805. sendInfo.RedirectTarget = 4
  806. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ARTICLE_ADD
  807. sendInfo.OpenIdArr = openIdArr
  808. sendInfo.RedirectUrl = redirectUrl
  809. err = SendCategoryTemplateMsg(sendInfo)
  810. if err != nil {
  811. return
  812. }
  813. return
  814. }
  815. // 研选专栏有新内容审核通过时,给关注此专栏的客户发送模板消息
  816. func SendWxCategoryMsgSpecialFollow(specialId int) (err error) {
  817. defer func() {
  818. if err != nil {
  819. go utils.SendAlarmMsg(fmt.Sprint("研选专栏有新内容审核通过时,给关注此专栏的客户发送类目模板消息失败", specialId, ", specialId", err.Error()), 2)
  820. }
  821. }()
  822. var keyword1 string
  823. var keyword2 string
  824. var keyword3 string
  825. var keyword4 string
  826. followers, e := models.GetYanxuanSpecialFollowUserById(specialId)
  827. if e != nil {
  828. err = errors.New("GetYanxuanSpecialFollowUserById, Err: " + e.Error())
  829. return
  830. }
  831. if len(followers) == 0 {
  832. return
  833. }
  834. specialItem, e := models.GetYanxuanSpecialItemById(specialId)
  835. if e != nil {
  836. err = errors.New("GetYanxuanSpecialFollowUserById, Err: " + e.Error())
  837. return
  838. }
  839. var allInUserId string
  840. for _, v := range followers {
  841. allInUserId += strconv.Itoa(v) + ","
  842. }
  843. allInUserId = strings.TrimRight(allInUserId, ",")
  844. userList, err := models.GetWxUserListByUserIds(allInUserId)
  845. if err != nil && err.Error() != utils.ErrNoRow() {
  846. return err
  847. }
  848. var mobiles []string
  849. for _, v := range userList {
  850. if v.Mobile != "" {
  851. mobiles = append(mobiles, v.Mobile)
  852. }
  853. }
  854. openIdList, e := models.GetMfyxUserRecordListByMobileArr(mobiles)
  855. if e != nil {
  856. err = errors.New("GetSellerByAdminId, Err: " + e.Error())
  857. return
  858. }
  859. if len(openIdList) == 0 {
  860. return
  861. }
  862. keyword1 = specialItem.SpecialName
  863. keyword2 = "发布了新报告"
  864. keyword3 = specialItem.Title
  865. keyword4 = time.Now().Format(utils.FormatDateTimeMinute2)
  866. openIdArr := make([]string, 0)
  867. for _, v := range openIdList {
  868. openIdArr = append(openIdArr, v.OpenId)
  869. }
  870. redirectUrl := ""
  871. redirectUrl = utils.WX_MSG_PATH_YX_SPECIAL_DETAIL + strconv.Itoa(specialId)
  872. keywords := []string{keyword1, keyword2, keyword3, keyword4}
  873. sendInfo := new(SendWxCategoryTemplate)
  874. sendInfo.Keywords = keywords
  875. sendInfo.TemplateId = utils.WxMsgCategoryTemplateIdActivityPublishApply
  876. sendInfo.RedirectTarget = 4
  877. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ARTICLE_ADD
  878. sendInfo.OpenIdArr = openIdArr
  879. sendInfo.RedirectUrl = redirectUrl
  880. err = SendCategoryTemplateMsg(sendInfo)
  881. if err != nil {
  882. return
  883. }
  884. return
  885. }
  886. // SendReviewCategoryTemplateMsgAdmin 专栏提交审核时给王芳、葛琳和沈涛发研选类目模板消息
  887. func SendReviewCategoryTemplateMsgAdmin(specialId int) (err error) {
  888. defer func() {
  889. if err != nil {
  890. go utils.SendAlarmMsg(fmt.Sprint("处理试用申请给王芳,汪洋发消息失败, specialId:", specialId, "ErrMsg", err.Error()), 2)
  891. }
  892. }()
  893. //王芳、葛琳和沈涛
  894. var configCode string
  895. //研选专栏修改之后给这些手机号推送审核模版消息
  896. configCode = utils.TPL_MSG_YAN_XUAN_SPECIAL_APPROVAL
  897. cnf, e := models.GetConfigByCode(configCode)
  898. if e != nil {
  899. err = errors.New("GetConfigByCode, Err: " + e.Error() + configCode)
  900. return
  901. }
  902. openIdList, e := models.GetMfyxWxOpenIdByMobileList(cnf.ConfigValue)
  903. if e != nil && e.Error() != utils.ErrNoRow() {
  904. err = errors.New("GetUserRecordListByMobile, Err: " + e.Error())
  905. return err
  906. }
  907. if len(openIdList) == 0 {
  908. return
  909. }
  910. specialItem, e := models.GetYanxuanSpecialItemById(specialId)
  911. if e != nil {
  912. err = errors.New("GetYanxuanSpecialFollowUserById, Err: " + e.Error())
  913. return
  914. }
  915. user, e := models.GetWxUserItemByUserId(specialItem.UserId)
  916. if e != nil {
  917. err = errors.New("GetWxUserItemByUserId, Err: " + e.Error())
  918. return err
  919. }
  920. var keyword1 string
  921. var keyword2 string
  922. var keyword3 string
  923. var keyword4 string
  924. var keyword5 string
  925. keyword1 = checkNickNameString(specialItem.NickName)
  926. keyword2 = specialItem.RealName + "-" + user.CompanyName
  927. keyword2 = utils.TruncateActivityNameString(keyword2)
  928. keyword3 = checkSpecialNameString(specialItem.SpecialName)
  929. keyword4 = time.Now().Format(utils.FormatDateTimeMinute2)
  930. keyword5 = "研选专栏提交了内容待审核"
  931. openIdArr := make([]string, 0)
  932. for _, v := range openIdList {
  933. openIdArr = append(openIdArr, v.OpenId)
  934. }
  935. redirectUrl := utils.WX_MSG_PATH_YX_SPECIAL_ENABLE_DETAIL + strconv.Itoa(specialId)
  936. keywords := []string{keyword1, keyword2, keyword3, keyword4, keyword5}
  937. sendInfo := new(SendWxCategoryTemplate)
  938. sendInfo.Keywords = keywords
  939. sendInfo.TemplateId = utils.WxCategoryMsgTemplateIdApplyXzs
  940. sendInfo.RedirectTarget = 4
  941. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ARTICLE_ADD
  942. sendInfo.OpenIdArr = openIdArr
  943. sendInfo.RedirectUrl = redirectUrl
  944. err = SendCategoryTemplateMsg(sendInfo)
  945. if err != nil {
  946. return
  947. }
  948. return
  949. }
  950. func checkNickNameString(s string) string {
  951. var trimmedString string
  952. hanCount := 0
  953. for _, r := range s {
  954. if unicode.Is(unicode.Han, r) {
  955. trimmedString += string(r)
  956. hanCount++
  957. if hanCount == 5 {
  958. break
  959. }
  960. } else {
  961. return "作者昵称"
  962. }
  963. }
  964. if trimmedString == "" {
  965. trimmedString = "作者昵称"
  966. }
  967. return trimmedString
  968. }
  969. func checkSpecialNameString(s string) string {
  970. var trimmedString string
  971. hanCount := 0
  972. for _, r := range s {
  973. if unicode.Is(unicode.Han, r) {
  974. trimmedString += string(r)
  975. hanCount++
  976. if hanCount == 5 {
  977. break
  978. }
  979. } else {
  980. return "专栏名称"
  981. }
  982. }
  983. if trimmedString == "" {
  984. trimmedString = "专栏名称"
  985. }
  986. return trimmedString
  987. }
  988. func SendCategoryTemplateMsgLikeCountDifferentByYxCategory(likeCount, yanxuanSpecialId int, mobile, title string) {
  989. var err error
  990. defer func() {
  991. if err != nil {
  992. fmt.Println("err:", err)
  993. go utils.SendAlarmMsg(" 专栏文章获得点赞时,模板消息通知作者(每个整点发送,不同文章分多条发送)失败,SendCategoryTemplateMsgLikeCountDifferentByYxCategory Err:"+err.Error(), 3)
  994. }
  995. }()
  996. openIdList, e := models.GetMfyxWxOpenIdByMobileList(mobile)
  997. if e != nil && e.Error() != utils.ErrNoRow() {
  998. err = errors.New("GetMfyxWxOpenIdByMobileList, Err: " + e.Error())
  999. return
  1000. }
  1001. if len(openIdList) == 0 {
  1002. err = nil
  1003. return
  1004. }
  1005. openIdArr := make([]string, 0)
  1006. for _, v := range openIdList {
  1007. openIdArr = append(openIdArr, v.OpenId)
  1008. }
  1009. var keyword1 string
  1010. var keyword2 string
  1011. var redirectUrl string
  1012. redirectUrl = utils.WX_MSG_PATH_YX_SPECIAL_DETAIL + strconv.Itoa(yanxuanSpecialId)
  1013. keyword1 = fmt.Sprint("有", likeCount, "人点赞了您的文章")
  1014. keyword2 = title
  1015. keyword1 = utils.TruncateActivityNameString(keyword1)
  1016. keywords := []string{keyword1, keyword2}
  1017. sendInfo := new(SendWxCategoryTemplate)
  1018. sendInfo.Keywords = keywords
  1019. sendInfo.TemplateId = utils.WxMsgCategoryTemplateIdAddMessage
  1020. sendInfo.RedirectTarget = 4
  1021. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ARTICLE_ADD
  1022. sendInfo.OpenIdArr = openIdArr
  1023. sendInfo.RedirectUrl = redirectUrl
  1024. err = SendCategoryTemplateMsg(sendInfo)
  1025. return
  1026. }
  1027. //专栏模块END