- 告警设置拆分为独立页面,支持钉钉/飞书/企业微信/Bark/通用Webhook 多渠道 - 通知策略:低于阈值后按间隔重复提醒,达到最大次数停止,余额恢复自动重置 - 旧 webhook 配置自动迁移为通用渠道,渠道支持测试发送 - 优化告警话术:去商户ID展示、数字千分位格式化
86 lines
3.5 KiB
Go
86 lines
3.5 KiB
Go
package model
|
||
|
||
import (
|
||
"time"
|
||
|
||
"gorm.io/gorm"
|
||
)
|
||
|
||
// 充值申请状态
|
||
const (
|
||
RechargeStatusPending = "pending"
|
||
RechargeStatusApproved = "approved"
|
||
RechargeStatusRejected = "rejected"
|
||
)
|
||
|
||
// RechargeApplication 商户提交的人民币充值申请,凭证图片必填,由平台管理员审核后入账。
|
||
type RechargeApplication struct {
|
||
ID uint `gorm:"primarykey" json:"id"`
|
||
CreatedAt time.Time `json:"created_at"`
|
||
UpdatedAt time.Time `json:"updated_at"`
|
||
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
||
|
||
MerchantID uint `gorm:"not null;index" json:"merchant_id"`
|
||
ApplicationNo string `gorm:"uniqueIndex;size:64;not null" json:"application_no"`
|
||
AmountCNY int64 `gorm:"not null" json:"amount_cny"` // 人民币金额,单位:分
|
||
PointsAmount int64 `gorm:"not null" json:"points_amount"`
|
||
Status string `gorm:"size:16;not null;default:pending;index" json:"status"`
|
||
Vouchers []string `gorm:"type:text;serializer:json" json:"vouchers"` // 打款凭证图片 URL
|
||
Note string `gorm:"size:512" json:"note"`
|
||
ReviewNote string `gorm:"size:512" json:"review_note"`
|
||
ReviewedAt *time.Time `json:"reviewed_at"`
|
||
ReviewedBy *uint `json:"reviewed_by"`
|
||
|
||
Merchant *Merchant `gorm:"foreignKey:MerchantID" json:"merchant,omitempty"`
|
||
}
|
||
|
||
// MerchantAlertConfig 低余额告警配置(每商户一份)。
|
||
// 通知策略:余额低于阈值期间按 NotifyIntervalMinutes 间隔重复通知,
|
||
// 最多 MaxNotifications 次(0 表示不限);余额恢复阈值以上后重置计数。
|
||
type MerchantAlertConfig struct {
|
||
ID uint `gorm:"primarykey" json:"id"`
|
||
CreatedAt time.Time `json:"created_at"`
|
||
UpdatedAt time.Time `json:"updated_at"`
|
||
|
||
MerchantID uint `gorm:"not null;uniqueIndex" json:"merchant_id"`
|
||
Enabled bool `gorm:"not null;default:false" json:"enabled"`
|
||
ThresholdPoints int64 `gorm:"not null;default:0" json:"threshold_points"`
|
||
WebhookURL string `gorm:"size:1024" json:"-"`
|
||
|
||
// 通知频率策略
|
||
NotifyIntervalMinutes int `gorm:"not null;default:60" json:"notify_interval_minutes"`
|
||
MaxNotifications int `gorm:"not null;default:5" json:"max_notifications"`
|
||
LastNotifiedAt *time.Time `json:"last_notified_at"`
|
||
NotificationCount int `gorm:"not null;default:0" json:"notification_count"`
|
||
}
|
||
|
||
// 告警通知渠道类型
|
||
const (
|
||
AlertChannelDingtalk = "dingtalk"
|
||
AlertChannelFeishu = "feishu"
|
||
AlertChannelWecom = "wecom"
|
||
AlertChannelBark = "bark"
|
||
AlertChannelWebhook = "webhook"
|
||
)
|
||
|
||
// AlertChannelConfig 告警渠道专属配置:webhook 类渠道用 WebhookURL,Bark 用 Server+Key。
|
||
type AlertChannelConfig struct {
|
||
WebhookURL string `json:"webhook_url,omitempty"`
|
||
Server string `json:"server,omitempty"`
|
||
Key string `json:"key,omitempty"`
|
||
}
|
||
|
||
// AlertNotifyChannel 余额告警通知渠道,Config 为渠道专属 JSON 配置。
|
||
type AlertNotifyChannel struct {
|
||
ID uint `gorm:"primarykey" json:"id"`
|
||
CreatedAt time.Time `json:"created_at"`
|
||
UpdatedAt time.Time `json:"updated_at"`
|
||
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
||
|
||
MerchantID uint `gorm:"not null;index" json:"merchant_id"`
|
||
ChannelType string `gorm:"size:32;not null" json:"channel_type"`
|
||
Name string `gorm:"size:64" json:"name"`
|
||
Config AlertChannelConfig `gorm:"type:text;serializer:json" json:"config"`
|
||
Enabled bool `gorm:"not null;default:true" json:"enabled"`
|
||
}
|