39 lines
1.6 KiB
Go
39 lines
1.6 KiB
Go
package model
|
||
|
||
import (
|
||
"gorm.io/gorm"
|
||
"hepa-calc-admin-api/global"
|
||
"time"
|
||
)
|
||
|
||
type UserCoupon struct {
|
||
UserCouponId int64 `gorm:"column:user_coupon_id;type:bigint(19);primary_key;comment:主键id" json:"user_coupon_id"`
|
||
UserId int64 `gorm:"column:user_id;type:bigint(19);comment:用户id;NOT NULL" json:"user_id"`
|
||
CouponId int64 `gorm:"column:coupon_id;type:bigint(19);comment:优惠卷id;NOT NULL" json:"coupon_id"`
|
||
UserCouponStatus int `gorm:"column:user_coupon_status;type:tinyint(1);default:0;comment:状态(0:未使用 1:已使用 3:已过期)" json:"user_coupon_status"`
|
||
IsWindows int `gorm:"column:is_windows;type:tinyint(1);default:0;comment:是否已弹窗(0:否 1:是)" json:"is_windows"`
|
||
CouponUseDate LocalTime `gorm:"column:coupon_use_date;type:datetime;comment:使用时间" json:"coupon_use_date"`
|
||
ValidStartTime LocalTime `gorm:"column:valid_start_time;type:datetime;comment:有效使用时间" json:"valid_start_time"`
|
||
ValidEndTime LocalTime `gorm:"column:valid_end_time;type:datetime;comment:过期使用时间" json:"valid_end_time"`
|
||
Model
|
||
Coupon *Coupon `gorm:"foreignKey:CouponId;references:coupon_id" json:"coupon"`
|
||
}
|
||
|
||
func (m *UserCoupon) TableName() string {
|
||
return "user_coupon"
|
||
}
|
||
|
||
func (m *UserCoupon) BeforeCreate(tx *gorm.DB) error {
|
||
if m.UserCouponId == 0 {
|
||
m.UserCouponId = global.Snowflake.Generate().Int64()
|
||
}
|
||
|
||
m.CreatedAt = LocalTime(time.Now())
|
||
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
|
||
|
||
m.UpdatedAt = LocalTime(time.Now())
|
||
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
|
||
|
||
return nil
|
||
}
|