Browse Source

no message

xingzai 10 months ago
parent
commit
4799434fb4
4 changed files with 50 additions and 63 deletions
  1. 5 9
      controllers/user.go
  2. 7 45
      services/user.go
  3. 37 8
      services/wechat_send_msg.go
  4. 1 1
      utils/constants.go

+ 5 - 9
controllers/user.go

@@ -933,6 +933,7 @@ func (this *UserController) ApplyTryOut() {
 	detailId := req.DetailId
 	detailId := req.DetailId
 	sourceId = detailId
 	sourceId = detailId
 	source = tryType
 	source = tryType
+	redirectUrl := ""
 	var isResearch bool // 是否属于研选
 	var isResearch bool // 是否属于研选
 	if tryType == "Article" {
 	if tryType == "Article" {
 		detail, err := models.GetArticleDetailById(detailId)
 		detail, err := models.GetArticleDetailById(detailId)
@@ -945,6 +946,7 @@ func (this *UserController) ApplyTryOut() {
 		if detail.ArticleTypeId > 0 {
 		if detail.ArticleTypeId > 0 {
 			isResearch = true
 			isResearch = true
 		}
 		}
+		redirectUrl = utils.WX_MSG_PATH_YX_ARTICLE_DETAIL + strconv.Itoa(detailId)
 	} else if tryType == "Activity" {
 	} else if tryType == "Activity" {
 		detail, err := models.GetAddActivityInfoById(detailId)
 		detail, err := models.GetAddActivityInfoById(detailId)
 		if err != nil {
 		if err != nil {
@@ -956,6 +958,7 @@ func (this *UserController) ApplyTryOut() {
 		if strings.Contains(detail.ChartPermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) {
 		if strings.Contains(detail.ChartPermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) {
 			isResearch = true
 			isResearch = true
 		}
 		}
+		redirectUrl = utils.WX_MSG_PATH_YX_ACTIVITY_DETAIL + strconv.Itoa(detailId)
 	} else if tryType == "MicroAudio" {
 	} else if tryType == "MicroAudio" {
 		// 微路演音频
 		// 微路演音频
 		microAudio, e := models.GetCygxActivityVoiceById(detailId)
 		microAudio, e := models.GetCygxActivityVoiceById(detailId)
@@ -1238,17 +1241,10 @@ func (this *UserController) ApplyTryOut() {
 		br.ErrMsg = "申请失败,Err:" + err.Error()
 		br.ErrMsg = "申请失败,Err:" + err.Error()
 		return
 		return
 	}
 	}
-	if sellerItem == nil {
-		go services.SendPermissionApplyTemplateMsgAdmin(req, mobile, applyMethod, isResearch)
-	} else {
-		openIpItem, _ := models.GetUserRecordByMobile(4, sellerItem.Mobile)
-		if openIpItem != nil && openIpItem.OpenId != "" {
-			go services.SendPermissionApplyTemplateMsg(req.RealName, req.CompanyName, mobile, applyMethod, openIpItem)
-		}
-	}
+	go services.SendPermissionApplyTemplateMsg(req.RealName, req.CompanyName, mobile, applyMethod, redirectUrl, user) //权限申请模板消息推送
 	if isResearch {
 	if isResearch {
 		//如果是研选的报告走研选的类目模版消息
 		//如果是研选的报告走研选的类目模版消息
-		go services.SendPermissionApplyTemplateMsgAdminByYxCategory(req, user.CompanyId)
+		go services.SendPermissionApplyTemplateMsgAdminByYxCategory(req, user.CompanyId, mobile, redirectUrl)
 	}
 	}
 	//添加成功后,设置5分钟缓存,不允许重复添加
 	//添加成功后,设置5分钟缓存,不允许重复添加
 	//utils.Rc.SetNX(cacheKey, user.Mobile, time.Second*60)
 	//utils.Rc.SetNX(cacheKey, user.Mobile, time.Second*60)

+ 7 - 45
services/user.go

@@ -1094,46 +1094,8 @@ func UpdateCygxSubscribe(uid int, unionId string) (err error) {
 	return
 	return
 }
 }
 
 
-// SendPermissionApplyTemplateMsgAdmin 处理试用申请给王芳,汪洋发消息
-func SendPermissionApplyTemplateMsgAdmin(req models.ApplyTryReq, usermobile, applyMethod string, isResearch bool) (err error) {
-	defer func() {
-		if err != nil {
-			go utils.SendAlarmMsg("处理试用申请给王芳,汪洋发消息失败, ErrMsg: "+err.Error(), 3)
-		}
-	}()
-	var configCode string
-	//如果是研选的就推送给汪洋跟王芳,否则就推送给王芳
-	if isResearch {
-		configCode = utils.TPL_MSG_WANG_YANG
-	} else {
-		configCode = utils.TPL_MSG
-	}
-	cnf, e := models.GetConfigByCode(configCode)
-	if e != nil {
-		err = errors.New("GetConfigByCode, Err: " + e.Error() + configCode)
-		return
-	}
-	openIdList, e := models.GetUserRecordListByMobile(4, cnf.ConfigValue)
-	if e != nil && e.Error() != utils.ErrNoRow() {
-		err = errors.New("GetUserRecordListByMobile, Err: " + e.Error() + cnf.ConfigValue)
-		return err
-	}
-
-	for _, v := range openIdList {
-		go SendPermissionApplyTemplateMsg(req.RealName, req.CompanyName, usermobile, applyMethod, v)
-	}
-
-	//openIpItem, e := models.GetUserRecordByMobile(4, cnf.ConfigValue)
-	//if e != nil {
-	//	err = errors.New("GetUserRecordByMobile, Err: " + e.Error() + cnf.ConfigValue)
-	//	return
-	//}
-
-	return
-}
-
 // 研选类目模板消息
 // 研选类目模板消息
-func SendPermissionApplyTemplateMsgAdminByYxCategory(req models.ApplyTryReq, companyId int) (err error) {
+func SendPermissionApplyTemplateMsgAdminByYxCategory(req models.ApplyTryReq, companyId int, usermobile, redirectUrl string) (err error) {
 	defer func() {
 	defer func() {
 		if err != nil {
 		if err != nil {
 			go utils.SendAlarmMsg("研选类目模板消息消息失败, SendPermissionApplyTemplateMsgAdminByYxCategoryErrMsg: "+err.Error(), 3)
 			go utils.SendAlarmMsg("研选类目模板消息消息失败, SendPermissionApplyTemplateMsgAdminByYxCategoryErrMsg: "+err.Error(), 3)
@@ -1141,7 +1103,7 @@ func SendPermissionApplyTemplateMsgAdminByYxCategory(req models.ApplyTryReq, com
 	}()
 	}()
 
 
 	//潜在客户、未开权益,已开FICC的客户推给王芳,开通权益的客户推给对应销售
 	//潜在客户、未开权益,已开FICC的客户推给王芳,开通权益的客户推给对应销售
-	mobile := utils.WxMsgTemplateIdAskMsgMobilePublic
+	mobileOpneid := utils.WxMsgTemplateIdAskMsgMobilePublic
 	if companyId > 1 {
 	if companyId > 1 {
 		raiCount, e := models.GetCompanyProductCount(companyId, utils.COMPANY_PRODUCT_RAI_ID)
 		raiCount, e := models.GetCompanyProductCount(companyId, utils.COMPANY_PRODUCT_RAI_ID)
 		if e != nil {
 		if e != nil {
@@ -1156,10 +1118,10 @@ func SendPermissionApplyTemplateMsgAdminByYxCategory(req models.ApplyTryReq, com
 			err = errors.New("GetRaiSellerByCompanyId, Err: " + e.Error())
 			err = errors.New("GetRaiSellerByCompanyId, Err: " + e.Error())
 			return
 			return
 		}
 		}
-		mobile = sealldetail.Mobile
+		mobileOpneid = sealldetail.Mobile
 	}
 	}
 
 
-	openIdList, e := models.GetMfyxWxOpenIdByMobileList(mobile)
+	openIdList, e := models.GetMfyxWxOpenIdByMobileList(mobileOpneid)
 	if e != nil {
 	if e != nil {
 		err = errors.New("GetMfyxWxOpenIdByMobileList, Err: " + e.Error())
 		err = errors.New("GetMfyxWxOpenIdByMobileList, Err: " + e.Error())
 		return err
 		return err
@@ -1185,12 +1147,12 @@ func SendPermissionApplyTemplateMsgAdminByYxCategory(req models.ApplyTryReq, com
 	for _, v := range openIdList {
 	for _, v := range openIdList {
 		openIdArr = append(openIdArr, v.OpenId)
 		openIdArr = append(openIdArr, v.OpenId)
 	}
 	}
-	detail, e := models.GetCygxApplyRecordByMobile(mobile)
+	detail, e := models.GetCygxApplyRecordByMobile(usermobile)
 	if e != nil {
 	if e != nil {
-		err = errors.New("GetActivitySignupNomeetingCountList" + e.Error())
+		err = errors.New("GetCygxApplyRecordByMobile" + e.Error())
 		return
 		return
 	}
 	}
-	redirectUrl := ""
+	//redirectUrl := ""
 	//如果是潜在客户就推送可查看详情的模版消息
 	//如果是潜在客户就推送可查看详情的模版消息
 	if detail.ApplyMethod == 2 {
 	if detail.ApplyMethod == 2 {
 		redirectUrl = utils.WX_MSG_PATH_APPLY_DETAIL + strconv.Itoa(detail.ApplyRecordId)
 		redirectUrl = utils.WX_MSG_PATH_APPLY_DETAIL + strconv.Itoa(detail.ApplyRecordId)

+ 37 - 8
services/wechat_send_msg.go

@@ -104,24 +104,54 @@ func SendInterviewApplyCancelTemplateMsg(realName, companyName, mobile, articleT
 }
 }
 
 
 // 权限申请
 // 权限申请
-func SendPermissionApplyTemplateMsg(realName, companyName, mobile, applyMethod string, itemOpenid *models.OpenIdList) (err error) {
-
+func SendPermissionApplyTemplateMsg(realName, companyName, mobile, applyMethod, redirectUrl string, user *models.WxUserItem) (err error) {
 	defer func() {
 	defer func() {
 		if err != nil {
 		if err != nil {
-			go utils.SendAlarmMsg(fmt.Sprint("权限申请模板消息推送消息失败,手机号", mobile, "公司:", companyName, "手机号:", mobile, ";Err:"+err.Error()), 2)
+			go utils.SendAlarmMsg(fmt.Sprint("权限申请模板消息推送消息失败,手机号", mobile, "公司:", companyName, "手机号:", mobile), 2)
 		}
 		}
 	}()
 	}()
+	companyId := user.CompanyId
+	//权益客户
+	raiCount, e := models.GetCompanyProductCount(companyId, utils.COMPANY_PRODUCT_RAI_ID)
+	if e != nil {
+		err = errors.New("GetCompanyProductCount, Err: " + e.Error())
+		return
+	}
+	var mobileOpenid string
+	if raiCount == 0 {
+		mobileOpenid = utils.WxMsgTemplateIdAskMsgMobilePublic
+	} else {
+		sealldetail, e := models.GetRaiSellerByCompanyId(companyId)
+		if e != nil {
+			err = errors.New("GetRaiSellerByCompanyId, Err: " + e.Error())
+			return
+		}
+		mobileOpenid = sealldetail.Mobile
+	}
+
+	openIdList, e := models.GetWxOpenIdByMobileList(mobileOpenid)
+	if e != nil {
+		err = errors.New("GetRaiSellerByCompanyId, Err: " + e.Error())
+		return
+	}
+	if len(openIdList) == 0 {
+		return
+	}
+	openIdArr := make([]string, 0)
+
+	for _, v := range openIdList {
+		openIdArr = append(openIdArr, v.OpenId)
+	}
 	var first string
 	var first string
 	var keyword1 string
 	var keyword1 string
 	var keyword2 string
 	var keyword2 string
 	var keyword3 string
 	var keyword3 string
 	var keyword4 string
 	var keyword4 string
 	var remark string
 	var remark string
-	var redirectUrl string
-
+	//var redirectUrl string
 	detail, e := models.GetCygxApplyRecordByMobile(mobile)
 	detail, e := models.GetCygxApplyRecordByMobile(mobile)
 	if e != nil {
 	if e != nil {
-		err = errors.New("GetActivitySignupNomeetingCountList" + e.Error())
+		err = errors.New("GetCygxApplyRecordByMobile" + e.Error())
 		return
 		return
 	}
 	}
 	//如果是潜在客户就推送可查看详情的模版消息
 	//如果是潜在客户就推送可查看详情的模版消息
@@ -132,8 +162,7 @@ func SendPermissionApplyTemplateMsg(realName, companyName, mobile, applyMethod s
 	keyword2 = mobile
 	keyword2 = mobile
 	keyword3 = time.Now().Format(utils.FormatDateTime)
 	keyword3 = time.Now().Format(utils.FormatDateTime)
 	keyword4 = applyMethod
 	keyword4 = applyMethod
-	openIdArr := make([]string, 0)
-	openIdArr = append(openIdArr, itemOpenid.OpenId)
+
 	sendInfo := new(SendWxTemplate)
 	sendInfo := new(SendWxTemplate)
 	sendInfo.First = first
 	sendInfo.First = first
 	sendInfo.Keyword1 = keyword1
 	sendInfo.Keyword1 = keyword1

+ 1 - 1
utils/constants.go

@@ -196,7 +196,7 @@ const (
 	WX_MSG_PATH_YX_COMMENT_DETAIL        = "pages-activity/generationAsk/generationAsk?id="               //研选报告留言详情
 	WX_MSG_PATH_YX_COMMENT_DETAIL        = "pages-activity/generationAsk/generationAsk?id="               //研选报告留言详情
 	WX_MSG_PATH_YX_ACTIVITY_DETAIL       = "pages-activity/activityDetail/activityDetail?IsSendWx=1&id="  //研选活动详情
 	WX_MSG_PATH_YX_ACTIVITY_DETAIL       = "pages-activity/activityDetail/activityDetail?IsSendWx=1&id="  //研选活动详情
 	WX_MSG_PATH_YX_SIGNUP_DETAIL         = "pages-message/activityTemplate/activityTemplate?id="          //研选报名详情
 	WX_MSG_PATH_YX_SIGNUP_DETAIL         = "pages-message/activityTemplate/activityTemplate?id="          //研选报名详情
-	WX_MSG_PATH_YX_ARTICLE_DETAIL        = "pages-user/reportDetail/reportDetail?id="                     //研选纪要详情
+	WX_MSG_PATH_YX_ARTICLE_DETAIL        = "pages-user/reportDetail/reportDetail?IsSendWx=1&id="          //研选纪要详情
 )
 )
 
 
 //2:文章详情  https://web.hzinsights.com/material/info/8436  小程序路径:/pageMy/reportDetail/reportDetail?id=
 //2:文章详情  https://web.hzinsights.com/material/info/8436  小程序路径:/pageMy/reportDetail/reportDetail?id=