// Code generated by go.ipao.vip/gen. DO NOT EDIT. // Code generated by go.ipao.vip/gen. DO NOT EDIT. // Code generated by go.ipao.vip/gen. DO NOT EDIT. package models import ( "context" "time" "quyun/v2/pkg/consts" "go.ipao.vip/gen" ) const TableNameCoupon = "coupons" // Coupon mapped from table type Coupon struct { ID int64 `gorm:"column:id;type:bigint;primaryKey;autoIncrement:true" json:"id"` TenantID int64 `gorm:"column:tenant_id;type:bigint;not null" json:"tenant_id"` Title string `gorm:"column:title;type:character varying(255);not null" json:"title"` Description string `gorm:"column:description;type:text" json:"description"` Type consts.CouponType `gorm:"column:type;type:character varying(32);not null" json:"type"` Value int64 `gorm:"column:value;type:bigint;not null" json:"value"` MinOrderAmount int64 `gorm:"column:min_order_amount;type:bigint;not null" json:"min_order_amount"` MaxDiscount int64 `gorm:"column:max_discount;type:bigint" json:"max_discount"` TotalQuantity int32 `gorm:"column:total_quantity;type:integer;not null" json:"total_quantity"` UsedQuantity int32 `gorm:"column:used_quantity;type:integer;not null" json:"used_quantity"` StartAt time.Time `gorm:"column:start_at;type:timestamp with time zone" json:"start_at"` EndAt time.Time `gorm:"column:end_at;type:timestamp with time zone" json:"end_at"` CreatedAt time.Time `gorm:"column:created_at;type:timestamp with time zone;not null;default:now()" json:"created_at"` UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp with time zone;not null;default:now()" json:"updated_at"` } // Quick operations without importing query package // Update applies changed fields to the database using the default DB. func (m *Coupon) Update(ctx context.Context) (gen.ResultInfo, error) { return Q.Coupon.WithContext(ctx).Updates(m) } // Save upserts the model using the default DB. func (m *Coupon) Save(ctx context.Context) error { return Q.Coupon.WithContext(ctx).Save(m) } // Create inserts the model using the default DB. func (m *Coupon) Create(ctx context.Context) error { return Q.Coupon.WithContext(ctx).Create(m) } // Delete removes the row represented by the model using the default DB. func (m *Coupon) Delete(ctx context.Context) (gen.ResultInfo, error) { return Q.Coupon.WithContext(ctx).Delete(m) } // ForceDelete permanently deletes the row (ignores soft delete) using the default DB. func (m *Coupon) ForceDelete(ctx context.Context) (gen.ResultInfo, error) { return Q.Coupon.WithContext(ctx).Unscoped().Delete(m) } // Reload reloads the model from database by its primary key and overwrites current fields. func (m *Coupon) Reload(ctx context.Context) error { fresh, err := Q.Coupon.WithContext(ctx).GetByID(m.ID) if err != nil { return err } *m = *fresh return nil }