新增支付配置备份导出功能
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
package paymentconfig
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"hfb_sys/backend/internal/middleware"
|
||||
"hfb_sys/backend/pkg/response"
|
||||
@@ -73,6 +75,40 @@ func (h *Handler) Get(c *gin.Context) {
|
||||
response.OK(c, config)
|
||||
}
|
||||
|
||||
// ExportBackup 导出支付配置备份
|
||||
// @Summary 导出支付配置备份
|
||||
// @Tags 管理后台-支付配置
|
||||
// @Success 200 {file} file "支付配置备份 JSON"
|
||||
// @Router /admin/payment-configs/export [get]
|
||||
func (h *Handler) ExportBackup(c *gin.Context) {
|
||||
adminID, ok := currentAdminID(c)
|
||||
if !ok {
|
||||
response.Unauthorized(c, "未授权")
|
||||
return
|
||||
}
|
||||
|
||||
backup, err := h.service.ExportBackup(adminID, auditMeta(c))
|
||||
if err == ErrDecryptionFailed {
|
||||
response.Error(c, http.StatusInternalServerError, "decrypt_failed", "密钥解密失败")
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
response.Error(c, http.StatusInternalServerError, "internal_error", "导出失败")
|
||||
return
|
||||
}
|
||||
|
||||
data, err := json.MarshalIndent(backup, "", " ")
|
||||
if err != nil {
|
||||
response.Error(c, http.StatusInternalServerError, "internal_error", "导出失败")
|
||||
return
|
||||
}
|
||||
|
||||
filename := "payment-config-backup-" + time.Now().Format("20060102-150405") + ".json"
|
||||
contentType := "application/json; charset=utf-8"
|
||||
c.Header("Content-Disposition", `attachment; filename="`+filename+`"`)
|
||||
c.Data(http.StatusOK, contentType, data)
|
||||
}
|
||||
|
||||
// Create 创建支付配置
|
||||
// @Summary 创建支付配置
|
||||
// @Tags 管理后台-支付配置
|
||||
|
||||
Reference in New Issue
Block a user