优化结构
This commit is contained in:
@@ -1,31 +1,31 @@
|
||||
package payment
|
||||
|
||||
import (
|
||||
"kra/internal/data/system"
|
||||
"kra/internal/adminsurface"
|
||||
"kra/internal/data/migration"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// Migrate creates the persistence owned by the payment module.
|
||||
func Migrate(db *gorm.DB) error {
|
||||
return db.AutoMigrate(&integrationConfigPO{}, &paymentOrderPO{})
|
||||
}
|
||||
|
||||
// Reconcile seeds disabled configuration rows for all built-in providers.
|
||||
func Reconcile(db *gorm.DB) error {
|
||||
return ensurePaymentIntegrationConfigs(db)
|
||||
func Migrations() []migration.Step {
|
||||
return []migration.Step{
|
||||
{ID: "202608200003_payment_schema", Migrate: func(db *gorm.DB) error {
|
||||
return db.AutoMigrate(&paymentOrderPO{})
|
||||
}},
|
||||
{ID: "202608200004_payment_defaults", Migrate: ensurePaymentIntegrationConfigs},
|
||||
}
|
||||
}
|
||||
|
||||
// AdminSurface describes the payment-owned entries shown in the system
|
||||
// administration UI. The system module persists these records because it owns
|
||||
// the menu/API/policy tables.
|
||||
func AdminSurface() system.AdminSurface {
|
||||
return system.AdminSurface{
|
||||
Menus: []system.AdminMenu{
|
||||
func AdminSurface() adminsurface.Surface {
|
||||
return adminsurface.Surface{
|
||||
Menus: []adminsurface.Menu{
|
||||
{Name: "paymentOrders", Path: "paymentOrders", ParentName: "extensions", Component: "view/systemTools/payment/orders.vue", Title: "支付订单", Icon: "wallet", Sort: 6},
|
||||
{Name: "paymentConfig", Path: "paymentConfig", ParentName: "extensions", Component: "view/systemTools/payment/config.vue", Title: "支付配置", Icon: "credit-card", Sort: 7},
|
||||
},
|
||||
APIs: []system.AdminAPI{
|
||||
APIs: []adminsurface.API{
|
||||
{Path: "/payment/configs", Method: "GET", APIGroup: "支付", Description: "获取支付渠道配置"},
|
||||
{Path: "/payment/config", Method: "POST", APIGroup: "支付", Description: "保存支付渠道配置"},
|
||||
{Path: "/payment/orders", Method: "GET", APIGroup: "支付", Description: "分页查询支付订单"},
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package payment
|
||||
|
||||
import "kra/pkg/paymentkit"
|
||||
import "kra/internal/utils/paymentutil"
|
||||
|
||||
func text(values map[string]any, key string) string {
|
||||
value, _ := values[key].(string)
|
||||
@@ -17,7 +17,7 @@ func firstAny(values map[string]any, keys ...string) string {
|
||||
}
|
||||
|
||||
// configuredInt64 keeps repository-side validation independent from the
|
||||
// provider adapter package while sharing the canonical paymentkit parser.
|
||||
// provider adapter package while sharing the canonical payment parser.
|
||||
func configuredInt64(values map[string]any, key string, fallback int64) int64 {
|
||||
return paymentkit.ConfiguredInt64(values, key, fallback)
|
||||
return paymentutil.ConfiguredInt64(values, key, fallback)
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"kra/internal/biz"
|
||||
"kra/pkg/pagination"
|
||||
"kra/internal/data/pagination"
|
||||
)
|
||||
|
||||
type paymentOrderPO struct {
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
|
||||
"github.com/glebarez/sqlite"
|
||||
"gorm.io/gorm"
|
||||
"kra/internal/biz"
|
||||
)
|
||||
|
||||
type Data struct{ gormDB *reloadableDB }
|
||||
@@ -49,19 +48,13 @@ func openIntegrationConfigTestDB(t *testing.T) *gorm.DB {
|
||||
}
|
||||
|
||||
func migrateAll(db *gorm.DB) error {
|
||||
if err := db.AutoMigrate(&integrationConfigPO{}, &paymentOrderPO{}); err != nil {
|
||||
if err := db.AutoMigrate(&integrationConfigPO{}); err != nil {
|
||||
return err
|
||||
}
|
||||
for _, provider := range biz.SupportedPaymentProviders {
|
||||
var count int64
|
||||
if err := db.Model(&integrationConfigPO{}).Where("kind = ? AND provider = ?", integrationKindPayment, provider).Count(&count).Error; err != nil {
|
||||
for _, step := range Migrations() {
|
||||
if err := step.Migrate(db); err != nil {
|
||||
return err
|
||||
}
|
||||
if count == 0 {
|
||||
if err := db.Create(&integrationConfigPO{Kind: integrationKindPayment, Provider: provider, Config: "{}"}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user