Эх сурвалжийг харах

Merge branch 'feature/migrate_wecht_msg' of hongze/hongze_mobile_admin into master

xyxie 2 жил өмнө
parent
commit
366c5264ca

+ 1 - 1
controllers/admin_wx.go

@@ -205,4 +205,4 @@ func (c *AdminWxController) BindMobile()  {
 
 	c.Ok()
 	return
-}
+}

+ 8 - 0
controllers/base_common.go

@@ -99,6 +99,14 @@ func (c BaseCommon) FailWithCodeUsed(message, errMessage string) {
 	c.Response.Data = map[string]interface{}{}
 	c.Result()
 }
+//token异常
+func (c BaseCommon) TokenError(data interface{}, message string) {
+	c.Response.Code = TOKEN_ERROR
+	c.Response.Msg = message
+	c.Response.Data = data
+	c.Result()
+}
+
 //token异常
 func (c BaseCommon) TokenMsgError(message, errMessage string) {
 	c.Response.Code = TOKEN_ERROR

+ 7 - 12
controllers/roadshow/calendar.go

@@ -236,19 +236,17 @@ func (this *CalendarController) Add() {
 						}
 						remark := "请尽快完成审批"
 						//wxAppPath := "pages-approve/activity/detail?RsCalendarId=" + strconv.Itoa(int(rsCalendarId)) + "&RsCalendarResearcherId=" + strconv.Itoa(int(rsCalendarResearcherId))
-						openIdList, _ := models.GetAdminOpenIdByMobile(sysAdmin.Mobile)
-						if len(openIdList) > 0 {
+						if sysAdmin.OpenId != "" {
 							go services.SendWxMsgWithRoadshowPending(first, keyword1, keyword2, keyword3, keyword4, remark, wxAppPath, sysAdmin.Mobile)
 						}
 					} else {
 						wxAppPath = ""
-						first := sysAdmin.RealName + "为你添加了一场【" + req.ActivityType + "】"
+						first := sysUser.RealName + "为你添加了一场【" + req.ActivityType + "】"
 						startDate := researcher.StartDate[5:]
 						startDate = strings.Replace(startDate, "-", ".", -1)
 						keyword1 := "会议时间:" + startDate + "(" + researcher.StartWeek + ")" + " " + researcher.StartTime[:5] + "-" + researcher.EndTime[:5]
 						keyword2 := "--"
-						openIdList, _ := models.GetAdminOpenIdByMobile(sysAdmin.Mobile)
-						if len(openIdList) > 0 {
+						if sysAdmin.OpenId != "" {
 							go services.SendWxMsgWithRoadshowDeleteNotice(first, keyword1, keyword2, "", wxAppPath, sysAdmin.Mobile)
 						}
 					}
@@ -1364,8 +1362,7 @@ func (this *CalendarController) Edit() {
 						}
 						remark := "请尽快完成审批"
 						wxAppPath := "pages-approve/activity/detail?RsCalendarId=" + strconv.Itoa(req.RsCalendarId) + "&RsCalendarResearcherId=" + strconv.Itoa(rsCalendarResearcherItem.RsCalendarResearcherId)
-						openIdList, _ := models.GetAdminOpenIdByMobile(sysAdmin.Mobile)
-						if len(openIdList) > 0 {
+						if sysAdmin.OpenId != "" {
 							services.SendWxMsgWithRoadshowPending(first, keyword1, keyword2, keyword3, keyword4, remark, wxAppPath, sysAdmin.Mobile)
 						}
 					}
@@ -1443,8 +1440,7 @@ func (this *CalendarController) Edit() {
 					}
 					remark := "请尽快完成审批"
 					wxAppPath := "pages-approve/activity/detail?RsCalendarId=" + strconv.Itoa(req.RsCalendarId) + "&RsCalendarResearcherId=" + strconv.Itoa(int(rsCalendarResearcherId))
-					openIdList, _ := models.GetAdminOpenIdByMobile(sysAdmin.Mobile)
-					if len(openIdList) > 0 {
+					if sysAdmin.OpenId != "" {
 						services.SendWxMsgWithRoadshowPending(first, keyword1, keyword2, keyword3, keyword4, remark, wxAppPath, sysAdmin.Mobile)
 					}
 				}
@@ -1592,7 +1588,7 @@ func (this *CalendarController) Delete() {
 		return
 	}
 
-	rsCalendarResearcherItemList, err := roadshow.GetRsCalendarResearcherListById(req.RsCalendarResearcherId)
+	rsCalendarResearcherItemList, err := roadshow.GetRsCalendarResearcherListById(req.RsCalendarId)
 	if err != nil {
 		this.FailWithMessage("获取数据失败!", "获取数据失败!GetRsCalendarResearcherById:"+err.Error())
 		return
@@ -1690,8 +1686,7 @@ func (this *CalendarController) Delete() {
 					keyword2 := "已删除"
 					remark := req.DeleteReason
 
-					openIdList, _ := models.GetAdminOpenIdByMobile(sysAdmin.Mobile)
-					if len(openIdList) > 0 {
+					if sysAdmin.OpenId != "" {
 						go services.SendWxMsgWithRoadshowDeleteNotice(first, keyword1, keyword2, remark, wxAppPath, sysAdmin.Mobile)
 					}
 				}

+ 0 - 1
controllers/wechat.go

@@ -303,7 +303,6 @@ func (c *WeChatCommon) AdminWeChatLogin() {
 		c.FailWithMessage(fmt.Sprintf("%v", err), fmt.Sprintf("%v", err))
 		return
 	}
-
 	if item.Errcode != 0 {
 		if item.Errcode == 40163 {
 			c.FailWithCodeUsed("获取用户信息失败", "获取access_token 失败 errCode:"+strconv.Itoa(item.Errcode)+" ;errMsg:"+item.Errmsg)

+ 1 - 0
models/tables/user_template_record/user_template_record.go

@@ -13,6 +13,7 @@ type UserTemplateRecord struct {
 	CreateTime string
 	SendStatus int
 	SendType   int
+	WxAppId    string
 }
 
 // AddUserTemplateRecord 添加记录

+ 1 - 1
services/admin_wechat.go

@@ -51,4 +51,4 @@ func AdminWxLogin(wxAccessToken *WxAccessToken, wxUserInfo *WxUserInfo) (ret adm
 
 	ret.BindFlag = true
 	return
-}
+}

+ 1 - 1
services/sms.go

@@ -66,4 +66,4 @@ func sendSms(mobile, tplId, code string) (rs []byte, err error) {
 	}
 	defer resp.Body.Close()
 	return ioutil.ReadAll(resp.Body)
-}
+}

+ 28 - 0
services/wechat.go

@@ -263,3 +263,31 @@ func WxUsersGet() (openIdStr string) {
 	openIdStr = "'" + openIdStr + "'"
 	return
 }
+
+func WxAdminOpenIdGet() (openIdStr string) {
+	accessToken, err := WxGetRedisAccessToken(utils.AdminWxAppId, utils.AdminWxAppSecret)
+	if err != nil {
+		utils.FileLog.Info("GetWxAccessToken Err:%s", err.Error())
+		return
+	}
+	url := "https://api.weixin.qq.com/cgi-bin/user/get?access_token=" + accessToken
+	result, err := http.Get(url)
+	if err != nil {
+		utils.FileLog.Info("GetUser Err:", err.Error())
+		return
+	}
+	item := new(WxUsers)
+	err = json.Unmarshal(result, &item)
+	if err != nil {
+		fmt.Println("Unmarshal Err:", err.Error())
+		return
+	}
+	if item.Errcode != 0 {
+		utils.FileLog.Info("微信接口返回异常 Err:", item.Errmsg)
+		return
+	}
+	err = errors.New(item.Errmsg)
+	openIdStr = strings.Join(item.Data.Openid, "','")
+	openIdStr = "'" + openIdStr + "'"
+	return
+}

+ 29 - 226
services/wechat_send_msg.go

@@ -1,23 +1,19 @@
 package services
 
 import (
-	"bytes"
 	"encoding/json"
 	"fmt"
-	"hongze/hongze_mobile_admin/models/tables/report"
-	"hongze/hongze_mobile_admin/models/tables/user_template_record"
-	"hongze/hongze_mobile_admin/models/tables/wx_user"
+	"hongze/hongze_mobile_admin/models/tables/admin"
 	"hongze/hongze_mobile_admin/services/alarm_msg"
 	"hongze/hongze_mobile_admin/utils"
 	"io/ioutil"
 	"net/http"
-	"strconv"
 	"strings"
 	"time"
 	"errors"
 )
-
 type SendWxTemplate struct {
+	WxAppId        string   `description:"公众号appId"`
 	First          string   `description:"模板消息first字段"`
 	Keyword1       string   `description:"模板消息keyword1字段"`
 	Keyword2       string   `description:"模板消息keyword2字段"`
@@ -43,147 +39,6 @@ type BaseResponse struct {
 	IsAddLog    bool `json:"-" description:"true 新增操作日志,false 不新增操作日志" `
 }
 
-
-
-func SendWxTemplateMsg(reportId int) (err error) {
-	var msg string
-	defer func() {
-		if err != nil {
-			go alarm_msg.SendAlarmMsg(fmt.Sprintf("发送模版消息失败,Err:%s,%s", err.Error(), msg), 3)
-			//go utils.SendEmail("发送模版消息失败"+time.Now().Format("2006-01-02 15:04:05"), msg+";Err:"+err.Error(), utils.EmailSendToUsers)
-			utils.FileLog.Info("发送模版消息失败,Err:%s,%s", err.Error(), msg)
-		}
-		if msg != "" {
-			utils.FileLog.Info("发送模版消息失败,msg:%s", msg)
-		}
-	}()
-	utils.FileLog.Info("%s", "services SendMsg")
-
-	report, err := report.GetReportById(reportId)
-	if err != nil {
-		msg = "GetReportInfo Err:" + err.Error()
-		return
-	}
-	if report == nil {
-		utils.FileLog.Info("报告信息不存在")
-		return
-	}
-	accessToken, err := WxGetAccessToken()
-	if err != nil {
-		msg = "GetWxAccessToken Err:" + err.Error()
-		return
-	}
-	if accessToken == "" {
-		msg = "accessToken is empty"
-		return
-	}
-	//获取openid列表
-	openIdStr := WxUsersGet()
-	openIdList, err := wx_user.GetOpenIdList(openIdStr)
-	if err != nil {
-		msg = "get openIdList err:" + err.Error()
-		return
-	}
-	fmt.Println("openIdListCount:", len(openIdList))
-	sendUrl := "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + accessToken
-	fmt.Println("send start")
-	utils.FileLog.Info("send start")
-	//if report.MsgIsSend == 0 {
-	sendMap := make(map[string]interface{})
-	sendData := make(map[string]interface{})
-
-	redirectUrl := utils.TemplateRedirectUrl + strconv.Itoa(reportId)
-	keyword1 := "弘则日度点评"
-	first := "Hi,最新一期日度点评已上线,欢迎查看"
-	keyword2 := report.Title
-	//keyword3 := report.PublishTime.Format(utils.FormatDateTime)
-	keyword3 := report.PublishTime
-	keyword4 := report.Abstract
-
-	sendData["first"] = map[string]interface{}{"value": first, "color": "#173177"}
-	sendData["keyword1"] = map[string]interface{}{"value": keyword1, "color": "#173177"}
-	sendData["keyword2"] = map[string]interface{}{"value": keyword2, "color": "#173177"}
-	sendData["keyword3"] = map[string]interface{}{"value": keyword3, "color": "#173177"}
-	sendData["keyword4"] = map[string]interface{}{"value": keyword4, "color": "#173177"}
-
-	sendMap["template_id"] = utils.TemplateIdByProduct
-	sendMap["url"] = redirectUrl
-	sendMap["data"] = sendData
-	sendTemplateMsg(sendUrl, sendMap, openIdList, strconv.Itoa(reportId), utils.TEMPLATE_MSG_REPORT)
-
-	//}
-	fmt.Println("send end")
-	utils.FileLog.Info("send end")
-	return
-}
-
-func sendTemplateMsg(sendUrl string, sendMap map[string]interface{}, items []*wx_user.OpenIdList, resource string, sendType int) (err error) {
-	for _, v := range items {
-		sendMap["touser"] = v.OpenId
-		data, err := json.Marshal(sendMap)
-		if err != nil {
-			fmt.Println("SendTemplateMsgOne Marshal Err:", err.Error())
-			utils.FileLog.Info(fmt.Sprintf("SendTemplateMsgOne Marshal Err:%s", err.Error()))
-			return err
-		}
-		err = toSendTemplateMsg(sendUrl, data, resource, sendType, v)
-		if err != nil {
-			fmt.Println("send err:", err.Error())
-			utils.FileLog.Info(fmt.Sprintf("ToSendTemplateMsg Err:%s", err.Error()))
-		}
-	}
-	return
-}
-
-func toSendTemplateMsg(sendUrl string, data []byte, resource string, sendType int, dataItem *wx_user.OpenIdList) (err error) {
-	utils.FileLog.Info("Send:" + string(data))
-	client := http.Client{}
-	resp, err := client.Post(sendUrl, "application/json", bytes.NewBuffer(data))
-	if err != nil {
-		return
-	}
-	defer resp.Body.Close()
-
-	body, _ := ioutil.ReadAll(resp.Body)
-	utils.FileLog.Info("SendResult:" + string(body))
-	var templateResponse SendTemplateResponse
-	err = json.Unmarshal(body, &templateResponse)
-	if err != nil {
-		utils.FileLog.Info("SendResult Unmarshal Err:%s", err.Error())
-		return err
-	}
-
-	//新增模板消息推送记录
-	{
-		sendStatus := 0
-		if templateResponse.Errcode == 0 {
-			sendStatus = 1
-		} else {
-			sendStatus = 0
-		}
-		tr := &user_template_record.UserTemplateRecord{
-			Id:         0,
-			UserId:     dataItem.UserId,
-			OpenId:     dataItem.OpenId,
-			Resource:   resource,
-			SendData:   string(data),
-			Result:     string(body),
-			CreateDate: time.Now().Format(utils.FormatDate),
-			CreateTime: time.Now().Format(utils.FormatDateTime),
-			SendStatus: sendStatus,
-			SendType:   sendType,
-		}
-		go func() {
-			err = user_template_record.AddUserTemplateRecord(tr)
-			if err != nil {
-				utils.FileLog.Info(fmt.Sprintf("AddUserTemplateRecord Err:%s", err.Error()))
-			}
-		}()
-	}
-
-	return
-}
-
 type SendTemplateResponse struct {
 	Errcode int    `json:"errcode"`
 	Errmsg  string `json:"errmsg"`
@@ -204,21 +59,11 @@ func SendCompanyApplyWxTemplateMsg(mobile, redirectUrl, wxAppPath string, wxMsgM
 		}
 	}()
 	utils.FileLog.Info("%s", "services SendMsg")
-
-	accessToken, err := WxGetAccessToken()
-	if err != nil {
-		msg = "GetWxAccessToken Err:" + err.Error()
-		return
-	}
-	if accessToken == "" {
-		msg = "accessToken is empty"
-		return
-	}
 	utils.FileLog.Info("mobile:%s", mobile)
 
 	//获取openid列表
-	//openIdStr := WxUsersGet()
-	openIdList, err := wx_user.GetOpenIdListByMobile(mobile)
+	openIdStr := WxAdminOpenIdGet()
+	openIdList, err := admin.GetOpenIdListByMobile(mobile, openIdStr)
 	if err != nil {
 		msg = "get openIdList err:" + err.Error()
 		return
@@ -274,6 +119,7 @@ func SendCompanyApplyWxTemplateMsg(mobile, redirectUrl, wxAppPath string, wxMsgM
 		}
 
 		sendInfo := new(SendWxTemplate)
+		sendInfo.WxAppId = utils.AdminWxAppId
 		sendInfo.First = first
 		sendInfo.Keyword1 = keyword1
 		sendInfo.Keyword2 = keyword2
@@ -294,7 +140,7 @@ func SendCompanyApplyWxTemplateMsg(mobile, redirectUrl, wxAppPath string, wxMsgM
 	return
 }
 
-// 路演->销售收到处理结果
+// SendWxMsgWithRoadshowDetailResult 路演->销售收到处理结果
 func SendWxMsgWithRoadshowDetailResult(first, keyword1, keyword2, remark, mobile, redirectUrl, wxAppPath string) (err error) {
 	var msg string
 	defer func() {
@@ -308,25 +154,16 @@ func SendWxMsgWithRoadshowDetailResult(first, keyword1, keyword2, remark, mobile
 		}
 	}()
 	utils.FileLog.Info("%s", "services SendMsg")
-
-	accessToken, err := WxGetAccessToken()
-	if err != nil {
-		msg = "GetWxAccessToken Err:" + err.Error()
-		return
-	}
-	if accessToken == "" {
-		msg = "accessToken is empty"
-		return
-	}
 	utils.FileLog.Info("mobile:%s", mobile)
 
 	//获取openid列表
-	//openIdStr := WxUsersGet()
-	openIdList, err := wx_user.GetOpenIdListByMobile(mobile)
+	openIdStr := WxAdminOpenIdGet()
+	openIdList, err := admin.GetOpenIdListByMobile(mobile, openIdStr)
 	if err != nil {
 		msg = "get openIdList err:" + err.Error()
 		return
 	}
+
 	utils.FileLog.Info("openIdListCount:%s", len(openIdList))
 	//fmt.Println("openIdListCount:", len(openIdList))
 	if len(openIdList) > 0 && utils.TemplateIdByCompanyApply != "" {
@@ -357,6 +194,7 @@ func SendWxMsgWithRoadshowDetailResult(first, keyword1, keyword2, remark, mobile
 		}
 
 		sendInfo := new(SendWxTemplate)
+		sendInfo.WxAppId = utils.AdminWxAppId
 		sendInfo.First = first
 		sendInfo.Keyword1 = keyword1
 		sendInfo.Keyword2 = keyword2
@@ -369,14 +207,13 @@ func SendWxMsgWithRoadshowDetailResult(first, keyword1, keyword2, remark, mobile
 		sendInfo.Resource = wxAppPath
 		sendInfo.SendType = utils.TEMPLATE_MSG_ACTIVITY_APPOINTMENT
 		sendInfo.OpenIdArr = openIdArr
-
 		err = SendTemplateMsg(sendInfo)
 	}
 	utils.FileLog.Info("send end")
 	return
 }
 
-// 路演->研究员收到待处理的申请
+// SendWxMsgWithRoadshowPending 路演->研究员收到待处理的申请
 func SendWxMsgWithRoadshowPending(first, keyword1, keyword2, keyword3, keyword4, remark, wxAppPath, mobile string) (err error) {
 	//utils.WxMsgTemplateIdWithRoadshowPending
 	var msg string
@@ -392,19 +229,9 @@ func SendWxMsgWithRoadshowPending(first, keyword1, keyword2, keyword3, keyword4,
 	}()
 	utils.FileLog.Info("%s", "services SendMsg")
 
-	accessToken, err := WxGetAccessToken()
-	if err != nil {
-		msg = "GetWxAccessToken Err:" + err.Error()
-		return
-	}
-	if accessToken == "" {
-		msg = "accessToken is empty"
-		return
-	}
-
 	//获取openid列表
-	//openIdStr := WxUsersGet()
-	openIdList, err := wx_user.GetOpenIdListByMobile(mobile)
+	openIdStr := WxAdminOpenIdGet()
+	openIdList, err := admin.GetOpenIdListByMobile(mobile, openIdStr)
 	if err != nil {
 		msg = "get openIdList err:" + err.Error()
 		return
@@ -440,6 +267,7 @@ func SendWxMsgWithRoadshowPending(first, keyword1, keyword2, keyword3, keyword4,
 		}
 
 		sendInfo := new(SendWxTemplate)
+		sendInfo.WxAppId = utils.AdminWxAppId
 		sendInfo.First = first
 		sendInfo.Keyword1 = keyword1
 		sendInfo.Keyword2 = keyword2
@@ -461,7 +289,7 @@ func SendWxMsgWithRoadshowPending(first, keyword1, keyword2, keyword3, keyword4,
 	return
 }
 
-// 路演->研究员收到活动删除通知
+// SendWxMsgWithRoadshowDeleteNotice 路演->研究员收到活动删除通知
 func SendWxMsgWithRoadshowDeleteNotice(first, keyword1, keyword2, remark, wxAppPath, mobile string) (err error) {
 	var msg string
 	defer func() {
@@ -475,20 +303,9 @@ func SendWxMsgWithRoadshowDeleteNotice(first, keyword1, keyword2, remark, wxAppP
 		}
 	}()
 	utils.FileLog.Info("%s", "services SendMsg")
-
-	accessToken, err := WxGetAccessToken()
-	if err != nil {
-		msg = "GetWxAccessToken Err:" + err.Error()
-		return
-	}
-	if accessToken == "" {
-		msg = "accessToken is empty"
-		return
-	}
-
 	//获取openid列表
-	//openIdStr := WxUsersGet()
-	openIdList, err := wx_user.GetOpenIdListByMobile(mobile)
+	openIdStr := WxAdminOpenIdGet()
+	openIdList, err := admin.GetOpenIdListByMobile(mobile, openIdStr)
 	if err != nil {
 		msg = "get openIdList err:" + err.Error()
 		return
@@ -519,6 +336,7 @@ func SendWxMsgWithRoadshowDeleteNotice(first, keyword1, keyword2, remark, wxAppP
 		}
 
 		sendInfo := new(SendWxTemplate)
+		sendInfo.WxAppId = utils.AdminWxAppId
 		sendInfo.First = first
 		sendInfo.Keyword1 = keyword1
 		sendInfo.Keyword2 = keyword2
@@ -538,7 +356,7 @@ func SendWxMsgWithRoadshowDeleteNotice(first, keyword1, keyword2, remark, wxAppP
 	return
 }
 
-// 给销售发送 用印申请已签回的模版消息
+// SendSealFinishedWxTemplateMsg 给销售发送 用印申请已签回的模版消息
 func SendSealFinishedWxTemplateMsg(mobile string, companyName string, sealId int) (err error) {
 	var msg string
 	defer func() {
@@ -552,22 +370,14 @@ func SendSealFinishedWxTemplateMsg(mobile string, companyName string, sealId int
 		}
 	}()
 	utils.FileLog.Info("%s", "services SendMsg")
-	accessToken, err := WxGetAccessToken()
-	if err != nil {
-		msg = "GetWxAccessToken Err:" + err.Error()
-		return
-	}
-	if accessToken == "" {
-		msg = "accessToken is empty"
-		return
-	}
 	utils.FileLog.Info("mobile:%s", mobile)
-	//openIdStr := WxUsersGet()
-	openIdList, err := wx_user.GetOpenIdListByMobile(mobile)
+	openIdStr := WxAdminOpenIdGet()
+	openIdList, err := admin.GetOpenIdListByMobile(mobile, openIdStr)
 	if err != nil {
 		msg = "get openIdList err:" + err.Error()
 		return
 	}
+
 	utils.FileLog.Info("openIdListCount:%s", len(openIdList))
 
 	if len(openIdList) > 0 && utils.WxMsgTemplateIdWithSealApplyFinished != "" {
@@ -602,6 +412,7 @@ func SendSealFinishedWxTemplateMsg(mobile string, companyName string, sealId int
 		}
 
 		sendInfo := new(SendWxTemplate)
+		sendInfo.WxAppId = utils.AdminWxAppId
 		sendInfo.First = first
 		sendInfo.Keyword1 = keyword1
 		sendInfo.Keyword2 = keyword2
@@ -620,7 +431,7 @@ func SendSealFinishedWxTemplateMsg(mobile string, companyName string, sealId int
 }
 
 // SendYbQuestionDistributeWxMsg 推送研报小程序模板消息-问答社区分配
-func SendYbQuestionDistributeWxMsg(questionId, userId int, openid, questionTitle string) (err error) {
+func SendYbQuestionDistributeWxMsg(questionId, adminId int, openid, questionTitle string) (err error) {
 	var errMsg string
 	defer func() {
 		if err != nil {
@@ -629,20 +440,10 @@ func SendYbQuestionDistributeWxMsg(questionId, userId int, openid, questionTitle
 			go alarm_msg.SendAlarmMsg(alarmMsg, 3)
 		}
 	}()
-
-	accessToken, err := WxGetAccessToken()
-	if err != nil {
-		errMsg = "GetWxAccessToken Err:" + err.Error()
-		return
-	}
-	if accessToken == "" {
-		errMsg = "accessToken is empty"
-		return
-	}
-	openIdList := make([]*wx_user.OpenIdList, 0)
-	openIdList = append(openIdList, &wx_user.OpenIdList{
+	openIdList := make([]*admin.OpenIdList, 0)
+	openIdList = append(openIdList, &admin.OpenIdList{
 		OpenId: openid,
-		UserId: userId,
+		AdminId: adminId,
 	})
 
 	//sendUrl := "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + accessToken
@@ -674,6 +475,7 @@ func SendYbQuestionDistributeWxMsg(questionId, userId int, openid, questionTitle
 	}
 
 	sendInfo := new(SendWxTemplate)
+	sendInfo.WxAppId = utils.AdminWxAppId
 	sendInfo.First = first
 	sendInfo.Keyword1 = keyword1
 	sendInfo.Keyword2 = keyword2
@@ -685,6 +487,7 @@ func SendYbQuestionDistributeWxMsg(questionId, userId int, openid, questionTitle
 	sendInfo.SendType = utils.TEMPLATE_MSG_YB_COMMUNITY_QUESTION
 	sendInfo.OpenIdArr = openIdArr
 	err = SendTemplateMsg(sendInfo)
+	utils.FileLog.Info("send end")
 	return
 }
 

+ 13 - 36
services/yb/community_question.go

@@ -9,7 +9,6 @@ import (
 	"hongze/hongze_mobile_admin/models/tables/company_approval_message"
 	"hongze/hongze_mobile_admin/models/tables/sys_role"
 	"hongze/hongze_mobile_admin/models/tables/sys_role_admin"
-	"hongze/hongze_mobile_admin/models/tables/user_record"
 	"hongze/hongze_mobile_admin/models/tables/variety_classify"
 	"hongze/hongze_mobile_admin/models/tables/variety_tag"
 	"hongze/hongze_mobile_admin/models/tables/wx_user"
@@ -199,22 +198,7 @@ func DistributeQuestion(questionId, adminId, researchGroupFirstId, researchGroup
 	}
 	// 回复人openid, 此处可能会出现取不到openid的情况, 可直接忽略掉
 	replierUserId := int(userInfo.UserId)
-	userRecord, e := user_record.GetUserRecordByUserId(replierUserId, utils.USER_RECORD_PLATFORM_RDDP)
-	if e != nil && e.Error() != utils.ErrNoRow() {
-		errMsg = "分配失败, 研究员相关的联系人记录有误"
-		err = errors.New("获取手机号所属联系人失败, Err:" + e.Error())
-		return
-	}
 	replierOpenid := ""
-	if userRecord != nil {
-		if userRecord.Subscribe == 0 {
-			errMsg = "该研究员已取消关注公众号,无法收到消息通知"
-		} else {
-			replierOpenid = userRecord.OpenId
-		}
-	} else {
-		errMsg = "该研究员未关注公众号,无法收到消息通知"
-	}
 	// 分组、品种权限信息
 	//firstGroup, e := admin.GetResearchGroupById(researchGroupFirstId)
 	firstGroup, e := variety_classify.GetVarietyClassifyById(researchGroupFirstId)
@@ -305,28 +289,21 @@ func SendMsgToReplier(questionId int) (errMsg string, err error) {
 	}
 	// 回复人openid为空时查询当前是否已有openid
 	updateCols := make([]string, 0)
-	if item.ReplierOpenid == "" {
-		userRecord, e := user_record.GetUserRecordByUserId(item.ReplierUserId, utils.USER_RECORD_PLATFORM_RDDP)
-		if e != nil && e.Error() != utils.ErrNoRow() {
-			errMsg = "发送失败, 研究员相关的联系人记录有误"
-			err = errors.New("获取手机号所属联系人失败, Err:" + e.Error())
-			return
-		}
-		if userRecord == nil {
-			errMsg = "该研究员未关注公众号,无法发送消息通知"
-			err = errors.New("回复人openid为空, 不可推送")
-			return
-		}
-		if userRecord.Subscribe == 0 {
-			errMsg = "该研究员已取消关注公众号,无法发送消息通知"
-			err = errors.New("回复人取消关注了公众号, 不可推送")
-			return
-		}
-		updateCols = append(updateCols, "ReplierOpenid")
-		item.ReplierOpenid = userRecord.OpenId
+
+	// 找到研究员的手机号,并查到管理员绑定的账号,找到对应的openid
+	adminInfo, e := admin.GetAdminById(item.ReplierAdminId)
+	if e != nil {
+		errMsg = "发送失败, 研究员账号查询失败"
+		err = errors.New("发送失败, 研究员账号查询失败, Err:" + e.Error())
+		return
+	}
+	if adminInfo.OpenId == "" {
+		errMsg = "该研究员未关注公众号,无法发送消息通知"
+		err = errors.New("回复人openid为空, 不可推送")
+		return
 	}
 
-	if e := services.SendYbQuestionDistributeWxMsg(item.CommunityQuestionId, item.ReplierUserId, item.ReplierOpenid, item.QuestionContent); e != nil {
+	if e := services.SendYbQuestionDistributeWxMsg(item.CommunityQuestionId, item.ReplierUserId, adminInfo.OpenId, item.QuestionContent); e != nil {
 		err = errors.New("推送模板消息失败, Err:" + e.Error())
 		return
 	}

+ 13 - 13
utils/config.go

@@ -179,18 +179,18 @@ func wxConfig() {
 		TemplateIdByProduct = "Cp2wF8gvBtxyWV4DeYuI172oqwyYXVRSm3AyJO42d84"
 		TemplateRedirectUrl = "https://ficc.hzinsights.com/reportdtl?id="
 		WxPlatform = 1
-		TemplateIdByCompanyApply = "ZKcOfNIWBpwHJxpptufHIK1mp2nIwkT3cxub-35cFqI"
+		TemplateIdByCompanyApply = "yqaDUavXAKBpsPqTr0zYXAGIQYeCijZtWwFsT07wTbE"
 		TemplateCompanyApplyRedirectUrl = "https://ficc.hzinsights.com/approval/approval/list"
 
 		//路演
-		WxMsgTemplateIdWithRoadshowPending = "PaoDanHGlt1kFw5q-4_ipJSwO3FyZpxSSNg4rwB7YCk"      //路演->研究员收到待处理的申请
-		WxMsgTemplateIdWithRoadshowDetailResult = "dYg6iHooRq74PyCXmw_Ns7qdJZmbtLoKS2p2FKeaXl0" //路演->销售收到处理结果
-		WxMsgTemplateIdWithRoadshowDeleteNotice = "dYg6iHooRq74PyCXmw_Ns7qdJZmbtLoKS2p2FKeaXl0" //路演->研究员收到活动删除通知
+		WxMsgTemplateIdWithRoadshowPending = "1JG9fvKx9o9B-wkZe_gBFQQzMBnp07-hvpZI9QiFcKQ"      //路演->研究员收到待处理的申请
+		WxMsgTemplateIdWithRoadshowDetailResult = "rciDm9ThigRBGi1SZ4TFd74XA4aoAxSz_ugdv_tZ450" //路演->销售收到处理结果
+		WxMsgTemplateIdWithRoadshowDeleteNotice = "rciDm9ThigRBGi1SZ4TFd74XA4aoAxSz_ugdv_tZ450" //路演->研究员收到活动删除通知
 
-		WxMsgTemplateIdWithSealApplyFinished   = "dYg6iHooRq74PyCXmw_Ns7qdJZmbtLoKS2p2FKeaXl0"   // 用印申请-已签回通知
+		WxMsgTemplateIdWithSealApplyFinished   = "rciDm9ThigRBGi1SZ4TFd74XA4aoAxSz_ugdv_tZ450"   // 用印申请-已签回通知
 
 		// 研报小程序
-		WxMsgTemplateIdWithYbCommunityQuestion = "dYg6iHooRq74PyCXmw_Ns7qdJZmbtLoKS2p2FKeaXl0" // 研报小程序->问答社区回复通知
+		WxMsgTemplateIdWithYbCommunityQuestion = "rciDm9ThigRBGi1SZ4TFd74XA4aoAxSz_ugdv_tZ450" // 研报小程序->问答社区回复通知
 
 		//内部员工公众号(弘则部门)
 		AdminWxAppId = "wx1392111da5426e9e"
@@ -204,23 +204,23 @@ func wxConfig() {
 		TemplateIdByProduct = "-YjuPOB7Fqd-S3ilabYa6wvjDY9aXmeEfPN6DCiy-EY"
 		TemplateRedirectUrl = "http://rddpweb.brilliantstart.cn/reportdtl?id="
 		WxPlatform = 1
-		TemplateIdByCompanyApply = "eTalI1LbiT_B0mTaBeDTlfSMITenK8dQIgEB5yqjjvA"
+		TemplateIdByCompanyApply = "yqaDUavXAKBpsPqTr0zYXAGIQYeCijZtWwFsT07wTbE"
 		TemplateCompanyApplyRedirectUrl = "http://advisoryadmin.brilliantstart.cn/approval/approval/list"
 
 		//路演
-		WxMsgTemplateIdWithRoadshowPending = "qfNuops-sKrfIkbA7U97A7gSrX03mUpoEpJksRUdloo"      //路演->研究员收到待处理的申请
-		WxMsgTemplateIdWithRoadshowDetailResult = "CB7bOl7f3viMG4s1uhRo7WM0Jbx3WvodKuIZ8A_z8fM" //路演->销售收到处理结果
-		WxMsgTemplateIdWithRoadshowDeleteNotice = "CB7bOl7f3viMG4s1uhRo7WM0Jbx3WvodKuIZ8A_z8fM" //路演->研究员收到活动删除通知
+		WxMsgTemplateIdWithRoadshowPending = "1JG9fvKx9o9B-wkZe_gBFQQzMBnp07-hvpZI9QiFcKQ"      //路演->研究员收到待处理的申请
+		WxMsgTemplateIdWithRoadshowDetailResult = "rciDm9ThigRBGi1SZ4TFd74XA4aoAxSz_ugdv_tZ450" //路演->销售收到处理结果
+		WxMsgTemplateIdWithRoadshowDeleteNotice = "rciDm9ThigRBGi1SZ4TFd74XA4aoAxSz_ugdv_tZ450" //路演->研究员收到活动删除通知
 
-		WxMsgTemplateIdWithSealApplyFinished   = "CB7bOl7f3viMG4s1uhRo7WM0Jbx3WvodKuIZ8A_z8fM"   // 用印申请-已签回通知
+		WxMsgTemplateIdWithSealApplyFinished   = "rciDm9ThigRBGi1SZ4TFd74XA4aoAxSz_ugdv_tZ450"   // 用印申请-已签回通知
 		
 		// 研报小程序
-		WxMsgTemplateIdWithYbCommunityQuestion = "CB7bOl7f3viMG4s1uhRo7WM0Jbx3WvodKuIZ8A_z8fM" // 研报小程序->问答社区回复通知
+		WxMsgTemplateIdWithYbCommunityQuestion = "rciDm9ThigRBGi1SZ4TFd74XA4aoAxSz_ugdv_tZ450" // 研报小程序->问答社区回复通知
 
 		//内部员工公众号(弘则部门)
 		AdminWxAppId = "wx1392111da5426e9e"
 		AdminWxAppSecret = "30eceb7cf29bf2f046031155ab55d7b4"
-		
+
 		SendWxTemplateMsgUrl = "http://127.0.0.1:8086/v1/wechat/send_template_msg"
 	}