package model import ( "context" "git.noahlan.cn/northlan/ntools-go/gorm-zero/gormx" "gorm.io/gorm" ) var _ GiftModel = (*customGiftModel)(nil) type ( // GiftModel is an interface to be customized, add more methods here, // and implement the added methods in customGiftModel. GiftModel interface { giftModel FindByPlatformGift(ctx context.Context, platform string, giftId string) (*Gift, error) } customGiftModel struct { *defaultGiftModel } ) // NewGiftModel returns a model for the database table. func NewGiftModel(conn *gorm.DB) GiftModel { return &customGiftModel{ defaultGiftModel: newGiftModel(conn), } } func (m *customGiftModel) FindByPlatformGift(ctx context.Context, platform string, giftId string) (*Gift, error) { var resp Gift db := m.DB.WithContext(ctx) err := db.Model(&Gift{}). Where("platform = ? AND gift_id = ?", platform, giftId). Take(&resp).Error err = gormx.WrapSelectErr(err) if err != nil { return nil, err } return &resp, nil }