setting.go 4.2 KB

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