hepa-calc-api/api/model/Coupon.go

46 lines
2.7 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package model
import (
"gorm.io/gorm"
"hepa-calc-api/global"
"time"
)
type Coupon struct {
CouponId int64 `gorm:"column:coupon_id;type:bigint(19);primary_key;comment:主键id" json:"coupon_id"`
CouponName string `gorm:"column:coupon_name;type:varchar(255);comment:优惠卷名称" json:"coupon_name"`
CouponType string `gorm:"column:coupon_type;type:varchar(255);comment:优惠卷类型1:无门槛 2:满减)" json:"coupon_type"`
CouponStatus int `gorm:"column:coupon_status;type:tinyint(1);default:1;comment:状态1:正常 2:强制失效 3:结束 4:删除)" json:"coupon_status"`
ApplicationScope int `gorm:"column:application_scope;type:tinyint(1);default:1;comment:适用范围1:全场通用)" json:"application_scope"`
IsMutex int `gorm:"column:is_mutex;type:tinyint(1);default:1;comment:是否互斥0:否 1:是)互斥情况下无法和其他优惠卷同时使用" json:"is_mutex"`
CouponCount int `gorm:"column:coupon_count;type:int(10);default:1;comment:发放数量;NOT NULL" json:"coupon_count"`
CouponTakeCount int `gorm:"column:coupon_take_count;type:int(10);comment:已领取数量" json:"coupon_take_count"`
CouponUsedCount int `gorm:"column:coupon_used_count;type:int(10);default:0;comment:已使用数量" json:"coupon_used_count"`
CouponPrice float64 `gorm:"column:coupon_price;type:decimal(10,2) unsigned;default:0.00;comment:优惠卷金额" json:"coupon_price"`
WithAmount float64 `gorm:"column:with_amount;type:decimal(10,2);comment:符合满减标准金额(优惠卷类型为满减时使用)" json:"with_amount"`
ValidType int `gorm:"column:valid_type;type:tinyint(1);comment:有效类型1:绝对时效xxx-xxx时间段有效 2:相对时效 n天内有效;NOT NULL" json:"valid_type"`
ValidDays int `gorm:"column:valid_days;type:int(3);comment:自领取之日起有效天数" json:"valid_days"`
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"`
CouponDesc string `gorm:"column:coupon_desc;type:varchar(200);comment:优惠卷描述" json:"coupon_desc"`
Model
}
func (m *Coupon) TableName() string {
return "coupon"
}
func (m *Coupon) BeforeCreate(tx *gorm.DB) error {
if m.CouponId == 0 {
m.CouponId = 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
}