Files
lckt-server/source/system/pay_config.go

98 lines
2.6 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package system
import (
"context"
sysModel "git.echol.cn/loser/lckt/model/system"
"git.echol.cn/loser/lckt/service/system"
"gorm.io/gorm"
)
type initPayConfig struct{}
const initOrderPayConfig = system.InitOrderSystem + 1
// auto run
func init() {
system.RegisterInit(initOrderPayConfig, &initPayConfig{})
}
func (i *initPayConfig) InitializerName() string {
return sysModel.PayConfig{}.TableName()
}
func (i *initPayConfig) MigrateTable(ctx context.Context) (context.Context, error) {
db, ok := ctx.Value("db").(*gorm.DB)
if !ok {
return ctx, system.ErrMissingDBContext
}
return ctx, db.AutoMigrate(&sysModel.PayConfig{})
}
func (i *initPayConfig) TableCreated(ctx context.Context) bool {
db, ok := ctx.Value("db").(*gorm.DB)
if !ok {
return false
}
return db.Migrator().HasTable(&sysModel.PayConfig{})
}
func (i *initPayConfig) InitializeData(ctx context.Context) (context.Context, error) {
db, ok := ctx.Value("db").(*gorm.DB)
if !ok {
return ctx, system.ErrMissingDBContext
}
entities := []sysModel.PayConfig{
{
Name: "微信支付-默认",
Code: "wechat_default",
Type: "wechat",
Enable: false,
Sort: 1,
Remark: "默认微信支付配置,请在后台修改密钥等信息",
// 微信支付配置(需要在后台管理界面修改)
WechatAppID: "wx3d21df18d7f8f9fc",
WechatMchID: "1646874753",
WechatMchApiV3Key: "1a3sd8561d5179Df152D4789aD38wG9s",
WechatPrivateKey: "", // 需要填写
WechatSerialNo: "59A891FB403EC7A1CF2090DB9C8EC704BD43B101",
WechatNotifyURL: "http://lckt.hnlc5588.cn/app_order/notify",
},
{
Name: "神奇支付-默认",
Code: "shenqi_default",
Type: "shenqi",
Enable: false,
Sort: 2,
Remark: "默认神奇支付配置请在后台修改商户ID和密钥",
// 神奇支付配置(需要在后台管理界面修改)
ShenqiPID: 1001,
ShenqiPrivateKey: "", // 需要填写商户私钥
ShenqiPlatformPubKey: "", // 需要填写平台公钥
ShenqiNotifyURL: "http://lckt.hnlc5588.cn/app_order/shenqi/notify/shenqi_default",
ShenqiReturnURL: "http://lckt.hnlc5588.cn/pay/success",
ShenqiBaseURL: "https://www.shenqiyzf.cn",
},
}
if err := db.Create(&entities).Error; err != nil {
return ctx, err
}
return ctx, nil
}
func (i *initPayConfig) DataInserted(ctx context.Context) bool {
db, ok := ctx.Value("db").(*gorm.DB)
if !ok {
return false
}
var count int64
if err := db.Model(&sysModel.PayConfig{}).
Where("code IN (?)", []string{"wechat_default", "shenqi_default"}).
Count(&count).Error; err != nil {
return false
}
return count >= 2
}