package svc import ( "applet/app/db" "applet/app/db/model" "applet/app/utils" "applet/app/utils/logx" "github.com/gin-gonic/gin" "github.com/tidwall/gjson" "strings" ) // 获取指定类型的域名:admin、wap、api func GetWebSiteDomainInfo(c *gin.Context, domainType string) string { if domainType == "" { domainType = "wap" } domainSetting := SysCfgGet(c, "domain_setting") domainTypePath := domainType + ".type" domainSslPath := domainType + ".isOpenHttps" domainPath := domainType + ".domain" domainTypeValue := gjson.Get(domainSetting, domainTypePath).String() domainSslValue := gjson.Get(domainSetting, domainSslPath).String() domain := gjson.Get(domainSetting, domainPath).String() scheme := "http://" if domainSslValue == "1" { scheme = "https://" } // 有自定义域名 返回自定义的 if domainTypeValue == "own" && domain != "" { return scheme + domain } // 否则返回官方的 official, err := db.GetOfficialDomainInfoByType(db.Db, c.GetString("mid"), domainType) if err != nil { _ = logx.Errorf("Get Official Domain Fail! %s", err) return "" } if strings.Contains(official, "http") { return official } return scheme + official } // 获取指定类型的域名对应的masterId:admin、wap、api func GetWebSiteDomainMasterId(domainType string, host string) string { obj := new(model.UserAppDomain) has, err := db.Db.Where("domain=? and type=?", host, domainType).Get(obj) if err != nil || !has { return "" } return utils.AnyToString(obj.Uuid) }