Browse Source

Merge branch 'fix_2022_0222' of hongze/hongze_yb into master

hsun 3 years ago
parent
commit
2922b896ed
1 changed files with 28 additions and 14 deletions
  1. 28 14
      controller/activity/activity.go

+ 28 - 14
controller/activity/activity.go

@@ -11,6 +11,7 @@ import (
 	"io/ioutil"
 	"os"
 	"strconv"
+	"strings"
 	"time"
 )
 
@@ -190,16 +191,17 @@ func GetActivityShareImg(c *gin.Context)  {
 	activityEnd := activityInfo.EndTime.Format("15:04")
 	activityWeek := activityInfo.StartTime.Weekday().String()
 	var WeekDayMap = map[string]string{
-		"Monday":    "一",
-		"Tuesday":   "二",
-		"Wednesday": "三",
-		"Thursday":  "四",
-		"Friday":    "五",
-		"Saturday":  "六",
-		"Sunday":    "日",
+		"Monday":    "星期一",
+		"Tuesday":   "星期二",
+		"Wednesday": "星期三",
+		"Thursday":  "星期四",
+		"Friday":    "星期五",
+		"Saturday":  "星期六",
+		"Sunday":    "星期日",
 	}
 	weekStr := WeekDayMap[activityWeek]
-	timeStr := activityDate + " " + activityStart + "-" + activityEnd + " " + weekStr
+	dateStr := "活动时间:" + activityDate
+	timeStr := activityStart + "-" + activityEnd + " " + weekStr
 
 	// 获取原分享图
 	originShareUrl := "static/img/report_share.png"
@@ -220,7 +222,7 @@ func GetActivityShareImg(c *gin.Context)  {
 
 	// 处理文字x轴y轴点
 	drawText := activityInfo.ActivityTypeName
-	fontSize := 40
+	fontSize := 42
 	fontWidth := 50
 	x, y, newSize, err := calcuDrawXandY(drawText, fontSize, 500, 400)
 	if err != nil {
@@ -231,12 +233,15 @@ func GetActivityShareImg(c *gin.Context)  {
 	// 生成新分享图
 	var drawInfo []*utils.DrawTextInfo
 	text := &utils.DrawTextInfo{
-		Text: drawText, X: x, Y: y - 20, FontSize: fontSize,
+		Text: drawText, X: x, Y: y - 50, FontSize: fontSize,
+	}
+	textDate := &utils.DrawTextInfo{
+		Text: dateStr, X: 100, Y: y + 15, FontSize: 28,
 	}
 	textTime := &utils.DrawTextInfo{
-		Text: timeStr, X: 35, Y: y + 30, FontSize: 30,
+		Text: timeStr, X: 120, Y: y + 75, FontSize: 28,
 	}
-	drawInfo = append(drawInfo, text, textTime)
+	drawInfo = append(drawInfo, text, textDate, textTime)
 	var colorRGBA = utils.FontRGBA{
 		R: 255, G: 255, B: 255, A: 255,
 	}
@@ -255,8 +260,17 @@ func GetActivityShareImg(c *gin.Context)  {
 func calcuDrawXandY(drawText string, fontSize, canvasLength, canvasWidth int) (x, y, newSize int, err error) {
 	// y轴取画布宽度的一半
 	y = canvasWidth / 2
-	// 文字所占总宽度
-	lenText := len(drawText)
+	// 拆分文字计算总宽度
+	lenText := 0
+	strArr := strings.Split(drawText, "")
+	for _, str := range strArr {
+		if len(str) == 1 {
+			// 将字母符号算作2个长度
+			lenText += 2
+		} else {
+			lenText += 3
+		}
+	}
 	textUnit := float64(lenText) / 3
 	textWidth := int(textUnit * float64(fontSize))
 	// x轴上的起点位置