feat: 实现注册优惠码功能

- 支持创建/编辑/删除优惠码,设置赠送金额和使用限制
  - 注册页面实时验证优惠码并显示赠送金额
  - 支持 URL 参数自动填充 (?promo=CODE)
  - 添加优惠码验证接口速率限制
  - 使用数据库行锁防止并发超限
  - 新增后台优惠码管理页面,支持复制注册链接
This commit is contained in:
long
2026-01-10 13:14:35 +08:00
parent 7d1fe818be
commit d2fc14fb97
79 changed files with 17045 additions and 54 deletions

View File

@@ -0,0 +1,165 @@
// Code generated by ent, DO NOT EDIT.
package promocode
import (
"time"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
)
const (
// Label holds the string label denoting the promocode type in the database.
Label = "promo_code"
// FieldID holds the string denoting the id field in the database.
FieldID = "id"
// FieldCode holds the string denoting the code field in the database.
FieldCode = "code"
// FieldBonusAmount holds the string denoting the bonus_amount field in the database.
FieldBonusAmount = "bonus_amount"
// FieldMaxUses holds the string denoting the max_uses field in the database.
FieldMaxUses = "max_uses"
// FieldUsedCount holds the string denoting the used_count field in the database.
FieldUsedCount = "used_count"
// FieldStatus holds the string denoting the status field in the database.
FieldStatus = "status"
// FieldExpiresAt holds the string denoting the expires_at field in the database.
FieldExpiresAt = "expires_at"
// FieldNotes holds the string denoting the notes field in the database.
FieldNotes = "notes"
// FieldCreatedAt holds the string denoting the created_at field in the database.
FieldCreatedAt = "created_at"
// FieldUpdatedAt holds the string denoting the updated_at field in the database.
FieldUpdatedAt = "updated_at"
// EdgeUsageRecords holds the string denoting the usage_records edge name in mutations.
EdgeUsageRecords = "usage_records"
// Table holds the table name of the promocode in the database.
Table = "promo_codes"
// UsageRecordsTable is the table that holds the usage_records relation/edge.
UsageRecordsTable = "promo_code_usages"
// UsageRecordsInverseTable is the table name for the PromoCodeUsage entity.
// It exists in this package in order to avoid circular dependency with the "promocodeusage" package.
UsageRecordsInverseTable = "promo_code_usages"
// UsageRecordsColumn is the table column denoting the usage_records relation/edge.
UsageRecordsColumn = "promo_code_id"
)
// Columns holds all SQL columns for promocode fields.
var Columns = []string{
FieldID,
FieldCode,
FieldBonusAmount,
FieldMaxUses,
FieldUsedCount,
FieldStatus,
FieldExpiresAt,
FieldNotes,
FieldCreatedAt,
FieldUpdatedAt,
}
// ValidColumn reports if the column name is valid (part of the table columns).
func ValidColumn(column string) bool {
for i := range Columns {
if column == Columns[i] {
return true
}
}
return false
}
var (
// CodeValidator is a validator for the "code" field. It is called by the builders before save.
CodeValidator func(string) error
// DefaultBonusAmount holds the default value on creation for the "bonus_amount" field.
DefaultBonusAmount float64
// DefaultMaxUses holds the default value on creation for the "max_uses" field.
DefaultMaxUses int
// DefaultUsedCount holds the default value on creation for the "used_count" field.
DefaultUsedCount int
// DefaultStatus holds the default value on creation for the "status" field.
DefaultStatus string
// StatusValidator is a validator for the "status" field. It is called by the builders before save.
StatusValidator func(string) error
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
DefaultCreatedAt func() time.Time
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
DefaultUpdatedAt func() time.Time
// UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field.
UpdateDefaultUpdatedAt func() time.Time
)
// OrderOption defines the ordering options for the PromoCode queries.
type OrderOption func(*sql.Selector)
// ByID orders the results by the id field.
func ByID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldID, opts...).ToFunc()
}
// ByCode orders the results by the code field.
func ByCode(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldCode, opts...).ToFunc()
}
// ByBonusAmount orders the results by the bonus_amount field.
func ByBonusAmount(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldBonusAmount, opts...).ToFunc()
}
// ByMaxUses orders the results by the max_uses field.
func ByMaxUses(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldMaxUses, opts...).ToFunc()
}
// ByUsedCount orders the results by the used_count field.
func ByUsedCount(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldUsedCount, opts...).ToFunc()
}
// ByStatus orders the results by the status field.
func ByStatus(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldStatus, opts...).ToFunc()
}
// ByExpiresAt orders the results by the expires_at field.
func ByExpiresAt(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldExpiresAt, opts...).ToFunc()
}
// ByNotes orders the results by the notes field.
func ByNotes(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldNotes, opts...).ToFunc()
}
// ByCreatedAt orders the results by the created_at field.
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
}
// ByUpdatedAt orders the results by the updated_at field.
func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc()
}
// ByUsageRecordsCount orders the results by usage_records count.
func ByUsageRecordsCount(opts ...sql.OrderTermOption) OrderOption {
return func(s *sql.Selector) {
sqlgraph.OrderByNeighborsCount(s, newUsageRecordsStep(), opts...)
}
}
// ByUsageRecords orders the results by usage_records terms.
func ByUsageRecords(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
return func(s *sql.Selector) {
sqlgraph.OrderByNeighborTerms(s, newUsageRecordsStep(), append([]sql.OrderTerm{term}, terms...)...)
}
}
func newUsageRecordsStep() *sqlgraph.Step {
return sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.To(UsageRecordsInverseTable, FieldID),
sqlgraph.Edge(sqlgraph.O2M, false, UsageRecordsTable, UsageRecordsColumn),
)
}

