Parcourir la source

Merge branch 'master' into feature/admin_wechat_login

# Conflicts:
#	utils/config.go
xiexiaoyuan il y a 2 ans
Parent
commit
249326f3d4

+ 7 - 1
controllers/message.go

@@ -161,7 +161,12 @@ func (c *MessageCommon) MessageList() {
 		c.FailWithMessage("获取失败", "获取消息总数失败,Err:"+err.Error())
 		return
 	}
-	list, err := company_approval_message.GetCompanyApprovalMessageList(sysUserId, sourceType, startSize, pageSize)
+	// 消息类型为6-评论时, 查询6-问答评论,7-视频评论
+	sourceTypeStr := strconv.Itoa(sourceType)
+	if sourceType == services.CompanyApprovalMessageSourceTypeByQuestionComment {
+		sourceTypeStr = fmt.Sprintf("%d,%d", services.CompanyApprovalMessageSourceTypeByQuestionComment, services.CompanyApprovalMessageSourceTypeByVideoComment)
+	}
+	list, err := company_approval_message.GetCompanyApprovalMessageList(sysUserId, startSize, pageSize, sourceTypeStr)
 	if err != nil {
 		c.FailWithMessage("获取失败", "获取消息列表失败,Err:"+err.Error())
 		return
@@ -377,6 +382,7 @@ func getMessageInfo(companyApprovalMessageList []*company_approval_message.Compa
 			ApplyTime:   createTime,
 			Content:     tmpMessageInfo.Content,
 			CompanyName: tmpMessageInfo.CompanyName,
+			Extra:       tmpMessageInfo.Extra,
 		}
 		v.ApprovalInfo = approvalInfo
 	}

+ 8 - 2
controllers/yb/community_question_comment.go

