diff --git a/soul-api/internal/handler/ckb.go b/soul-api/internal/handler/ckb.go index d528c850..059784e3 100644 --- a/soul-api/internal/handler/ckb.go +++ b/soul-api/internal/handler/ckb.go @@ -25,27 +25,125 @@ const ckbAPIURL = "https://ckbapi.quwanzhi.com/v1/api/scenarios" var ckbSourceMap = map[string]string{"team": "团队招募", "investor": "资源对接", "mentor": "导师顾问", "partner": "创业合伙"} var ckbTagsMap = map[string]string{"team": "切片团队,团队招募", "investor": "资源对接,资源群", "mentor": "导师顾问,咨询服务", "partner": "创业合伙,创业伙伴"} -func getCKBRuntimeConfig() (apiKey string, apiURL string, docNotes string) { - apiKey = ckbAPIKey - apiURL = ckbAPIURL +type CKBRouteConfig struct { + APIURL string `json:"apiUrl"` + APIKey string `json:"apiKey"` + Source string `json:"source"` + Tags string `json:"tags"` + SiteTags string `json:"siteTags"` + Notes string `json:"notes"` +} + +type CKBConfigPayload struct { + Routes map[string]CKBRouteConfig `json:"routes"` + DocNotes string `json:"docNotes"` + DocContent string `json:"docContent"` + APIURL string `json:"apiUrl,omitempty"` + APIKey string `json:"apiKey,omitempty"` +} + +func defaultCKBRouteConfig(routeKey string) CKBRouteConfig { + cfg := CKBRouteConfig{ + APIURL: ckbAPIURL, + APIKey: ckbAPIKey, + SiteTags: "创业实验APP", + } + switch routeKey { + case "join_partner": + cfg.Source = "创业实验-创业合伙" + cfg.Tags = "创业合伙,创业伙伴" + case "join_investor": + cfg.Source = "创业实验-资源对接" + cfg.Tags = "资源对接,资源群" + case "join_mentor": + cfg.Source = "创业实验-导师顾问" + cfg.Tags = "导师顾问,咨询服务" + case "join_team": + cfg.Source = "创业实验-团队招募" + cfg.Tags = "切片团队,团队招募" + case "match": + cfg.Source = "创业实验-找伙伴匹配" + cfg.Tags = "找伙伴" + cfg.SiteTags = "创业实验APP,匹配用户" + case "lead": + cfg.Source = "小程序-链接卡若" + cfg.Tags = "链接卡若,创业实验" + cfg.SiteTags = "创业实验APP,链接卡若" + } + return cfg +} + +func getCKBConfigPayload() CKBConfigPayload { + payload := CKBConfigPayload{ + Routes: map[string]CKBRouteConfig{}, + } var cfg model.SystemConfig if err := database.DB().Where("config_key = ?", "ckb_config").First(&cfg).Error; err != nil { - return + return payload } var m map[string]interface{} if err := json.Unmarshal(cfg.ConfigValue, &m); err != nil { - return - } - if v, ok := m["apiKey"].(string); ok && strings.TrimSpace(v) != "" { - apiKey = strings.TrimSpace(v) - } - if v, ok := m["apiUrl"].(string); ok && strings.TrimSpace(v) != "" { - apiURL = strings.TrimSpace(v) + return payload } if v, ok := m["docNotes"].(string); ok { - docNotes = v + payload.DocNotes = v } - return + if v, ok := m["docContent"].(string); ok { + payload.DocContent = v + } + if v, ok := m["apiKey"].(string); ok { + payload.APIKey = v + } + if v, ok := m["apiUrl"].(string); ok { + payload.APIURL = v + } + if routes, ok := m["routes"].(map[string]interface{}); ok { + for key, raw := range routes { + itemMap, ok := raw.(map[string]interface{}) + if !ok { + continue + } + item := defaultCKBRouteConfig(key) + if v, ok := itemMap["apiUrl"].(string); ok && strings.TrimSpace(v) != "" { + item.APIURL = strings.TrimSpace(v) + } + if v, ok := itemMap["apiKey"].(string); ok && strings.TrimSpace(v) != "" { + item.APIKey = strings.TrimSpace(v) + } + if v, ok := itemMap["source"].(string); ok && strings.TrimSpace(v) != "" { + item.Source = strings.TrimSpace(v) + } + if v, ok := itemMap["tags"].(string); ok && strings.TrimSpace(v) != "" { + item.Tags = strings.TrimSpace(v) + } + if v, ok := itemMap["siteTags"].(string); ok && strings.TrimSpace(v) != "" { + item.SiteTags = strings.TrimSpace(v) + } + if v, ok := itemMap["notes"].(string); ok { + item.Notes = v + } + payload.Routes[key] = item + } + } + return payload +} + +func getCKBRouteConfig(routeKey string) (cfg CKBRouteConfig, docNotes string, docContent string) { + cfg = defaultCKBRouteConfig(routeKey) + payload := getCKBConfigPayload() + docNotes = payload.DocNotes + docContent = payload.DocContent + if item, ok := payload.Routes[routeKey]; ok { + cfg = item + } else { + if strings.TrimSpace(payload.APIURL) != "" { + cfg.APIURL = strings.TrimSpace(payload.APIURL) + } + if strings.TrimSpace(payload.APIKey) != "" { + cfg.APIKey = strings.TrimSpace(payload.APIKey) + } + } + return cfg, docNotes, docContent } // ckbSign 与 next-project app/api/ckb/join 一致:排除 sign/apiKey/portrait,空值跳过,按键升序拼接值,MD5(拼接串) 再 MD5(结果+apiKey)