新增支付配置备份导出功能

This commit is contained in:
yml2213
2026-06-07 14:11:16 +08:00
parent 53eb4acad8
commit 9740ff8799
11 changed files with 161 additions and 14 deletions
@@ -153,6 +153,45 @@ func (r *Repository) FindByProviderMerchant(provider string, merchantID string,
return &dto, nil
}
// ExportBackup 导出所有支付配置备份,包含解密后的密钥。
func (r *Repository) ExportBackup(actorID uint64, meta AuditMeta) (*ExportBackup, error) {
var backup *ExportBackup
err := r.db.Transaction(func(tx *gorm.DB) error {
var items []model.PaymentMerchantConfig
if err := tx.Order("is_default DESC, id DESC").Find(&items).Error; err != nil {
return err
}
configs := make([]ConfigDTO, 0, len(items))
for _, item := range items {
dto, err := r.toDTO(item, true)
if err != nil {
return err
}
configs = append(configs, dto)
}
exportedAt := time.Now().Format(time.RFC3339)
backup = &ExportBackup{
Type: "payment_config_backup",
Version: 1,
ExportedAt: exportedAt,
ExportedBy: actorID,
Total: len(configs),
Configs: configs,
}
return appendAuditLog(tx, actorID, "payment_config.export", 0, meta, map[string]any{
"total": len(configs),
"exported_at": exportedAt,
})
})
if err != nil {
return nil, err
}
return backup, nil
}
// FindActiveByProvider 查询提供商的所有激活配置
func (r *Repository) FindActiveByProvider(provider string) ([]model.PaymentMerchantConfig, error) {
var items []model.PaymentMerchantConfig