@@ -35,7 +35,13 @@ func (c *CommunityQuestionCommentController) List() {
 	condition := ""
 	pars := make([]interface{}, 0)
 
-	//问答id
+	// 来源
+	source, _ := c.GetInt("Source", 1)
+	if source <= 0 {
+		source = 1
+	}
+
+	// 评论ID
 	communityQuestionCommentId, _ := c.GetInt("CommunityQuestionCommentId", 0)
 	if communityQuestionCommentId > 0 {
 		condition += ` AND a.community_question_comment_id = ? `
@@ -65,7 +71,7 @@ func (c *CommunityQuestionCommentController) List() {
 	}
 	startSize = paging.StartIndex(currentIndex, pageSize)
 
-	total, list, err := yb.GetCommunityQuestionCommentList(condition, pars, startSize, pageSize)
+	total, list, err := yb.GetCommunityQuestionCommentList(condition, pars, startSize, pageSize, source)
 	if err != nil {
 		c.FailWithMessage("获取问答列表失败", "QuestionList ErrMsg:"+err.Error())
 		return

+ 2 - 0
models/response/yb/community_question.go

@@ -97,4 +97,6 @@ type CommunityQuestionCommentItem struct {
 	UserName                   string    `description:"评论人名称"`
 	CompanyName                string    `description:"客户名称"`
 	CompanyProductStatus       string    `description:"客户ficc状态"`
+	Source                     int       `description:"来源: 1-问答社区; 2-视频社区"`
+	TagName                    string    `description:"标签名称"`
 }

+ 10 - 5
models/tables/company_approval_message/company_approval_message.go

@@ -67,6 +67,7 @@ type ApprovalInfo struct {
 	CompanyName  string    `description:"客户信息"`
 	ApplyTime    time.Time `description:"提交时间"`
 	ApprovalTime time.Time `description:"审批时间"`
+	Extra        string    `description:"附加字段: 比如视频评论的标签"`
 }
 
 type CompanyApprovalMessageListResp struct {
@@ -91,13 +92,17 @@ func GetCompanyApprovalMessageCount(sysUserId, sourceType int) (count int, err e
 }
 
 //消息列表页
-func GetCompanyApprovalMessageList(sysUserId, sourceType, startSize, pageSize int) (items []*CompanyApprovalMessageList, err error) {
-	sql := `SELECT a.*,b.real_name FROM company_approval_message AS a
-			INNER JOIN admin AS b ON a.create_user_id=b.admin_id
-			WHERE receive_user_id=? AND message_status !=2 AND a.source_type=? `
+func GetCompanyApprovalMessageList(sysUserId, startSize, pageSize int, sourceType string) (items []*CompanyApprovalMessageList, err error) {
+	sql := `SELECT
+				a.*, b.real_name
+			FROM
+				company_approval_message AS a
+			INNER JOIN admin AS b ON a.create_user_id = b.admin_id
+			WHERE
+				receive_user_id =? AND message_status != 2 AND a.source_type IN (` + sourceType + `)`
 	sql += ` ORDER BY create_time DESC LIMIT ?,? `
 	o := orm.NewOrm()
-	_, err = o.Raw(sql, sysUserId, sourceType, startSize, pageSize).QueryRows(&items)
+	_, err = o.Raw(sql, sysUserId, startSize, pageSize).QueryRows(&items)
 	return
 }
 

+ 5 - 5
models/tables/wx_user/wx_user.go

@@ -42,14 +42,14 @@ func GetOpenIdList(openIdStr string) (items []*OpenIdList, err error) {
 }
 
 //根据手机号获取用户的openid列表
-func GetOpenIdListByMobile(mobile, openIdStr string) (items []*OpenIdList, err error) {
+func GetOpenIdListByMobile(mobile string) (items []*OpenIdList, err error) {
 	sql := `SELECT DISTINCT ur.open_id,wu.user_id FROM wx_user AS wu 
           INNER JOIN company AS c ON c.company_id = wu.company_id 
           INNER join user_record  as ur on wu.user_id=ur.user_id
-          WHERE ur.open_id != "" and ur.create_platform=1 AND wu.mobile=? `
-	if openIdStr != "" {
-		sql += ` AND ur.open_id in (` + openIdStr + `) `
-	}
+          WHERE ur.open_id != "" and ur.create_platform=1  	AND ur.subscribe = 1  AND wu.mobile=? `
+	//if openIdStr != "" {
+	//	sql += ` AND ur.open_id in (` + openIdStr + `) `
+	//}
 	_, err = orm.NewOrm().Raw(sql, mobile).QueryRows(&items)
 	return
 }

+ 31 - 2
models/tables/yb_community_question_comment/yb_community_question_comment.go

@@ -24,6 +24,7 @@ type YbCommunityQuestionComment struct {
 	HotTime                    time.Time `orm:"column(hot_time)" description:"设置精选的时间"`
 	ModifyTime                 time.Time `orm:"column(modify_time)" description:"修改时间"`
 	CreateTime                 time.Time `orm:"column(create_time)" description:"创建时间"`
+	Source                     int       `orm:"column(source)" description:"来源: 1-问答社区; 2-视频社区"`
 }
 
 // GetQuestionCommentById 主键获取提问评论
@@ -59,7 +60,9 @@ type YbCommunityQuestionCommentAndQuestion struct {
 	HotTime                    time.Time `orm:"column(hot_time)" description:"设置精选的时间"`
 	ModifyTime                 time.Time `orm:"column(modify_time)" description:"修改时间"`
 	CreateTime                 time.Time `orm:"column(create_time)" description:"创建时间"`
+	Source                     int       `orm:"column(source)" description:"来源:1-问答社区; 2-视频社区"`
 	QuestionContent            string    `description:"问题内容"`
+	TagName                    string    `description:"标签名称"`
 }
 
 // GetCommunityQuestionCommentList 获取问答列表
@@ -67,14 +70,14 @@ func GetCommunityQuestionCommentList(condition string, pars []interface{}, start
 	o := orm.NewOrm()
 
 	//汇总数据
-	totalSQl := `SELECT COUNT(1) total FROM yb_community_question_comment a join yb_community_question b on a.community_question_id = b.community_question_id WHERE a.enabled = 1 and b.is_deleted=0 `
+	totalSQl := `SELECT COUNT(1) total FROM yb_community_question_comment a join yb_community_question b on a.community_question_id = b.community_question_id WHERE a.enabled = 1 and b.is_deleted=0 AND source = 1 `
 	totalSQl += condition
 	if err = o.Raw(totalSQl, pars).QueryRow(&total); err != nil {
 		return
 	}
 
 	// 列表数据
-	sql := `SELECT a.*,b.question_content FROM yb_community_question_comment a join yb_community_question b on a.community_question_id = b.community_question_id WHERE a.enabled = 1 and b.is_deleted=0 `
+	sql := `SELECT a.*,b.question_content FROM yb_community_question_comment a join yb_community_question b on a.community_question_id = b.community_question_id WHERE a.enabled = 1 and b.is_deleted=0 AND source = 1 `
 	sql += condition
 	sql += ` ORDER BY a.create_time DESC LIMIT ?,?`
 	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
@@ -89,3 +92,29 @@ func GetCommunityQuestionCommentListByIds(CommunityQuestionCommentIds string) (l
 	_, err = o.Raw(sql).QueryRows(&list)
 	return
 }
+
+// GetCommunityVideoCommentList 获取视频评论列表
+func GetCommunityVideoCommentList(condition string, pars []interface{}, startSize, pageSize int) (total int, list []*YbCommunityQuestionCommentAndQuestion, err error) {
+	o := orm.NewOrm()
+
+	//汇总数据
+	totalSQl := `SELECT COUNT(1) total FROM yb_community_question_comment a JOIN yb_community_video b ON a.community_question_id = b.community_video_id WHERE a.enabled = 1 AND b.is_deleted = 0 AND source = 2 `
+	totalSQl += condition
+	if err = o.Raw(totalSQl, pars).QueryRow(&total); err != nil {
+		return
+	}
+
+	// 列表数据
+	sql := `SELECT
+				a.*, b.title AS question_content,
+				b.variety_tag_name AS tag_name
+			FROM
+				yb_community_question_comment a
+			JOIN yb_community_video b ON a.community_question_id = b.community_video_id
+			WHERE
+				a.enabled = 1 AND b.is_deleted = 0 AND source = 2 `
+	sql += condition
+	sql += ` ORDER BY a.create_time DESC LIMIT ?,?`
+	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
+	return
+}

+ 4 - 1
services/company_approval_message.go

@@ -8,7 +8,7 @@ import (
 	"time"
 )
 
-//消息来源类型,1:客户,2:合同,3:用印,4:指标替换,5:问答社区,6:问答评论
+//消息来源类型,1:客户,2:合同,3:用印,4:指标替换,5:问答社区,6:问答评论,7:视频评论
 const (
 	CompanyApprovalMessageSourceTypeByCompany         = 1
 	CompanyApprovalMessageSourceTypeByContract        = 2
@@ -16,6 +16,7 @@ const (
 	CompanyApprovalMessageSourceTypeByEdbInfo         = 4
 	CompanyApprovalMessageSourceTypeByQuestion        = 5
 	CompanyApprovalMessageSourceTypeByQuestionComment = 6
+	CompanyApprovalMessageSourceTypeByVideoComment    = 7
 )
 
 // 1:申请消息,2:审批结果,3:消息通知
@@ -42,6 +43,7 @@ type MessageInfo struct {
 	UserId               uint64    `json:"user_id"`
 	UserName             string    `json:"user_name"`
 	CreateTime           time.Time `json:"create_time"`
+	Extra                string    `json:"extra" description:"附加字段"`
 }
 
 // AddCompanyApprovalMessage 添加待办消息
@@ -122,6 +124,7 @@ func AddCompanyApprovalMessage(createUserId, receiveUserId, companyId, companyAp
 				wxAppPath = tmpWxAppPath
 			}
 		}
+
 		go SendCompanyApplyWxTemplateMsg(mobile, redirectUrl, wxAppPath, wxMsgMap)
 	}
 	return

+ 300 - 105
services/wechat_send_msg.go

@@ -12,9 +12,39 @@ import (
 	"io/ioutil"
 	"net/http"
 	"strconv"
+	"strings"
 	"time"
+	"errors"
 )
 
+type SendWxTemplate struct {
+	First          string   `description:"模板消息first字段"`
+	Keyword1       string   `description:"模板消息keyword1字段"`
+	Keyword2       string   `description:"模板消息keyword2字段"`
+	Keyword3       string   `description:"模板消息keyword3字段"`
+	Keyword4       string   `description:"模板消息keyword4字段"`
+	Remark         string   `description:"模板消息remark字段"`
+	TemplateId     string   `description:"模板id"`
+	RedirectUrl    string   `description:"跳转地址"`
+	RedirectTarget int      `description:"小程序跳转目标:1:弘则研报小程序,2:随手办公小程序"`
+	Resource       string   `description:"资源唯一标识"`
+	SendType       int      `description:"发送的消息类型:1:报告,2:指标更新提醒,3:审批通知,4:销售领取客户通知,5:活动取消通知,6活动更改时间通知,7:关注的作者发布报告通知,8:发送日报(周报、双周报、月报)模板消息,9:活动预约/报名时间通知"`
+	OpenIdArr      []string `description:"消息接收者openid"`
+}
+
+type BaseResponse struct {
+	Ret         int
+	Msg         string
+	ErrMsg      string
+	ErrCode     string
+	Data        interface{}
+	Success     bool `description:"true 执行成功,false 执行失败"`
+	IsSendEmail bool `json:"-" description:"true 发送邮件,false 不发送邮件"`
+	IsAddLog    bool `json:"-" description:"true 新增操作日志,false 不新增操作日志" `
+}
+
+
+
 func SendWxTemplateMsg(reportId int) (err error) {
 	var msg string
 	defer func() {
@@ -187,8 +217,8 @@ func SendCompanyApplyWxTemplateMsg(mobile, redirectUrl, wxAppPath string, wxMsgM
 	utils.FileLog.Info("mobile:%s", mobile)
 
 	//获取openid列表
-	openIdStr := WxUsersGet()
-	openIdList, err := wx_user.GetOpenIdListByMobile(mobile, openIdStr)
+	//openIdStr := WxUsersGet()
+	openIdList, err := wx_user.GetOpenIdListByMobile(mobile)
 	if err != nil {
 		msg = "get openIdList err:" + err.Error()
 		return
@@ -197,11 +227,11 @@ func SendCompanyApplyWxTemplateMsg(mobile, redirectUrl, wxAppPath string, wxMsgM
 	//fmt.Println("openIdListCount:", len(openIdList))
 	if len(openIdList) > 0 && utils.TemplateIdByCompanyApply != "" {
 		utils.FileLog.Info("start send")
-		sendUrl := "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + accessToken
+		//sendUrl := "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + accessToken
 		fmt.Println("send start")
 		utils.FileLog.Info("send start")
-		sendMap := make(map[string]interface{})
-		sendData := make(map[string]interface{})
+		//sendMap := make(map[string]interface{})
+		//sendData := make(map[string]interface{})
 
 		var first, keyword1, keyword2, keyword3, remark string
 		if tmpStr, ok := wxMsgMap[0]; ok {
@@ -222,20 +252,43 @@ func SendCompanyApplyWxTemplateMsg(mobile, redirectUrl, wxAppPath string, wxMsgM
 			remark = tmpStr
 		}
 
-		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["remark"] = map[string]interface{}{"value": remark, "color": "#173177"}
+		//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["remark"] = map[string]interface{}{"value": remark, "color": "#173177"}
+		//
+		//sendMap["template_id"] = utils.TemplateIdByCompanyApply
+		//sendMap["url"] = redirectUrl
+		//sendMap["data"] = sendData
+		////小程序信息
+		//if wxAppPath != "" {
+		//	sendMap["miniprogram"] = map[string]interface{}{"appid": utils.WxAppId2, "pagepath": wxAppPath}
+		//}
+		//sendTemplateMsg(sendUrl, sendMap, openIdList, mobile, utils.TEMPLATE_MSG_APPLY)
+
+
+		openIdArr := make([]string, len(openIdList))
+		for i, v := range openIdList {
+			openIdArr[i] = v.OpenId
+		}
 
-		sendMap["template_id"] = utils.TemplateIdByCompanyApply
-		sendMap["url"] = redirectUrl
-		sendMap["data"] = sendData
-		//小程序信息
+		sendInfo := new(SendWxTemplate)
+		sendInfo.First = first
+		sendInfo.Keyword1 = keyword1
+		sendInfo.Keyword2 = keyword2
+		sendInfo.Keyword3 = keyword3
+		sendInfo.Remark = remark
+		sendInfo.TemplateId = utils.TemplateIdByCompanyApply
+		sendInfo.RedirectUrl = redirectUrl
+		sendInfo.RedirectTarget = 2
+		sendInfo.Resource = mobile
+		sendInfo.SendType = utils.TEMPLATE_MSG_APPLY
+		sendInfo.OpenIdArr = openIdArr
 		if wxAppPath != "" {
-			sendMap["miniprogram"] = map[string]interface{}{"appid": utils.WxAppId2, "pagepath": wxAppPath}
+			sendInfo.RedirectUrl = wxAppPath
 		}
-		sendTemplateMsg(sendUrl, sendMap, openIdList, mobile, utils.TEMPLATE_MSG_APPLY)
+		err = SendTemplateMsg(sendInfo)
 	}
 	utils.FileLog.Info("send end")
 	return
@@ -268,8 +321,8 @@ func SendWxMsgWithRoadshowDetailResult(first, keyword1, keyword2, remark, mobile
 	utils.FileLog.Info("mobile:%s", mobile)
 
 	//获取openid列表
-	openIdStr := WxUsersGet()
-	openIdList, err := wx_user.GetOpenIdListByMobile(mobile, openIdStr)
+	//openIdStr := WxUsersGet()
+	openIdList, err := wx_user.GetOpenIdListByMobile(mobile)
 	if err != nil {
 		msg = "get openIdList err:" + err.Error()
 		return
@@ -278,25 +331,46 @@ func SendWxMsgWithRoadshowDetailResult(first, keyword1, keyword2, remark, mobile
 	//fmt.Println("openIdListCount:", len(openIdList))
 	if len(openIdList) > 0 && utils.TemplateIdByCompanyApply != "" {
 		utils.FileLog.Info("start send")
-		sendUrl := "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + accessToken
-		fmt.Println("send start")
-		utils.FileLog.Info("send start")
-		sendMap := make(map[string]interface{})
-		sendData := make(map[string]interface{})
-
-		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["remark"] = map[string]interface{}{"value": remark, "color": "#173177"}
-
-		sendMap["template_id"] = utils.WxMsgTemplateIdWithRoadshowDetailResult
-		sendMap["url"] = redirectUrl
-		sendMap["data"] = sendData
-		//小程序信息
-		if wxAppPath != "" {
-			sendMap["miniprogram"] = map[string]interface{}{"appid": utils.WxAppId2, "pagepath": wxAppPath}
+		//sendUrl := "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + accessToken
+		//fmt.Println("send start")
+		//utils.FileLog.Info("send start")
+		//sendMap := make(map[string]interface{})
+		//sendData := make(map[string]interface{})
+		//
+		//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["remark"] = map[string]interface{}{"value": remark, "color": "#173177"}
+		//
+		//sendMap["template_id"] = utils.WxMsgTemplateIdWithRoadshowDetailResult
+		//sendMap["url"] = redirectUrl
+		//sendMap["data"] = sendData
+		////小程序信息
+		//if wxAppPath != "" {
+		//	sendMap["miniprogram"] = map[string]interface{}{"appid": utils.WxAppId2, "pagepath": wxAppPath}
+		//}
+		//sendTemplateMsg(sendUrl, sendMap, openIdList, wxAppPath, utils.TEMPLATE_MSG_ACTIVITY_APPOINTMENT)
+
+		openIdArr := make([]string, len(openIdList))
+		for i, v := range openIdList {
+			openIdArr[i] = v.OpenId
+		}
+
+		sendInfo := new(SendWxTemplate)
+		sendInfo.First = first
+		sendInfo.Keyword1 = keyword1
+		sendInfo.Keyword2 = keyword2
+		sendInfo.Remark = remark
+		sendInfo.TemplateId = utils.WxMsgTemplateIdWithRoadshowDetailResult
+		if wxAppPath != "" && utils.RunMode == "release" {
+			sendInfo.RedirectUrl = wxAppPath
 		}
-		sendTemplateMsg(sendUrl, sendMap, openIdList, wxAppPath, utils.TEMPLATE_MSG_ACTIVITY_APPOINTMENT)
+		sendInfo.RedirectTarget = 2
+		sendInfo.Resource = wxAppPath
+		sendInfo.SendType = utils.TEMPLATE_MSG_ACTIVITY_APPOINTMENT
+		sendInfo.OpenIdArr = openIdArr
+
+		err = SendTemplateMsg(sendInfo)
 	}
 	utils.FileLog.Info("send end")
 	return
@@ -329,8 +403,8 @@ func SendWxMsgWithRoadshowPending(first, keyword1, keyword2, keyword3, keyword4,
 	}
 
 	//获取openid列表
-	openIdStr := WxUsersGet()
-	openIdList, err := wx_user.GetOpenIdListByMobile(mobile, openIdStr)
+	//openIdStr := WxUsersGet()
+	openIdList, err := wx_user.GetOpenIdListByMobile(mobile)
 	if err != nil {
 		msg = "get openIdList err:" + err.Error()
 		return
@@ -339,26 +413,49 @@ func SendWxMsgWithRoadshowPending(first, keyword1, keyword2, keyword3, keyword4,
 	//fmt.Println("openIdListCount:", len(openIdList))
 	if len(openIdList) > 0 && utils.TemplateIdByCompanyApply != "" {
 		utils.FileLog.Info("start send")
-		sendUrl := "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + accessToken
-		fmt.Println("send start")
-		utils.FileLog.Info("send start")
-		sendMap := make(map[string]interface{})
-		sendData := make(map[string]interface{})
-
-		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"}
-		sendData["remark"] = map[string]interface{}{"value": remark, "color": "#173177"}
-
-		sendMap["template_id"] = utils.WxMsgTemplateIdWithRoadshowPending
-		sendMap["data"] = sendData
-		//小程序信息
-		if wxAppPath != "" {
-			sendMap["miniprogram"] = map[string]interface{}{"appid": utils.WxAppId2, "pagepath": wxAppPath}
+		//sendUrl := "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + accessToken
+		//fmt.Println("send start")
+		//utils.FileLog.Info("send start")
+		//sendMap := make(map[string]interface{})
+		//sendData := make(map[string]interface{})
+		//
+		//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"}
+		//sendData["remark"] = map[string]interface{}{"value": remark, "color": "#173177"}
+		//
+		//sendMap["template_id"] = utils.WxMsgTemplateIdWithRoadshowPending
+		//sendMap["data"] = sendData
+		////小程序信息
+		//if wxAppPath != "" {
+		//	sendMap["miniprogram"] = map[string]interface{}{"appid": utils.WxAppId2, "pagepath": wxAppPath}
+		//}
+		//sendTemplateMsg(sendUrl, sendMap, openIdList, wxAppPath, utils.TEMPLATE_MSG_ACTIVITY_APPOINTMENT)
+
+		openIdArr := make([]string, len(openIdList))
+		for i, v := range openIdList {
+			openIdArr[i] = v.OpenId
+		}
+
+		sendInfo := new(SendWxTemplate)
+		sendInfo.First = first
+		sendInfo.Keyword1 = keyword1
+		sendInfo.Keyword2 = keyword2
+		sendInfo.Keyword3 = keyword3
+		sendInfo.Keyword4 = keyword4
+		sendInfo.Remark = remark
+		sendInfo.TemplateId = utils.WxMsgTemplateIdWithRoadshowPending
+		if wxAppPath != "" && utils.RunMode == "release" {
+			sendInfo.RedirectUrl = wxAppPath
 		}
-		sendTemplateMsg(sendUrl, sendMap, openIdList, wxAppPath, utils.TEMPLATE_MSG_ACTIVITY_APPOINTMENT)
+		sendInfo.RedirectTarget = 2
+		sendInfo.Resource = wxAppPath
+		sendInfo.SendType = utils.TEMPLATE_MSG_ACTIVITY_APPOINTMENT
+		sendInfo.OpenIdArr = openIdArr
+
+		err = SendTemplateMsg(sendInfo)
 	}
 	utils.FileLog.Info("send end")
 	return
@@ -390,8 +487,8 @@ func SendWxMsgWithRoadshowDeleteNotice(first, keyword1, keyword2, remark, wxAppP
 	}
 
 	//获取openid列表
-	openIdStr := WxUsersGet()
-	openIdList, err := wx_user.GetOpenIdListByMobile(mobile, openIdStr)
+	//openIdStr := WxUsersGet()
+	openIdList, err := wx_user.GetOpenIdListByMobile(mobile)
 	if err != nil {
 		msg = "get openIdList err:" + err.Error()
 		return
@@ -400,21 +497,42 @@ func SendWxMsgWithRoadshowDeleteNotice(first, keyword1, keyword2, remark, wxAppP
 	//fmt.Println("openIdListCount:", len(openIdList))
 	if len(openIdList) > 0 && utils.TemplateIdByCompanyApply != "" {
 		utils.FileLog.Info("start send")
-		sendUrl := "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + accessToken
-		sendMap := make(map[string]interface{})
-		sendData := make(map[string]interface{})
-
-		sendMap["template_id"] = utils.WxMsgTemplateIdWithRoadshowDeleteNotice
-		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["remark"] = map[string]interface{}{"value": remark, "color": "#173177"}
-		//小程序信息
-		if wxAppPath != "" {
-			sendMap["miniprogram"] = map[string]interface{}{"appid": utils.WxAppId2, "pagepath": wxAppPath}
+		//sendUrl := "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + accessToken
+		//sendMap := make(map[string]interface{})
+		//sendData := make(map[string]interface{})
+		//
+		//sendMap["template_id"] = utils.WxMsgTemplateIdWithRoadshowDeleteNotice
+		//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["remark"] = map[string]interface{}{"value": remark, "color": "#173177"}
+		////小程序信息
+		//if wxAppPath != "" {
+		//	sendMap["miniprogram"] = map[string]interface{}{"appid": utils.WxAppId2, "pagepath": wxAppPath}
+		//}
+		//sendMap["data"] = sendData
+		//sendTemplateMsg(sendUrl, sendMap, openIdList, wxAppPath, utils.TEMPLATE_MSG_ACTIVITY_APPOINTMENT)
+
+		openIdArr := make([]string, len(openIdList))
+		for i, v := range openIdList {
+			openIdArr[i] = v.OpenId
+		}
+
+		sendInfo := new(SendWxTemplate)
+		sendInfo.First = first
+		sendInfo.Keyword1 = keyword1
+		sendInfo.Keyword2 = keyword2
+		sendInfo.Remark = remark
+		sendInfo.TemplateId = utils.WxMsgTemplateIdWithRoadshowDeleteNotice
+		if wxAppPath != "" && utils.RunMode == "release" {
+			sendInfo.RedirectUrl = wxAppPath
 		}
-		sendMap["data"] = sendData
-		sendTemplateMsg(sendUrl, sendMap, openIdList, wxAppPath, utils.TEMPLATE_MSG_ACTIVITY_APPOINTMENT)
+		sendInfo.RedirectTarget = 2
+		sendInfo.Resource = wxAppPath
+		sendInfo.SendType = utils.TEMPLATE_MSG_ACTIVITY_APPOINTMENT
+		sendInfo.OpenIdArr = openIdArr
+
+		err = SendTemplateMsg(sendInfo)
 	}
 	utils.FileLog.Info("send end")
 	return
@@ -444,8 +562,8 @@ func SendSealFinishedWxTemplateMsg(mobile string, companyName string, sealId int
 		return
 	}
 	utils.FileLog.Info("mobile:%s", mobile)
-	openIdStr := WxUsersGet()
-	openIdList, err := wx_user.GetOpenIdListByMobile(mobile, openIdStr)
+	//openIdStr := WxUsersGet()
+	openIdList, err := wx_user.GetOpenIdListByMobile(mobile)
 	if err != nil {
 		msg = "get openIdList err:" + err.Error()
 		return
@@ -454,29 +572,48 @@ func SendSealFinishedWxTemplateMsg(mobile string, companyName string, sealId int
 
 	if len(openIdList) > 0 && utils.WxMsgTemplateIdWithSealApplyFinished != "" {
 		utils.FileLog.Info("start send")
-		sendUrl := "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + accessToken
-		fmt.Println("send start")
-		utils.FileLog.Info("send start")
-		sendMap := make(map[string]interface{})
-		sendData := make(map[string]interface{})
+		//sendUrl := "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + accessToken
+		//fmt.Println("send start")
+		//utils.FileLog.Info("send start")
+		//sendMap := make(map[string]interface{})
+		//sendData := make(map[string]interface{})
 		first := "您的用印申请已签回,可前往提交转正/续约申请"
 		keyword1 := companyName
 		keyword2 := "已签回"
 		remark := "点击查看用印详情"
-
-		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["remark"] = map[string]interface{}{"value": remark, "color": "#173177"}
-
-		sendMap["template_id"] = utils.WxMsgTemplateIdWithSealApplyFinished
-		sendMap["url"] = "" //跳转地址
-		sendMap["data"] = sendData
+		//
+		//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["remark"] = map[string]interface{}{"value": remark, "color": "#173177"}
+		//
+		//sendMap["template_id"] = utils.WxMsgTemplateIdWithSealApplyFinished
+		//sendMap["url"] = "" //跳转地址
+		//sendMap["data"] = sendData
 
 		// TODO 随手办公小程序的跳转地址
 		wxAppPath := fmt.Sprintf("pages-approve/seal/detail?SealId=%d", sealId)
-		sendMap["miniprogram"] = map[string]interface{}{"appid": utils.WxAppId2, "pagepath": wxAppPath}
-		err = sendTemplateMsg(sendUrl, sendMap, openIdList, wxAppPath, utils.TEMPLATE_MSG_SEAL_FINISHED)
+		//sendMap["miniprogram"] = map[string]interface{}{"appid": utils.WxAppId2, "pagepath": wxAppPath}
+		//err = sendTemplateMsg(sendUrl, sendMap, openIdList, wxAppPath, utils.TEMPLATE_MSG_SEAL_FINISHED)
+
+		openIdArr := make([]string, len(openIdList))
+		for i, v := range openIdList {
+			openIdArr[i] = v.OpenId
+		}
+
+		sendInfo := new(SendWxTemplate)
+		sendInfo.First = first
+		sendInfo.Keyword1 = keyword1
+		sendInfo.Keyword2 = keyword2
+		sendInfo.Remark = remark
+		sendInfo.RedirectUrl = wxAppPath
+		sendInfo.TemplateId = utils.WxMsgTemplateIdWithSealApplyFinished
+		sendInfo.RedirectTarget = 2
+		sendInfo.Resource = wxAppPath
+		sendInfo.SendType = utils.TEMPLATE_MSG_SEAL_FINISHED
+		sendInfo.OpenIdArr = openIdArr
+
+		err = SendTemplateMsg(sendInfo)
 	}
 	utils.FileLog.Info("send end")
 	return
@@ -508,27 +645,85 @@ func SendYbQuestionDistributeWxMsg(questionId, userId int, openid, questionTitle
 		UserId: userId,
 	})
 
-	sendUrl := "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + accessToken
-	sendMap := make(map[string]interface{})
-	sendData := make(map[string]interface{})
+	//sendUrl := "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + accessToken
+	//sendMap := make(map[string]interface{})
+	//sendData := make(map[string]interface{})
 
 	first := "您好,有新的提问待回复"
 	keyword1 := questionTitle
 	keyword2 := "待回复"
 	remark := "请点击详情尽快处理"
 
-	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["remark"] = map[string]interface{}{"value": remark, "color": "#173177"}
+	//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["remark"] = map[string]interface{}{"value": remark, "color": "#173177"}
+	//
+	//sendMap["template_id"] = utils.WxMsgTemplateIdWithYbCommunityQuestion
+	//sendMap["data"] = sendData
+	//
+	wxAppPath := fmt.Sprintf("pages-question/answerDetail?id=%d", questionId)
+	//if wxAppPath != "" {
+	//	sendMap["miniprogram"] = map[string]interface{}{"appid": utils.WxYbAppId, "pagepath": wxAppPath}
+	//}
+	//err = sendTemplateMsg(sendUrl, sendMap, openIdList, wxAppPath, utils.TEMPLATE_MSG_YB_COMMUNITY_QUESTION)
+
+	openIdArr := make([]string, len(openIdList))
+	for i, v := range openIdList {
+		openIdArr[i] = v.OpenId
+	}
+
+	sendInfo := new(SendWxTemplate)
+	sendInfo.First = first
+	sendInfo.Keyword1 = keyword1
+	sendInfo.Keyword2 = keyword2
+	sendInfo.Remark = remark
+	sendInfo.RedirectUrl = wxAppPath
+	sendInfo.TemplateId = utils.WxMsgTemplateIdWithYbCommunityQuestion
+	sendInfo.RedirectTarget = 1
+	sendInfo.Resource = wxAppPath
+	sendInfo.SendType = utils.TEMPLATE_MSG_YB_COMMUNITY_QUESTION
+	sendInfo.OpenIdArr = openIdArr
+	err = SendTemplateMsg(sendInfo)
+	return
+}
 
-	sendMap["template_id"] = utils.WxMsgTemplateIdWithYbCommunityQuestion
-	sendMap["data"] = sendData
 
-	wxAppPath := fmt.Sprintf("pages-question/answerDetail?id=%d", questionId)
-	if wxAppPath != "" {
-		sendMap["miniprogram"] = map[string]interface{}{"appid": utils.WxYbAppId, "pagepath": wxAppPath}
+//推送模板消息
+func SendTemplateMsg(sendInfo *SendWxTemplate) (err error) {
+	postData, err := json.Marshal(sendInfo)
+	if err != nil {
+		alarm_msg.SendAlarmMsg("SendTemplateMsg json.Marshal Err:"+err.Error(), 1)
+		return err
+	}
+	body := ioutil.NopCloser(strings.NewReader(string(postData)))
+	client := &http.Client{}
+	req, err := http.NewRequest("POST", utils.SendWxTemplateMsgUrl, body)
+	if err != nil {
+		alarm_msg.SendAlarmMsg("SendTemplateMsg 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(BaseResponse)
+	err = json.Unmarshal(b, &result)
+	if err != nil {
+		return err
+	}
+	if result.Ret != 200 {
+		err = errors.New(string(b))
+		return err
 	}
-	err = sendTemplateMsg(sendUrl, sendMap, openIdList, wxAppPath, utils.TEMPLATE_MSG_YB_COMMUNITY_QUESTION)
 	return
-}
+}

+ 28 - 6
services/yb/community_question_comment.go

@@ -15,13 +15,29 @@ import (
 )
 
 // GetCommunityQuestionCommentList 问答评论列表
-func GetCommunityQuestionCommentList(condition string, pars []interface{}, startSize, pageSize int) (total int, commentList []*ybResponse.CommunityQuestionCommentItem, err error) {
+func GetCommunityQuestionCommentList(condition string, pars []interface{}, startSize, pageSize, source int) (total int, commentList []*ybResponse.CommunityQuestionCommentItem, err error) {
 	commentList = make([]*ybResponse.CommunityQuestionCommentItem, 0)
-	total, list, e := yb_community_question_comment.GetCommunityQuestionCommentList(condition, pars, startSize, pageSize)
-	if e != nil {
-		err = errors.New("获取问题列表失败 Err:" + e.Error())
-		return
+	list := make([]*yb_community_question_comment.YbCommunityQuestionCommentAndQuestion, 0)
+	// 来源
+	if source == 1 {
+		qaTotal, qaList, e := yb_community_question_comment.GetCommunityQuestionCommentList(condition, pars, startSize, pageSize)
+		if e != nil {
+			err = errors.New("获取问题列表失败 Err:" + e.Error())
+			return
+		}
+		list = qaList
+		total = qaTotal
+	} else {
+		// 视频社区
+		vcTotal, vcList, e := yb_community_question_comment.GetCommunityVideoCommentList(condition, pars, startSize, pageSize)
+		if e != nil {
+			err = errors.New("获取视频评论列表失败 Err:" + e.Error())
+			return
+		}
+		list = vcList
+		total = vcTotal
 	}
+
 	if len(list) == 0 {
 		return
 	}
@@ -65,6 +81,8 @@ func GetCommunityQuestionCommentList(condition string, pars []interface{}, start
 			UserName:                   "",
 			CompanyName:                "",
 			CompanyProductStatus:       "",
+			Source:                     v.Source,
+			TagName:                    v.TagName,
 		}
 
 		//评论人信息
@@ -143,6 +161,10 @@ func afterDeleteComment(communityQuestionComment *yb_community_question_comment.
 			go alarm_msg.SendAlarmMsg("问答评论信息删除后,标记站内消息失败"+time.Now().Format(utils.FormatDateTime)+";Err:"+err.Error(), 3)
 		}
 	}()
-	err = company_approval_message.CancelCompanyApprovalMessage(int(communityQuestionComment.CommunityQuestionCommentId), services.CompanyApprovalMessageSourceTypeByQuestionComment)
+	sourceType := services.CompanyApprovalMessageSourceTypeByQuestionComment
+	if communityQuestionComment.Source == 2 {
+		sourceType = services.CompanyApprovalMessageSourceTypeByVideoComment
+	}
+	err = company_approval_message.CancelCompanyApprovalMessage(int(communityQuestionComment.CommunityQuestionCommentId), sourceType)
 	return
 }

+ 4 - 0
utils/config.go

@@ -46,6 +46,7 @@ var (
 	WxMsgTemplateIdWithRoadshowDeleteNotice string //路演->研究员收到活动删除通知
 	WxMsgTemplateIdWithSealApplyFinished      string // 用印申请-已签回通知
 	WxMsgTemplateIdWithYbCommunityQuestion  string // 研报小程序->问答社区回复通知
+	SendWxTemplateMsgUrl string  //模板消息推送
 )
 
 var (
@@ -195,6 +196,7 @@ func wxConfig() {
 		AdminWxAppId = "wx1392111da5426e9e"
 		AdminWxAppSecret = "30eceb7cf29bf2f046031155ab55d7b4"
 
+		SendWxTemplateMsgUrl = "http://127.0.0.1:8086/v1/wechat/send_template_msg"
 	} else {
 		WxAppId = "wx9b5d7291e581233a"
 		WxAppSecret = "f4d52e34021eee262dce9682b31f8861"
@@ -218,6 +220,8 @@ func wxConfig() {
 		//内部员工公众号(弘则部门)
 		AdminWxAppId = "wx1392111da5426e9e"
 		AdminWxAppSecret = "30eceb7cf29bf2f046031155ab55d7b4"
+		
+		SendWxTemplateMsgUrl = "http://127.0.0.1:8086/v1/wechat/send_template_msg"
 	}
 
 }

+ 5 - 0
utils/constants.go

@@ -144,3 +144,8 @@ const (
 	TEMPLATE_MSG_YB_PRICE_DRIVEN                  //研报价格驱动 14
 	TEMPLATE_MSG_SEAL_FINISHED                    //用印申请已迁回通知 15
 )
+
+
+const (
+	SendTemplateMsgAuthorization = "dc855fce962a639faa779cbdd4cd332f"
+)