You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
2.1 KiB
Go

package coupon
import "time"
// CouponType 优惠券类型
type CouponType int
const (
CouponTypeFullReduction CouponType = 1 // 满减
CouponTypeDiscount CouponType = 2 // 折扣
)
// CouponStatus 优惠券状态
type CouponStatus int
const (
CouponStatusNormal CouponStatus = 1 // 正常
CouponStatusUsed CouponStatus = 2 // 已使用
CouponStatusExpired CouponStatus = 3 // 已过期
CouponStatusDisabled CouponStatus = 4 // 已停用
)
// Coupon 优惠券实体
type Coupon struct {
ID uint64 `xorm:"pk autoincr"` // 优惠券ID
Code string `xorm:"varchar(255)"` // 优惠券码
Name string `xorm:"varchar(255)"` // 优惠券名称
Type CouponType `xorm:"int"` // 优惠券类型
Value int64 `xorm:"int"` // 优惠券值
MinAmount int64 `xorm:"int"` // 最低使用金额
StartTime time.Time `xorm:"datetime"` // 开始时间
EndTime time.Time `xorm:"datetime"` // 结束时间
Status CouponStatus `xorm:"int"` // 优惠券状态
AdminID uint64 `xorm:"int"` // 创建者ID
UserID uint64 `xorm:"int"` // 使用者ID
UsedAt time.Time `xorm:"datetime"` // 使用时间
CreatedAt time.Time `xorm:"created"` // 创建时间
UpdatedAt time.Time `xorm:"updated"` // 更新时间
DeletedAt time.Time `xorm:"deleted"` // 删除时间
}
// TableName 指定表名
// IsValid 检查优惠券是否有效
func (c *Coupon) IsValid() bool {
return c.ID > 0 && c.Code != "" && c.Name != "" && c.Status == CouponStatusNormal
}
// IsExpired 检查优惠券是否已过期
func (c *Coupon) IsExpired() bool {
return time.Now().After(c.EndTime)
}
// IsNotStarted 检查优惠券是否未开始
func (c *Coupon) IsNotStarted() bool {
return time.Now().Before(c.StartTime)
}
// IsUsed 检查优惠券是否已使用
func (c *Coupon) IsUsed() bool {
return c.Status == CouponStatusUsed
}
// IsDisabled 检查优惠券是否已停用
func (c *Coupon) IsDisabled() bool {
return c.Status == CouponStatusDisabled
}