123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591 |
- package cygx
- import (
- "errors"
- "fmt"
- "hongze/hz_crm_api/models"
- "hongze/hz_crm_api/models/company"
- "hongze/hz_crm_api/models/cygx"
- "hongze/hz_crm_api/services"
- "hongze/hz_crm_api/services/alarm_msg"
- "hongze/hz_crm_api/utils"
- "html"
- "strconv"
- "strings"
- "time"
- )
- // 修改活动人数限制之后,对于因为人数已满而失败的用户,推送模板消息
- func SendWxMsgWithCygxActivityUpdateLimitPeople(activityId int) (err error) {
- var msg string
- defer func() {
- if err != nil {
- fmt.Println(err)
- go alarm_msg.SendAlarmMsg("修改活动人数限制之后,对于因为人数已满而失败的用户,推送模板消息,发送模版消息失败,Err:"+err.Error()+";msg:"+msg, 3)
- utils.FileLogCygx.Info(fmt.Sprintf("发送模版消息失败,Err:%s,%s", err.Error(), msg))
- }
- }()
- activityInfo, e := cygx.GetAddActivityInfoById(activityId)
- if e != nil {
- err = errors.New("活动不存在, Err: " + e.Error())
- return
- }
- if activityInfo == nil {
- return
- }
- //已经推送过的不做二次推送
- //listSendOpendId, err := models.GeUserTemplateRecordListBysendType(utils.TEMPLATE_MSG_CYGX_ACTIVITY_LIMIT_PEOPLE, strconv.Itoa(activityId))
- //已经推送过的不做二次推送
- //listSendOpendId, err := cygx.GeCygxActivityUserTemplateRecordListByActivityId(activityId, utils.TEMPLATE_MSG_CYGX_ACTIVITY_LIMIT_PEOPLE)
- //if err != nil && err.Error() != utils.ErrNoRow() {
- // return err
- //}
- //if err != nil && err.Error() != utils.ErrNoRow() {
- // return err
- //}
- //mapSendOpenid := make(map[string]int)
- //for _, v := range listSendOpendId {
- // mapSendOpenid[v.OpenId] = v.UserId
- //}
- var condition string
- var pars []interface{}
- condition = ` AND do_fail_type = 1 AND activity_id = ? `
- pars = append(pars, activityId)
- listSignup, e := cygx.GetActivitySignupList(condition, pars)
- if e != nil {
- err = errors.New("GetResourceDataList, Err: " + e.Error())
- return
- }
- var mobileArr []string
- for _, v := range listSignup {
- if v.Mobile != "" {
- mobileArr = append(mobileArr, v.Mobile)
- }
- }
- mobileLen := len(mobileArr)
- if mobileLen == 0 {
- return
- }
- //condition = ""
- //pars = make([]interface{}, 0)
- //condition += ` AND u.mobile IN (` + utils.GetOrmInReplace(mobileLen) + `)`
- //pars = append(pars, mobileArr)
- openIdList, e := cygx.GetUserRecordListByMobileArr(mobileArr)
- if e != nil {
- err = errors.New("GetWxOpenIdBList, Err: " + e.Error())
- return
- }
- if len(openIdList) == 0 {
- return
- }
- //openIdArr := make([]string, len(openIdList))
- //for i, v := range openIdList {
- // if mapSendOpenid[v.OpenId] > 0 {
- // continue
- // }
- // openIdArr[i] = v.OpenId
- //}
- var openiditems []*cygx.CygxActivityUserTemplateRecord
- var openIdArr []string
- for _, v := range openIdList {
- openIdArr = append(openIdArr, v.OpenId)
- openiditem := new(cygx.CygxActivityUserTemplateRecord)
- openiditem.ActivityId = activityId
- openiditem.UserId = v.UserId
- openiditem.OpenId = v.OpenId
- openiditem.SendType = utils.TEMPLATE_MSG_CYGX_ACTIVITY_LIMIT_PEOPLE
- openiditem.CreateTime = time.Now()
- openiditems = append(openiditems, openiditem)
- }
- if activityInfo.ChartPermissionId != utils.CHART_PERMISSION_ID_YANXUAN {
- //需求池 1043:深圳进门财经科技股份有限公司下所有的账号,所有活动的新增修改都做推送,所有的报告的新增修改都不做推送。
- jmcjOpenId := GetUserOpenidByComapnyIdRai(utils.JMCJ_COMPANY_ID)
- for _, v := range jmcjOpenId {
- if !utils.InArrayByStr(openIdArr, v) {
- openIdArr = append(openIdArr, v)
- }
- }
- }
- first := "您好,本场活动已增加活动名额至" + activityInfo.LimitPeopleNum + "人,欢迎报名"
- keyword1 := activityInfo.ActivityName
- keyword2 := "已增加活动名额至" + activityInfo.LimitPeopleNum + "人,欢迎报名"
- keyword3 := ""
- keyword4 := ""
- remark := "点击查看活动详情"
- redirectUrl := utils.WX_MSG_PATH_ACTIVITY_DETAIL + strconv.Itoa(activityId)
- sendInfo := new(services.SendWxTemplate)
- sendInfo.First = first
- sendInfo.Keyword1 = keyword1
- sendInfo.Keyword2 = keyword2
- sendInfo.Keyword3 = keyword3
- sendInfo.Keyword4 = keyword4
- sendInfo.Remark = remark
- sendInfo.TemplateId = utils.WxMsgTemplateIdActivityChangeApplyXzs
- sendInfo.RedirectUrl = redirectUrl
- sendInfo.RedirectTarget = 3
- sendInfo.Resource = strconv.Itoa(activityId)
- sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ACTIVITY_LIMIT_PEOPLE
- sendInfo.OpenIdArr = openIdArr
- e = services.SendTemplateMsg(sendInfo)
- if e != nil {
- err = errors.New("SendTemplateMsg, Err: " + e.Error())
- return
- }
- //活动发布推送的Openid记录
- if len(openiditems) > 0 {
- e = cygx.AddCygxActivityUserTemplateRecordMulti(openiditems)
- if e != nil {
- err = errors.New("AddCygxActivityUserTemplateRecordMulti, Err: " + e.Error())
- return
- }
- }
- return
- }
- // 销售或后台管理员给用户添加报名之后,进行模版消息推送
- func SendWxMsgWithCygxActivitySignUpBySell(items []*cygx.CygxSignupUser) (err error) {
- var msg string
- defer func() {
- if err != nil {
- fmt.Println(err)
- go alarm_msg.SendAlarmMsg("修改活动人数限制之后,对于因为人数已满而失败的用户,推送模板消息,发送模版消息失败,Err:"+err.Error()+";msg:"+msg, 3)
- utils.FileLogCygx.Info(fmt.Sprintf("发送模版消息失败,Err:%s,%s", err.Error(), msg))
- }
- }()
- if len(items) == 0 {
- return
- }
- //var condition string
- //var pars []interface{}
- for _, v := range items {
- activityId := v.ActivityId
- uid := v.UserId
- activityInfo, e := cygx.GetAddActivityInfoById(activityId)
- if e != nil {
- err = errors.New("活动不存在, Err: " + e.Error())
- return
- }
- if activityInfo == nil {
- return
- }
- wxUser, e := models.GetWxUserByUserId(uid)
- if e != nil {
- err = errors.New("查询用户信息失败, Err: " + e.Error())
- return
- }
- var mobileArr []string
- mobileArr = append(mobileArr, wxUser.Mobile)
- mobileLen := len(mobileArr)
- if mobileLen == 0 {
- return
- }
- //condition = ""
- //pars = make([]interface{}, 0)
- //condition += ` AND u.mobile IN (` + utils.GetOrmInReplace(mobileLen) + `)`
- //pars = append(pars, mobileArr)
- openIdList, e := cygx.GetUserRecordListByMobileArr(mobileArr)
- if e != nil {
- err = errors.New("GetWxOpenIdBList, Err: " + e.Error())
- return
- }
- if len(openIdList) == 0 {
- return
- }
- openIdArr := make([]string, len(openIdList))
- for i, v := range openIdList {
- fmt.Println(v.OpenId)
- openIdArr[i] = v.OpenId
- }
- first := "对口销售已为您报名本场活动"
- keyword1 := "销售已为您报名:" + activityInfo.ActivityName
- keyword2 := activityInfo.ActivityTimeText
- keyword3 := ""
- keyword4 := ""
- remark := "点击查看活动详情"
- redirectUrl := utils.WX_MSG_PATH_ACTIVITY_DETAIL + strconv.Itoa(activityId)
- sendInfo := new(services.SendWxTemplate)
- sendInfo.First = first
- sendInfo.Keyword1 = keyword1
- sendInfo.Keyword2 = keyword2
- sendInfo.Keyword3 = keyword3
- sendInfo.Keyword4 = keyword4
- sendInfo.Remark = remark
- sendInfo.TemplateId = utils.WxMsgTemplateIdActivityApplyXzs
- sendInfo.RedirectUrl = redirectUrl
- sendInfo.RedirectTarget = 3
- sendInfo.Resource = strconv.Itoa(activityId)
- sendInfo.SendType = utils.TEMPLATE_MSG_ACTIVITY_APPOINTMENT
- sendInfo.OpenIdArr = openIdArr
- e = services.SendTemplateMsg(sendInfo)
- if e != nil {
- err = errors.New("SendTemplateMsg, Err: " + e.Error())
- return
- }
- }
- return
- }
- // 已结束的活动上传音频或视频后给已关注这个活动关联的产业的正式、试用 客户发送模板信息
- func SendWxMsgWithUpdateActivityVideoAndVoice(activityId int, fileName string) (err error) {
- defer func() {
- if err != nil {
- fmt.Println(err)
- go alarm_msg.SendAlarmMsg(fmt.Sprint("已结束的活动上传音频或视频后给已关注这个活动关联的产业的正式、试用 客户发送模板信息失败,Err:"+err.Error()+";activityId:", activityId), 3)
- //utils.FileLogCygx.Info(fmt.Sprintf("发送模版消息失败,Err:%s,%s", err.Error(), msg))
- }
- }()
- activityInfo, e := cygx.GetAddActivityInfoById(activityId)
- if e != nil {
- err = errors.New("活动不存在, Err: " + e.Error())
- return
- }
- if activityInfo == nil {
- return
- }
- industrialList, e := cygx.GetIndustrialActivityGroupListByactivityIds(strconv.Itoa(activityId))
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = errors.New("GetIndustrialActivityGroupListByactivityIds: " + e.Error())
- return
- }
- //if len(industrialList) == 0 {
- // return
- //}
- var industrialManagementIds []int
- for _, v := range industrialList {
- industrialManagementIds = append(industrialManagementIds, v.IndustrialManagementId)
- }
- lenindustrialManagementIds := len(industrialManagementIds)
- if lenindustrialManagementIds == 0 {
- return
- }
- var condition string
- var pars []interface{}
- //获取试用正式权益客户
- condition = " AND product_id = 2 AND `status` IN('正式','试用') "
- listCompany, e := company.GetCompanyProductList(condition, pars)
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = errors.New("GetCompanyProductList, Err: " + e.Error())
- return
- }
- var companyIds []int
- for _, v := range listCompany {
- companyIds = append(companyIds, v.CompanyId)
- }
- lencompanyIds := len(companyIds)
- if lencompanyIds == 0 {
- return
- }
- //根据产业关注ID,与有权限的公司ID获取对应的用户列表
- condition = " AND industrial_management_id IN (" + utils.GetOrmInReplace(lenindustrialManagementIds) + ") AND company_id IN (" + utils.GetOrmInReplace(lencompanyIds) + ") "
- pars = append(pars, industrialManagementIds, companyIds)
- userFllowList, e := cygx.GetCygxIndustryFllowList(condition, pars, 0, 0)
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = errors.New("GetCygxIndustryFllowList, Err: " + e.Error())
- return
- }
- //获取这些用户的手机号
- var mobileArr []string
- for _, v := range userFllowList {
- mobileArr = append(mobileArr, v.Mobile)
- }
- mobileLen := len(mobileArr)
- if mobileLen == 0 {
- return
- }
- openIdList, e := cygx.GetUserRecordListByMobileArr(mobileArr)
- if e != nil {
- err = errors.New("GetWxOpenIdBList, Err: " + e.Error())
- return
- }
- if len(openIdList) == 0 {
- return
- }
- openIdArr := make([]string, len(openIdList))
- for _, v := range openIdList {
- openIdArr = append(openIdArr, v.OpenId)
- }
- keyword1 := fileName
- keyword2 := "路演回放已发布,欢迎查看"
- keyword3 := ""
- keyword4 := ""
- redirectUrl := utils.WX_MSG_PATH_ACTIVITY_DETAIL + strconv.Itoa(activityId)
- sendInfo := new(services.SendWxTemplate)
- sendInfo.Keyword1 = keyword1
- sendInfo.Keyword2 = keyword2
- sendInfo.Keyword3 = keyword3
- sendInfo.Keyword4 = keyword4
- sendInfo.TemplateId = utils.WxMsgTemplateIdActivityChangeApplyXzs
- sendInfo.RedirectUrl = redirectUrl
- sendInfo.RedirectTarget = 3
- sendInfo.Resource = strconv.Itoa(activityId)
- sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ACTIVITY_LIMIT_PEOPLE
- sendInfo.OpenIdArr = openIdArr
- e = services.SendTemplateMsg(sendInfo)
- if e != nil {
- err = errors.New("SendTemplateMsg, Err: " + e.Error())
- return
- }
- return
- }
- // 活动更改时间消息通知
- func SendWxMsgWithCygxActivityUpdateTime(activityId int, oldStr, newStr, strType string) (err error) {
- var msg string
- defer func() {
- if err != nil {
- go alarm_msg.SendAlarmMsg("发送模版消息失败,Err:"+err.Error()+";msg:"+msg, 3)
- utils.FileLogCygx.Info(fmt.Sprintf("发送模版消息失败,Err:%s,%s", err.Error(), msg))
- }
- if msg != "" {
- utils.FileLogCygx.Info("发送模版消息失败,msg:%s", msg)
- }
- }()
- activityInfo, err := cygx.GetAddActivityInfoById(activityId)
- if err != nil {
- msg = "GetReportInfo Err:" + err.Error()
- return
- }
- if activityInfo == nil {
- utils.FileLogCygx.Info("活动信息不存在")
- return
- }
- var openIdList []*cygx.OpenIdList
- openIdList, err = cygx.GetActivityOpenIdList(activityId)
- if err != nil {
- msg = "get openIdList err:" + err.Error()
- return
- }
- mapOpenid := make(map[int]string)
- for _, v := range openIdList {
- mapOpenid[v.UserId] = v.OpenId
- }
- //添加预约纪要的openid
- openIdListAppointment, err := cygx.GetActivityAppointmentOpenIdList(activityId)
- if err != nil {
- msg = "GetActivityAppointmentOpenIdList err:" + err.Error()
- return
- }
- if len(openIdListAppointment) > 0 {
- for _, v := range openIdListAppointment {
- if _, ok := mapOpenid[v.UserId]; !ok {
- item := new(cygx.OpenIdList)
- item.UserId = v.UserId
- item.OpenId = v.OpenId
- openIdList = append(openIdList, item)
- }
- mapOpenid[v.UserId] = v.OpenId
- }
- }
- //添加带问的openid
- openIdListActivityHelpAsk, err := cygx.GetActivityHelpAskOpenIdList(activityId)
- if err != nil {
- msg = "openIdListActivityHelpAsk err:" + err.Error()
- return
- }
- if len(openIdListActivityHelpAsk) > 0 {
- for _, v := range openIdListActivityHelpAsk {
- if _, ok := mapOpenid[v.UserId]; !ok {
- item := new(cygx.OpenIdList)
- item.UserId = v.UserId
- item.OpenId = v.OpenId
- openIdList = append(openIdList, item)
- }
- mapOpenid[v.UserId] = v.OpenId
- }
- }
- if len(openIdList) == 0 {
- return err
- }
- //sendMap := make(map[string]interface{})
- //sendData := make(map[string]interface{})
- var first string
- var keyword1, keyword2, keyword3, keyword4, redirectUrl string
- activityInfo.ActivityTypeName = strings.Replace(activityInfo.ActivityTypeName, "(C类)", "", -1)
- if strType == "timeType" {
- //first = "您有一场【" + activityInfo.ActivityTypeName + "】发生了时间变更"
- keyword2 = "时间变更为:【 " + newStr + "】"
- } else if strType == "expertType" {
- //first = "您有一场【" + activityInfo.ActivityTypeName + "】发生了专家变更"
- keyword2 = "专家变更为:【" + newStr + "】"
- } else if strType == "addressType" {
- //first = "您有一场【" + activityInfo.ActivityTypeName + "】发生了地址变更"
- keyword2 = "地点变更为:【" + newStr + "】"
- } else if strType == "participationCode" {
- //first = "您有一场【" + activityInfo.ActivityTypeName + "】公布了拨入密码"
- keyword2 = "拨入密码为: " + newStr
- } else if strType == "Theme" {
- //first = "您有一场【" + activityInfo.ActivityTypeName + "】更新了活动主题"
- newStr = strings.Replace(newStr, "</p><p>", "\n", -1)
- newStr = html.EscapeString(newStr)
- newStrHtml, _ := cygx.GetReportContentTextSub(newStr)
- newStr = newStrHtml
- keyword2 = "主题变更为: " + newStr
- }
- keyword1 = activityInfo.ActivityName
- var openIdArr []string
- for _, v := range openIdList {
- openIdArr = append(openIdArr, v.OpenId)
- }
- if activityInfo.ChartPermissionId != utils.CHART_PERMISSION_ID_YANXUAN {
- //需求池 1043:深圳进门财经科技股份有限公司下所有的账号,所有活动的新增修改都做推送,所有的报告的新增修改都不做推送。
- jmcjOpenId := GetUserOpenidByComapnyIdRai(utils.JMCJ_COMPANY_ID)
- for _, v := range jmcjOpenId {
- if !utils.InArrayByStr(openIdArr, v) {
- openIdArr = append(openIdArr, v)
- }
- }
- }
- redirectUrl = utils.WX_MSG_PATH_ACTIVITY_DETAIL + strconv.Itoa(activityId) + "&IsSendWx=1"
- sendInfo := new(services.SendWxTemplate)
- sendInfo.First = first
- sendInfo.Keyword1 = keyword1
- sendInfo.Keyword2 = keyword2
- sendInfo.Keyword3 = keyword3
- sendInfo.Keyword4 = keyword4
- //sendInfo.Remark = remark
- sendInfo.TemplateId = utils.WxMsgTemplateIdActivityChangeApplyXzs
- sendInfo.RedirectUrl = redirectUrl
- sendInfo.RedirectTarget = 3
- sendInfo.Resource = strconv.Itoa(activityId)
- sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ACTIVITY_UPDATE
- sendInfo.OpenIdArr = openIdArr
- e := services.SendTemplateMsg(sendInfo)
- if e != nil {
- err = errors.New("推送模板消息失败" + e.Error())
- return
- }
- return
- }
- // 活动取消消息通知
- func SendWxMsgWithCygxActivity(activityId int) (err error) {
- var msg string
- defer func() {
- if err != nil {
- go alarm_msg.SendAlarmMsg("发送模版消息失败,Err:"+err.Error()+";msg:"+msg, 3)
- utils.FileLogCygx.Info(fmt.Sprintf("发送模版消息失败,Err:%s,%s", err.Error(), msg))
- }
- if msg != "" {
- utils.FileLogCygx.Info("发送模版消息失败,msg:%s", msg)
- }
- }()
- activityInfo, err := cygx.GetAddActivityInfoById(activityId)
- if err != nil {
- msg = "GetReportInfo Err:" + err.Error()
- return
- }
- var openIdList []*cygx.OpenIdList
- openIdList, err = cygx.GetActivityOpenIdList(activityId)
- if err != nil {
- msg = "get GetActivityOpenIdList err:" + err.Error()
- return
- }
- mapOpenid := make(map[int]string)
- for _, v := range openIdList {
- mapOpenid[v.UserId] = v.OpenId
- }
- //添加预约纪要的openid
- openIdListAppointment, err := cygx.GetActivityAppointmentOpenIdList(activityId)
- if err != nil {
- msg = "GetActivityAppointmentOpenIdList err:" + err.Error()
- return
- }
- if len(openIdListAppointment) > 0 {
- for _, v := range openIdListAppointment {
- if _, ok := mapOpenid[v.UserId]; !ok {
- item := new(cygx.OpenIdList)
- item.UserId = v.UserId
- item.OpenId = v.OpenId
- openIdList = append(openIdList, item)
- }
- mapOpenid[v.UserId] = v.OpenId
- }
- }
- //添加带问的openid
- openIdListActivityHelpAsk, err := cygx.GetActivityHelpAskOpenIdList(activityId)
- if err != nil {
- msg = "openIdListActivityHelpAsk err:" + err.Error()
- return
- }
- if len(openIdListActivityHelpAsk) > 0 {
- for _, v := range openIdListActivityHelpAsk {
- if _, ok := mapOpenid[v.UserId]; !ok {
- item := new(cygx.OpenIdList)
- item.UserId = v.UserId
- item.OpenId = v.OpenId
- openIdList = append(openIdList, item)
- }
- mapOpenid[v.UserId] = v.OpenId
- }
- }
- activityInfo.ActivityTypeName = strings.Replace(activityInfo.ActivityTypeName, "(C类)", "", -1)
- if len(openIdList) == 0 {
- return err
- }
- var keyword1, keyword2, keyword3, keyword4, redirectUrl string
- keyword1 = activityInfo.ActivityName
- keyword2 = "活动已取消"
- var openIdArr []string
- for _, v := range openIdList {
- openIdArr = append(openIdArr, v.OpenId)
- }
- if activityInfo.ChartPermissionId != utils.CHART_PERMISSION_ID_YANXUAN {
- //需求池 1043:深圳进门财经科技股份有限公司下所有的账号,所有活动的新增修改都做推送,所有的报告的新增修改都不做推送。
- jmcjOpenId := GetUserOpenidByComapnyIdRai(utils.JMCJ_COMPANY_ID)
- for _, v := range jmcjOpenId {
- if !utils.InArrayByStr(openIdArr, v) {
- openIdArr = append(openIdArr, v)
- }
- }
- }
- redirectUrl = utils.WX_MSG_PATH_ACTIVITY_DETAIL + strconv.Itoa(activityId) + "&IsSendWx=1"
- sendInfo := new(services.SendWxTemplate)
- //sendInfo.First = first
- sendInfo.Keyword1 = keyword1
- sendInfo.Keyword2 = keyword2
- sendInfo.Keyword3 = keyword3
- sendInfo.Keyword4 = keyword4
- //sendInfo.Remark = remark
- sendInfo.TemplateId = utils.WxMsgTemplateIdActivityChangeApplyXzs
- sendInfo.RedirectUrl = redirectUrl
- sendInfo.RedirectTarget = 3
- sendInfo.Resource = strconv.Itoa(activityId)
- sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ACTIVITY_CACLE
- sendInfo.OpenIdArr = openIdArr
- err = services.SendTemplateMsg(sendInfo)
- return
- }
|