优化抢购成功图片生成逻辑
This commit is contained in:
+11
-2
@@ -23,11 +23,19 @@ func SaveSuccessImage(account types.Account, product types.Product, roleName str
|
||||
if font == nil {
|
||||
return
|
||||
}
|
||||
if successDir == "" {
|
||||
successDir = constants.DefaultSuccessDir
|
||||
}
|
||||
if err := os.MkdirAll(successDir, 0755); err != nil {
|
||||
logger.LogEvent("图片", "error", "成功图片目录创建失败: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
productName := product.CommodityName
|
||||
if productName == "" {
|
||||
productName = product.CommodityID
|
||||
}
|
||||
now := time.Now().In(constants.CST)
|
||||
|
||||
width, height := 600, 280
|
||||
img := image.NewRGBA(image.Rect(0, 0, width, height))
|
||||
@@ -59,7 +67,7 @@ func SaveSuccessImage(account types.Account, product types.Product, roleName str
|
||||
Color color.Color
|
||||
}{
|
||||
{productName, 20, 25, 42, white},
|
||||
{"兑换时间:" + time.Now().In(constants.CST).Format("2006年01月02日 15:04:05"), 16, 25, 110, black},
|
||||
{"兑换时间:" + now.Format("2006年01月02日 15:04:05"), 16, 25, 110, black},
|
||||
{"游戏昵称:" + utils.EmptyDefault(roleName, "未知"), 16, 25, 150, black},
|
||||
{"兑换账号:" + account.Name, 16, 25, 190, black},
|
||||
}
|
||||
@@ -69,7 +77,8 @@ func SaveSuccessImage(account types.Account, product types.Product, roleName str
|
||||
_, _ = ctx.DrawString(line.Text, freetype.Pt(line.X, line.Y))
|
||||
}
|
||||
|
||||
name := utils.SafeFilename(fmt.Sprintf("%s_%s_%d.png", account.Name, productName, time.Now().Unix()))
|
||||
ownerName := utils.EmptyDefault(roleName, account.Name)
|
||||
name := utils.SafeFilename(fmt.Sprintf("%s_%s_%s.png", ownerName, productName, now.Format("20060102_150405.000")))
|
||||
path := filepath.Join(successDir, name)
|
||||
file, err := os.Create(path)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user