🎨 新增兑换码库导出excel功能

This commit is contained in:
2025-09-27 17:17:47 +08:00
parent 013b7af7e3
commit 0ec44fad2c
4 changed files with 130 additions and 5 deletions

View File

@@ -1,6 +1,7 @@
package app
import (
"fmt"
"git.echol.cn/loser/lckt/global"
"git.echol.cn/loser/lckt/model/app"
"git.echol.cn/loser/lckt/model/app/request"
@@ -8,6 +9,7 @@ import (
r "git.echol.cn/loser/lckt/model/common/response"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
"time"
)
type RedeemCodeApi struct{}
@@ -169,6 +171,7 @@ func (rc *RedeemCodeApi) DeleteCDK(ctx *gin.Context) {
r.OkWithMessage("删除兑换码成功", ctx)
}
// Redeem 兑换码兑换
func (rc *RedeemCodeApi) Redeem(context *gin.Context) {
var p request.RedeemCDK
if err := context.ShouldBind(&p); err != nil {
@@ -186,3 +189,29 @@ func (rc *RedeemCodeApi) Redeem(context *gin.Context) {
r.OkWithMessage("兑换成功", context)
}
// ExportCDK 导出Excel
func (rc *RedeemCodeApi) ExportCDK(ctx *gin.Context) {
var p request.ExportCDK
if err := ctx.ShouldBind(&p); err != nil {
r.FailWithMessage("导出Excel失败"+err.Error(), ctx)
global.GVA_LOG.Error("导出Excel失败", zap.Error(err))
return
}
f, err := redeemCodeService.ExportCDK(p)
if err != nil {
r.FailWithMessage("导出Excel失败"+err.Error(), ctx)
global.GVA_LOG.Error("导出Excel失败", zap.Error(err))
return
}
// Return the excel file.
ctx.Header("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
filename := fmt.Sprintf("好运助手兑换码%v.xlsx", time.Now().Format("2006-01-02T15:04:05"))
ctx.Header("Content-Disposition", "attachment; filename="+filename)
if err := f.Write(ctx.Writer); err != nil {
r.FailWithMessage("导出Excel失败"+err.Error(), ctx)
return
}
r.OkWithMessage("导出Excel成功", ctx)
}