44 lines
1.2 KiB
Go
44 lines
1.2 KiB
Go
package repository
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
"gorm.io/gorm"
|
|
"pay-bridge/internal/model"
|
|
)
|
|
|
|
// WechatRepository 微信通知数据访问
|
|
type WechatRepository struct {
|
|
db *gorm.DB
|
|
}
|
|
|
|
func NewWechatRepository(db *gorm.DB) *WechatRepository {
|
|
return &WechatRepository{db: db}
|
|
}
|
|
|
|
// GetBinding 查询应用微信绑定配置
|
|
func (r *WechatRepository) GetBinding(ctx context.Context, appID string) (*model.WechatBinding, error) {
|
|
var b model.WechatBinding
|
|
err := r.db.WithContext(ctx).Where("app_id = ? AND status = 1", appID).First(&b).Error
|
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
return nil, nil
|
|
}
|
|
return &b, err
|
|
}
|
|
|
|
// UpsertBinding 创建或更新绑定
|
|
func (r *WechatRepository) UpsertBinding(ctx context.Context, b *model.WechatBinding) error {
|
|
return r.db.WithContext(ctx).Save(b).Error
|
|
}
|
|
|
|
// CreateMessageLog 记录消息发送日志
|
|
func (r *WechatRepository) CreateMessageLog(ctx context.Context, log *model.WechatMessageLog) error {
|
|
return r.db.WithContext(ctx).Create(log).Error
|
|
}
|
|
|
|
// UpdateMessageLog 更新消息日志状态
|
|
func (r *WechatRepository) UpdateMessageLog(ctx context.Context, id uint64, updates map[string]any) error {
|
|
return r.db.WithContext(ctx).Model(&model.WechatMessageLog{}).Where("id = ?", id).Updates(updates).Error
|
|
}
|