Files
hospital-admin-api/api/model/couponGrant.go
T
2024-06-07 09:19:04 +08:00

41 lines
1.7 KiB
Go

package model
import (
"gorm.io/gorm"
"hospital-admin-api/global"
"time"
)
// CouponGrant 优惠卷发放记录表
type CouponGrant struct {
GrantId int64 `gorm:"column:grant_id;type:bigint(19);primary_key;comment:主键id" json:"grant_id"`
CouponId int64 `gorm:"column:coupon_id;type:bigint(19);comment:优惠卷id" json:"coupon_id"`
GrantType int `gorm:"column:grant_type;type:tinyint(1);default:1;comment:发放类型(1:具体用户 2:未拥有用户)" json:"grant_type"`
UserId int64 `gorm:"column:user_id;type:bigint(19);comment:用户id(发放类型为具体用户时存在)" json:"user_id"`
TotalQuantity int `gorm:"column:total_quantity;type:int(5);default:0;comment:目标发放数量" json:"total_quantity"`
GrantQuantity int `gorm:"column:grant_quantity;type:int(5);comment:已发放数量" json:"grant_quantity"`
GrantResult int `gorm:"column:grant_result;type:tinyint(1);default:2;comment:发放结果(1:成功 2:发放中 3:部分 4:失败)" json:"grant_result"`
StopReason string `gorm:"column:stop_reason;type:varchar(255);comment:停止原因" json:"stop_reason"`
AdminUserId int64 `gorm:"column:admin_user_id;type:bigint(19);comment:后台操作用户id" json:"admin_user_id"`
Model
User *User `gorm:"foreignKey:UserId;references:user_id" json:"user"` // 用户
}
func (m *CouponGrant) TableName() string {
return "gdxz_coupon_grant"
}
func (m *CouponGrant) BeforeCreate(tx *gorm.DB) error {
if m.GrantId == 0 {
m.GrantId = 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
}