setting.go 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. package model
  2. import (
  3. "time"
  4. "gorm.io/datatypes"
  5. )
  6. // Setting stores system configuration as key-value pairs with JSON values.
  7. type Setting struct {
  8. ID uint `gorm:"primaryKey;autoIncrement" json:"id"`
  9. Key string `gorm:"uniqueIndex;size:100;not null" json:"key"`
  10. Value datatypes.JSON `gorm:"type:json;not null" json:"value"`
  11. UpdatedAt time.Time `json:"updated_at"`
  12. }
  13. // GradingConfig is the structure stored under the "grading" setting key.
  14. type GradingConfig struct {
  15. Levels []LevelDef `json:"levels"`
  16. IndustryKeywords map[string][]string `json:"industry_keywords"`
  17. }
  18. // LevelDef defines a single merchant grade level.
  19. type LevelDef struct {
  20. Key string `json:"key"` // internal key: e.g. "Hot"
  21. Label string `json:"label"` // display label: e.g. "优质商户"
  22. Color string `json:"color"` // display color: e.g. "red"
  23. Description string `json:"description"` // explain what this level means
  24. Rules []GradeRule `json:"rules"` // any rule match → this level (OR logic)
  25. }
  26. // GradeRule defines one condition that qualifies a merchant for a level.
  27. // All non-empty fields within a rule must ALL match (AND logic).
  28. type GradeRule struct {
  29. HasIndustry *bool `json:"has_industry,omitempty"` // must have industry tag
  30. HasWebsite *bool `json:"has_website,omitempty"` // must have website
  31. HasEmail *bool `json:"has_email,omitempty"` // must have email
  32. HasPhone *bool `json:"has_phone,omitempty"` // must have phone
  33. MinSourceCount *int `json:"min_source_count,omitempty"` // minimum source count
  34. }
  35. // DefaultGradingConfig returns the built-in default grading configuration.
  36. func DefaultGradingConfig() GradingConfig {
  37. boolTrue := true
  38. minSrc2 := 2
  39. return GradingConfig{
  40. Levels: []LevelDef{
  41. {
  42. Key: "Hot",
  43. Label: "优质商户",
  44. Color: "red",
  45. Description: "有行业标签 + 有网站或邮箱,或有行业标签 + 多来源/有电话",
  46. Rules: []GradeRule{
  47. {HasIndustry: &boolTrue, HasWebsite: &boolTrue},
  48. {HasIndustry: &boolTrue, HasEmail: &boolTrue},
  49. {HasIndustry: &boolTrue, HasPhone: &boolTrue},
  50. {HasIndustry: &boolTrue, MinSourceCount: &minSrc2},
  51. },
  52. },
  53. {
  54. Key: "Warm",
  55. Label: "普通商户",
  56. Color: "orange",
  57. Description: "有行业标签,或有网站/邮箱/电话等联系方式",
  58. Rules: []GradeRule{
  59. {HasIndustry: &boolTrue},
  60. {HasWebsite: &boolTrue, MinSourceCount: &minSrc2},
  61. {HasWebsite: &boolTrue},
  62. {HasEmail: &boolTrue},
  63. {HasPhone: &boolTrue},
  64. },
  65. },
  66. {
  67. Key: "Cold",
  68. Label: "待跟进",
  69. Color: "blue",
  70. Description: "仅有TG用户名,缺少其他联系方式和行业信息",
  71. Rules: []GradeRule{}, // default fallback
  72. },
  73. },
  74. IndustryKeywords: map[string][]string{
  75. "机场": {"机场", "节点", "订阅", "clash", "v2ray", "trojan", "shadowsocks", "ss/ssr", "翻墙", "梯子", "科学上网", "加速器", "proxy", "代理", "xray", "hysteria", "surge", "quantumult", "shadowrocket", "小火箭"},
  76. "VPN": {"vpn", "wireguard", "openvpn", "expressvpn", "nordvpn"},
  77. "交易所": {"交易所", "exchange", "otc", "usdt", "btc", "eth", "加密货币", "数字货币", "币", "crypto", "binance", "okx"},
  78. "支付": {"支付", "payment", "收款", "代收", "代付", "换汇", "承兑", "跑分", "三方支付", "四方支付"},
  79. "博彩": {"博彩", "棋牌", "彩票", "赌", "百家乐", "龙虎", "六合彩", "时时彩", "体育投注"},
  80. "引流": {"引流", "推广", "广告", "拉人", "涨粉", "群发", "营销", "seo", "流量"},
  81. "开发": {"开发", "定制", "搭建", "源码", "app开发", "网站建设", "小程序", "h5", "二开"},
  82. },
  83. }
  84. }