wx_category_template_msg.go 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187
  1. package services
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "fmt"
  6. "hongze/hongze_mfyx/models"
  7. "hongze/hongze_mfyx/models/order"
  8. "hongze/hongze_mfyx/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. postData, err := json.Marshal(sendInfo)
  29. if err != nil {
  30. go utils.SendAlarmMsg("SendCategoryTemplateMsg json.Marshal Err:"+err.Error(), 1)
  31. return err
  32. }
  33. body := ioutil.NopCloser(strings.NewReader(string(postData)))
  34. client := &http.Client{}
  35. req, err := http.NewRequest("POST", utils.SendWxCategoryTemplateMsgUrl, body)
  36. if err != nil {
  37. go utils.SendAlarmMsg("SendCategoryTemplateMsg http.NewRequest Err:"+err.Error(), 1)
  38. return err
  39. }
  40. contentType := "application/json;charset=utf-8"
  41. req.Header.Set("Content-Type", contentType)
  42. req.Header.Set("Authorization", utils.SendTemplateMsgAuthorization)
  43. resp, err := client.Do(req)
  44. if err != nil {
  45. fmt.Println("http client.Do Err:" + err.Error())
  46. return err
  47. }
  48. defer resp.Body.Close()
  49. b, err := ioutil.ReadAll(resp.Body)
  50. if err != nil {
  51. return err
  52. }
  53. result := new(models.BaseResponse)
  54. err = json.Unmarshal(b, &result)
  55. if err != nil {
  56. return err
  57. }
  58. if result.Ret != 200 {
  59. err = errors.New(string(b))
  60. return err
  61. }
  62. return
  63. }
  64. // 发送用户操作活动消息提醒
  65. func SendWxCategoryMsgWithActivityUserRemind(keyWord1, keyWord2, keyWord3, keyWord4, redirectUrl string, openIdList []*models.OpenIdList, activityId int) (err error) {
  66. if len(openIdList) == 0 {
  67. return
  68. }
  69. defer func() {
  70. if err != nil {
  71. go utils.SendAlarmMsg(fmt.Sprint("发送用户操作活动消息提醒,文章ID:", activityId), 2)
  72. }
  73. }()
  74. keyWord1 = utils.TruncateActivityNameString(keyWord1)
  75. openIdArr := make([]string, 0)
  76. for _, v := range openIdList {
  77. openIdArr = append(openIdArr, v.OpenId)
  78. }
  79. var keywords []string
  80. keywords = append(keywords, keyWord1, keyWord2, keyWord3, keyWord4)
  81. sendInfo := new(SendWxCategoryTemplate)
  82. sendInfo.Keywords = keywords
  83. sendInfo.TemplateId = utils.WxMsgCategoryTemplateIdActivityPublishApply
  84. sendInfo.RedirectTarget = 4
  85. sendInfo.RedirectUrl = redirectUrl
  86. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_APPLY
  87. sendInfo.OpenIdArr = openIdArr
  88. err = SendCategoryTemplateMsg(sendInfo)
  89. //sendMap["miniprogram"] = map[string]interface{}{"appid": utils.WxAppId, "pagepath": "activityPages/activityDetail/activityDetail?id=" + strconv.Itoa(activityId)}
  90. return
  91. }
  92. // 试用申请模板消息
  93. func SendPermissionApplyCategoryTemplateMsg(realName, companyName, mobile, applyMethod string, itemOpenid *models.OpenIdList, redirectUrl string) (err error) {
  94. defer func() {
  95. if err != nil {
  96. go utils.SendAlarmMsg(fmt.Sprint("权限申请模板消息推送消息失败,手机号", mobile, "公司:", companyName, "手机号:", mobile, ";Err:"+err.Error()), 2)
  97. }
  98. }()
  99. var keyword1 string
  100. var keyword2 string
  101. var keyword3 string
  102. var keyword4 string
  103. var keyword5 string
  104. detail, e := models.GetCygxApplyRecordByMobile(mobile)
  105. if e != nil {
  106. err = errors.New("GetCygxApplyRecordByMobile" + e.Error())
  107. return
  108. }
  109. //如果是潜在客户就推送可查看详情的模版消息
  110. if utils.RunMode == "release" {
  111. if detail.ApplyMethod == 2 {
  112. redirectUrl = utils.WX_MSG_PATH_APPLY_DETAIL + strconv.Itoa(detail.ApplyRecordId)
  113. }
  114. }
  115. openIdArr := make([]string, 0)
  116. openIdArr = append(openIdArr, itemOpenid.OpenId)
  117. sendInfo := new(SendWxCategoryTemplate)
  118. keyword1 = realName
  119. keyword2 = companyName
  120. keyword3 = "权限申请"
  121. keyword4 = time.Now().Format(utils.FormatDateTimeMinute2)
  122. keyword5 = applyMethod
  123. sendInfo.Keywords = []string{keyword1, keyword2, keyword3, keyword4, keyword5}
  124. sendInfo.TemplateId = utils.WxCategoryMsgTemplateIdApplyXzs
  125. sendInfo.RedirectUrl = redirectUrl
  126. sendInfo.RedirectTarget = 4
  127. sendInfo.Resource = mobile
  128. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_APPLY
  129. sendInfo.OpenIdArr = openIdArr
  130. err = SendCategoryTemplateMsg(sendInfo)
  131. return
  132. }
  133. // 用户报名模板消息推送(研选公众号类目模版消息)
  134. func SendNeiRongZuActivitieSignCategoryTemplateMsg(user *models.WxUserItem, activityDetail *models.ActivityDetail) (err error) {
  135. defer func() {
  136. if err != nil {
  137. go utils.SendAlarmMsg(fmt.Sprint("发送用户操作活动消息提醒,文章ID:", activityDetail.ActivityId), 2)
  138. fmt.Println(err)
  139. }
  140. }()
  141. sellerItemQy, e := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  142. if e != nil && e.Error() != utils.ErrNoRow() {
  143. return
  144. }
  145. var mobile string
  146. var sellerRealName string
  147. var mobiles []string
  148. mobiles = append(mobiles, utils.RAI_MOBILE_GAO_YI_WEN, utils.RAI_MOBILE_DONG_HENG, utils.RAI_MOBILE_WU_ANG_DI, utils.MobileShenTao, utils.MobileZhangChuanXin) //高亦文、董衡、吴昂迪手机号
  149. if sellerItemQy != nil {
  150. mobiles = append(mobiles, sellerItemQy.Mobile)
  151. sellerRealName = sellerItemQy.RealName
  152. } else {
  153. sellerRealName = "__"
  154. }
  155. mobile = strings.Join(mobiles, ",")
  156. openIdList, e := models.GetMfyxWxOpenIdByMobileList(mobile)
  157. if e != nil {
  158. err = errors.New("GetMfyxWxOpenIdByMobileList, Err: " + e.Error())
  159. return err
  160. }
  161. if len(openIdList) == 0 {
  162. err = nil
  163. return
  164. }
  165. openIdArr := make([]string, 0)
  166. for _, v := range openIdList {
  167. openIdArr = append(openIdArr, v.OpenId)
  168. }
  169. var keywords []string
  170. keywords = append(keywords, user.RealName, user.CompanyName, sellerRealName, time.Now().Format(utils.FormatDateTimeMinute2), utils.TruncateActivityNameString("报名:"+activityDetail.ActivityName))
  171. redirectUrl := utils.WX_MSG_PATH_YX_ACTIVITY_DETAIL + strconv.Itoa(activityDetail.ActivityId) //活动详情地址
  172. sendInfo := new(SendWxCategoryTemplate)
  173. sendInfo.Keywords = keywords
  174. sendInfo.TemplateId = utils.WxCategoryMsgTemplateIdApplyXzs
  175. sendInfo.RedirectTarget = 4
  176. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_APPLY
  177. sendInfo.OpenIdArr = openIdArr
  178. sendInfo.RedirectUrl = redirectUrl
  179. err = SendCategoryTemplateMsg(sendInfo)
  180. return
  181. }
  182. // 用户取消报名模板消息推送(研选公众号类目模版消息)
  183. func SendActivitieCancelSignCategoryTemplateMsg(user *models.WxUserItem, activityDetail *models.ActivityDetail) (err error) {
  184. defer func() {
  185. if err != nil {
  186. fmt.Println(err)
  187. go utils.SendAlarmMsg(fmt.Sprint("发送用户操作活动消息提醒,活动ID:", activityDetail.ActivityId), 2)
  188. }
  189. }()
  190. sellerItemQy, e := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  191. if e != nil && e.Error() != utils.ErrNoRow() {
  192. return
  193. }
  194. var mobile string
  195. var sellerRealName string
  196. var mobiles []string
  197. mobiles = append(mobiles, utils.RAI_MOBILE_GAO_YI_WEN, utils.RAI_MOBILE_DONG_HENG, utils.RAI_MOBILE_WU_ANG_DI, utils.MobileShenTao, utils.MobileZhangChuanXin) //高亦文、董衡、吴昂迪手机号
  198. if sellerItemQy != nil {
  199. mobiles = append(mobiles, sellerItemQy.Mobile)
  200. sellerRealName = sellerItemQy.RealName
  201. } else {
  202. sellerRealName = "__"
  203. }
  204. mobile = strings.Join(mobiles, ",")
  205. openIdList, e := models.GetMfyxWxOpenIdByMobileList(mobile)
  206. if e != nil {
  207. err = errors.New("GetMfyxWxOpenIdByMobileList, Err: " + e.Error())
  208. return err
  209. }
  210. if len(openIdList) == 0 {
  211. err = nil
  212. return
  213. }
  214. openIdArr := make([]string, 0)
  215. for _, v := range openIdList {
  216. openIdArr = append(openIdArr, v.OpenId)
  217. }
  218. var keywords []string
  219. keywords = append(keywords, user.RealName, user.CompanyName, sellerRealName, time.Now().Format(utils.FormatDateTimeMinute2), utils.TruncateActivityNameString("取消报名:"+activityDetail.ActivityName))
  220. redirectUrl := utils.WX_MSG_PATH_YX_ACTIVITY_DETAIL + strconv.Itoa(activityDetail.ActivityId) //活动详情地址
  221. sendInfo := new(SendWxCategoryTemplate)
  222. sendInfo.Keywords = keywords
  223. sendInfo.TemplateId = utils.WxCategoryMsgTemplateIdApplyXzs
  224. sendInfo.RedirectTarget = 4
  225. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_APPLY
  226. sendInfo.OpenIdArr = openIdArr
  227. sendInfo.RedirectUrl = redirectUrl
  228. err = SendCategoryTemplateMsg(sendInfo)
  229. return
  230. }
  231. // 发送用户留言提醒
  232. func SendCommentWxCategoryTemplateMsg(req models.AddCygxArticleCommentReq, user *models.WxUserItem, articleInfo *models.ArticleDetail, msgId int) (err error) {
  233. defer func() {
  234. if err != nil {
  235. go utils.SendAlarmMsg(fmt.Sprint("发送用户用户留言提醒失败,文章ID:", req.ArticleId), 2)
  236. }
  237. }()
  238. companyItem, e := models.GetSellerDetailAllByCompanyId(user.CompanyId)
  239. if e != nil {
  240. err = errors.New("GetSellerDetailAllByCompanyId, Err: " + e.Error())
  241. return
  242. }
  243. var keyword1 string
  244. var keyword2 string
  245. var keyword3 string
  246. var keyword4 string
  247. var keyword5 string
  248. var redirectUrl string
  249. var mobile string
  250. var keywords []string
  251. keyword1 = user.RealName
  252. keyword2 = companyItem.CompanyName
  253. keyword3 = companyItem.SellerName
  254. keyword4 = time.Now().Format(utils.FormatDateTimeMinute2)
  255. keyword5 = "报告留言:" + req.Content
  256. keyword5 = utils.TruncateActivityNameString(keyword5)
  257. keywords = append(keywords, keyword1, keyword2, keyword3, keyword4, keyword5)
  258. if articleInfo.ArticleTypeId > 0 {
  259. //研选报告添加汪洋
  260. mobile = companyItem.Mobile + "," + utils.WxMsgTemplateIdAskMsgMobilePublic + "," + utils.ActSendMsgMobile
  261. } else {
  262. mobile = companyItem.Mobile + "," + utils.WxMsgTemplateIdAskMsgMobilePublic
  263. }
  264. openIdList, e := models.GetMfyxWxOpenIdByMobileList(mobile)
  265. if e != nil {
  266. err = errors.New("GetMfyxWxOpenIdByMobileList, Err: " + e.Error())
  267. return
  268. }
  269. openIdArr := make([]string, 0)
  270. for _, v := range openIdList {
  271. openIdArr = append(openIdArr, v.OpenId)
  272. }
  273. redirectUrl = utils.WX_MSG_PATH_YX_COMMENT_DETAIL + strconv.Itoa(msgId) + "&type=文章"
  274. sendInfo := new(SendWxCategoryTemplate)
  275. sendInfo.Keywords = keywords
  276. sendInfo.TemplateId = utils.WxCategoryMsgTemplateIdApplyXzs
  277. sendInfo.RedirectTarget = 4
  278. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_APPLY
  279. sendInfo.OpenIdArr = openIdArr
  280. sendInfo.RedirectUrl = redirectUrl
  281. err = SendCategoryTemplateMsg(sendInfo)
  282. return
  283. }
  284. // 发送活动提问消息提醒(研选公众号类目模版消息)
  285. func SendWxCategoryMsgWithAsk(user *models.WxUserItem, activityInfo *models.ActivityDetail, askMsg string, askId int) (err error) {
  286. if activityInfo.ChartPermissionId != utils.CHART_PERMISSION_ID_YANXUAN {
  287. return
  288. }
  289. defer func() {
  290. if err != nil {
  291. fmt.Println(err)
  292. go utils.SendAlarmMsg(fmt.Sprint("发送活动提问消息提醒类目模版消息失败,用户名", user.RealName, "提问ID:", askId), 2)
  293. }
  294. }()
  295. companyId := user.CompanyId
  296. var sellerName string
  297. //潜在客户、未开权益,已开FICC的客户推给王芳,开通权益的客户推给对应销售
  298. mobile := utils.WxMsgTemplateIdAskMsgMobilePublic
  299. if companyId > 1 {
  300. raiCount, e := models.GetCompanyProductCount(companyId, utils.COMPANY_PRODUCT_RAI_ID)
  301. if e != nil {
  302. err = errors.New("GetCompanyProductCount, Err: " + e.Error())
  303. return
  304. }
  305. if raiCount > 0 {
  306. sealldetail, e := models.GetRaiSellerByCompanyId(companyId)
  307. if e != nil {
  308. err = errors.New("GetRaiSellerByCompanyId, Err: " + e.Error())
  309. return
  310. }
  311. sellerName = sealldetail.RealName
  312. mobile += "," + sealldetail.Mobile
  313. }
  314. }
  315. var mobiles []string
  316. 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) //葛琳、高亦文、董衡、吴昂迪手机号
  317. mobile += "," + strings.Join(mobiles, ",")
  318. openIdList, e := models.GetMfyxWxOpenIdByMobileList(mobile)
  319. if e != nil {
  320. err = errors.New("GetMfyxWxOpenIdByMobileList, Err: " + e.Error())
  321. return err
  322. }
  323. if len(openIdList) == 0 {
  324. return
  325. }
  326. var keyword1 string
  327. var keyword2 string
  328. var keyword3 string
  329. var keyword4 string
  330. var keyword5 string
  331. keyword1 = user.RealName
  332. keyword2 = utils.TruncateActivityNameString(user.CompanyName)
  333. keyword3 = sellerName
  334. keyword4 = time.Now().Format(utils.FormatDateTimeMinute2)
  335. keyword5 = utils.TruncateActivityNameString("活动提问:" + askMsg)
  336. keywords := []string{keyword1, keyword2, keyword3, keyword4, keyword5}
  337. openIdArr := make([]string, 0)
  338. for _, v := range openIdList {
  339. openIdArr = append(openIdArr, v.OpenId)
  340. }
  341. redirectUrl := utils.WX_MSG_PATH_TEMPLATE_MSG + "SourceId=" + strconv.Itoa(askId) + "&SourceType=2"
  342. //redirectUrl = ""
  343. sendInfo := new(SendWxCategoryTemplate)
  344. sendInfo.Keywords = keywords
  345. sendInfo.TemplateId = utils.WxCategoryMsgTemplateIdApplyXzs
  346. sendInfo.RedirectTarget = 4
  347. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ARTICLE_ADD
  348. sendInfo.OpenIdArr = openIdArr
  349. sendInfo.RedirectUrl = redirectUrl
  350. err = SendCategoryTemplateMsg(sendInfo)
  351. return
  352. }
  353. // 线下调研活动扫码签到给对应销售发类目模班消息
  354. func SendActivitieSignCategoryTemplateMsg(user *models.WxUserItem, activityDetail *models.ActivityDetail) (err error) {
  355. defer func() {
  356. if err != nil {
  357. go utils.SendAlarmMsg(fmt.Sprint("线下调研活动扫码签到给对应销售发模班消息推送失败Err:", err.Error(), "活动ID:", activityDetail.ActivityId, "手机号:", user.Mobile), 2)
  358. }
  359. }()
  360. var mobiles []string
  361. //获取销售信息
  362. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  363. if err != nil && err.Error() != utils.ErrNoRow() {
  364. return
  365. }
  366. if sellerItem != nil {
  367. mobiles = append(mobiles, sellerItem.Mobile, utils.MobileWuAngDi, utils.MobileDongHeng, utils.MobileShenTao, utils.MobileZhangChuanXin)
  368. }
  369. var keyword1 string
  370. var keyword2 string
  371. var keyword3 string
  372. var keyword4 string
  373. var keyword5 string
  374. var redirectUrl string
  375. keyword1 = user.RealName
  376. keyword2 = user.CompanyName
  377. keyword3 = sellerItem.RealName
  378. keyword4 = activityDetail.ActivityName
  379. keyword5 = time.Now().Format(utils.FormatDateTimeMinute2)
  380. openIdList, e := models.GetMfyxUserRecordListByMobileArr(mobiles)
  381. if e != nil {
  382. err = errors.New("GetMfyxUserRecordListByMobileArr, Err: " + e.Error())
  383. return
  384. }
  385. if len(openIdList) == 0 {
  386. return
  387. }
  388. openIdArr := make([]string, 0)
  389. for _, v := range openIdList {
  390. openIdArr = append(openIdArr, v.OpenId)
  391. }
  392. redirectUrl = utils.WX_MSG_PATH_YX_SIGNUP_DETAIL + strconv.Itoa(activityDetail.ActivityId)
  393. keywords := []string{keyword1, keyword2, keyword3, keyword4, keyword5}
  394. sendInfo := new(SendWxCategoryTemplate)
  395. sendInfo.Keywords = keywords
  396. sendInfo.TemplateId = utils.WxCategoryMsgTemplateIdActivitySign
  397. sendInfo.RedirectTarget = 4
  398. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ARTICLE_ADD
  399. sendInfo.OpenIdArr = openIdArr
  400. sendInfo.RedirectUrl = redirectUrl
  401. err = SendCategoryTemplateMsg(sendInfo)
  402. if err != nil {
  403. return
  404. }
  405. return
  406. }
  407. // SendReviewCategoryTemplateMsgAdmin 提交审核时给王芳,汪洋发消息
  408. func SendReviewCategoryTemplateMsgAdmin(specialId int) (err error) {
  409. defer func() {
  410. if err != nil {
  411. go utils.SendAlarmMsg(fmt.Sprint("处理试用申请给王芳,汪洋发消息失败, specialId:", specialId, "ErrMsg", err.Error()), 2)
  412. }
  413. }()
  414. var configCode string
  415. //研选专栏修改之后给这些手机号推送审核模版消息
  416. configCode = utils.TPL_MSG_YAN_XUAN_SPECIAL_APPROVAL
  417. cnf, e := models.GetConfigByCode(configCode)
  418. if e != nil {
  419. err = errors.New("GetConfigByCode, Err: " + e.Error() + configCode)
  420. return
  421. }
  422. //王芳、葛琳和沈涛
  423. openIdList, e := models.GetMfyxWxOpenIdByMobileList(cnf.ConfigValue)
  424. if e != nil && e.Error() != utils.ErrNoRow() {
  425. err = errors.New("GetUserRecordListByMobile, Err: " + e.Error())
  426. return err
  427. }
  428. specialItem, e := models.GetYanxuanSpecialItemById(specialId)
  429. if e != nil {
  430. err = errors.New("GetYanxuanSpecialFollowUserById, Err: " + e.Error())
  431. return
  432. }
  433. user, e := models.GetWxUserItemByUserId(specialItem.UserId)
  434. if e != nil {
  435. err = errors.New("GetWxUserItemByUserId, Err: " + e.Error())
  436. return err
  437. }
  438. var keyword1 string
  439. var keyword2 string
  440. var keyword3 string
  441. var keyword4 string
  442. var keyword5 string
  443. keyword1 = checkNickNameString(specialItem.NickName)
  444. keyword2 = specialItem.RealName + "-" + user.CompanyName
  445. keyword2 = utils.TruncateActivityNameString(keyword2)
  446. keyword3 = checkSpecialNameString(specialItem.SpecialName)
  447. keyword4 = time.Now().Format(utils.FormatDateTimeMinute2)
  448. keyword5 = "研选专栏提交了内容待审核"
  449. openIdArr := make([]string, 0)
  450. for _, v := range openIdList {
  451. openIdArr = append(openIdArr, v.OpenId)
  452. }
  453. redirectUrl := ""
  454. redirectUrl = utils.WX_MSG_PATH_YX_SPECIAL_ENABLE_DETAIL + strconv.Itoa(specialId)
  455. keywords := []string{keyword1, keyword2, keyword3, keyword4, keyword5}
  456. sendInfo := new(SendWxCategoryTemplate)
  457. sendInfo.Keywords = keywords
  458. sendInfo.TemplateId = utils.WxCategoryMsgTemplateIdApplyXzs
  459. sendInfo.RedirectTarget = 4
  460. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ARTICLE_ADD
  461. sendInfo.OpenIdArr = openIdArr
  462. sendInfo.RedirectUrl = redirectUrl
  463. err = SendCategoryTemplateMsg(sendInfo)
  464. if err != nil {
  465. return
  466. }
  467. return
  468. }
  469. func checkNickNameString(s string) string {
  470. var trimmedString string
  471. hanCount := 0
  472. for _, r := range s {
  473. if unicode.Is(unicode.Han, r) {
  474. trimmedString += string(r)
  475. hanCount++
  476. if hanCount == 5 {
  477. break
  478. }
  479. } else {
  480. return "作者昵称"
  481. }
  482. }
  483. if trimmedString == "" {
  484. trimmedString = "作者昵称"
  485. }
  486. return trimmedString
  487. }
  488. func checkSpecialNameString(s string) string {
  489. var trimmedString string
  490. hanCount := 0
  491. for _, r := range s {
  492. if unicode.Is(unicode.Han, r) {
  493. trimmedString += string(r)
  494. hanCount++
  495. if hanCount == 5 {
  496. break
  497. }
  498. } else {
  499. return "专栏名称"
  500. }
  501. }
  502. if trimmedString == "" {
  503. trimmedString = "专栏名称"
  504. }
  505. return trimmedString
  506. }
  507. // 研选专栏审核完成时,给提交人发送类目模板消息
  508. func SendWxCategoryMsgSpecialAuthor(specialId, status int) (err error) {
  509. defer func() {
  510. if err != nil {
  511. go utils.SendAlarmMsg(fmt.Sprint("研选专栏审核完成时,给提交人发送模板消息", specialId, ", specialId", err.Error()), 2)
  512. }
  513. }()
  514. var keyword1 string
  515. var keyword2 string
  516. var keyword3 string
  517. var keyword4 string
  518. var redirectUrl string
  519. specialItem, e := models.GetYanxuanSpecialItemById(specialId)
  520. if e != nil {
  521. err = errors.New("GetYanxuanSpecialFollowUserById, Err: " + e.Error())
  522. return
  523. }
  524. user, e := models.GetWxUserItemByUserId(specialItem.UserId)
  525. if e != nil {
  526. err = errors.New("GetWxUserItemByUserId, Err: " + e.Error())
  527. return err
  528. }
  529. openIdList, err := models.GetMfyxWxOpenIdByMobileList(user.Mobile)
  530. if err != nil && err.Error() != utils.ErrNoRow() {
  531. return err
  532. }
  533. keyword1 = specialItem.Title
  534. keyword2 = specialItem.NickName
  535. if status == 1 {
  536. keyword3 = "文章已通过审核,点击查看详情"
  537. redirectUrl = utils.WX_MSG_PATH_YX_SPECIAL_DETAIL + strconv.Itoa(specialId)
  538. } else {
  539. keyword3 = "文章未通过审核,点击查看驳回原因"
  540. redirectUrl = utils.WX_MSG_PATH_YX_SPECIAL_CENTER
  541. }
  542. keyword4 = time.Now().Format(utils.FormatDateTimeMinute2)
  543. openIdArr := make([]string, 0)
  544. for _, v := range openIdList {
  545. openIdArr = append(openIdArr, v.OpenId)
  546. }
  547. keywords := []string{keyword1, keyword2, keyword3, keyword4}
  548. sendInfo := new(SendWxCategoryTemplate)
  549. sendInfo.Keywords = keywords
  550. sendInfo.TemplateId = utils.WxMsgCategoryTemplateIdCompanyApprovalMessageRai
  551. sendInfo.RedirectTarget = 4
  552. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ARTICLE_ADD
  553. sendInfo.OpenIdArr = openIdArr
  554. sendInfo.RedirectUrl = redirectUrl
  555. err = SendCategoryTemplateMsg(sendInfo)
  556. if err != nil {
  557. return
  558. }
  559. return
  560. }
  561. // 研选专栏有新内容审核通过时,给关注此专栏的客户发送模板消息
  562. func SendWxCategoryMsgSpecialFollow(specialId int) (err error) {
  563. defer func() {
  564. if err != nil {
  565. go utils.SendAlarmMsg(fmt.Sprint("研选专栏有新内容审核通过时,给关注此专栏的客户发送类目模板消息失败", specialId, ", specialId", err.Error()), 2)
  566. }
  567. }()
  568. var keyword1 string
  569. var keyword2 string
  570. var keyword3 string
  571. var keyword4 string
  572. followers, e := models.GetYanxuanSpecialFollowUserById(specialId)
  573. if e != nil {
  574. err = errors.New("GetYanxuanSpecialFollowUserById, Err: " + e.Error())
  575. return
  576. }
  577. if len(followers) == 0 {
  578. return
  579. }
  580. specialItem, e := models.GetYanxuanSpecialItemById(specialId)
  581. if e != nil {
  582. err = errors.New("GetYanxuanSpecialFollowUserById, Err: " + e.Error())
  583. return
  584. }
  585. var allInUserId string
  586. for _, v := range followers {
  587. allInUserId += strconv.Itoa(v) + ","
  588. }
  589. allInUserId = strings.TrimRight(allInUserId, ",")
  590. userList, err := models.GetWxUserListByUserIds(allInUserId)
  591. if err != nil && err.Error() != utils.ErrNoRow() {
  592. return err
  593. }
  594. mobile := ``
  595. for _, v := range userList {
  596. mobile += v.Mobile + ","
  597. }
  598. mobile = strings.TrimRight(mobile, ",")
  599. openIdList, e := models.GetMfyxWxOpenIdByMobileList(mobile)
  600. if e != nil {
  601. err = errors.New("GetMfyxWxOpenIdByMobileList, Err: " + e.Error())
  602. return
  603. }
  604. if len(openIdList) == 0 {
  605. return
  606. }
  607. keyword1 = specialItem.SpecialName
  608. keyword2 = "发布了新报告"
  609. keyword3 = specialItem.Title
  610. keyword4 = time.Now().Format(utils.FormatDateTimeMinute2)
  611. openIdArr := make([]string, 0)
  612. for _, v := range openIdList {
  613. openIdArr = append(openIdArr, v.OpenId)
  614. }
  615. redirectUrl := ""
  616. redirectUrl = utils.WX_MSG_PATH_YX_SPECIAL_DETAIL + strconv.Itoa(specialId)
  617. keywords := []string{keyword1, keyword2, keyword3, keyword4}
  618. sendInfo := new(SendWxCategoryTemplate)
  619. sendInfo.Keywords = keywords
  620. sendInfo.TemplateId = utils.WxMsgCategoryTemplateIdActivityPublishApply
  621. sendInfo.RedirectTarget = 4
  622. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ARTICLE_ADD
  623. sendInfo.OpenIdArr = openIdArr
  624. sendInfo.RedirectUrl = redirectUrl
  625. err = SendCategoryTemplateMsg(sendInfo)
  626. if err != nil {
  627. return
  628. }
  629. return
  630. }
  631. // 文章互动相关类目模版消息
  632. func SendWxCategoryMsgInteractive(user *models.WxUserItem, interactive string, articleId int, title string) (err error) {
  633. if interactive == "阅读报告" {
  634. //30秒内阅读同一篇报告不做重复推送
  635. key := "CYGX_" + utils.CYGX_OBJ_RESEARCHSUMMARY + "_READ" + strconv.Itoa(articleId) + "_" + strconv.Itoa(user.UserId) + "_CATEGORY"
  636. if utils.Rc.IsExist(key) {
  637. return
  638. }
  639. utils.Rc.Put(key, 1, 30*time.Second)
  640. }
  641. defer func() {
  642. if err != nil {
  643. go utils.SendAlarmMsg(fmt.Sprint("文章互动相关,类目模板消息推送 ,SendWxCategoryMsgInteractive"+err.Error(), "userId:", user.UserId, "互动类型:", interactive), 2)
  644. }
  645. }()
  646. countUser, err := models.GetUserRemind(user.UserId)
  647. if err != nil {
  648. return err
  649. }
  650. if err != nil {
  651. return err
  652. }
  653. if countUser == 0 {
  654. return err
  655. }
  656. var keyword1 string
  657. var keyword2 string
  658. var keyword3 string
  659. var keyword4 string
  660. //获取销售手机号
  661. sellerItemQy, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  662. if err != nil && err.Error() != utils.ErrNoRow() {
  663. return err
  664. }
  665. if sellerItemQy != nil {
  666. sllerAndShareMobileArr, e := GetCompanySellerAndShareMobileByRai(user.CompanyId) //获取所属销售以及对应销售的手机号
  667. if e != nil {
  668. err = errors.New("GetCompanySellerAndShareMobileByRai, Err: " + e.Error())
  669. return
  670. }
  671. sllerAndShareMobiles := strings.Join(sllerAndShareMobileArr, ",")
  672. openIdList, e := models.GetMfyxWxOpenIdByMobileList(sllerAndShareMobiles)
  673. if e != nil {
  674. err = errors.New("GetMfyxWxOpenIdByMobileList, Err: " + e.Error())
  675. return
  676. }
  677. if len(openIdList) == 0 {
  678. return
  679. }
  680. keyword1 = user.RealName + "-" + user.CompanyName
  681. keyword1 = utils.TruncateActivityNameString(keyword1)
  682. keyword2 = fmt.Sprint("互动提醒:", interactive)
  683. keyword3 = utils.TruncateActivityNameString(title)
  684. keyword4 = time.Now().Format(utils.FormatDateTimeMinute2)
  685. openIdArr := make([]string, 0)
  686. for _, v := range openIdList {
  687. openIdArr = append(openIdArr, v.OpenId)
  688. }
  689. redirectUrl := ``
  690. redirectUrl = utils.WX_MSG_PATH_YX_ARTICLE_DETAIL + strconv.Itoa(articleId)
  691. keywords := []string{keyword1, keyword2, keyword3, keyword4}
  692. sendInfo := new(SendWxCategoryTemplate)
  693. sendInfo.Keywords = keywords
  694. sendInfo.TemplateId = utils.WxMsgCategoryTemplateIdActivityPublishApply
  695. sendInfo.RedirectTarget = 4
  696. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ARTICLE_ADD
  697. sendInfo.OpenIdArr = openIdArr
  698. sendInfo.RedirectUrl = redirectUrl
  699. err = SendCategoryTemplateMsg(sendInfo)
  700. if err != nil {
  701. return
  702. }
  703. }
  704. return
  705. }
  706. // 用户搜索操作操作行为,类目模板消息推送
  707. func SearchKeywordUserRmindCategoryMsg(user *models.WxUserItem, keyWord string) (err error) {
  708. defer func() {
  709. if err != nil {
  710. fmt.Println(err)
  711. go utils.SendAlarmMsg(fmt.Sprint("用户搜索操作操作行为,类目模板消息推送失败"+err.Error(), "UserId:", user.UserId, "keyWord:", keyWord), 2)
  712. }
  713. }()
  714. countUser, e := models.GetUserRemind(user.UserId)
  715. if e != nil {
  716. err = errors.New("GetUserRemind, Err: " + e.Error())
  717. return
  718. }
  719. if countUser == 0 {
  720. return
  721. }
  722. var keyword1 string
  723. var keyword2 string
  724. var keyword3 string
  725. var keyword4 string
  726. //获取销售手机号
  727. sellerItemQy, e := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  728. if e != nil && e.Error() != utils.ErrNoRow() {
  729. err = errors.New("GetSellerByCompanyIdCheckFicc, Err: " + e.Error())
  730. return
  731. }
  732. if sellerItemQy != nil {
  733. sllerAndShareMobileArr, e := GetCompanySellerAndShareMobileByRai(user.CompanyId) //获取所属销售以及对应销售的手机号
  734. if e != nil {
  735. err = errors.New("GetCompanySellerAndShareMobileByRai, Err: " + e.Error())
  736. return
  737. }
  738. sllerAndShareMobiles := strings.Join(sllerAndShareMobileArr, ",")
  739. openIdList, e := models.GetMfyxWxOpenIdByMobileList(sllerAndShareMobiles)
  740. if e != nil {
  741. err = errors.New("GetMfyxWxOpenIdByMobileList, Err: " + e.Error())
  742. return
  743. }
  744. if len(openIdList) == 0 {
  745. return
  746. }
  747. keyword1 = user.RealName + "-" + user.CompanyName
  748. keyword2 = fmt.Sprint("互动提醒:搜索")
  749. keyword3 = keyWord
  750. keyword4 = time.Now().Format(utils.FormatDateTimeMinute2)
  751. openIdArr := make([]string, 0)
  752. for _, v := range openIdList {
  753. openIdArr = append(openIdArr, v.OpenId)
  754. }
  755. redirectUrl := ""
  756. keywords := []string{keyword1, keyword2, keyword3, keyword4}
  757. sendInfo := new(SendWxCategoryTemplate)
  758. sendInfo.Keywords = keywords
  759. sendInfo.TemplateId = utils.WxMsgCategoryTemplateIdCompanyApprovalMessageRai
  760. sendInfo.RedirectTarget = 4
  761. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ARTICLE_ADD
  762. sendInfo.OpenIdArr = openIdArr
  763. sendInfo.RedirectUrl = redirectUrl
  764. err = SendCategoryTemplateMsg(sendInfo)
  765. if err != nil {
  766. return
  767. }
  768. }
  769. return
  770. }
  771. // 发送报告提问消息提醒
  772. func SendWxCategoryMsgWithActivityAsk(companyName, realName, sellerName, askTime, askMsg string, openIdList []*models.OpenIdList, msgId int) (err error) {
  773. if len(openIdList) == 0 {
  774. return
  775. }
  776. var msg string
  777. defer func() {
  778. if err != nil {
  779. go utils.SendEmail("发送类目模版消息失败"+"【"+utils.APPNAME+"】"+time.Now().Format("2006-01-02 15:04:05"), msg+";Err:"+err.Error(), utils.EmailSendToUsers)
  780. go utils.SendAlarmMsg(fmt.Sprint("发送报告提问消息提醒类目模版消息失败,用户名", realName, "留言ID:", msgId), 2)
  781. utils.FileLog.Info("发送类目模版消息失败,Err:%s", err.Error())
  782. }
  783. fmt.Println("line 21", err, msg)
  784. }()
  785. var keyword1 string
  786. var keyword2 string
  787. var keyword3 string
  788. var keyword4 string
  789. var keyword5 string
  790. keyword1 = realName
  791. keyword2 = companyName
  792. keyword3 = sellerName
  793. keyword4 = askTime
  794. keyword5 = utils.TruncateActivityNameString("活动提问:" + askMsg)
  795. keywords := []string{keyword1, keyword2, keyword3, keyword4, keyword5}
  796. openIdArr := make([]string, 0)
  797. for _, v := range openIdList {
  798. openIdArr = append(openIdArr, v.OpenId)
  799. }
  800. redirectUrl := utils.WX_MSG_PATH_YX_ACTIVITY_DETAIL + strconv.Itoa(msgId)
  801. sendInfo := new(SendWxCategoryTemplate)
  802. sendInfo.Keywords = keywords
  803. sendInfo.TemplateId = utils.WxCategoryMsgTemplateIdApplyXzs
  804. sendInfo.RedirectTarget = 4
  805. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ARTICLE_ADD
  806. sendInfo.OpenIdArr = openIdArr
  807. sendInfo.RedirectUrl = redirectUrl
  808. err = SendCategoryTemplateMsg(sendInfo)
  809. if err != nil {
  810. return
  811. }
  812. return
  813. }
  814. // 研选类目模板消息
  815. func SendPermissionApplyTemplateMsgAdminByYxCategory(req models.ApplyTryReq, companyId int, usermobile, applyMethod, redirectUrl string) (err error) {
  816. defer func() {
  817. if err != nil {
  818. go utils.SendAlarmMsg("研选类目模板消息消息失败, SendPermissionApplyTemplateMsgAdminByYxCategoryErrMsg: "+err.Error(), 3)
  819. }
  820. }()
  821. //潜在客户、未开权益,已开FICC的客户推给王芳,开通权益的客户推给对应销售
  822. mobileOpenid := utils.WxMsgTemplateIdAskMsgMobilePublic
  823. if companyId > 1 {
  824. raiCount, e := models.GetCompanyProductCount(companyId, utils.COMPANY_PRODUCT_RAI_ID)
  825. if e != nil {
  826. err = errors.New("GetCompanyProductCount, Err: " + e.Error())
  827. return
  828. }
  829. if raiCount > 0 {
  830. sealldetail, e := models.GetRaiSellerByCompanyId(companyId)
  831. if e != nil {
  832. err = errors.New("GetRaiSellerByCompanyId, Err: " + e.Error())
  833. return
  834. }
  835. //如果有共享销售给共享销售也推模版消息
  836. if sealldetail.ShareSellerId > 0 {
  837. adminShare, e := models.GetSellerByAdminId(sealldetail.ShareSellerId)
  838. if e != nil {
  839. err = errors.New("GetSellerByAdminId, Err: " + e.Error())
  840. return
  841. }
  842. listSellerMobile, e := models.GetCygxSellerMobileMap()
  843. if e != nil {
  844. err = errors.New("GetCygxSellerMobileMap, Err: " + e.Error())
  845. return
  846. }
  847. //mapMobile := make(map[string]string)
  848. for _, vm := range listSellerMobile {
  849. if adminShare.Mobile == vm.ServerMobile {
  850. adminShare.Mobile = vm.Mobile
  851. }
  852. }
  853. mobileOpenid = sealldetail.Mobile + "," + adminShare.Mobile
  854. } else {
  855. mobileOpenid = sealldetail.Mobile
  856. }
  857. }
  858. }
  859. fmt.Println("mobileOpenid", mobileOpenid)
  860. openIdList, e := models.GetMfyxWxOpenIdByMobileList(mobileOpenid)
  861. if e != nil {
  862. err = errors.New("GetMfyxWxOpenIdByMobileList, Err: " + e.Error())
  863. return err
  864. }
  865. if len(openIdList) == 0 {
  866. return
  867. }
  868. var keyword1 string
  869. var keyword2 string
  870. var keyword3 string
  871. var keyword4 string
  872. var keyword5 string
  873. keyword1 = req.RealName
  874. keyword2 = utils.TruncateActivityNameString(req.CompanyName)
  875. keyword3 = "权限申请"
  876. keyword4 = time.Now().Format(utils.FormatDateTimeMinute2)
  877. keyword5 = applyMethod
  878. openIdArr := make([]string, 0)
  879. for _, v := range openIdList {
  880. openIdArr = append(openIdArr, v.OpenId)
  881. }
  882. detail, e := models.GetCygxApplyRecordByMobile(usermobile)
  883. if e != nil {
  884. err = errors.New("GetCygxApplyRecordByMobile" + e.Error())
  885. return
  886. }
  887. //redirectUrl := ""
  888. //如果是潜在客户就推送可查看详情的模版消息
  889. if detail.ApplyMethod == 2 {
  890. redirectUrl = utils.WX_MSG_PATH_APPLY_DETAIL + strconv.Itoa(detail.ApplyRecordId)
  891. }
  892. keywords := []string{keyword1, keyword2, keyword3, keyword4, keyword5}
  893. sendInfo := new(SendWxCategoryTemplate)
  894. sendInfo.Keywords = keywords
  895. sendInfo.TemplateId = utils.WxCategoryMsgTemplateIdApplyXzs
  896. sendInfo.RedirectTarget = 4
  897. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ARTICLE_ADD
  898. sendInfo.OpenIdArr = openIdArr
  899. sendInfo.RedirectUrl = redirectUrl
  900. err = SendCategoryTemplateMsg(sendInfo)
  901. return
  902. }
  903. // 有人支付成功时,模板消息发送给王芳、沈涛和推荐人(没有推荐人时给销售)
  904. func SendWxCategoryMsgWxPay(orderDetail *order.CygxOrder) (err error) {
  905. orderCode := orderDetail.OrderCode
  906. defer func() {
  907. if err != nil {
  908. go utils.SendAlarmMsg(fmt.Sprint("有人支付成功时,模板消息发送给王芳、沈涛和推荐人(没有推荐人时给销售)发送模板消息失败:orderCode", orderCode, "Err:", err.Error()), 2)
  909. }
  910. }()
  911. var keyword1 string
  912. var keyword2 string
  913. var keyword3 string
  914. var keyword4 string
  915. var redirectUrl string
  916. var mobile string
  917. mobile = utils.WxMsgTemplateIdAskMsgMobilePublic
  918. keyword1 = orderDetail.CompanyName
  919. if orderDetail.RealName == "" {
  920. keyword2 = "--"
  921. } else {
  922. keyword2 = orderDetail.RealName
  923. }
  924. switch orderDetail.GoodsId {
  925. case 1:
  926. keyword3 = fmt.Sprint(orderDetail.OrderMoney, "元—畅读日卡")
  927. case 2:
  928. keyword3 = fmt.Sprint(orderDetail.OrderMoney, "元—畅读月卡")
  929. default:
  930. keyword3 = fmt.Sprint(orderDetail.OrderMoney, "元—", orderDetail.SourceTitle)
  931. }
  932. //判断跳转文章、活动、专栏详情
  933. switch orderDetail.Source {
  934. case utils.CYGX_OBJ_ARTICLE:
  935. redirectUrl = utils.WX_MSG_PATH_YX_ARTICLE_DETAIL + strconv.Itoa(orderDetail.SourceId)
  936. case utils.CYGX_OBJ_ACTIVITY:
  937. redirectUrl = utils.WX_MSG_PATH_YX_ACTIVITY_DETAIL + strconv.Itoa(orderDetail.SourceId)
  938. case utils.CYGX_OBJ_ACTIVITYVIDEO:
  939. redirectUrl = utils.WX_MSG_PATH_YX_ACTIVITY_DETAIL + strconv.Itoa(orderDetail.SourceId)
  940. case utils.CYGX_OBJ_ACTIVITYVOICE:
  941. redirectUrl = utils.WX_MSG_PATH_YX_ACTIVITY_DETAIL + strconv.Itoa(orderDetail.SourceId)
  942. case utils.CYGX_OBJ_YANXUANSPECIAL:
  943. redirectUrl = utils.WX_MSG_PATH_YX_SPECIAL_DETAIL + strconv.Itoa(orderDetail.SourceId)
  944. }
  945. //判断是否有分享人或者销售
  946. var adminId int
  947. if orderDetail.ShareId > 0 {
  948. adminId = orderDetail.ShareId
  949. } else if orderDetail.SellerId > 0 {
  950. adminId = orderDetail.SellerId
  951. }
  952. if adminId > 0 {
  953. adminDetail, e := models.GetSellerByAdminId(adminId)
  954. if e != nil {
  955. err = errors.New("GetYanxuanSpecialFollowUserById, Err: " + e.Error())
  956. return
  957. }
  958. mobile += "," + adminDetail.Mobile
  959. }
  960. openIdList, err := models.GetMfyxWxOpenIdByMobileList(mobile)
  961. if err != nil && err.Error() != utils.ErrNoRow() {
  962. return err
  963. }
  964. if len(openIdList) == 0 {
  965. err = nil
  966. return
  967. }
  968. keyword4 = time.Now().Format(utils.FormatDateTimeMinute2)
  969. openIdArr := make([]string, 0)
  970. for _, v := range openIdList {
  971. openIdArr = append(openIdArr, v.OpenId)
  972. }
  973. keyword1 = utils.TruncateActivityNameString(keyword1)
  974. keyword3 = utils.TruncateActivityNameString(keyword3)
  975. keywords := []string{keyword1, keyword2, keyword3, keyword4}
  976. sendInfo := new(SendWxCategoryTemplate)
  977. sendInfo.Keywords = keywords
  978. sendInfo.TemplateId = utils.WxMsgCategoryTemplateIdCompanyApprovalMessageRai
  979. sendInfo.RedirectTarget = 4
  980. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ARTICLE_ADD
  981. sendInfo.OpenIdArr = openIdArr
  982. sendInfo.RedirectUrl = redirectUrl
  983. err = SendCategoryTemplateMsg(sendInfo)
  984. if err != nil {
  985. return
  986. }
  987. return
  988. }
  989. // 专栏文章有留言时,模板消息通知作者
  990. func SendWxCategoryMsgByYanxuanSpecialMassageByAuthor(content string, yanxuanSpecialBySpeciaDetail *models.CygxYanxuanSpecialItem) (err error) {
  991. defer func() {
  992. if err != nil {
  993. go utils.SendAlarmMsg(fmt.Sprint(" 作者回复读者留言时,模板消息通知作者 发送模板消息失败:yanxuanSpecialBySpeciaDetail , messageId :", "Err:", err.Error()), 2)
  994. }
  995. }()
  996. var keyword1 string
  997. var keyword2 string
  998. var redirectUrl string
  999. var mobile string
  1000. //mobile = utils.WxMsgTemplateIdAskMsgMobilePublic
  1001. keyword1 = "专栏文章有新的留言"
  1002. keyword2 = utils.TruncateActivityNameString(content)
  1003. userInfo, e := models.GetWxUserItemByUserId(yanxuanSpecialBySpeciaDetail.UserId)
  1004. if e != nil {
  1005. err = errors.New("GetMfyxWxOpenIdByMobileList, Err: " + e.Error())
  1006. return
  1007. }
  1008. mobile = userInfo.Mobile
  1009. if utils.RunMode == "release" {
  1010. redirectUrl = utils.WX_MSG_PATH_YX_SPECIAL_MASSAGE_MANAGE_LIST
  1011. }
  1012. openIdList, e := models.GetMfyxWxOpenIdByMobileList(mobile)
  1013. if e != nil && e.Error() != utils.ErrNoRow() {
  1014. err = errors.New("GetMfyxWxOpenIdByMobileList, Err: " + e.Error())
  1015. return
  1016. }
  1017. if len(openIdList) == 0 {
  1018. err = nil
  1019. return
  1020. }
  1021. openIdArr := make([]string, 0)
  1022. for _, v := range openIdList {
  1023. openIdArr = append(openIdArr, v.OpenId)
  1024. }
  1025. keyword1 = utils.TruncateActivityNameString(keyword1)
  1026. keywords := []string{keyword1, keyword2}
  1027. sendInfo := new(SendWxCategoryTemplate)
  1028. sendInfo.Keywords = keywords
  1029. sendInfo.TemplateId = utils.WxMsgCategoryTemplateIdAddMessage
  1030. sendInfo.RedirectTarget = 4
  1031. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ARTICLE_ADD
  1032. sendInfo.OpenIdArr = openIdArr
  1033. sendInfo.RedirectUrl = redirectUrl
  1034. err = SendCategoryTemplateMsg(sendInfo)
  1035. if err != nil {
  1036. return
  1037. }
  1038. return
  1039. }
  1040. // 作者回复读者留言时,模板消息通知读者
  1041. func SendWxCategoryMsgByYanxuanSpecialMassage(parentId, messageId int, content string, yanxuanSpecialBySpeciaDetail *models.CygxYanxuanSpecialItem) (err error) {
  1042. defer func() {
  1043. if err != nil {
  1044. go utils.SendAlarmMsg(fmt.Sprint(" 作者回复读者留言时,模板消息通知读者 发送模板消息失败:SendWxCategoryMsgByYanxuanSpecialMassage , messageId :", messageId, "Err:", err.Error()), 2)
  1045. }
  1046. }()
  1047. var keyword1 string
  1048. var keyword2 string
  1049. var keyword3 string
  1050. var keyword4 string
  1051. var redirectUrl string
  1052. var mobile string
  1053. //mobile = utils.WxMsgTemplateIdAskMsgMobilePublic
  1054. keyword1 = yanxuanSpecialBySpeciaDetail.Title
  1055. keyword2 = "作者回复了您的留言"
  1056. keyword3 = utils.TruncateActivityNameString(content)
  1057. keyword4 = time.Now().Format(utils.FormatDateTimeMinute2)
  1058. if utils.RunMode == "release" {
  1059. redirectUrl = utils.WX_MSG_PATH_YX_SPECIAL_MASSAGE_DETAIL + strconv.Itoa(messageId)
  1060. }
  1061. messagerDetail, e := models.GetCygxYanxuanSpecialMessagerDetailById(parentId)
  1062. if e != nil {
  1063. err = errors.New("GetMfyxWxOpenIdByMobileList, Err: " + e.Error())
  1064. return
  1065. }
  1066. mobile = messagerDetail.Mobile
  1067. openIdList, e := models.GetMfyxWxOpenIdByMobileList(mobile)
  1068. if e != nil && e.Error() != utils.ErrNoRow() {
  1069. err = errors.New("GetMfyxWxOpenIdByMobileList, Err: " + e.Error())
  1070. return
  1071. }
  1072. if len(openIdList) == 0 {
  1073. err = nil
  1074. return
  1075. }
  1076. openIdArr := make([]string, 0)
  1077. for _, v := range openIdList {
  1078. openIdArr = append(openIdArr, v.OpenId)
  1079. }
  1080. keyword1 = utils.TruncateActivityNameString(keyword1)
  1081. keyword3 = utils.TruncateActivityNameString(keyword3)
  1082. keywords := []string{keyword1, keyword2, keyword3, keyword4}
  1083. sendInfo := new(SendWxCategoryTemplate)
  1084. sendInfo.Keywords = keywords
  1085. sendInfo.TemplateId = utils.WxMsgCategoryTemplateIdActivityPublishApply
  1086. sendInfo.RedirectTarget = 4
  1087. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ARTICLE_ADD
  1088. sendInfo.OpenIdArr = openIdArr
  1089. sendInfo.RedirectUrl = redirectUrl
  1090. err = SendCategoryTemplateMsg(sendInfo)
  1091. if err != nil {
  1092. return
  1093. }
  1094. return
  1095. }