123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688 |
- package services
- import (
- "encoding/json"
- "errors"
- "fmt"
- "hongze/hongze_clpt/models"
- "hongze/hongze_clpt/utils"
- "io/ioutil"
- "net/http"
- "strconv"
- "strings"
- "time"
- "unicode"
- )
- type SendWxCategoryTemplate struct {
- WxAppId string `description:"公众号appId"`
- Keywords []string `description:"模板消息keyword字段"`
- TemplateId string `description:"模板id"`
- RedirectUrl string `description:"跳转地址"`
- RedirectTarget int `description:"小程序跳转目标:1:弘则研报小程序,2:随手办公小程序,3:查研观向,4:买方研选"`
- Resource string `description:"资源唯一标识"`
- SendType int `description:"发送的消息类型:1:报告,2:指标更新提醒,3:审批通知,4:销售领取客户通知,5:活动取消通知,6活动更改时间通知,7:关注的作者发布报告通知,8:发送日报(周报、双周报、月报)模板消息,9:活动预约/报名时间通知"`
- OpenIdArr []string `description:"消息接收者openid"`
- }
- // 推送类目模板消息
- func SendCategoryTemplateMsg(sendInfo *SendWxCategoryTemplate) (err error) {
- //没有获取到openID不推送
- if len(sendInfo.OpenIdArr) == 0 {
- return
- }
- postData, err := json.Marshal(sendInfo)
- if err != nil {
- utils.SendAlarmMsg("SendCategoryTemplateMsg json.Marshal Err:"+err.Error(), 1)
- return err
- }
- body := ioutil.NopCloser(strings.NewReader(string(postData)))
- client := &http.Client{}
- req, err := http.NewRequest("POST", utils.SendWxCategoryTemplateMsgUrl, body)
- if err != nil {
- utils.SendAlarmMsg("SendCategoryTemplateMsg http.NewRequest Err:"+err.Error(), 1)
- return err
- }
- contentType := "application/json;charset=utf-8"
- req.Header.Set("Content-Type", contentType)
- req.Header.Set("Authorization", utils.SendTemplateMsgAuthorization)
- resp, err := client.Do(req)
- if err != nil {
- fmt.Println("http client.Do Err:" + err.Error())
- return err
- }
- defer resp.Body.Close()
- b, err := ioutil.ReadAll(resp.Body)
- if err != nil {
- return err
- }
- result := new(models.BaseResponse)
- err = json.Unmarshal(b, &result)
- if err != nil {
- return err
- }
- if result.Ret != 200 {
- err = errors.New(string(b))
- return err
- }
- return
- }
- // 研选专栏审核完成时,给提交人发送类目模板消息
- func SendWxCategoryMsgSpecialAuthor(specialId, status int) (err error) {
- defer func() {
- if err != nil {
- go utils.SendAlarmMsg(fmt.Sprint("研选专栏审核完成时,给提交人发送模板消息", specialId, ", specialId", err.Error()), 2)
- }
- }()
- var keyword1 string
- var keyword2 string
- var keyword3 string
- var keyword4 string
- var redirectUrl string
- specialItem, e := models.GetYanxuanSpecialItemById(specialId)
- if e != nil {
- err = errors.New("GetYanxuanSpecialFollowUserById, Err: " + e.Error())
- return
- }
- user, e := models.GetWxUserItemByUserId(specialItem.UserId)
- if e != nil {
- err = errors.New("GetWxUserItemByUserId, Err: " + e.Error())
- return err
- }
- openIdList, err := models.GetMfyxUserRecordListByMobile(12, user.Mobile)
- if err != nil && err.Error() != utils.ErrNoRow() {
- return err
- }
- keyword1 = utils.TruncateActivityNameString(specialItem.Title)
- keyword2 = specialItem.NickName
- if status == 1 {
- keyword3 = "文章已通过审核,点击查看详情"
- redirectUrl = utils.WX_MSG_PATH_YX_SPECIAL_DETAIL + strconv.Itoa(specialId)
- } else {
- keyword3 = "文章未通过审核,点击查看驳回原因"
- redirectUrl = utils.WX_MSG_PATH_YX_SPECIAL_CENTER
- }
- keyword4 = time.Now().Format(utils.FormatDateTimeMinute2)
- openIdArr := make([]string, 0)
- for _, v := range openIdList {
- openIdArr = append(openIdArr, v.OpenId)
- }
- keywords := []string{keyword1, keyword2, keyword3, keyword4}
- sendInfo := new(SendWxCategoryTemplate)
- sendInfo.Keywords = keywords
- sendInfo.TemplateId = utils.WxMsgCategoryTemplateIdCompanyApprovalMessageRai
- sendInfo.RedirectTarget = 4
- sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ARTICLE_ADD
- sendInfo.OpenIdArr = openIdArr
- sendInfo.RedirectUrl = redirectUrl
- err = SendCategoryTemplateMsg(sendInfo)
- if err != nil {
- return
- }
- return
- }
- // 研选专栏有新内容审核通过时,给关注此专栏的客户发送模板消息
- func SendWxCategoryMsgSpecialFollow(specialId int) (err error) {
- defer func() {
- if err != nil {
- go utils.SendAlarmMsg(fmt.Sprint("研选专栏有新内容审核通过时,给关注此专栏的客户发送类目模板消息失败", specialId, ", specialId", err.Error()), 2)
- }
- }()
- var keyword1 string
- var keyword2 string
- var keyword3 string
- var keyword4 string
- followers, e := models.GetYanxuanSpecialFollowUserById(specialId)
- if e != nil {
- err = errors.New("GetYanxuanSpecialFollowUserById, Err: " + e.Error())
- return
- }
- if len(followers) == 0 {
- return
- }
- specialItem, e := models.GetYanxuanSpecialItemById(specialId)
- if e != nil {
- err = errors.New("GetYanxuanSpecialFollowUserById, Err: " + e.Error())
- return
- }
- var allInUserId string
- for _, v := range followers {
- allInUserId += strconv.Itoa(v) + ","
- }
- allInUserId = strings.TrimRight(allInUserId, ",")
- userList, err := models.GetWxUserListByUserIds(allInUserId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- return err
- }
- mobile := ``
- for _, v := range userList {
- mobile += v.Mobile + ","
- }
- mobile = strings.TrimRight(mobile, ",")
- openIdList, e := models.GetMfyxWxOpenIdByMobileList(mobile)
- if e != nil {
- err = errors.New("GetSellerByAdminId, Err: " + e.Error())
- return
- }
- if len(openIdList) == 0 {
- return
- }
- keyword1 = specialItem.SpecialName
- keyword2 = "发布了新报告"
- keyword3 = specialItem.Title
- keyword4 = time.Now().Format(utils.FormatDateTimeMinute2)
- openIdArr := make([]string, 0)
- for _, v := range openIdList {
- openIdArr = append(openIdArr, v.OpenId)
- }
- redirectUrl := ""
- redirectUrl = utils.WX_MSG_PATH_YX_SPECIAL_DETAIL + strconv.Itoa(specialId)
- keywords := []string{keyword1, keyword2, keyword3, keyword4}
- sendInfo := new(SendWxCategoryTemplate)
- sendInfo.Keywords = keywords
- sendInfo.TemplateId = utils.WxMsgCategoryTemplateIdActivityPublishApply
- sendInfo.RedirectTarget = 4
- sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ARTICLE_ADD
- sendInfo.OpenIdArr = openIdArr
- sendInfo.RedirectUrl = redirectUrl
- err = SendCategoryTemplateMsg(sendInfo)
- if err != nil {
- return
- }
- return
- }
- // SendReviewCategoryTemplateMsgAdmin 提交审核时给王芳,汪洋发消息
- func SendReviewCategoryTemplateMsgAdmin(specialId int) (err error) {
- defer func() {
- if err != nil {
- go utils.SendAlarmMsg(fmt.Sprint("处理试用申请给王芳,汪洋发消息失败, specialId:", specialId, "ErrMsg", err.Error()), 2)
- }
- }()
- var configCode string
- //研选专栏修改之后给这些手机号推送审核模版消息
- configCode = utils.TPL_MSG_YAN_XUAN_SPECIAL_APPROVAL
- cnf, e := models.GetConfigByCode(configCode)
- if e != nil {
- err = errors.New("GetConfigByCode, Err: " + e.Error() + configCode)
- return
- }
- //王芳、葛琳和沈涛
- openIdList, e := models.GetMfyxWxOpenIdByMobileList(cnf.ConfigValue)
- if e != nil {
- err = errors.New("GetMfyxWxOpenIdByMobileList, Err: " + e.Error())
- return err
- }
- if len(openIdList) == 0 {
- return
- }
- specialItem, e := models.GetYanxuanSpecialItemById(specialId)
- if e != nil {
- err = errors.New("GetYanxuanSpecialFollowUserById, Err: " + e.Error())
- return
- }
- user, e := models.GetWxUserItemByUserId(specialItem.UserId)
- if e != nil {
- err = errors.New("GetWxUserItemByUserId, Err: " + e.Error())
- return err
- }
- var keyword1 string
- var keyword2 string
- var keyword3 string
- var keyword4 string
- var keyword5 string
- keyword1 = checkNickNameString(specialItem.NickName)
- keyword2 = specialItem.RealName + "-" + user.CompanyName
- keyword2 = utils.TruncateActivityNameString(keyword2)
- keyword3 = checkSpecialNameString(specialItem.SpecialName)
- keyword4 = time.Now().Format(utils.FormatDateTimeMinute2)
- keyword5 = "研选专栏提交了内容待审核"
- openIdArr := make([]string, 0)
- for _, v := range openIdList {
- openIdArr = append(openIdArr, v.OpenId)
- }
- redirectUrl := ""
- redirectUrl = utils.WX_MSG_PATH_YX_SPECIAL_ENABLE_DETAIL + strconv.Itoa(specialId)
- keywords := []string{keyword1, keyword2, keyword3, keyword4, keyword5}
- sendInfo := new(SendWxCategoryTemplate)
- sendInfo.Keywords = keywords
- sendInfo.TemplateId = utils.WxCategoryMsgTemplateIdApplyXzs
- sendInfo.RedirectTarget = 4
- sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ARTICLE_ADD
- sendInfo.OpenIdArr = openIdArr
- sendInfo.RedirectUrl = redirectUrl
- err = SendCategoryTemplateMsg(sendInfo)
- if err != nil {
- return
- }
- return
- }
- func checkNickNameString(s string) string {
- var trimmedString string
- hanCount := 0
- for _, r := range s {
- if unicode.Is(unicode.Han, r) {
- trimmedString += string(r)
- hanCount++
- if hanCount == 5 {
- break
- }
- } else {
- return "作者昵称"
- }
- }
- if trimmedString == "" {
- trimmedString = "作者昵称"
- }
- return trimmedString
- }
- func checkSpecialNameString(s string) string {
- var trimmedString string
- hanCount := 0
- for _, r := range s {
- if unicode.Is(unicode.Han, r) {
- trimmedString += string(r)
- hanCount++
- if hanCount == 5 {
- break
- }
- } else {
- return "专栏名称"
- }
- }
- if trimmedString == "" {
- trimmedString = "专栏名称"
- }
- return trimmedString
- }
- // 发送活动提问消息提醒(研选公众号类目模版消息)
- func SendWxCategoryMsgWithAsk(user *models.WxUserItem, activityInfo *models.ActivityDetail, askMsg string, askId int) (err error) {
- if activityInfo.ChartPermissionId != utils.CHART_PERMISSION_ID_YANXUAN {
- return
- }
- defer func() {
- if err != nil {
- fmt.Println(err)
- go utils.SendAlarmMsg(fmt.Sprint("发送活动提问消息提醒类目模版消息失败,用户名", user.RealName, "提问ID:", askId), 2)
- }
- }()
- companyId := user.CompanyId
- var sellerName string
- //潜在客户、未开权益,已开FICC的客户推给王芳,开通权益的客户推给对应销售
- mobile := utils.WxMsgTemplateIdAskMsgMobilePublic
- if companyId > 1 {
- raiCount, e := models.GetCompanyProductCount(companyId, utils.COMPANY_PRODUCT_RAI_ID)
- if e != nil {
- err = errors.New("GetCompanyProductCount, Err: " + e.Error())
- return
- }
- if raiCount > 0 {
- sealldetail, e := models.GetRaiSellerByCompanyId(companyId)
- if e != nil {
- err = errors.New("GetRaiSellerByCompanyId, Err: " + e.Error())
- return
- }
- sellerName = sealldetail.RealName
- mobile += "," + sealldetail.Mobile
- }
- }
- var mobiles []string
- 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) //葛琳、高亦文、董衡、吴昂迪手机号
- mobile += "," + strings.Join(mobiles, ",")
- openIdList, e := models.GetMfyxWxOpenIdByMobileList(mobile)
- if e != nil {
- err = errors.New("GetMfyxWxOpenIdByMobileList, Err: " + e.Error())
- return err
- }
- if len(openIdList) == 0 {
- return
- }
- var keyword1 string
- var keyword2 string
- var keyword3 string
- var keyword4 string
- var keyword5 string
- keyword1 = user.RealName
- keyword2 = utils.TruncateActivityNameString(user.CompanyName)
- keyword3 = sellerName
- keyword4 = time.Now().Format(utils.FormatDateTimeMinute2)
- keyword5 = utils.TruncateActivityNameString("活动提问:" + askMsg)
- keywords := []string{keyword1, keyword2, keyword3, keyword4, keyword5}
- openIdArr := make([]string, 0)
- for _, v := range openIdList {
- openIdArr = append(openIdArr, v.OpenId)
- }
- redirectUrl := utils.WX_MSG_PATH_TEMPLATE_MSG + "SourceId=" + strconv.Itoa(askId) + "&SourceType=2"
- //redirectUrl = ""
- sendInfo := new(SendWxCategoryTemplate)
- sendInfo.Keywords = keywords
- sendInfo.TemplateId = utils.WxCategoryMsgTemplateIdApplyXzs
- sendInfo.RedirectTarget = 4
- sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ARTICLE_ADD
- sendInfo.OpenIdArr = openIdArr
- sendInfo.RedirectUrl = redirectUrl
- err = SendCategoryTemplateMsg(sendInfo)
- return
- }
- // 用户报名模板消息推送(研选公众号类目模版消息)
- func SendNeiRongZuActivitieSignCategoryTemplateMsg(user *models.WxUserItem, activityDetail *models.ActivityDetail) (err error) {
- if activityDetail.ChartPermissionId != utils.CHART_PERMISSION_ID_YANXUAN {
- return
- }
- defer func() {
- if err != nil {
- go utils.SendAlarmMsg(fmt.Sprint("发送用户操作活动消息提醒,文章ID:", activityDetail.ActivityId), 2)
- fmt.Println(err)
- }
- }()
- sellerItemQy, e := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
- if e != nil && e.Error() != utils.ErrNoRow() {
- return
- }
- var mobile string
- var sellerRealName string
- var mobiles []string
- mobiles = append(mobiles, utils.RAI_MOBILE_GAO_YI_WEN, utils.RAI_MOBILE_DONG_HENG, utils.RAI_MOBILE_WU_ANG_DI, utils.MobileShenTao, utils.MobileZhangChuanXin) //高亦文、董衡、吴昂迪手机号
- if sellerItemQy != nil {
- mobiles = append(mobiles, sellerItemQy.Mobile)
- sellerRealName = sellerItemQy.RealName
- } else {
- sellerRealName = "__"
- }
- mobile = strings.Join(mobiles, ",")
- openIdList, e := models.GetMfyxWxOpenIdByMobileList(mobile)
- if e != nil {
- err = errors.New("GetMfyxWxOpenIdByMobileList, Err: " + e.Error())
- return err
- }
- if len(openIdList) == 0 {
- err = nil
- return
- }
- openIdArr := make([]string, 0)
- for _, v := range openIdList {
- openIdArr = append(openIdArr, v.OpenId)
- }
- var keywords []string
- keywords = append(keywords, user.RealName, user.CompanyName, sellerRealName, time.Now().Format(utils.FormatDateTimeMinute2), utils.TruncateActivityNameString("报名:"+activityDetail.ActivityName))
- redirectUrl := utils.WX_MSG_PATH_YX_ACTIVITY_DETAIL + strconv.Itoa(activityDetail.ActivityId) //活动详情地址
- sendInfo := new(SendWxCategoryTemplate)
- sendInfo.Keywords = keywords
- sendInfo.TemplateId = utils.WxCategoryMsgTemplateIdApplyXzs
- sendInfo.RedirectTarget = 4
- sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_APPLY
- sendInfo.OpenIdArr = openIdArr
- sendInfo.RedirectUrl = redirectUrl
- err = SendCategoryTemplateMsg(sendInfo)
- return
- }
- // 用户取消报名模板消息推送(研选公众号类目模版消息)
- func SendActivitieCancelSignCategoryTemplateMsg(user *models.WxUserItem, activityDetail *models.ActivityDetail) (err error) {
- if activityDetail.ChartPermissionId != utils.CHART_PERMISSION_ID_YANXUAN {
- return
- }
- defer func() {
- if err != nil {
- fmt.Println(err)
- go utils.SendAlarmMsg(fmt.Sprint("发送用户操作活动消息提醒,活动ID:", activityDetail.ActivityId), 2)
- }
- }()
- sellerItemQy, e := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
- if e != nil && e.Error() != utils.ErrNoRow() {
- return
- }
- var mobile string
- var sellerRealName string
- var mobiles []string
- mobiles = append(mobiles, utils.RAI_MOBILE_GAO_YI_WEN, utils.RAI_MOBILE_DONG_HENG, utils.RAI_MOBILE_WU_ANG_DI, utils.MobileShenTao, utils.MobileZhangChuanXin) //高亦文、董衡、吴昂迪手机号
- if sellerItemQy != nil {
- mobiles = append(mobiles, sellerItemQy.Mobile)
- sellerRealName = sellerItemQy.RealName
- } else {
- sellerRealName = "__"
- }
- mobile = strings.Join(mobiles, ",")
- openIdList, e := models.GetMfyxWxOpenIdByMobileList(mobile)
- if e != nil {
- err = errors.New("GetMfyxWxOpenIdByMobileList, Err: " + e.Error())
- return err
- }
- if len(openIdList) == 0 {
- err = nil
- return
- }
- openIdArr := make([]string, 0)
- for _, v := range openIdList {
- openIdArr = append(openIdArr, v.OpenId)
- }
- var keywords []string
- keywords = append(keywords, user.RealName, user.CompanyName, sellerRealName, time.Now().Format(utils.FormatDateTimeMinute2), utils.TruncateActivityNameString("取消报名:"+activityDetail.ActivityName))
- redirectUrl := utils.WX_MSG_PATH_YX_ACTIVITY_DETAIL + strconv.Itoa(activityDetail.ActivityId) //活动详情地址
- sendInfo := new(SendWxCategoryTemplate)
- sendInfo.Keywords = keywords
- sendInfo.TemplateId = utils.WxCategoryMsgTemplateIdApplyXzs
- sendInfo.RedirectTarget = 4
- sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_APPLY
- sendInfo.OpenIdArr = openIdArr
- sendInfo.RedirectUrl = redirectUrl
- err = SendCategoryTemplateMsg(sendInfo)
- return
- }
- // 研选类目模板消息
- func SendPermissionApplyTemplateMsgAdminByYxCategory(req models.ApplyTryReq, companyId int, usermobile, applyMethod, redirectUrl string) (err error) {
- defer func() {
- if err != nil {
- go utils.SendAlarmMsg("研选类目模板消息消息失败, SendPermissionApplyTemplateMsgAdminByYxCategoryErrMsg: "+err.Error(), 3)
- }
- }()
- //潜在客户、未开权益,已开FICC的客户推给王芳,开通权益的客户推给对应销售
- mobileOpenid := utils.WxMsgTemplateIdAskMsgMobilePublic
- if companyId > 1 {
- raiCount, e := models.GetCompanyProductCount(companyId, utils.COMPANY_PRODUCT_RAI_ID)
- if e != nil {
- err = errors.New("GetCompanyProductCount, Err: " + e.Error())
- return
- }
- if raiCount > 0 {
- sealldetail, e := models.GetRaiSellerByCompanyId(companyId)
- if e != nil {
- err = errors.New("GetRaiSellerByCompanyId, Err: " + e.Error())
- return
- }
- //如果有共享销售给共享销售也推模版消息
- if sealldetail.ShareSellerId > 0 {
- adminShare, e := models.GetSellerByAdminId(sealldetail.ShareSellerId)
- if e != nil {
- err = errors.New("GetSellerByAdminId, Err: " + e.Error())
- return
- }
- listSellerMobile, e := models.GetCygxSellerMobileMap()
- if e != nil {
- err = errors.New("GetCygxSellerMobileMap, Err: " + e.Error())
- return
- }
- //mapMobile := make(map[string]string)
- for _, vm := range listSellerMobile {
- if adminShare.Mobile == vm.ServerMobile {
- adminShare.Mobile = vm.Mobile
- }
- }
- mobileOpenid = sealldetail.Mobile + "," + adminShare.Mobile
- } else {
- mobileOpenid = sealldetail.Mobile
- }
- }
- }
- openIdList, e := models.GetMfyxWxOpenIdByMobileList(mobileOpenid)
- if e != nil {
- err = errors.New("GetMfyxWxOpenIdByMobileList, Err: " + e.Error())
- return err
- }
- if len(openIdList) == 0 {
- return
- }
- var keyword1 string
- var keyword2 string
- var keyword3 string
- var keyword4 string
- var keyword5 string
- keyword1 = req.RealName
- keyword2 = utils.TruncateActivityNameString(req.CompanyName)
- keyword3 = "权限申请"
- keyword4 = time.Now().Format(utils.FormatDateTimeMinute2)
- keyword5 = applyMethod
- openIdArr := make([]string, 0)
- for _, v := range openIdList {
- openIdArr = append(openIdArr, v.OpenId)
- }
- detail, e := models.GetCygxApplyRecordByMobile(usermobile)
- if e != nil {
- err = errors.New("GetCygxApplyRecordByMobile" + e.Error())
- return
- }
- //redirectUrl := ""
- //如果是潜在客户就推送可查看详情的模版消息
- if detail.ApplyMethod == 2 {
- redirectUrl = utils.WX_MSG_PATH_APPLY_DETAIL + strconv.Itoa(detail.ApplyRecordId)
- }
- keywords := []string{keyword1, keyword2, keyword3, keyword4, keyword5}
- sendInfo := new(SendWxCategoryTemplate)
- sendInfo.Keywords = keywords
- sendInfo.TemplateId = utils.WxCategoryMsgTemplateIdApplyXzs
- sendInfo.RedirectTarget = 4
- sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ARTICLE_ADD
- sendInfo.OpenIdArr = openIdArr
- sendInfo.RedirectUrl = redirectUrl
- err = SendCategoryTemplateMsg(sendInfo)
- return
- }
- // 发送用户留言提醒(研选公众号类目模版消息)
- func SendCommentWxTemplateMsgByYxCategory(req models.AddCygxArticleCommentReq, user *models.WxUserItem, articleInfo *models.ArticleDetail, msgId int) (err error) {
- if articleInfo.ArticleTypeId == 0 {
- return // 非研选的文章不做推送
- }
- defer func() {
- if err != nil {
- go utils.SendAlarmMsg(fmt.Sprint("发送用户用户留言提醒失败,文章ID:", req.ArticleId, "err", err.Error()), 2)
- }
- }()
- companyItem, e := models.GetSellerDetailAllByCompanyId(user.CompanyId)
- if e != nil {
- return
- }
- if companyItem == nil {
- err = errors.New("获取客户所属销售信息失败")
- return
- }
- var keyword1 string
- var keyword2 string
- var keyword3 string
- var keyword4 string
- var keyword5 string
- var redirectUrl string
- var mobile string
- var keywords []string
- keyword1 = user.RealName
- keyword2 = utils.TruncateActivityNameString(companyItem.CompanyName)
- keyword3 = companyItem.SellerName
- keyword4 = time.Now().Format(utils.FormatDateTimeMinute2)
- keyword5 = "报告留言:" + req.Content
- keyword5 = utils.TruncateActivityNameString(keyword5)
- keywords = append(keywords, keyword1, keyword2, keyword3, keyword4, keyword5)
- var mobiles []string
- 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) //葛琳、高亦文、董衡、吴昂迪手机号
- mobile = companyItem.Mobile + "," + utils.WxMsgTemplateIdAskMsgMobilePublic + "," + strings.Join(mobiles, ",")
- //mobile =
- openIdList, e := models.GetMfyxWxOpenIdByMobileList(mobile)
- if e != nil {
- err = errors.New("GetMfyxWxOpenIdByMobileList, Err: " + e.Error())
- return
- }
- if len(openIdList) == 0 {
- return
- }
- openIdArr := make([]string, 0)
- for _, v := range openIdList {
- openIdArr = append(openIdArr, v.OpenId)
- }
- redirectUrl = utils.WX_MSG_PATH_TEMPLATE_MSG + "SourceId=" + strconv.Itoa(msgId) + "&SourceType=1"
- sendInfo := new(SendWxCategoryTemplate)
- sendInfo.Keywords = keywords
- sendInfo.TemplateId = utils.WxCategoryMsgTemplateIdApplyXzs
- sendInfo.RedirectTarget = 4
- sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_APPLY
- sendInfo.OpenIdArr = openIdArr
- sendInfo.RedirectUrl = redirectUrl
- err = SendCategoryTemplateMsg(sendInfo)
- return
- }
- // 发送用户操作活动消息提醒
- func SendWxCategoryMsgWithActivityUserRemind(keyWord1, keyWord2, keyWord3, keyWord4, redirectUrl string, openIdList []*models.OpenIdList, activityId int) (err error) {
- if len(openIdList) == 0 {
- return
- }
- defer func() {
- if err != nil {
- go utils.SendAlarmMsg(fmt.Sprint("发送用户操作活动消息提醒,SendWxCategoryMsgWithActivityUserRemind 文章ID:", activityId), 2)
- }
- }()
- keyWord1 = utils.TruncateActivityNameString(keyWord1)
- openIdArr := make([]string, 0)
- for _, v := range openIdList {
- openIdArr = append(openIdArr, v.OpenId)
- }
- var keywords []string
- keywords = append(keywords, keyWord1, keyWord2, keyWord3, keyWord4)
- sendInfo := new(SendWxCategoryTemplate)
- sendInfo.Keywords = keywords
- sendInfo.TemplateId = utils.WxMsgCategoryTemplateIdActivityPublishApply
- sendInfo.RedirectTarget = 4
- sendInfo.RedirectUrl = redirectUrl
- sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_APPLY
- sendInfo.OpenIdArr = openIdArr
- err = SendCategoryTemplateMsg(sendInfo)
- return
- }
|