View File

@@ -0,0 +1,594 @@
// Code generated by ent, DO NOT EDIT.
package promocode
import (
"time"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"github.com/Wei-Shaw/sub2api/ent/predicate"
)
// ID filters vertices based on their ID field.
func ID(id int64) predicate.PromoCode {
return predicate.PromoCode(sql.FieldEQ(FieldID, id))
}
// IDEQ applies the EQ predicate on the ID field.
func IDEQ(id int64) predicate.PromoCode {
return predicate.PromoCode(sql.FieldEQ(FieldID, id))
}
// IDNEQ applies the NEQ predicate on the ID field.
func IDNEQ(id int64) predicate.PromoCode {
return predicate.PromoCode(sql.FieldNEQ(FieldID, id))
}
// IDIn applies the In predicate on the ID field.
func IDIn(ids ...int64) predicate.PromoCode {
return predicate.PromoCode(sql.FieldIn(FieldID, ids...))
}
// IDNotIn applies the NotIn predicate on the ID field.
func IDNotIn(ids ...int64) predicate.PromoCode {
return predicate.PromoCode(sql.FieldNotIn(FieldID, ids...))
}
// IDGT applies the GT predicate on the ID field.
func IDGT(id int64) predicate.PromoCode {
return predicate.PromoCode(sql.FieldGT(FieldID, id))
}
// IDGTE applies the GTE predicate on the ID field.
func IDGTE(id int64) predicate.PromoCode {
return predicate.PromoCode(sql.FieldGTE(FieldID, id))
}
// IDLT applies the LT predicate on the ID field.
func IDLT(id int64) predicate.PromoCode {
return predicate.PromoCode(sql.FieldLT(FieldID, id))
}
// IDLTE applies the LTE predicate on the ID field.
func IDLTE(id int64) predicate.PromoCode {
return predicate.PromoCode(sql.FieldLTE(FieldID, id))
}
// Code applies equality check predicate on the "code" field. It's identical to CodeEQ.
func Code(v string) predicate.PromoCode {
return predicate.PromoCode(sql.FieldEQ(FieldCode, v))
}
// BonusAmount applies equality check predicate on the "bonus_amount" field. It's identical to BonusAmountEQ.
func BonusAmount(v float64) predicate.PromoCode {
return predicate.PromoCode(sql.FieldEQ(FieldBonusAmount, v))
}
// MaxUses applies equality check predicate on the "max_uses" field. It's identical to MaxUsesEQ.
func MaxUses(v int) predicate.PromoCode {
return predicate.PromoCode(sql.FieldEQ(FieldMaxUses, v))
}
// UsedCount applies equality check predicate on the "used_count" field. It's identical to UsedCountEQ.
func UsedCount(v int) predicate.PromoCode {
return predicate.PromoCode(sql.FieldEQ(FieldUsedCount, v))
}
// Status applies equality check predicate on the "status" field. It's identical to StatusEQ.
func Status(v string) predicate.PromoCode {
return predicate.PromoCode(sql.FieldEQ(FieldStatus, v))
}
// ExpiresAt applies equality check predicate on the "expires_at" field. It's identical to ExpiresAtEQ.
func ExpiresAt(v time.Time) predicate.PromoCode {
return predicate.PromoCode(sql.FieldEQ(FieldExpiresAt, v))
}
// Notes applies equality check predicate on the "notes" field. It's identical to NotesEQ.
func Notes(v string) predicate.PromoCode {
return predicate.PromoCode(sql.FieldEQ(FieldNotes, v))
}
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
func CreatedAt(v time.Time) predicate.PromoCode {
return predicate.PromoCode(sql.FieldEQ(FieldCreatedAt, v))
}
// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ.
func UpdatedAt(v time.Time) predicate.PromoCode {
return predicate.PromoCode(sql.FieldEQ(FieldUpdatedAt, v))
}
// CodeEQ applies the EQ predicate on the "code" field.
func CodeEQ(v string) predicate.PromoCode {
return predicate.PromoCode(sql.FieldEQ(FieldCode, v))
}
// CodeNEQ applies the NEQ predicate on the "code" field.
func CodeNEQ(v string) predicate.PromoCode {
return predicate.PromoCode(sql.FieldNEQ(FieldCode, v))
}
// CodeIn applies the In predicate on the "code" field.
func CodeIn(vs ...string) predicate.PromoCode {
return predicate.PromoCode(sql.FieldIn(FieldCode, vs...))
}
// CodeNotIn applies the NotIn predicate on the "code" field.
func CodeNotIn(vs ...string) predicate.PromoCode {
return predicate.PromoCode(sql.FieldNotIn(FieldCode, vs...))
}
// CodeGT applies the GT predicate on the "code" field.
func CodeGT(v string) predicate.PromoCode {
return predicate.PromoCode(sql.FieldGT(FieldCode, v))
}
// CodeGTE applies the GTE predicate on the "code" field.
func CodeGTE(v string) predicate.PromoCode {
return predicate.PromoCode(sql.FieldGTE(FieldCode, v))
}
// CodeLT applies the LT predicate on the "code" field.
func CodeLT(v string) predicate.PromoCode {
return predicate.PromoCode(sql.FieldLT(FieldCode, v))
}
// CodeLTE applies the LTE predicate on the "code" field.
func CodeLTE(v string) predicate.PromoCode {
return predicate.PromoCode(sql.FieldLTE(FieldCode, v))
}
// CodeContains applies the Contains predicate on the "code" field.
func CodeContains(v string) predicate.PromoCode {
return predicate.PromoCode(sql.FieldContains(FieldCode, v))
}
// CodeHasPrefix applies the HasPrefix predicate on the "code" field.
func CodeHasPrefix(v string) predicate.PromoCode {
return predicate.PromoCode(sql.FieldHasPrefix(FieldCode, v))
}
// CodeHasSuffix applies the HasSuffix predicate on the "code" field.
func CodeHasSuffix(v string) predicate.PromoCode {
return predicate.PromoCode(sql.FieldHasSuffix(FieldCode, v))
}
// CodeEqualFold applies the EqualFold predicate on the "code" field.
func CodeEqualFold(v string) predicate.PromoCode {
return predicate.PromoCode(sql.FieldEqualFold(FieldCode, v))
}
// CodeContainsFold applies the ContainsFold predicate on the "code" field.
func CodeContainsFold(v string) predicate.PromoCode {
return predicate.PromoCode(sql.FieldContainsFold(FieldCode, v))
}
// BonusAmountEQ applies the EQ predicate on the "bonus_amount" field.
func BonusAmountEQ(v float64) predicate.PromoCode {
return predicate.PromoCode(sql.FieldEQ(FieldBonusAmount, v))
}
// BonusAmountNEQ applies the NEQ predicate on the "bonus_amount" field.
func BonusAmountNEQ(v float64) predicate.PromoCode {
return predicate.PromoCode(sql.FieldNEQ(FieldBonusAmount, v))
}
// BonusAmountIn applies the In predicate on the "bonus_amount" field.
func BonusAmountIn(vs ...float64) predicate.PromoCode {
return predicate.PromoCode(sql.FieldIn(FieldBonusAmount, vs...))
}
// BonusAmountNotIn applies the NotIn predicate on the "bonus_amount" field.
func BonusAmountNotIn(vs ...float64) predicate.PromoCode {
return predicate.PromoCode(sql.FieldNotIn(FieldBonusAmount, vs...))
}
// BonusAmountGT applies the GT predicate on the "bonus_amount" field.
func BonusAmountGT(v float64) predicate.PromoCode {
return predicate.PromoCode(sql.FieldGT(FieldBonusAmount, v))
}
// BonusAmountGTE applies the GTE predicate on the "bonus_amount" field.
func BonusAmountGTE(v float64) predicate.PromoCode {
return predicate.PromoCode(sql.FieldGTE(FieldBonusAmount, v))
}
// BonusAmountLT applies the LT predicate on the "bonus_amount" field.
func BonusAmountLT(v float64) predicate.PromoCode {
return predicate.PromoCode(sql.FieldLT(FieldBonusAmount, v))
}
// BonusAmountLTE applies the LTE predicate on the "bonus_amount" field.
func BonusAmountLTE(v float64) predicate.PromoCode {
return predicate.PromoCode(sql.FieldLTE(FieldBonusAmount, v))
}
// MaxUsesEQ applies the EQ predicate on the "max_uses" field.
func MaxUsesEQ(v int) predicate.PromoCode {
return predicate.PromoCode(sql.FieldEQ(FieldMaxUses, v))
}
// MaxUsesNEQ applies the NEQ predicate on the "max_uses" field.
func MaxUsesNEQ(v int) predicate.PromoCode {
return predicate.PromoCode(sql.FieldNEQ(FieldMaxUses, v))
}
// MaxUsesIn applies the In predicate on the "max_uses" field.
func MaxUsesIn(vs ...int) predicate.PromoCode {
return predicate.PromoCode(sql.FieldIn(FieldMaxUses, vs...))
}
// MaxUsesNotIn applies the NotIn predicate on the "max_uses" field.
func MaxUsesNotIn(vs ...int) predicate.PromoCode {
return predicate.PromoCode(sql.FieldNotIn(FieldMaxUses, vs...))
}
// MaxUsesGT applies the GT predicate on the "max_uses" field.
func MaxUsesGT(v int) predicate.PromoCode {
return predicate.PromoCode(sql.FieldGT(FieldMaxUses, v))
}
// MaxUsesGTE applies the GTE predicate on the "max_uses" field.
func MaxUsesGTE(v int) predicate.PromoCode {
return predicate.PromoCode(sql.FieldGTE(FieldMaxUses, v))
}
// MaxUsesLT applies the LT predicate on the "max_uses" field.
func MaxUsesLT(v int) predicate.PromoCode {
return predicate.PromoCode(sql.FieldLT(FieldMaxUses, v))
}
// MaxUsesLTE applies the LTE predicate on the "max_uses" field.
func MaxUsesLTE(v int) predicate.PromoCode {
return predicate.PromoCode(sql.FieldLTE(FieldMaxUses, v))
}
// UsedCountEQ applies the EQ predicate on the "used_count" field.
func UsedCountEQ(v int) predicate.PromoCode {
return predicate.PromoCode(sql.FieldEQ(FieldUsedCount, v))
}
// UsedCountNEQ applies the NEQ predicate on the "used_count" field.
func UsedCountNEQ(v int) predicate.PromoCode {
return predicate.PromoCode(sql.FieldNEQ(FieldUsedCount, v))
}
// UsedCountIn applies the In predicate on the "used_count" field.
func UsedCountIn(vs ...int) predicate.PromoCode {
return predicate.PromoCode(sql.FieldIn(FieldUsedCount, vs...))
}
// UsedCountNotIn applies the NotIn predicate on the "used_count" field.
func UsedCountNotIn(vs ...int) predicate.PromoCode {
return predicate.PromoCode(sql.FieldNotIn(FieldUsedCount, vs...))
}
// UsedCountGT applies the GT predicate on the "used_count" field.
func UsedCountGT(v int) predicate.PromoCode {
return predicate.PromoCode(sql.FieldGT(FieldUsedCount, v))
}
// UsedCountGTE applies the GTE predicate on the "used_count" field.
func UsedCountGTE(v int) predicate.PromoCode {
return predicate.PromoCode(sql.FieldGTE(FieldUsedCount, v))
}
// UsedCountLT applies the LT predicate on the "used_count" field.
func UsedCountLT(v int) predicate.PromoCode {
return predicate.PromoCode(sql.FieldLT(FieldUsedCount, v))
}
// UsedCountLTE applies the LTE predicate on the "used_count" field.
func UsedCountLTE(v int) predicate.PromoCode {
return predicate.PromoCode(sql.FieldLTE(FieldUsedCount, v))
}
// StatusEQ applies the EQ predicate on the "status" field.
func StatusEQ(v string) predicate.PromoCode {
return predicate.PromoCode(sql.FieldEQ(FieldStatus, v))
}
// StatusNEQ applies the NEQ predicate on the "status" field.
func StatusNEQ(v string) predicate.PromoCode {
return predicate.PromoCode(sql.FieldNEQ(FieldStatus, v))
}
// StatusIn applies the In predicate on the "status" field.
func StatusIn(vs ...string) predicate.PromoCode {
return predicate.PromoCode(sql.FieldIn(FieldStatus, vs...))
}
// StatusNotIn applies the NotIn predicate on the "status" field.
func StatusNotIn(vs ...string) predicate.PromoCode {
return predicate.PromoCode(sql.FieldNotIn(FieldStatus, vs...))
}
// StatusGT applies the GT predicate on the "status" field.
func StatusGT(v string) predicate.PromoCode {
return predicate.PromoCode(sql.FieldGT(FieldStatus, v))
}
// StatusGTE applies the GTE predicate on the "status" field.
func StatusGTE(v string) predicate.PromoCode {
return predicate.PromoCode(sql.FieldGTE(FieldStatus, v))
}
// StatusLT applies the LT predicate on the "status" field.
func StatusLT(v string) predicate.PromoCode {
return predicate.PromoCode(sql.FieldLT(FieldStatus, v))
}
// StatusLTE applies the LTE predicate on the "status" field.
func StatusLTE(v string) predicate.PromoCode {
return predicate.PromoCode(sql.FieldLTE(FieldStatus, v))
}
// StatusContains applies the Contains predicate on the "status" field.
func StatusContains(v string) predicate.PromoCode {
return predicate.PromoCode(sql.FieldContains(FieldStatus, v))
}
// StatusHasPrefix applies the HasPrefix predicate on the "status" field.
func StatusHasPrefix(v string) predicate.PromoCode {
return predicate.PromoCode(sql.FieldHasPrefix(FieldStatus, v))
}
// StatusHasSuffix applies the HasSuffix predicate on the "status" field.
func StatusHasSuffix(v string) predicate.PromoCode {
return predicate.PromoCode(sql.FieldHasSuffix(FieldStatus, v))
}
// StatusEqualFold applies the EqualFold predicate on the "status" field.
func StatusEqualFold(v string) predicate.PromoCode {
return predicate.PromoCode(sql.FieldEqualFold(FieldStatus, v))
}
// StatusContainsFold applies the ContainsFold predicate on the "status" field.
func StatusContainsFold(v string) predicate.PromoCode {
return predicate.PromoCode(sql.FieldContainsFold(FieldStatus, v))
}
// ExpiresAtEQ applies the EQ predicate on the "expires_at" field.
func ExpiresAtEQ(v time.Time) predicate.PromoCode {
return predicate.PromoCode(sql.FieldEQ(FieldExpiresAt, v))
}
// ExpiresAtNEQ applies the NEQ predicate on the "expires_at" field.
func ExpiresAtNEQ(v time.Time) predicate.PromoCode {
return predicate.PromoCode(sql.FieldNEQ(FieldExpiresAt, v))
}
// ExpiresAtIn applies the In predicate on the "expires_at" field.
func ExpiresAtIn(vs ...time.Time) predicate.PromoCode {
return predicate.PromoCode(sql.FieldIn(FieldExpiresAt, vs...))
}
// ExpiresAtNotIn applies the NotIn predicate on the "expires_at" field.
func ExpiresAtNotIn(vs ...time.Time) predicate.PromoCode {
return predicate.PromoCode(sql.FieldNotIn(FieldExpiresAt, vs...))
}
// ExpiresAtGT applies the GT predicate on the "expires_at" field.
func ExpiresAtGT(v time.Time) predicate.PromoCode {
return predicate.PromoCode(sql.FieldGT(FieldExpiresAt, v))
}
// ExpiresAtGTE applies the GTE predicate on the "expires_at" field.
func ExpiresAtGTE(v time.Time) predicate.PromoCode {
return predicate.PromoCode(sql.FieldGTE(FieldExpiresAt, v))
}
// ExpiresAtLT applies the LT predicate on the "expires_at" field.
func ExpiresAtLT(v time.Time) predicate.PromoCode {
return predicate.PromoCode(sql.FieldLT(FieldExpiresAt, v))
}
// ExpiresAtLTE applies the LTE predicate on the "expires_at" field.
func ExpiresAtLTE(v time.Time) predicate.PromoCode {
return predicate.PromoCode(sql.FieldLTE(FieldExpiresAt, v))
}
// ExpiresAtIsNil applies the IsNil predicate on the "expires_at" field.
func ExpiresAtIsNil() predicate.PromoCode {
return predicate.PromoCode(sql.FieldIsNull(FieldExpiresAt))
}
// ExpiresAtNotNil applies the NotNil predicate on the "expires_at" field.
func ExpiresAtNotNil() predicate.PromoCode {
return predicate.PromoCode(sql.FieldNotNull(FieldExpiresAt))
}
// NotesEQ applies the EQ predicate on the "notes" field.
func NotesEQ(v string) predicate.PromoCode {
return predicate.PromoCode(sql.FieldEQ(FieldNotes, v))
}
// NotesNEQ applies the NEQ predicate on the "notes" field.
func NotesNEQ(v string) predicate.PromoCode {
return predicate.PromoCode(sql.FieldNEQ(FieldNotes, v))
}
// NotesIn applies the In predicate on the "notes" field.
func NotesIn(vs ...string) predicate.PromoCode {
return predicate.PromoCode(sql.FieldIn(FieldNotes, vs...))
}
// NotesNotIn applies the NotIn predicate on the "notes" field.
func NotesNotIn(vs ...string) predicate.PromoCode {
return predicate.PromoCode(sql.FieldNotIn(FieldNotes, vs...))
}
// NotesGT applies the GT predicate on the "notes" field.
func NotesGT(v string) predicate.PromoCode {
return predicate.PromoCode(sql.FieldGT(FieldNotes, v))
}
// NotesGTE applies the GTE predicate on the "notes" field.
func NotesGTE(v string) predicate.PromoCode {
return predicate.PromoCode(sql.FieldGTE(FieldNotes, v))
}
// NotesLT applies the LT predicate on the "notes" field.
func NotesLT(v string) predicate.PromoCode {
return predicate.PromoCode(sql.FieldLT(FieldNotes, v))
}
// NotesLTE applies the LTE predicate on the "notes" field.
func NotesLTE(v string) predicate.PromoCode {
return predicate.PromoCode(sql.FieldLTE(FieldNotes, v))
}
// NotesContains applies the Contains predicate on the "notes" field.
func NotesContains(v string) predicate.PromoCode {
return predicate.PromoCode(sql.FieldContains(FieldNotes, v))
}
// NotesHasPrefix applies the HasPrefix predicate on the "notes" field.
func NotesHasPrefix(v string) predicate.PromoCode {
return predicate.PromoCode(sql.FieldHasPrefix(FieldNotes, v))
}
// NotesHasSuffix applies the HasSuffix predicate on the "notes" field.
func NotesHasSuffix(v string) predicate.PromoCode {
return predicate.PromoCode(sql.FieldHasSuffix(FieldNotes, v))
}
// NotesIsNil applies the IsNil predicate on the "notes" field.
func NotesIsNil() predicate.PromoCode {
return predicate.PromoCode(sql.FieldIsNull(FieldNotes))
}
// NotesNotNil applies the NotNil predicate on the "notes" field.
func NotesNotNil() predicate.PromoCode {
return predicate.PromoCode(sql.FieldNotNull(FieldNotes))
}
// NotesEqualFold applies the EqualFold predicate on the "notes" field.
func NotesEqualFold(v string) predicate.PromoCode {
return predicate.PromoCode(sql.FieldEqualFold(FieldNotes, v))
}
// NotesContainsFold applies the ContainsFold predicate on the "notes" field.
func NotesContainsFold(v string) predicate.PromoCode {
return predicate.PromoCode(sql.FieldContainsFold(FieldNotes, v))
}
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
func CreatedAtEQ(v time.Time) predicate.PromoCode {
return predicate.PromoCode(sql.FieldEQ(FieldCreatedAt, v))
}
// CreatedAtNEQ applies the NEQ predicate on the "created_at" field.
func CreatedAtNEQ(v time.Time) predicate.PromoCode {
return predicate.PromoCode(sql.FieldNEQ(FieldCreatedAt, v))
}
// CreatedAtIn applies the In predicate on the "created_at" field.
func CreatedAtIn(vs ...time.Time) predicate.PromoCode {
return predicate.PromoCode(sql.FieldIn(FieldCreatedAt, vs...))
}
// CreatedAtNotIn applies the NotIn predicate on the "created_at" field.
func CreatedAtNotIn(vs ...time.Time) predicate.PromoCode {
return predicate.PromoCode(sql.FieldNotIn(FieldCreatedAt, vs...))
}
// CreatedAtGT applies the GT predicate on the "created_at" field.
func CreatedAtGT(v time.Time) predicate.PromoCode {
return predicate.PromoCode(sql.FieldGT(FieldCreatedAt, v))
}
// CreatedAtGTE applies the GTE predicate on the "created_at" field.
func CreatedAtGTE(v time.Time) predicate.PromoCode {
return predicate.PromoCode(sql.FieldGTE(FieldCreatedAt, v))
}
// CreatedAtLT applies the LT predicate on the "created_at" field.
func CreatedAtLT(v time.Time) predicate.PromoCode {
return predicate.PromoCode(sql.FieldLT(FieldCreatedAt, v))
}
// CreatedAtLTE applies the LTE predicate on the "created_at" field.
func CreatedAtLTE(v time.Time) predicate.PromoCode {
return predicate.PromoCode(sql.FieldLTE(FieldCreatedAt, v))
}
// UpdatedAtEQ applies the EQ predicate on the "updated_at" field.
func UpdatedAtEQ(v time.Time) predicate.PromoCode {
return predicate.PromoCode(sql.FieldEQ(FieldUpdatedAt, v))
}
// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field.
func UpdatedAtNEQ(v time.Time) predicate.PromoCode {
return predicate.PromoCode(sql.FieldNEQ(FieldUpdatedAt, v))
}
// UpdatedAtIn applies the In predicate on the "updated_at" field.
func UpdatedAtIn(vs ...time.Time) predicate.PromoCode {
return predicate.PromoCode(sql.FieldIn(FieldUpdatedAt, vs...))
}
// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field.
func UpdatedAtNotIn(vs ...time.Time) predicate.PromoCode {
return predicate.PromoCode(sql.FieldNotIn(FieldUpdatedAt, vs...))
}
// UpdatedAtGT applies the GT predicate on the "updated_at" field.
func UpdatedAtGT(v time.Time) predicate.PromoCode {
return predicate.PromoCode(sql.FieldGT(FieldUpdatedAt, v))
}
// UpdatedAtGTE applies the GTE predicate on the "updated_at" field.
func UpdatedAtGTE(v time.Time) predicate.PromoCode {
return predicate.PromoCode(sql.FieldGTE(FieldUpdatedAt, v))
}
// UpdatedAtLT applies the LT predicate on the "updated_at" field.
func UpdatedAtLT(v time.Time) predicate.PromoCode {
return predicate.PromoCode(sql.FieldLT(FieldUpdatedAt, v))
}
// UpdatedAtLTE applies the LTE predicate on the "updated_at" field.
func UpdatedAtLTE(v time.Time) predicate.PromoCode {
return predicate.PromoCode(sql.FieldLTE(FieldUpdatedAt, v))
}
// HasUsageRecords applies the HasEdge predicate on the "usage_records" edge.
func HasUsageRecords() predicate.PromoCode {
return predicate.PromoCode(func(s *sql.Selector) {
step := sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.Edge(sqlgraph.O2M, false, UsageRecordsTable, UsageRecordsColumn),
)
sqlgraph.HasNeighbors(s, step)
})
}
// HasUsageRecordsWith applies the HasEdge predicate on the "usage_records" edge with a given conditions (other predicates).
func HasUsageRecordsWith(preds ...predicate.PromoCodeUsage) predicate.PromoCode {
return predicate.PromoCode(func(s *sql.Selector) {
step := newUsageRecordsStep()
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
for _, p := range preds {
p(s)
}
})
})
}
// And groups predicates with the AND operator between them.
func And(predicates ...predicate.PromoCode) predicate.PromoCode {
return predicate.PromoCode(sql.AndPredicates(predicates...))
}
// Or groups predicates with the OR operator between them.
func Or(predicates ...predicate.PromoCode) predicate.PromoCode {
return predicate.PromoCode(sql.OrPredicates(predicates...))
}
// Not applies the not operator on the given predicate.
func Not(p predicate.PromoCode) predicate.PromoCode {
return predicate.PromoCode(sql.NotPredicates(p))
}