package model import ( "context" "git.noahlan.cn/northlan/ntools-go/gorm-zero/gormx" "gorm.io/gorm" ) var _ UserGiftPackModel = (*customUserGiftPackModel)(nil) type ( // UserGiftPackModel is an interface to be customized, add more methods here, // and implement the added methods in customUserGiftPackModel. UserGiftPackModel interface { userGiftPackModel // FindOneByUserPack 获取用户领取的礼包 FindOneByUserPack(ctx context.Context, tx *gorm.DB, userId int64, packType string) (*UserGiftPack, error) // AddDrawCount 新增领取次数 AddDrawCount(ctx context.Context, tx *gorm.DB, userId int64, packType string) error } PackContent struct { Integral int64 `json:"integral"` // 奖励积分数量 Title []string `json:"title,optional"` // 称号列表 } customUserGiftPackModel struct { *defaultUserGiftPackModel } ) // NewUserGiftPackModel returns a model for the database table. func NewUserGiftPackModel(conn *gorm.DB) UserGiftPackModel { return &customUserGiftPackModel{ defaultUserGiftPackModel: newUserGiftPackModel(conn), } } func (m *customUserGiftPackModel) FindOneByUserPack(ctx context.Context, tx *gorm.DB, userId int64, packType string) (*UserGiftPack, error) { var resp UserGiftPack err := withTx(ctx, m.conn, tx).Model(&UserGiftPack{}). Where("user_id = ? AND pack_type = ?", userId, packType).Take(&resp).Error switch err { case nil: return &resp, nil case gormx.ErrNotFound: return nil, ErrNotFound default: return nil, err } }