feat: 为订单表添加 app_account_token 字段并增强 Apple IAP 对账逻辑,支持通过交易历史记录查找。
Build docker and publish / build (20.15.1) (push) Successful in 7m25s
Build docker and publish / build (20.15.1) (push) Successful in 7m25s
This commit is contained in:
@@ -15,6 +15,7 @@ type Model interface {
|
||||
Insert(ctx context.Context, data *Transaction, tx ...*gorm.DB) error
|
||||
FindByOriginalId(ctx context.Context, originalId string) (*Transaction, error)
|
||||
FindByUserAndProduct(ctx context.Context, userId int64, productId string) (*Transaction, error)
|
||||
FindLatestByUserId(ctx context.Context, userId int64) (*Transaction, error)
|
||||
}
|
||||
|
||||
type defaultModel struct {
|
||||
@@ -66,3 +67,13 @@ func (m *customModel) FindByUserAndProduct(ctx context.Context, userId int64, pr
|
||||
return &data, err
|
||||
}
|
||||
|
||||
// FindLatestByUserId 查找指定用户最近的一条交易记录
|
||||
// 用于获取已知的 originalTransactionId,以便查询 Apple 交易历史
|
||||
func (m *customModel) FindLatestByUserId(ctx context.Context, userId int64) (*Transaction, error) {
|
||||
var data Transaction
|
||||
err := m.QueryNoCacheCtx(ctx, &data, func(conn *gorm.DB, v interface{}) error {
|
||||
return conn.Model(&Transaction{}).Where("user_id = ?", userId).Order("purchase_at DESC").First(&data).Error
|
||||
})
|
||||
return &data, err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user