2024-10-21 17:01:16 +08:00

48 lines
3.2 KiB
Go
Raw Permalink 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-admin-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 int `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:全场通用 2:单项 3:会员)" json:"application_scope"`
DistributionObject int `gorm:"column:distribution_object;type:tinyint(1);default:1;comment:发放对象1:全部用户 2:新注册用户 3:会员 4:完善资料)" json:"distribution_object"`
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"`
SystemMemberIds string `gorm:"column:system_member_ids;type:bigint(19);comment:会员id适用范围为会员时生效如果此项为null则表示所有会员通用" json:"system_member_ids"`
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
}