shanshanzhong 40a45199a5
All checks were successful
Build docker and publish / build (20.15.1) (push) Successful in 6m52s
feat(apple支付): 添加按平台查询支付方式和恢复交易逻辑优化
添加FindListByPlatform方法用于按平台查询支付方式
优化apple支付恢复交易逻辑,支持直接使用交易ID查询
添加API配置处理逻辑和错误回退机制
2025-12-16 18:58:55 -08:00

79 lines
2.5 KiB
Go

package payment
import (
"context"
"github.com/redis/go-redis/v9"
"gorm.io/gorm"
)
type customPaymentLogicModel interface {
FindOneByPaymentToken(ctx context.Context, token string) (*Payment, error)
FindAll(ctx context.Context) ([]*Payment, error)
FindListByPage(ctx context.Context, page, size int, req *Filter) (int64, []*Payment, error)
FindAvailableMethods(ctx context.Context) ([]*Payment, error)
FindListByPlatform(ctx context.Context, platform string) ([]*Payment, error)
}
// NewModel returns a model for the database table.
func NewModel(conn *gorm.DB, c *redis.Client) Model {
return &customPaymentModel{
defaultPaymentModel: newPaymentModel(conn, c),
}
}
func (m *customPaymentModel) FindListByPlatform(ctx context.Context, platform string) ([]*Payment, error) {
var resp []*Payment
err := m.QueryNoCacheCtx(ctx, &resp, func(conn *gorm.DB, v interface{}) error {
return conn.Model(&Payment{}).Where("platform = ?", platform).Find(v).Error
})
return resp, err
}
func (m *customPaymentModel) FindOneByPaymentToken(ctx context.Context, token string) (*Payment, error) {
var resp *Payment
key := cachePaymentTokenPrefix + token
err := m.QueryCtx(ctx, &resp, key, func(conn *gorm.DB, v interface{}) error {
return conn.Model(&Payment{}).Where("token = ?", token).First(v).Error
})
return resp, err
}
func (m *customPaymentModel) FindAll(ctx context.Context) ([]*Payment, error) {
var resp []*Payment
err := m.QueryNoCacheCtx(ctx, &resp, func(conn *gorm.DB, v interface{}) error {
return conn.Model(&Payment{}).Find(v).Error
})
return resp, err
}
func (m *customPaymentModel) FindAvailableMethods(ctx context.Context) ([]*Payment, error) {
var resp []*Payment
err := m.QueryNoCacheCtx(ctx, &resp, func(conn *gorm.DB, v interface{}) error {
return conn.Model(&Payment{}).Where("enable = ?", true).Find(v).Error
})
return resp, err
}
func (m *customPaymentModel) FindListByPage(ctx context.Context, page, size int, req *Filter) (int64, []*Payment, error) {
var resp []*Payment
var total int64
err := m.QueryNoCacheCtx(ctx, &resp, func(conn *gorm.DB, v interface{}) error {
conn = conn.Model(&Payment{})
if req != nil {
if req.Enable != nil {
conn = conn.Where("`enable` = ?", *req.Enable)
}
if req.Mark != "" {
conn = conn.Where("`mark` = ?", req.Mark)
}
if req.Search != "" {
conn = conn.Where("`name` LIKE ?", "%"+req.Search+"%")
}
}
return conn.Count(&total).Offset((page - 1) * size).Limit(size).Find(v).Error
})
return total, resp, err
}