瀏覽代碼

Merge branch 'cygx_need_907_909' of http://8.136.199.33:3000/hongze/hongze_cygx into debug

xingzai 1 年之前
父節點
當前提交
6c1bb82f61
共有 2 個文件被更改,包括 51 次插入12 次删除
  1. 14 12
      services/activity.go
  2. 37 0
      services/wx_template_msg.go

+ 14 - 12
services/activity.go

@@ -46,12 +46,12 @@ func SendActivityBeginMsg(cont context.Context) (err error) {
 	if len(listActivity) == 0 {
 		return
 	}
-	var remark = "点击查看活动详情"
+	//var remark = "点击查看活动详情"
 	var signupIds string
 	for _, v := range listActivity {
 		signupIds += strconv.Itoa(v.Id) + ","
-		var reserveResults string
-		var first string
+		//var reserveResults string
+		//var first string
 		openIdItem := new(models.OpenIdList)
 		openIdItem.OpenId = v.OpenId
 		openIdItem.UserId = v.UserId
@@ -66,9 +66,10 @@ func SendActivityBeginMsg(cont context.Context) (err error) {
 		//} else if v.FailType == 3 {
 		//	reserveResults = "失败(爽约次数超限)"
 		//}
-		reserveResults = "--"
-		first = "将在1小时后开始"
-		SendWxMsgWithFrequency(first, v.ActivityName, reserveResults, v.ActivityTimeText, v.Address, remark, openIdList, v.ActivityId)
+		//reserveResults = "--"
+		//first = "将在1小时后开始"
+		//SendWxMsgWithFrequency(first, v.ActivityName, reserveResults, v.ActivityTimeText, v.Address, remark, openIdList, v.ActivityId)
+		SendWxMsgWithFrequencyBycategory(v.ActivityName, v.ActivityTime, openIdList, v.ActivityId)
 	}
 	if len(signupIds) == 0 {
 		return
@@ -110,7 +111,7 @@ func SendActivityBeginMsgMeeting(cont context.Context) (err error) {
 		return
 	}
 	//var signupIds string
-	var remark = "点击查看活动详情"
+	//var remark = "点击查看活动详情"
 
 	var activityIds []int
 	//同一时间举办的活动不多所以这里循环查询
@@ -155,11 +156,12 @@ func SendActivityBeginMsgMeeting(cont context.Context) (err error) {
 			openIdItem.UserId = vOpenid.UserId
 			openIdList = append(openIdList, openIdItem)
 		}
-		var reserveResults string
-		var keyword2 string
-		reserveResults = "--"
-		keyword2 = "将在15分钟后开始"
-		SendWxMsgWithFrequency(keyword2, v.ActivityName, reserveResults, v.ActivityTimeText, "--", remark, openIdList, v.ActivityId)
+		//var reserveResults string
+		//var keyword2 string
+		//reserveResults = "--"
+		//keyword2 = "将在15分钟后开始"
+		//SendWxMsgWithFrequency(keyword2, v.ActivityName, reserveResults, v.ActivityTimeText, "--", remark, openIdList, v.ActivityId)
+		SendWxMsgWithFrequencyBycategory(v.ActivityName, v.ActivityTime, openIdList, v.ActivityId)
 	}
 	err = models.UpdateSendedMsgMeetingSendWxMsg(activityIds)
 	return

+ 37 - 0
services/wx_template_msg.go

@@ -46,6 +46,43 @@ func SendWxMsgWithFrequency(keyword2, activityName, reserveResults, activityTime
 	return
 }
 
+// 活动预开始模版消息通知(类目模版消息,暂时单独推送)
+func SendWxMsgWithFrequencyBycategory(keyWord1, keyWord2 string, openIdList []*models.OpenIdList, activityId int) (err error) {
+	if len(openIdList) == 0 {
+		return
+	}
+	var msg string
+	defer func() {
+		if err != nil {
+			go utils.SendAlarmMsg(fmt.Sprint("活动预开始模版消息通知消息失败SendWxMsgWithFrequencyBycategory ,activityId:", activityId, msg+";Err:"+err.Error()), 2)
+			utils.FileLog.Info("发送模版消息失败,Err:%s", err.Error())
+		}
+	}()
+	accessToken, err := models.GetWxAccessTokenByXzs()
+	if err != nil {
+		msg = "GetWxAccessToken Err:" + err.Error()
+		return
+	}
+	if accessToken == "" {
+		msg = "accessToken is empty"
+		return
+	}
+	//keyword1 := keyWord2
+	//keyword1 := keyWord2
+	sendUrl := "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + accessToken
+	templateId := utils.WxMsgTemplateIdActivityChangeApplyXzs
+	redirectUrl := utils.WX_MSG_PATH_ACTIVITY_DETAIL + strconv.Itoa(activityId)
+	sendMap := make(map[string]interface{})
+	sendData := make(map[string]interface{})
+	sendMap["template_id"] = templateId
+	sendMap["miniprogram"] = map[string]interface{}{"appid": utils.WxAppId, "pagepath": redirectUrl}
+	sendData["ting18"] = map[string]interface{}{"value": keyWord1, "color": "#173177"}
+	sendData["time23"] = map[string]interface{}{"value": keyWord2, "color": "#173177"}
+	sendMap["data"] = sendData
+	WxSendTemplateMsg(sendUrl, sendMap, openIdList, strconv.Itoa(activityId), utils.TEMPLATE_MSG_CYGX_ACTIVITY_ADD)
+	return
+}
+
 // 专项调研活动预开始消息通知
 // func SendWxMsgWithFrequencySpecial(first, activityName, reserveResults, activityTime, activityAddress, remark string, openIdList []*models.OpenIdList, activityId int) (err error) {
 func SendWxMsgWithFrequencySpecial(first, keyword1, keyword2, keyword3, keyword4, remark string, openIdList []*models.OpenIdList, activityId int) (err error) {