Files
hi-server/internal/model/promo/promo.go
T
shanshanzhong147 02b41e7a2c
Build docker and publish / build (20.15.1) (push) Failing after 8m50s
Build docker and publish / build (20.15.1) (pull_request) Successful in 8m19s
修复(#85): 促销系统 quantity 设计修正补丁(跨任务统一修复)
- subscribe_promo 表加 quantity 字段,BIGINT NOT NULL DEFAULT 1
- EvaluatePromo 加 quantity 参数,按 subscribeID + quantity 精确匹配
- Promo 从 Subscribe 顶层移到 SubscribeDiscount
- 查询加 quantity,返回 map[subscribeID][quantity] 二级映射
- recordPromoUsage 错误向上传播,不再静默吞掉
- preCreate 和 purchase 的 allowPromo 判定统一为 orderType==1
- 迁移脚本增加幂等处理(guarded DROP/ADD/MODIFY)

Co-authored-by: multica-agent <github@multica.ai>
2026-05-27 05:57:21 -07:00

60 lines
2.2 KiB
Go

package promo
import (
"time"
"gorm.io/gorm"
)
const (
RuleTypeNewUser = "new_user"
RuleTypeInactiveUser = "inactive_user"
RuleTypeCampaign = "campaign"
)
type Rule struct {
Id int64 `gorm:"primaryKey"`
Name string `gorm:"type:varchar(100);not null;default:'';comment:Rule Name"`
Type string `gorm:"type:varchar(32);not null;default:'';comment:Rule Type"`
Params string `gorm:"type:json;not null;comment:Rule Params"`
Priority int64 `gorm:"type:int;not null;default:0;comment:Priority"`
Enabled bool `gorm:"type:tinyint(1);not null;default:1;comment:Enabled"`
StartTime *time.Time `gorm:"default:null;comment:Start Time"`
EndTime *time.Time `gorm:"default:null;comment:End Time"`
CreatedAt time.Time `gorm:"<-:create;comment:Create Time"`
UpdatedAt time.Time `gorm:"comment:Update Time"`
DeletedAt gorm.DeletedAt `gorm:"index;comment:Delete Time"`
}
func (Rule) TableName() string {
return "promo_rule"
}
type SubscribePromo struct {
Id int64 `gorm:"primaryKey"`
SubscribeId int64 `gorm:"type:bigint unsigned;not null;comment:Subscribe ID"`
Quantity int64 `gorm:"type:bigint;not null;default:1;comment:Quantity"`
PromoRuleId int64 `gorm:"type:bigint unsigned;not null;comment:Promo Rule ID"`
PromoPrice int64 `gorm:"type:bigint;not null;default:0;comment:Promo Price"`
CreatedAt time.Time `gorm:"<-:create;comment:Create Time"`
UpdatedAt time.Time `gorm:"comment:Update Time"`
}
func (SubscribePromo) TableName() string {
return "subscribe_promo"
}
type Usage struct {
Id int64 `gorm:"primaryKey"`
UserId int64 `gorm:"type:bigint unsigned;not null;comment:User ID"`
PromoRuleId int64 `gorm:"type:bigint unsigned;not null;comment:Promo Rule ID"`
SubscribeId int64 `gorm:"type:bigint unsigned;not null;comment:Subscribe ID"`
OrderNo string `gorm:"type:varchar(255);not null;default:'';comment:Order No"`
PromoPrice int64 `gorm:"type:bigint;not null;default:0;comment:Promo Price"`
CreatedAt time.Time `gorm:"<-:create;comment:Create Time"`
}
func (Usage) TableName() string {
return "promo_usage"
}