Browse Source

Merge branch 'yx_1.1' into debug

zwxi 1 year ago
parent
commit
c53c15fb8a
3 changed files with 27 additions and 4 deletions
  1. 3 3
      controllers/cygx/activity.go
  2. 1 1
      services/wechat_send_category_template_msg.go
  3. 23 0
      utils/common.go

+ 3 - 3
controllers/cygx/activity.go

@@ -744,13 +744,13 @@ func (this *ActivityCoAntroller) PreserveAndPublish() {
 				if activityInfo.PublishStatus == 1 && oldExpert != newExpert {
 					go services.SendWxMsgWithCygxActivityUpdateTime(req.ActivityId, oldExpert, newExpert, "expertType")
 					if activityInfo.ChartPermissionId == utils.CHART_PERMISSION_ID_YANXUAN {
-						go services.SendWxCategoryMsgWithCygxActivityUpdateTime(req.ActivityId, activityInfo.ActivityTimeText, item.ActivityTimeText, "expertType")
+						go services.SendWxCategoryMsgWithCygxActivityUpdateTime(req.ActivityId, activityInfo.ActivityTimeText, newExpert, "expertType")
 					}
 				}
 				if activityInfo.PublishStatus == 1 && activityInfo.Address != item.Address {
 					go services.SendWxMsgWithCygxActivityUpdateTime(req.ActivityId, activityInfo.Address, item.Address, "addressType")
 					if activityInfo.ChartPermissionId == utils.CHART_PERMISSION_ID_YANXUAN {
-						go services.SendWxCategoryMsgWithCygxActivityUpdateTime(req.ActivityId, activityInfo.ActivityTimeText, item.Address[:20]+"...", "addressType")
+						go services.SendWxCategoryMsgWithCygxActivityUpdateTime(req.ActivityId, activityInfo.ActivityTimeText, item.Address, "addressType")
 					}
 				}
 				if activityInfo.PublishStatus == 1 && activityInfo.ParticipationCode != item.ParticipationCode {
@@ -763,7 +763,7 @@ func (this *ActivityCoAntroller) PreserveAndPublish() {
 				if activityInfo.PublishStatus == 1 && activityInfo.Theme != item.Theme {
 					go services.SendWxMsgWithCygxActivityUpdateTime(req.ActivityId, activityInfo.Theme, item.Theme, "Theme")
 					if activityInfo.ChartPermissionId == utils.CHART_PERMISSION_ID_YANXUAN {
-						go services.SendWxCategoryMsgWithCygxActivityUpdateTime(req.ActivityId, activityInfo.ActivityTimeText, item.Theme[:20]+"...", "Theme")
+						go services.SendWxCategoryMsgWithCygxActivityUpdateTime(req.ActivityId, activityInfo.ActivityTimeText, item.Theme, "Theme")
 					}
 				}
 

+ 1 - 1
services/wechat_send_category_template_msg.go

@@ -178,7 +178,7 @@ func SendWxCategoryMsgWithCygxActivityUpdateTime(activityId int, oldStr, newStr,
 		openIdArr[i] = v.OpenId
 	}
 
-	keyword3 = newStr
+	keyword3 = utils.TruncateActivityNameString(newStr)
 
 	redirectUrl = utils.WX_MSG_PATH_ACTIVITY_DETAIL + strconv.Itoa(activityId) + "&IsSendWx=1"
 	sendInfo := new(SendWxCategoryTemplate)

+ 23 - 0
utils/common.go

@@ -29,6 +29,7 @@ import (
 	"strings"
 	"time"
 	"unicode"
+	"unicode/utf8"
 )
 
 // 随机数种子
@@ -2201,3 +2202,25 @@ func GetLikeKeywordPars(pars []interface{}, keyword string, num int) (newPars []
 	}
 	return
 }
+
+// 处理活动名称
+func TruncateActivityNameString(s string) string {
+	// 计算字符串总字数(按汉字、数字、字母和特殊符号计算)
+	totalCharCount := utf8.RuneCountInString(s)
+	// 如果总字数不超过18,则直接返回整个字符串
+	if totalCharCount <= 18 {
+		return s
+	}
+	// 计算前15个汉字所需的字节位置
+	hanziCount := 0
+	byteIndex := 0
+	for byteIndex < len(s) && hanziCount < 15 {
+		r, size := utf8.DecodeRuneInString(s[byteIndex:])
+		if r != utf8.RuneError {
+			hanziCount++
+		}
+		byteIndex += size
+	}
+	// 截取前15个汉字,并添加省略号
+	return s[:byteIndex] + "…"
+}